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