1- require ( [
1+ require ( [
22 "require" ,
33 "dojo/_base/declare" ,
44 "mxui/widget/_WidgetBase" ,
@@ -12,12 +12,13 @@ require( [
1212 "dojo/dom-construct" ,
1313 "dojo/dom-style" ,
1414 "dojo/_base/lang" ,
15+ "dojo/_base/window" ,
1516 "dojo/text" ,
1617 "dojo/text!FileDocumentViewer/widget/templates/FileDocumentViewer.html"
17- ] , function ( require , declare , _WidgetBase , _TemplatedMixin , dom , dojoDom , dojoHtml , domQuery , domClass , domAttr , domConstruct , domStyle , lang , text , widgetTemplate ) {
18+ ] , function ( require , declare , _WidgetBase , _TemplatedMixin , dom , dojoDom , dojoHtml , domQuery , domClass , domAttr , domConstruct , domStyle , lang , dojoWindow , text , widgetTemplate ) {
1819 "use strict" ;
1920
20- return declare ( "FileDocumentViewer.widget.FileDocumentViewer" , [ _WidgetBase , _TemplatedMixin ] , {
21+ return declare ( "FileDocumentViewer.widget.FileDocumentViewer" , [ _WidgetBase , _TemplatedMixin ] , {
2122
2223 templateString : widgetTemplate ,
2324
@@ -27,12 +28,23 @@ require( [
2728 backgroundColor : "" ,
2829 usePDFjs : false ,
2930 escapeTitle : true ,
31+ hideDownload : false ,
32+ hidePrint : false ,
33+ hideOpenFile : false ,
34+ usePDFjsAttribute : "" ,
35+ hideDownloadAttribute : "" ,
36+ hidePrintAttribute : "" ,
37+ hideOpenFileAttribute : "" ,
3038
3139 // Internal variables.
3240 _handle : null ,
3341 _contextObj : null ,
3442 _objProperty : null ,
35- iframeNode :null ,
43+ _usePDFjs : null ,
44+ _hideDownload : null ,
45+ _hidePrint : null ,
46+ _hideOpenFile : null ,
47+ iframeNode : null ,
3648
3749 postCreate : function ( ) {
3850 logger . debug ( this . id + ".postCreate" ) ;
@@ -46,6 +58,11 @@ require( [
4658 "width" : this . width === 0 ? "auto" : this . width + "px"
4759 } ) ;
4860
61+ this . _usePDFjs = this . usePDFjs ;
62+ this . _hideDownload = this . hideDownload ;
63+ this . _hideOpenFile = this . hideOpenFile ;
64+ this . _hidePrint = this . hidePrint ;
65+
4966 this . _setupEvents ( ) ;
5067 } ,
5168
@@ -57,7 +74,7 @@ require( [
5774
5875 domStyle . set ( this . iframeNode , {
5976 "height" : this . height === 0 ? "auto" : this . height + "px" ,
60- "width" : "100%" ,
77+ "width" : "100%" ,
6178 "border-width" : 0
6279 } ) ;
6380 } ,
@@ -67,25 +84,52 @@ require( [
6784
6885 if ( obj ) {
6986 this . _contextObj = obj ;
87+ this . _getSettings ( ) ;
7088 this . _resetSubscriptions ( ) ;
7189 this . _updateRendering ( callback ) ;
7290 } else {
7391 this . _executeCallback ( callback , "update" ) ;
7492 }
7593 } ,
7694
95+ _getSettings : function ( ) {
96+ logger . debug ( this . id + "._getSettings" ) ;
97+
98+ if ( this . usePDFjsAttribute && this . usePDFjsAttribute . length ) {
99+ this . _usePDFjs = this . _contextObj . get ( this . usePDFjsAttribute ) ;
100+ }
101+
102+ if ( this . hideDownloadAttribute && this . hideDownloadAttribute . length ) {
103+ this . _hideDownload = this . _contextObj . get ( this . hideDownloadAttribute ) ;
104+ }
105+
106+ if ( this . hidePrintAttribute && this . hidePrintAttribute . length ) {
107+ this . _hidePrint = this . _contextObj . get ( this . hidePrintAttribute ) ;
108+ }
109+
110+ if ( this . hideOpenFileAttribute && this . hideOpenFileAttribute . length ) {
111+ this . _hideOpenFile = this . _contextObj . get ( this . hideOpenFileAttribute ) ;
112+ }
113+ } ,
114+
77115 _updateRendering : function ( callback ) {
78116 logger . debug ( this . id + "._updateRendering" ) ;
79117 domConstruct . destroy ( this . iframeNode ) ;
80118 this . iframeNode = null ;
81119 this . _iframeNodeCreate ( ) ;
82120
83- if ( this . _contextObj && this . _contextObj . get ( "HasContents" ) ) {
84- if ( this . usePDFjs /* && this._contextObj.get("Name").indexOf(".pdf") !== -1*/ ) {
121+ if ( this . _contextObj && this . _contextObj . get ( "HasContents" ) ) {
122+ if ( this . _usePDFjs /* && this._contextObj.get("Name").indexOf(".pdf") !== -1*/ ) {
85123 var pdfJSViewer = require . toUrl ( "FileDocumentViewer/lib/pdfjs/web/viewer.html" ) . split ( "?" ) [ 0 ] ,
86124 encoded = pdfJSViewer + "?file=" + encodeURIComponent ( this . _getFileUrl ( ) ) ;
87125
88126 domAttr . set ( this . iframeNode , "src" , encoded ) ;
127+
128+ if ( this . _hideDownload || this . _hidePrint || this . _hideOpenFile ) {
129+ this . iframeNode . onload = lang . hitch ( this , function ( ) {
130+ dojoWindow . withDoc ( this . iframeNode . contentWindow . document , lang . hitch ( this , this . _hideButtonsFromUI ) )
131+ } )
132+ }
89133 } else {
90134 domAttr . set ( this . iframeNode , "src" , this . _getFileUrl ( ) ) ;
91135 }
@@ -100,7 +144,7 @@ require( [
100144 dojoHtml . set ( this . headerTextNode , title ) ;
101145 } else {
102146 domAttr . set ( this . iframeNode , "src" , require . toUrl ( "FileDocumentViewer/widget/ui/blank.html" ) ) ;
103- domAttr . set ( this . headerTextNode , "innerHTML" , "..." ) ;
147+ domAttr . set ( this . headerTextNode , "innerHTML" , "..." ) ;
104148 }
105149
106150 this . _executeCallback ( callback , "_updateRendering" ) ;
@@ -123,13 +167,13 @@ require( [
123167 }
124168 } ,
125169
126- _setupEvents : function ( ) {
170+ _setupEvents : function ( ) {
127171 logger . debug ( this . id + "._setupEvents" ) ;
128172 this . connect ( this . enlargeNode , "onclick" , this . _eventEnlarge ) ;
129- this . connect ( this . popoutNode , "onclick" , this . _eventPopout ) ;
173+ this . connect ( this . popoutNode , "onclick" , this . _eventPopout ) ;
130174 } ,
131175
132- _getFileUrl : function ( ) {
176+ _getFileUrl : function ( ) {
133177 logger . debug ( this . id + "._getFileUrl" ) ;
134178 var changedDate = Math . floor ( Date . now ( ) / 1 ) ; // Right now;
135179 if ( this . _contextObj === null || this . _contextObj . get ( "Name" ) === null ) {
@@ -152,14 +196,29 @@ require( [
152196 }
153197 } ,
154198
155- _eventEnlarge : function ( ) {
199+ _hideButtonsFromUI : function ( ) {
200+ logger . debug ( this . id + "._hideButtons" ) ;
201+
202+ if ( this . _hideDownload ) {
203+ domQuery ( 'button.download' ) . style ( 'display' , 'none' ) ;
204+ }
205+ if ( this . _hidePrint ) {
206+ domQuery ( 'button.print' ) . style ( 'display' , 'none' ) ;
207+ }
208+ if ( this . _hideOpenFile ) {
209+ domQuery ( 'button.openFile' ) . style ( 'display' , 'none' ) ;
210+ }
211+
212+ } ,
213+
214+ _eventEnlarge : function ( ) {
156215 logger . debug ( this . id + "._eventEnlarge" ) ;
157216 domStyle . set ( this . iframeNode , {
158- height : ( domStyle . get ( this . iframeNode , "height" ) * 1.5 ) + "px"
217+ height : ( domStyle . get ( this . iframeNode , "height" ) * 1.5 ) + "px"
159218 } ) ;
160219 } ,
161220
162- _eventPopout : function ( ) {
221+ _eventPopout : function ( ) {
163222 logger . debug ( this . id + "._eventPopout" ) ;
164223 window . open ( this . _getFileUrl ( ) ) ;
165224 } ,
@@ -179,4 +238,4 @@ require( [
179238 }
180239 }
181240 } ) ;
182- } ) ;
241+ } ) ;
0 commit comments