@@ -21,7 +21,7 @@ define([
2121 "dijit/_TemplatedMixin" ,
2222 "dojo/_base/array" ,
2323 "dojo/_base/lang" ,
24- "mxui/dom" ,
24+ "mxui/dom" ,
2525 "dojo/text!CustomString/widget/template/CustomString.html"
2626] , function ( declare , _WidgetBase , _TemplatedMixin , dojoArray , dojoLang , dom , widgetTemplate ) {
2727 "use strict" ;
@@ -42,31 +42,35 @@ define([
4242
4343 // dojo.declare.constructor is called to construct the widget instance. Implement to initialize non-primitive properties.
4444 constructor : function ( ) {
45+ logger . level ( logger . DEBUG ) ;
4546 this . _handles = [ ] ;
4647 } ,
4748
4849 // dijit._WidgetBase.postCreate is called after constructing the widget. Implement to do extra setup work.
4950 postCreate : function ( ) {
51+ logger . debug ( this . id + ".postCreate" ) ;
5052 this . _setupEvents ( ) ;
5153 } ,
5254
5355 // mxui.widget._WidgetBase.update is called when context is changed or initialized. Implement to re-render and / or fetch data.
5456 update : function ( obj , callback ) {
57+ logger . debug ( this . id + ".update" ) ;
5558 this . _contextObj = obj ;
56-
57- if ( this . _contextObj )
58- {
59+
60+ if ( this . _contextObj ) {
5961 this . _resetSubscriptions ( ) ;
60- this . _updateRendering ( ) ;
62+ this . _updateRendering ( callback ) ;
63+ } else if ( this . _render ) {
64+ this . _render ( callback ) ;
65+ } else {
66+ this . _runCallback ( callback ) ;
6167 }
62- callback ( ) ;
6368 } ,
64-
69+
6570 // Attach events to HTML dom elements
6671 _setupEvents : function ( ) {
67-
72+ logger . debug ( this . id + "._setupEvents" ) ;
6873 this . connect ( this . customString , "click" , function ( e ) {
69-
7074 // If a microflow has been set execute the microflow on a click.
7175 if ( this . mfToExecute !== "" ) {
7276 mx . data . action ( {
@@ -75,9 +79,9 @@ define([
7579 actionname : this . mfToExecute ,
7680 guids : [ this . _contextObj . getGuid ( ) ]
7781 } ,
78- store : {
79- caller : this . mxform
80- } ,
82+ store : {
83+ caller : this . mxform
84+ } ,
8185 callback : function ( obj ) {
8286 //TODO what to do when all is ok!
8387 } ,
@@ -88,36 +92,53 @@ define([
8892 }
8993 } ) ;
9094 } ,
91- _updateRendering : function ( ) {
92- mx . data . action ( {
93- params : {
94- actionname : this . sourceMF ,
95- applyto : "selection" ,
96- guids : [ this . _contextObj . getGuid ( ) ]
97-
98- } ,
99- callback : dojoLang . hitch ( this , this . _processSourceMFCallback ) ,
100- error : dojoLang . hitch ( this , function ( error ) {
101- alert ( error . description ) ;
102- } ) ,
103- onValidation : dojoLang . hitch ( this , function ( validations ) {
104- alert ( "There were " + validations . length + " validation errors" ) ;
105- } )
106- } ) ;
107- } ,
108-
109- _processSourceMFCallback : function ( returnedString ) {
95+ _updateRendering : function ( callback ) {
96+ logger . debug ( this . id + "._updateRendering" ) ;
97+ mx . data . action ( {
98+ params : {
99+ actionname : this . sourceMF ,
100+ applyto : "selection" ,
101+ guids : [ this . _contextObj . getGuid ( ) ]
102+
103+ } ,
104+ callback : dojoLang . hitch ( this , this . _processSourceMFCallback , callback ) ,
105+ error : dojoLang . hitch ( this , function ( error ) {
106+ alert ( error . description ) ;
107+ this . _runCallback ( callback ) ;
108+ } ) ,
109+ onValidation : dojoLang . hitch ( this , function ( validations ) {
110+ alert ( "There were " + validations . length + " validation errors" ) ;
111+ this . _runCallback ( callback ) ;
112+ } )
113+ } ) ;
114+ } ,
115+
116+
117+ _processSourceMFCallback : function ( callback , returnedString ) {
118+ logger . debug ( this . id + "._processSourceMFCallback" ) ;
110119 this . customString . innerHTML = this . checkString ( returnedString , this . renderHTML ) ;
120+ this . _runCallback ( callback ) ;
121+ } ,
122+
123+
124+ _runCallback : function ( callback ) {
125+ logger . debug ( this . id + "._runCallback" ) ;
126+ if ( typeof callback === "function" ) {
127+ callback ( ) ;
128+ }
111129 } ,
112130
113131 checkString : function ( string , htmlBool ) {
114- if ( string . indexOf ( "<script" ) > - 1 || ! htmlBool )
115- string = dom . escapeString ( string ) ;
116- return string ;
117- } ,
132+ logger . debug ( this . id + ".checkString" ) ;
133+ if ( string . indexOf ( "<script" ) > - 1 || ! htmlBool ) {
134+ string = dom . escapeString ( string ) ;
135+ }
136+ return string ;
137+ } ,
118138
119139 // Reset subscriptions.
120140 _resetSubscriptions : function ( ) {
141+ logger . debug ( this . id + "._resetSubscriptions" ) ;
121142 // Release handles on previous object, if any.
122143 if ( this . _handles ) {
123144 dojoArray . forEach ( this . _handles , function ( handle ) {
@@ -126,7 +147,7 @@ define([
126147 this . _handles = [ ] ;
127148 }
128149
129- // When a mendix object exists create subscribtions.
150+ // When a mendix object exists create subscribtions.
130151 if ( this . _contextObj ) {
131152 var objectHandle = this . subscribe ( {
132153 guid : this . _contextObj . getGuid ( ) ,
@@ -135,7 +156,7 @@ define([
135156 } )
136157 } ) ;
137158
138- this . _handles = [ objectHandle ] ;
159+ this . _handles = [ objectHandle ] ;
139160 }
140161 }
141162 } ) ;
0 commit comments