1- /*jslint white:true, nomen: true, plusplus: true */
2- /*global mx, require */
3- /*mendix */
4-
5- // Required module list. Remove unnecessary modules, you can always get them back from the boilerplate.
61require ( [
7- ' require' , // require.toUrl
8- ' dojo/_base/declare' ,
9- ' mxui/widget/_WidgetBase' ,
10- ' dijit/_TemplatedMixin' ,
11- ' mxui/dom' ,
12- ' dojo/dom' ,
13- ' dojo/query' ,
14- ' dojo/dom-class' ,
15- ' dojo/dom-attr' ,
16- ' dojo/dom-construct' ,
17- ' dojo/dom-style' ,
18- ' dojo/_base/lang' ,
19- ' dojo/text' ,
20- ' dojo/text!FileDocumentViewer/widget/templates/FileDocumentViewer.html'
2+ " require" ,
3+ " dojo/_base/declare" ,
4+ " mxui/widget/_WidgetBase" ,
5+ " dijit/_TemplatedMixin" ,
6+ " mxui/dom" ,
7+ " dojo/dom" ,
8+ " dojo/query" ,
9+ " dojo/dom-class" ,
10+ " dojo/dom-attr" ,
11+ " dojo/dom-construct" ,
12+ " dojo/dom-style" ,
13+ " dojo/_base/lang" ,
14+ " dojo/text" ,
15+ " dojo/text!FileDocumentViewer/widget/templates/FileDocumentViewer.html"
2116] , function ( require , declare , _WidgetBase , _TemplatedMixin , dom , dojoDom , domQuery , domClass , domAttr , domConstruct , domStyle , lang , text , widgetTemplate ) {
22- 'use strict' ;
17+ "use strict" ;
18+
19+ return declare ( "FileDocumentViewer.widget.FileDocumentViewer" , [ _WidgetBase , _TemplatedMixin ] , {
2320
24- // Declare widget's prototype.
25- return declare ( 'FileDocumentViewer.widget.FileDocumentViewer' , [ _WidgetBase , _TemplatedMixin ] , {
26- // _TemplatedMixin will create our dom node using this HTML template.
2721 templateString : widgetTemplate ,
2822
2923 // Parameters configured in the Modeler.
30- mfToExecute : '' ,
31- messageString : '' ,
32- backgroundColor : '' ,
24+ mfToExecute : "" ,
25+ messageString : "" ,
26+ backgroundColor : "" ,
3327 usePDFjs : false ,
3428
35- // Internal variables. Non-primitives created in the prototype are shared between all widget instances.
29+ // Internal variables.
3630 _handle : null ,
3731 _contextObj : null ,
3832 _objProperty : null ,
3933 iframeNode :null ,
4034
41- // dijit._WidgetBase.postCreate is called after constructing the widget. Implement to do extra setup work.
4235 postCreate : function ( ) {
43- console . log ( this ) ;
36+ logger . debug ( this . id + ".postCreate" ) ;
37+
4438 if ( ! this . showheader ) {
45- domStyle . set ( this . toolbarNode , ' display' , ' none' ) ;
46- domClass . add ( this . groupboxBody , ' no-header' ) ;
39+ domStyle . set ( this . toolbarNode , " display" , " none" ) ;
40+ domClass . add ( this . groupboxBody , " no-header" ) ;
4741 }
4842
4943 domStyle . set ( this . domNode , {
50- ' width' : this . width === 0 ? ' auto' : this . width + 'px'
44+ " width" : this . width === 0 ? " auto" : this . width + "px"
5145 } ) ;
5246
5347 this . _setupEvents ( ) ;
5448 } ,
5549
56- _iframeNodeCreate : function ( ) {
57- this . iframeNode = domConstruct . create ( 'iframe' , null , this . groupboxBody ) ;
58- domAttr . set ( this . iframeNode , 'id' , 'iframeNode' ) ;
59- domAttr . set ( this . iframeNode , 'class' , 'documentiframe' ) ;
50+ _iframeNodeCreate : function ( ) {
51+ logger . debug ( this . id + "._iframeNodeCreate" ) ;
52+ this . iframeNode = domConstruct . create ( "iframe" , null , this . groupboxBody ) ;
53+ domAttr . set ( this . iframeNode , "id" , "iframeNode" ) ;
54+ domAttr . set ( this . iframeNode , "class" , "documentiframe" ) ;
6055
6156 domStyle . set ( this . iframeNode , {
62- ' height' : this . height === 0 ? ' auto' : this . height + 'px' ,
63- ' width' : ' 100%' ,
64- ' border-width' : 0
57+ " height" : this . height === 0 ? " auto" : this . height + "px" ,
58+ " width" : " 100%" ,
59+ " border-width" : 0
6560 } ) ;
6661 } ,
6762
68- // mxui.widget._WidgetBase.update is called when context is changed or initialized. Implement to re-render and / or fetch data.
6963 update : function ( obj , callback ) {
70- console . log ( obj ) ;
64+ logger . debug ( this . id + ".update" ) ;
7165 this . _contextObj = obj ;
7266 this . _resetSubscriptions ( ) ;
73- this . _updateRendering ( ) ;
74-
75- callback ( ) ;
67+ this . _updateRendering ( callback ) ;
7668 } ,
7769
78- _updateRendering : function ( ) {
79-
70+ _updateRendering : function ( callback ) {
71+ logger . debug ( this . id + "._updateRendering" ) ;
8072 domConstruct . destroy ( this . iframeNode ) ;
8173 this . iframeNode = null ;
8274 this . _iframeNodeCreate ( ) ;
8375
84- if ( this . _contextObj && this . _contextObj . get ( ' HasContents' ) ) {
76+ if ( this . _contextObj && this . _contextObj . get ( " HasContents" ) ) {
8577 if ( this . usePDFjs /* && this._contextObj.get("Name").indexOf(".pdf") !== -1*/ ) {
86- var pdfJSViewer = require . toUrl ( ' FileDocumentViewer/lib/pdfjs/web/viewer.html' ) . split ( "?" ) [ 0 ] ,
78+ var pdfJSViewer = require . toUrl ( " FileDocumentViewer/lib/pdfjs/web/viewer.html" ) . split ( "?" ) [ 0 ] ,
8779 encoded = pdfJSViewer + "?file=" + encodeURIComponent ( mx . appUrl + this . _getFileUrl ( ) ) ;
8880
89- domAttr . set ( this . iframeNode , ' src' , encoded ) ;
81+ domAttr . set ( this . iframeNode , " src" , encoded ) ;
9082 } else {
91- domAttr . set ( this . iframeNode , ' src' , this . _getFileUrl ( ) ) ;
83+ domAttr . set ( this . iframeNode , " src" , this . _getFileUrl ( ) ) ;
9284 }
9385
94- domAttr . set ( this . headerTextNode , ' innerHTML' , this . _contextObj . get ( this . headertitle ) ) ;
86+ domAttr . set ( this . headerTextNode , " innerHTML" , this . _contextObj . get ( this . headertitle ) ) ;
9587 } else {
96- domAttr . set ( this . iframeNode , ' src' , require . toUrl ( ' FileDocumentViewer/widget/ui/blank.html' ) )
97- domAttr . set ( this . headerTextNode , ' innerHTML' , ' ...' ) ;
88+ domAttr . set ( this . iframeNode , " src" , require . toUrl ( " FileDocumentViewer/widget/ui/blank.html" ) ) ;
89+ domAttr . set ( this . headerTextNode , " innerHTML" , " ..." ) ;
9890 }
91+
92+ mendix . lang . nullExec ( callback ) ;
9993 } ,
10094
10195 _resetSubscriptions : function ( ) {
102- // Release handle on previous object, if any.
96+ logger . debug ( this . id + "._resetSubscriptions" ) ;
10397 if ( this . _handle ) {
10498 this . unsubscribe ( this . _handle ) ;
10599 this . _handle = null ;
@@ -113,28 +107,30 @@ require( [
113107 }
114108 } ,
115109
116- _setupEvents : function ( ) {
117- this . connect ( this . enlargeNode , 'onclick' , this . _eventEnlarge ) ;
118- this . connect ( this . popoutNode , 'onclick' , this . _eventPopout ) ;
110+ _setupEvents : function ( ) {
111+ logger . debug ( this . id + "._setupEvents" ) ;
112+ this . connect ( this . enlargeNode , "onclick" , this . _eventEnlarge ) ;
113+ this . connect ( this . popoutNode , "onclick" , this . _eventPopout ) ;
119114 } ,
120115
121- _getFileUrl : function ( ) {
122- var url ;
123- if ( this . _contextObj === null || this . _contextObj . get ( ' Name' ) === null ) {
124- url = require . toUrl ( ' FileDocumentViewer/widget/ui/error.html' ) ;
116+ _getFileUrl : function ( ) {
117+ logger . debug ( this . id + "._getFileUrl" ) ;
118+ if ( this . _contextObj === null || this . _contextObj . get ( " Name" ) === null ) {
119+ return require . toUrl ( " FileDocumentViewer/widget/ui/error.html" ) ;
125120 } else {
126- url = ' file?target=window&guid=' + this . _contextObj . getGuid ( ) + ' &csrfToken=' + mx . session . getCSRFToken ( ) + ' &time=' + Date . now ( ) ;
121+ return " file?target=window&guid=" + this . _contextObj . getGuid ( ) + " &csrfToken=" + mx . session . getCSRFToken ( ) + " &time=" + Date . now ( ) ;
127122 }
128- return url ;
129123 } ,
130124
131- _eventEnlarge : function ( ) {
125+ _eventEnlarge : function ( ) {
126+ logger . debug ( this . id + "._eventEnlarge" ) ;
132127 domStyle . set ( this . iframeNode , {
133- height : ( domStyle . get ( this . iframeNode , ' height' ) * 1.5 ) + 'px'
128+ height : ( domStyle . get ( this . iframeNode , " height" ) * 1.5 ) + "px"
134129 } ) ;
135130 } ,
136131
137- _eventPopout : function ( ) {
132+ _eventPopout : function ( ) {
133+ logger . debug ( this . id + "._eventPopout" ) ;
138134 window . open ( this . _getFileUrl ( ) ) ;
139135 }
140136 } ) ;
0 commit comments