1 | define(['dojo/_base/declare','dojo/_base/lang','dojo/_base/array','dojo/parser','dojo/query','dojo/_base/Deferred', |
---|
2 | 'dijit/_WidgetBase','dijit/_TemplatedMixin','dijit/_WidgetsInTemplateMixin','rft/ui/_PageController'], |
---|
3 | function(declare,lang,array,parser,query,Deferred,_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_PageController){ |
---|
4 | return declare('rft.ui._Page',[_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_PageController],{ |
---|
5 | _controllerLoaded: false, |
---|
6 | _hasStarted: false, |
---|
7 | _triggeredOnVisit: false, |
---|
8 | pageController: null, /* class derived from rft.ui._PageController, mixed in at creation */ |
---|
9 | buildRendering: function() { |
---|
10 | this.inherited(arguments); |
---|
11 | var dfd = new Deferred(); |
---|
12 | var mixinType = this.domNode.getAttribute("data-rft-mixin"); |
---|
13 | if ( mixinType ) { |
---|
14 | require([mixinType],lang.hitch(this,function(SomePageController){ |
---|
15 | declare.safeMixin(this,new SomePageController()); |
---|
16 | dfd.resolve(); |
---|
17 | })); |
---|
18 | } else { |
---|
19 | dfd.resolve(); |
---|
20 | } |
---|
21 | dfd.then(lang.hitch(this,function(){ |
---|
22 | var methods = query('> script[type^="rft/method"]',this.domNode).orphan(); |
---|
23 | array.forEach(methods,lang.hitch(this,function(s){ |
---|
24 | var method = s.getAttribute("data-rft-method"); |
---|
25 | var func = parser._functionFromScript(s); |
---|
26 | this[method] = func; |
---|
27 | })); |
---|
28 | this._controllerLoaded = true; |
---|
29 | this._triggerOnVisit(); |
---|
30 | })); |
---|
31 | }, |
---|
32 | startup: function() { |
---|
33 | this.inherited(arguments); |
---|
34 | this._hasStarted = true; |
---|
35 | this._triggerOnVisit(); |
---|
36 | }, |
---|
37 | _triggerOnVisit: function() { |
---|
38 | if ( this._controllerLoaded && this._hasStarted && !this._triggeredOnVisit ) { |
---|
39 | this._triggeredOnVisit = false; |
---|
40 | this.onVisit(); |
---|
41 | } |
---|
42 | } |
---|
43 | }); |
---|
44 | }); |
---|