Skip to content

Commit 03f27cd

Browse files
author
Jelte Lagendijk
committed
Merge branch 'master' of ssh://github.com/bizzomate/FileDocumentViewer into bizzomate-master
2 parents 56678f9 + 4f5a34f commit 03f27cd

File tree

5 files changed

+123
-16
lines changed

5 files changed

+123
-16
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ node_modules/
1818
*DS_Store*
1919
.vscode/
2020
*.bak
21+
package-lock.json

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@
3434
"folders": "node ./node_modules/gulp/bin/gulp folders",
3535
"modeler": "node ./node_modules/gulp/bin/gulp modeler"
3636
}
37-
}
37+
}

src/FileDocumentViewer/FileDocumentViewer.xml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,52 @@
4141
<category>PDF</category>
4242
<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>
4343
</property>
44+
<property key="usePDFjsAttribute" type="attribute" required="false">
45+
<caption>Use PDF js (attribute)</caption>
46+
<category>PDF</category>
47+
<description>Set the "use PDF js" via an attribute of the context object. Overwrites the static "use PDF js" value. (optional)</description>
48+
<attributeTypes>
49+
<attributeType name="Boolean"/>
50+
</attributeTypes>
51+
</property>
52+
<property key="hideOpenFile" type="boolean" defaultValue="false">
53+
<caption>Hide "Open file" button</caption>
54+
<category>PDF</category>
55+
<description>Hide the "Open File" button rendered by PDFjs</description>
56+
</property>
57+
<property key="hideOpenFileAttribute" type="attribute" required="false">
58+
<caption>Hide "Open file" button (attribute)</caption>
59+
<category>PDF</category>
60+
<description>Set the "hide open file" via an attribute of the context object. Overwrites the static value. (optional)</description>
61+
<attributeTypes>
62+
<attributeType name="Boolean"/>
63+
</attributeTypes>
64+
</property>
65+
<property key="hideDownload" type="boolean" defaultValue="false">
66+
<caption>Hide "Download" button</caption>
67+
<category>PDF</category>
68+
<description>Hide the dowload button rendered by PDFjs</description>
69+
</property>
70+
<property key="hideDownloadAttribute" type="attribute" required="false">
71+
<caption>Hide "Download" button (attribute)</caption>
72+
<category>PDF</category>
73+
<description>Set the "hide download button" via an attribute of the context object. Overwrites the static value. (optional)</description>
74+
<attributeTypes>
75+
<attributeType name="Boolean"/>
76+
</attributeTypes>
77+
</property>
78+
<property key="hidePrint" type="boolean" defaultValue="false">
79+
<caption>Hide "Print" button</caption>
80+
<category>PDF</category>
81+
<description>Hide the print button rendered by PDFjs</description>
82+
</property>
83+
<property key="hidePrintAttribute" type="attribute" required="false">
84+
<caption>Hide "Print" button (attribute)</caption>
85+
<category>PDF</category>
86+
<description>Set the "hide print" via an attribute of the context object. Overwrites the static value. (optional)</description>
87+
<attributeTypes>
88+
<attributeType name="Boolean"/>
89+
</attributeTypes>
90+
</property>
4491
</properties>
4592
</widget>

src/FileDocumentViewer/widget/FileDocumentViewer.js

Lines changed: 74 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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+
});

test/[Test] DocumentViewer.mpr

83 KB
Binary file not shown.

0 commit comments

Comments
 (0)