Skip to content

Commit 4f5a34f

Browse files
committed
Allow settings from context object
1 parent 58e9e48 commit 4f5a34f

File tree

4 files changed

+73
-7
lines changed

4 files changed

+73
-7
lines changed

src/FileDocumentViewer/FileDocumentViewer.xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +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>
4452
<property key="hideOpenFile" type="boolean" defaultValue="false">
4553
<caption>Hide "Open file" button</caption>
4654
<category>PDF</category>
4755
<description>Hide the "Open File" button rendered by PDFjs</description>
4856
</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>
4965
<property key="hideDownload" type="boolean" defaultValue="false">
5066
<caption>Hide "Download" button</caption>
5167
<category>PDF</category>
5268
<description>Hide the dowload button rendered by PDFjs</description>
5369
</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>
5478
<property key="hidePrint" type="boolean" defaultValue="false">
5579
<caption>Hide "Print" button</caption>
5680
<category>PDF</category>
5781
<description>Hide the print button rendered by PDFjs</description>
5882
</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>
5991
</properties>
6092
</widget>

src/FileDocumentViewer/widget/FileDocumentViewer.js

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,19 @@ require([
3131
hideDownload: false,
3232
hidePrint: false,
3333
hideOpenFile: false,
34+
usePDFjsAttribute: "",
35+
hideDownloadAttribute: "",
36+
hidePrintAttribute: "",
37+
hideOpenFileAttribute: "",
3438

3539
// Internal variables.
3640
_handle: null,
3741
_contextObj: null,
3842
_objProperty: null,
43+
_usePDFjs: null,
44+
_hideDownload: null,
45+
_hidePrint: null,
46+
_hideOpenFile: null,
3947
iframeNode: null,
4048

4149
postCreate: function () {
@@ -50,6 +58,11 @@ require([
5058
"width": this.width === 0 ? "auto" : this.width + "px"
5159
});
5260

61+
this._usePDFjs = this.usePDFjs;
62+
this._hideDownload = this.hideDownload;
63+
this._hideOpenFile = this.hideOpenFile;
64+
this._hidePrint = this.hidePrint;
65+
5366
this._setupEvents();
5467
},
5568

@@ -71,29 +84,50 @@ require([
7184

7285
if (obj) {
7386
this._contextObj = obj;
87+
this._getSettings();
7488
this._resetSubscriptions();
7589
this._updateRendering(callback);
7690
} else {
7791
this._executeCallback(callback, "update");
7892
}
7993
},
8094

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+
81115
_updateRendering: function (callback) {
82116
logger.debug(this.id + "._updateRendering");
83117
domConstruct.destroy(this.iframeNode);
84118
this.iframeNode = null;
85119
this._iframeNodeCreate();
86120

87121
if (this._contextObj && this._contextObj.get("HasContents")) {
88-
if (this.usePDFjs /* && this._contextObj.get("Name").indexOf(".pdf") !== -1*/ ) {
122+
if (this._usePDFjs /* && this._contextObj.get("Name").indexOf(".pdf") !== -1*/ ) {
89123
var pdfJSViewer = require.toUrl("FileDocumentViewer/lib/pdfjs/web/viewer.html").split("?")[0],
90124
encoded = pdfJSViewer + "?file=" + encodeURIComponent(this._getFileUrl());
91125

92126
domAttr.set(this.iframeNode, "src", encoded);
93127

94-
if (this.hideDownload || this.hidePrint || this.hideOpenFile) {
128+
if (this._hideDownload || this._hidePrint || this._hideOpenFile) {
95129
this.iframeNode.onload = lang.hitch(this, function(){
96-
dojoWindow.withDoc(this.iframeNode.contentWindow.document, lang.hitch(this, this._hideButtons))
130+
dojoWindow.withDoc(this.iframeNode.contentWindow.document, lang.hitch(this, this._hideButtonsFromUI))
97131
})
98132
}
99133
} else {
@@ -162,16 +196,16 @@ require([
162196
}
163197
},
164198

165-
_hideButtons: function() {
199+
_hideButtonsFromUI: function() {
166200
logger.debug(this.id + "._hideButtons");
167201

168-
if (this.hideDownload){
202+
if (this._hideDownload){
169203
domQuery('button.download').style('display','none');
170204
}
171-
if (this.hidePrint){
205+
if (this._hidePrint){
172206
domQuery('button.print').style('display','none');
173207
}
174-
if (this.hideOpenFile){
208+
if (this._hideOpenFile){
175209
domQuery('button.openFile').style('display', 'none');
176210
}
177211

test/[Test] DocumentViewer.mpr

56 KB
Binary file not shown.
328 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)