1 | define([ |
---|
2 | 'dojo/_base/declare', |
---|
3 | 'dojo/_base/lang', |
---|
4 | 'dojo/dom-attr', |
---|
5 | 'dojo/parser', |
---|
6 | 'dojo/query', |
---|
7 | 'dijit/layout/ContentPane', |
---|
8 | 'dijit/registry' |
---|
9 | ],function(declare,lang,attr,parser,query,ContentPane,registry){ |
---|
10 | return declare('rft.ui._Page',[ContentPane],{ |
---|
11 | startup: function() { |
---|
12 | if ( this._started ){ return; } |
---|
13 | this.inherited(arguments); |
---|
14 | this._attachPointsAndEvents(); |
---|
15 | this.onVisit(); |
---|
16 | }, |
---|
17 | _attachPointsAndEvents: function() { |
---|
18 | query('*[data-rft-attach-point]'/*, this.domNode*/).forEach(lang.hitch(this,function(node){ |
---|
19 | var point = attr.get(node,'data-rft-attach-point'); |
---|
20 | var widget = registry.byId(attr.get(node,'id')); |
---|
21 | this[point] = widget || node; |
---|
22 | })); |
---|
23 | query('*[data-rft-attach-event]'/*, this.domNode*/).forEach(lang.hitch(this,function(node){ |
---|
24 | var event = attr.get(node,'data-rft-attach-event').split(':'); |
---|
25 | var eventName = event[0]; |
---|
26 | var eventHandler = event[1]; |
---|
27 | var widget = registry.byId(attr.get(node,'id')); |
---|
28 | if ( widget ) { |
---|
29 | this.connect(widget,eventName,lang.hitch(this,eventHandler)); |
---|
30 | } else { |
---|
31 | this.connect(node,eventName,lang.hitch(this,eventHandler)); |
---|
32 | } |
---|
33 | })); |
---|
34 | query('> script[type^="rft/method"]',this.domNode) |
---|
35 | .orphan().forEach(lang.hitch(this,function(s){ |
---|
36 | var methodName = s.getAttribute("data-rft-method"); |
---|
37 | var func = parser._functionFromScript(s); |
---|
38 | this[methodName] = func; |
---|
39 | })); |
---|
40 | }, |
---|
41 | /** Event fired after startup of all widgets is complete */ |
---|
42 | onVisit: function(){}, |
---|
43 | /** Event fired before leaving the page. Return false to prevent */ |
---|
44 | onLeave: function(){ |
---|
45 | registry.findWidgets(this.domNode).forEach(function(w){ |
---|
46 | w.destroyRecursive(false); |
---|
47 | }); |
---|
48 | return true; |
---|
49 | } |
---|
50 | }); |
---|
51 | }); |
---|