@@ -21,7 +21,7 @@ define([
21
21
"dijit/_TemplatedMixin" ,
22
22
"dojo/_base/array" ,
23
23
"dojo/_base/lang" ,
24
- "mxui/dom" ,
24
+ "mxui/dom" ,
25
25
"dojo/text!CustomString/widget/template/CustomString.html"
26
26
] , function ( declare , _WidgetBase , _TemplatedMixin , dojoArray , dojoLang , dom , widgetTemplate ) {
27
27
"use strict" ;
@@ -42,31 +42,35 @@ define([
42
42
43
43
// dojo.declare.constructor is called to construct the widget instance. Implement to initialize non-primitive properties.
44
44
constructor : function ( ) {
45
+ logger . level ( logger . DEBUG ) ;
45
46
this . _handles = [ ] ;
46
47
} ,
47
48
48
49
// dijit._WidgetBase.postCreate is called after constructing the widget. Implement to do extra setup work.
49
50
postCreate : function ( ) {
51
+ logger . debug ( this . id + ".postCreate" ) ;
50
52
this . _setupEvents ( ) ;
51
53
} ,
52
54
53
55
// mxui.widget._WidgetBase.update is called when context is changed or initialized. Implement to re-render and / or fetch data.
54
56
update : function ( obj , callback ) {
57
+ logger . debug ( this . id + ".update" ) ;
55
58
this . _contextObj = obj ;
56
-
57
- if ( this . _contextObj )
58
- {
59
+
60
+ if ( this . _contextObj ) {
59
61
this . _resetSubscriptions ( ) ;
60
- this . _updateRendering ( ) ;
62
+ this . _updateRendering ( callback ) ;
63
+ } else if ( this . _render ) {
64
+ this . _render ( callback ) ;
65
+ } else {
66
+ this . _runCallback ( callback ) ;
61
67
}
62
- callback ( ) ;
63
68
} ,
64
-
69
+
65
70
// Attach events to HTML dom elements
66
71
_setupEvents : function ( ) {
67
-
72
+ logger . debug ( this . id + "._setupEvents" ) ;
68
73
this . connect ( this . customString , "click" , function ( e ) {
69
-
70
74
// If a microflow has been set execute the microflow on a click.
71
75
if ( this . mfToExecute !== "" ) {
72
76
mx . data . action ( {
@@ -75,9 +79,9 @@ define([
75
79
actionname : this . mfToExecute ,
76
80
guids : [ this . _contextObj . getGuid ( ) ]
77
81
} ,
78
- store : {
79
- caller : this . mxform
80
- } ,
82
+ store : {
83
+ caller : this . mxform
84
+ } ,
81
85
callback : function ( obj ) {
82
86
//TODO what to do when all is ok!
83
87
} ,
@@ -88,36 +92,53 @@ define([
88
92
}
89
93
} ) ;
90
94
} ,
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" ) ;
110
119
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
+ }
111
129
} ,
112
130
113
131
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
+ } ,
118
138
119
139
// Reset subscriptions.
120
140
_resetSubscriptions : function ( ) {
141
+ logger . debug ( this . id + "._resetSubscriptions" ) ;
121
142
// Release handles on previous object, if any.
122
143
if ( this . _handles ) {
123
144
dojoArray . forEach ( this . _handles , function ( handle ) {
@@ -126,7 +147,7 @@ define([
126
147
this . _handles = [ ] ;
127
148
}
128
149
129
- // When a mendix object exists create subscribtions.
150
+ // When a mendix object exists create subscribtions.
130
151
if ( this . _contextObj ) {
131
152
var objectHandle = this . subscribe ( {
132
153
guid : this . _contextObj . getGuid ( ) ,
@@ -135,7 +156,7 @@ define([
135
156
} )
136
157
} ) ;
137
158
138
- this . _handles = [ objectHandle ] ;
159
+ this . _handles = [ objectHandle ] ;
139
160
}
140
161
}
141
162
} ) ;
0 commit comments