diff --git a/.gitignore b/.gitignore index 4f4740d..abce4e0 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ node_modules/ *DS_Store* .vscode/ *.bak +package-lock.json diff --git a/package.json b/package.json index 997922c..91d6f89 100644 --- a/package.json +++ b/package.json @@ -34,4 +34,4 @@ "folders": "node ./node_modules/gulp/bin/gulp folders", "modeler": "node ./node_modules/gulp/bin/gulp modeler" } -} \ No newline at end of file +} diff --git a/src/FileDocumentViewer/FileDocumentViewer.xml b/src/FileDocumentViewer/FileDocumentViewer.xml index b2ce3cb..352ab78 100644 --- a/src/FileDocumentViewer/FileDocumentViewer.xml +++ b/src/FileDocumentViewer/FileDocumentViewer.xml @@ -41,5 +41,52 @@ PDF Some browsers (Android for example) might run into problems displaying PDF files. We included PDFjs from Mozilla to display PDFs correctly. You can try this if you have problems. Warning: enable this if you are only using PDFs (other formats will result in an error) + + Use PDF js (attribute) + PDF + Set the "use PDF js" via an attribute of the context object. Overwrites the static "use PDF js" value. (optional) + + + + + + Hide "Open file" button + PDF + Hide the "Open File" button rendered by PDFjs + + + Hide "Open file" button (attribute) + PDF + Set the "hide open file" via an attribute of the context object. Overwrites the static value. (optional) + + + + + + Hide "Download" button + PDF + Hide the dowload button rendered by PDFjs + + + Hide "Download" button (attribute) + PDF + Set the "hide download button" via an attribute of the context object. Overwrites the static value. (optional) + + + + + + Hide "Print" button + PDF + Hide the print button rendered by PDFjs + + + Hide "Print" button (attribute) + PDF + Set the "hide print" via an attribute of the context object. Overwrites the static value. (optional) + + + + diff --git a/src/FileDocumentViewer/widget/FileDocumentViewer.js b/src/FileDocumentViewer/widget/FileDocumentViewer.js index 77b8daf..c2ccd59 100644 --- a/src/FileDocumentViewer/widget/FileDocumentViewer.js +++ b/src/FileDocumentViewer/widget/FileDocumentViewer.js @@ -1,4 +1,4 @@ -require( [ +require([ "require", "dojo/_base/declare", "mxui/widget/_WidgetBase", @@ -12,12 +12,13 @@ require( [ "dojo/dom-construct", "dojo/dom-style", "dojo/_base/lang", + "dojo/_base/window", "dojo/text", "dojo/text!FileDocumentViewer/widget/templates/FileDocumentViewer.html" -], function (require, declare, _WidgetBase, _TemplatedMixin, dom, dojoDom, dojoHtml, domQuery, domClass, domAttr, domConstruct, domStyle, lang, text, widgetTemplate) { +], function (require, declare, _WidgetBase, _TemplatedMixin, dom, dojoDom, dojoHtml, domQuery, domClass, domAttr, domConstruct, domStyle, lang, dojoWindow, text, widgetTemplate) { "use strict"; - return declare("FileDocumentViewer.widget.FileDocumentViewer", [ _WidgetBase, _TemplatedMixin ], { + return declare("FileDocumentViewer.widget.FileDocumentViewer", [_WidgetBase, _TemplatedMixin], { templateString: widgetTemplate, @@ -27,12 +28,23 @@ require( [ backgroundColor: "", usePDFjs: false, escapeTitle: true, + hideDownload: false, + hidePrint: false, + hideOpenFile: false, + usePDFjsAttribute: "", + hideDownloadAttribute: "", + hidePrintAttribute: "", + hideOpenFileAttribute: "", // Internal variables. _handle: null, _contextObj: null, _objProperty: null, - iframeNode:null, + _usePDFjs: null, + _hideDownload: null, + _hidePrint: null, + _hideOpenFile: null, + iframeNode: null, postCreate: function () { logger.debug(this.id + ".postCreate"); @@ -46,6 +58,11 @@ require( [ "width": this.width === 0 ? "auto" : this.width + "px" }); + this._usePDFjs = this.usePDFjs; + this._hideDownload = this.hideDownload; + this._hideOpenFile = this.hideOpenFile; + this._hidePrint = this.hidePrint; + this._setupEvents(); }, @@ -57,7 +74,7 @@ require( [ domStyle.set(this.iframeNode, { "height": this.height === 0 ? "auto" : this.height + "px", - "width" : "100%", + "width": "100%", "border-width": 0 }); }, @@ -67,6 +84,7 @@ require( [ if (obj) { this._contextObj = obj; + this._getSettings(); this._resetSubscriptions(); this._updateRendering(callback); } else { @@ -74,18 +92,44 @@ require( [ } }, + _getSettings: function() { + logger.debug(this.id + "._getSettings"); + + if (this.usePDFjsAttribute && this.usePDFjsAttribute.length) { + this._usePDFjs = this._contextObj.get(this.usePDFjsAttribute); + } + + if (this.hideDownloadAttribute && this.hideDownloadAttribute.length) { + this._hideDownload = this._contextObj.get(this.hideDownloadAttribute); + } + + if (this.hidePrintAttribute && this.hidePrintAttribute.length) { + this._hidePrint = this._contextObj.get(this.hidePrintAttribute); + } + + if (this.hideOpenFileAttribute && this.hideOpenFileAttribute.length) { + this._hideOpenFile = this._contextObj.get(this.hideOpenFileAttribute); + } + }, + _updateRendering: function (callback) { logger.debug(this.id + "._updateRendering"); domConstruct.destroy(this.iframeNode); this.iframeNode = null; this._iframeNodeCreate(); - if (this._contextObj && this._contextObj.get("HasContents")) { - if (this.usePDFjs/* && this._contextObj.get("Name").indexOf(".pdf") !== -1*/) { + if (this._contextObj && this._contextObj.get("HasContents")) { + if (this._usePDFjs /* && this._contextObj.get("Name").indexOf(".pdf") !== -1*/ ) { var pdfJSViewer = require.toUrl("FileDocumentViewer/lib/pdfjs/web/viewer.html").split("?")[0], encoded = pdfJSViewer + "?file=" + encodeURIComponent(this._getFileUrl()); domAttr.set(this.iframeNode, "src", encoded); + + if (this._hideDownload || this._hidePrint || this._hideOpenFile) { + this.iframeNode.onload = lang.hitch(this, function(){ + dojoWindow.withDoc(this.iframeNode.contentWindow.document, lang.hitch(this, this._hideButtonsFromUI)) + }) + } } else { domAttr.set(this.iframeNode, "src", this._getFileUrl()); } @@ -100,7 +144,7 @@ require( [ dojoHtml.set(this.headerTextNode, title); } else { domAttr.set(this.iframeNode, "src", require.toUrl("FileDocumentViewer/widget/ui/blank.html")); - domAttr.set(this.headerTextNode, "innerHTML","..."); + domAttr.set(this.headerTextNode, "innerHTML", "..."); } this._executeCallback(callback, "_updateRendering"); @@ -123,13 +167,13 @@ require( [ } }, - _setupEvents : function () { + _setupEvents: function () { logger.debug(this.id + "._setupEvents"); this.connect(this.enlargeNode, "onclick", this._eventEnlarge); - this.connect(this.popoutNode, "onclick", this._eventPopout); + this.connect(this.popoutNode, "onclick", this._eventPopout); }, - _getFileUrl : function () { + _getFileUrl: function () { logger.debug(this.id + "._getFileUrl"); var changedDate = Math.floor(Date.now() / 1); // Right now; if (this._contextObj === null || this._contextObj.get("Name") === null) { @@ -152,14 +196,29 @@ require( [ } }, - _eventEnlarge : function () { + _hideButtonsFromUI: function() { + logger.debug(this.id + "._hideButtons"); + + if (this._hideDownload){ + domQuery('button.download').style('display','none'); + } + if (this._hidePrint){ + domQuery('button.print').style('display','none'); + } + if (this._hideOpenFile){ + domQuery('button.openFile').style('display', 'none'); + } + + }, + + _eventEnlarge: function () { logger.debug(this.id + "._eventEnlarge"); domStyle.set(this.iframeNode, { - height: (domStyle.get(this.iframeNode, "height") * 1.5) +"px" + height: (domStyle.get(this.iframeNode, "height") * 1.5) + "px" }); }, - _eventPopout : function () { + _eventPopout: function () { logger.debug(this.id + "._eventPopout"); window.open(this._getFileUrl()); }, @@ -179,4 +238,4 @@ require( [ } } }); -}); +}); \ No newline at end of file diff --git a/test/[Test] DocumentViewer.mpr b/test/[Test] DocumentViewer.mpr index a820888..2b4a34f 100644 Binary files a/test/[Test] DocumentViewer.mpr and b/test/[Test] DocumentViewer.mpr differ diff --git a/test/widgets/FileDocumentViewer.mpk b/test/widgets/FileDocumentViewer.mpk index 12ecec5..2a155b9 100644 Binary files a/test/widgets/FileDocumentViewer.mpk and b/test/widgets/FileDocumentViewer.mpk differ