Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ node_modules/
*DS_Store*
.vscode/
*.bak
package-lock.json
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
"folders": "node ./node_modules/gulp/bin/gulp folders",
"modeler": "node ./node_modules/gulp/bin/gulp modeler"
}
}
}
47 changes: 47 additions & 0 deletions src/FileDocumentViewer/FileDocumentViewer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,52 @@
<category>PDF</category>
<description>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)</description>
</property>
<property key="usePDFjsAttribute" type="attribute" required="false">
<caption>Use PDF js (attribute)</caption>
<category>PDF</category>
<description>Set the "use PDF js" via an attribute of the context object. Overwrites the static "use PDF js" value. (optional)</description>
<attributeTypes>
<attributeType name="Boolean"/>
</attributeTypes>
</property>
<property key="hideOpenFile" type="boolean" defaultValue="false">
<caption>Hide "Open file" button</caption>
<category>PDF</category>
<description>Hide the "Open File" button rendered by PDFjs</description>
</property>
<property key="hideOpenFileAttribute" type="attribute" required="false">
<caption>Hide "Open file" button (attribute)</caption>
<category>PDF</category>
<description>Set the "hide open file" via an attribute of the context object. Overwrites the static value. (optional)</description>
<attributeTypes>
<attributeType name="Boolean"/>
</attributeTypes>
</property>
<property key="hideDownload" type="boolean" defaultValue="false">
<caption>Hide "Download" button</caption>
<category>PDF</category>
<description>Hide the dowload button rendered by PDFjs</description>
</property>
<property key="hideDownloadAttribute" type="attribute" required="false">
<caption>Hide "Download" button (attribute)</caption>
<category>PDF</category>
<description>Set the "hide download button" via an attribute of the context object. Overwrites the static value. (optional)</description>
<attributeTypes>
<attributeType name="Boolean"/>
</attributeTypes>
</property>
<property key="hidePrint" type="boolean" defaultValue="false">
<caption>Hide "Print" button</caption>
<category>PDF</category>
<description>Hide the print button rendered by PDFjs</description>
</property>
<property key="hidePrintAttribute" type="attribute" required="false">
<caption>Hide "Print" button (attribute)</caption>
<category>PDF</category>
<description>Set the "hide print" via an attribute of the context object. Overwrites the static value. (optional)</description>
<attributeTypes>
<attributeType name="Boolean"/>
</attributeTypes>
</property>
</properties>
</widget>
89 changes: 74 additions & 15 deletions src/FileDocumentViewer/widget/FileDocumentViewer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require( [
require([
"require",
"dojo/_base/declare",
"mxui/widget/_WidgetBase",
Expand All @@ -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,

Expand All @@ -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");
Expand All @@ -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();
},

Expand All @@ -57,7 +74,7 @@ require( [

domStyle.set(this.iframeNode, {
"height": this.height === 0 ? "auto" : this.height + "px",
"width" : "100%",
"width": "100%",
"border-width": 0
});
},
Expand All @@ -67,25 +84,52 @@ require( [

if (obj) {
this._contextObj = obj;
this._getSettings();
this._resetSubscriptions();
this._updateRendering(callback);
} else {
this._executeCallback(callback, "update");
}
},

_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());
}
Expand All @@ -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");
Expand All @@ -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) {
Expand All @@ -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());
},
Expand All @@ -179,4 +238,4 @@ require( [
}
}
});
});
});
Binary file modified test/[Test] DocumentViewer.mpr
Binary file not shown.
Binary file modified test/widgets/FileDocumentViewer.mpk
Binary file not shown.