diff --git a/apps/api/documents/api.js b/apps/api/documents/api.js
index 9d3fbabdf8..a49fff5d95 100644
--- a/apps/api/documents/api.js
+++ b/apps/api/documents/api.js
@@ -132,7 +132,11 @@
url: 'http://...',
text: 'Go to London',
blank: true,
- requestClose: false // if true - goback send onRequestClose event instead opening url
+ requestClose: false // if true - goback send onRequestClose event instead opening url, deprecated, use customization.close instead
+ },
+ close: {
+ visible: true,
+ text: 'Close file'
},
reviewPermissions: {
"Group1": ["Group2"], // users from Group1 can accept/reject review changes made by users from Group2
@@ -282,7 +286,8 @@
'onRequestOpen': ,
'onRequestSelectDocument': , // used for compare and combine documents. must call setRequestedDocument method. use instead of onRequestCompareFile/setRevisedFile
'onRequestSelectSpreadsheet': , // used for mailmerge id de. must call setRequestedSpreadsheet method. use instead of onRequestMailMergeRecipients/setMailMergeRecipients
- 'onRequestReferenceSource': , // used for external links in sse. must call setReferenceSource method
+ 'onRequestReferenceSource': , // used for external links in sse. must call setReferenceSource method,
+ 'onSaveDocument': 'save document from binary'
}
}
@@ -351,6 +356,7 @@
_config.editorConfig.canRequestSelectDocument = _config.events && !!_config.events.onRequestSelectDocument;
_config.editorConfig.canRequestSelectSpreadsheet = _config.events && !!_config.events.onRequestSelectSpreadsheet;
_config.editorConfig.canRequestReferenceSource = _config.events && !!_config.events.onRequestReferenceSource;
+ _config.editorConfig.canSaveDocumentToBinary = _config.events && !!_config.events.onSaveDocument;
_config.frameEditorId = placeholderId;
_config.parentOrigin = window.location.origin;
@@ -473,7 +479,7 @@
}
}
- var type = /^(?:(pdf|djvu|xps|oxps))$/.exec(_config.document.fileType);
+ var type = /^(?:(djvu|xps|oxps))$/.exec(_config.document.fileType);
if (type && typeof type[1] === 'string') {
_config.editorConfig.canUseHistory = false;
}
@@ -560,9 +566,9 @@
}
};
- var _sendCommand = function(cmd) {
+ var _sendCommand = function(cmd, buffer) {
if (iframe && iframe.contentWindow)
- postMessage(iframe.contentWindow, cmd);
+ postMessage(iframe.contentWindow, cmd, buffer);
};
var _init = function(editorConfig) {
@@ -583,6 +589,13 @@
});
};
+ var _openDocumentFromBinary = function(doc) {
+ doc && _sendCommand({
+ command: 'openDocumentFromBinary',
+ data: doc.buffer
+ }, doc.buffer);
+ };
+
var _showMessage = function(title, msg) {
msg = msg || title;
_sendCommand({
@@ -842,7 +855,8 @@
setReferenceData : _setReferenceData,
setRequestedDocument: _setRequestedDocument,
setRequestedSpreadsheet: _setRequestedSpreadsheet,
- setReferenceSource: _setReferenceSource
+ setReferenceSource: _setReferenceSource,
+ openDocument: _openDocumentFromBinary
}
};
@@ -893,6 +907,12 @@
var _onMessage = function(msg) {
// TODO: check message origin
if (msg && window.JSON && _scope.frameOrigin==msg.origin ) {
+ if (msg.data && msg.data.event === 'onSaveDocument') {
+ if (_fn) {
+ _fn.call(_scope, msg.data);
+ }
+ return;
+ }
try {
var msg = window.JSON.parse(msg.data);
@@ -956,46 +976,53 @@
'word': 'documenteditor',
'cell': 'spreadsheeteditor',
'slide': 'presentationeditor',
- 'pdf': 'pdfeditor'
+ 'pdf': 'pdfeditor',
+ 'common': 'common'
},
- appType = 'word';
-
- if (typeof config.documentType === 'string') {
- appType = config.documentType.toLowerCase();
- if (config.type !== 'mobile' && config.type !== 'embedded' && !!config.document && typeof config.document.fileType === 'string') {
- var type = /^(?:(pdf|djvu|xps|oxps))$/.exec(config.document.fileType);
- if (type && typeof type[1] === 'string')
- appType = 'pdf';
- }
- } else
- if (!!config.document && typeof config.document.fileType === 'string') {
- var type = /^(?:(xls|xlsx|ods|csv|xlst|xlsy|gsheet|xlsm|xlt|xltm|xltx|fods|ots|xlsb)|(pps|ppsx|ppt|pptx|odp|pptt|ppty|gslides|pot|potm|potx|ppsm|pptm|fodp|otp)|(pdf|djvu|xps|oxps))$/
- .exec(config.document.fileType);
- if (type) {
- if (typeof type[1] === 'string') appType = 'cell'; else
- if (typeof type[2] === 'string') appType = 'slide'; else
- if (typeof type[3] === 'string' && config.type !== 'mobile' && config.type !== 'embedded') appType = 'pdf';
- }
+ appType = 'word',
+ type,
+ fillForms = false,
+ isForm = false;
+ if (config.document) {
+ if (typeof config.document.fileType === 'string')
+ type = /^(?:(pdf)|(djvu|xps|oxps)|(xls|xlsx|ods|csv|xlst|xlsy|gsheet|xlsm|xlt|xltm|xltx|fods|ots|xlsb)|(pps|ppsx|ppt|pptx|odp|pptt|ppty|gslides|pot|potm|potx|ppsm|pptm|fodp|otp))$/
+ .exec(config.document.fileType);
+
+ if (config.document.permissions)
+ fillForms = (config.document.permissions.fillForms===undefined ? config.document.permissions.edit !== false : config.document.permissions.fillForms) &&
+ config.editorConfig && (config.editorConfig.mode !== 'view');
}
- if (appType === 'pdf' && (config.type === 'mobile' || config.type === 'embedded')) {
- appType = 'word';
+ if (type && typeof type[2] === 'string') { // djvu|xps|oxps
+ appType = config.type === 'mobile' || config.type === 'embedded' ? 'word' : 'pdf';
+ } else if (type && typeof type[1] === 'string') { // pdf - need check
+ isForm = config.document ? config.document.isForm : undefined;
+ if (config.type === 'embedded')
+ appType = fillForms && isForm===undefined ? 'common' : 'word';
+ else if (config.type !== 'mobile')
+ appType = isForm===undefined ? 'common' : isForm ? 'word' : 'pdf';
+ } else {
+ if (typeof config.documentType === 'string')
+ appType = config.documentType.toLowerCase();
+ else {
+ if (type && typeof type[3] === 'string') appType = 'cell'; else
+ if (type && typeof type[4] === 'string') appType = 'slide';
+ }
}
+ path += appMap[appType];
- path += appMap[appType] + "/";
- const path_type = config.type === "mobile"
- ? "mobile" : (config.type === "embedded")
- ? "embed" : "main";
+ const path_type = config.type === "mobile" ? "mobile" :
+ config.type === "embedded" ? (fillForms && isForm ? "forms" : "embed") : "main";
+ if (appType !== 'common')
+ path += "/" + path_type;
- path += path_type;
var index = "/index.html";
- if (config.editorConfig && path_type!=="forms") {
+ if (config.editorConfig && path_type!=="forms" && appType!=='common') {
var customization = config.editorConfig.customization;
if ( typeof(customization) == 'object' && ( customization.toolbarNoTabs ||
- (config.editorConfig.targetApp!=='desktop') && (customization.loaderName || customization.loaderLogo))) {
+ (config.editorConfig.targetApp!=='desktop') && (customization.loaderName || customization.loaderLogo))) {
index = "/index_loader.html";
} else if (config.editorConfig.mode === 'editdiagram' || config.editorConfig.mode === 'editmerge' || config.editorConfig.mode === 'editole')
index = "/index_internal.html";
-
}
path += index;
return path;
@@ -1032,6 +1059,9 @@
if (config.editorConfig && (config.editorConfig.mode == 'editdiagram' || config.editorConfig.mode == 'editmerge' || config.editorConfig.mode == 'editole'))
params += "&internal=true";
+ if (config.type)
+ params += "&type=" + config.type;
+
if (config.frameEditorId)
params += "&frameEditorId=" + config.frameEditorId;
@@ -1060,6 +1090,12 @@
if (config.document && config.document.fileType)
params += "&fileType=" + config.document.fileType;
+ if (config.editorConfig) {
+ var customization = config.editorConfig.customization;
+ if ( customization && typeof(customization) == 'object' && ( customization.toolbarNoTabs || (config.editorConfig.targetApp!=='desktop') && (customization.loaderName || customization.loaderLogo))) {
+ params += "&indexPostfix=_loader";
+ }
+ }
return params;
}
@@ -1087,12 +1123,11 @@
return iframe;
}
- function postMessage(wnd, msg) {
+ function postMessage(wnd, msg, buffer) {
if (wnd && wnd.postMessage && window.JSON) {
// TODO: specify explicit origin
- wnd.postMessage(window.JSON.stringify(msg), "*");
+ buffer ? wnd.postMessage(msg, "*", [buffer]) : wnd.postMessage(window.JSON.stringify(msg), "*");
}
-
}
function extend(dest, src) {
diff --git a/apps/api/wopi/editor-wopi.ejs b/apps/api/wopi/editor-wopi.ejs
index ab427dc66a..9dcc39e4b9 100644
--- a/apps/api/wopi/editor-wopi.ejs
+++ b/apps/api/wopi/editor-wopi.ejs
@@ -219,6 +219,10 @@ div {
window.open(fileInfo.HostEditUrl, "_blank");
};
+ var onRequestSaveAs = function (event) {
+ //SaveAs work via PutRelativeFile server-server request
+ };
+
var onRequestSharingSettings = function (event) {
if (fileInfo.FileSharingPostMessage)
_postMessage('UI_Sharing', {});
@@ -243,6 +247,19 @@ div {
innerAlert(event.data);
};
+ var getWopiFileUrl = function(fileInfo, userAuth) {
+ let url;
+ if (fileInfo.FileUrl) {
+ //Requests to the FileUrl can not be signed using proof keys. The FileUrl is used exactly as provided by the host, so it does not necessarily include the access token, which is required to construct the expected proof.
+ url = fileInfo.FileUrl;
+ } else if (fileInfo.TemplateSource) {
+ url = fileInfo.TemplateSource;
+ } else if (userAuth) {
+ url = userAuth.wopiSrc + "/contents?access_token=" + userAuth.access_token;
+ }
+ return url;
+ }
+
var connectEditor = function () {
fileInfo = <%- JSON.stringify(fileInfo) %>;
@@ -276,7 +293,7 @@ div {
"token": token,
"document": {
"title": fileInfo.BreadcrumbDocName || fileInfo.BaseFileName,
- "url": userAuth.wopiSrc,
+ "url": getWopiFileUrl(fileInfo, userAuth),
"fileType": fileType,
"key": key,
"info": {
@@ -324,7 +341,8 @@ div {
"events": {
"onAppReady": onAppReady,
"onDocumentStateChange": fileInfo.EditNotificationPostMessage ? onDocumentStateChange : undefined,
- 'onRequestEditRights': fileInfo.EditModePostMessage || (fileInfo.HostEditUrl && !fileInfo.UserCanNotWriteRelative) ? onRequestEditRights : undefined,
+ 'onRequestEditRights': fileInfo.EditModePostMessage || fileInfo.HostEditUrl ? onRequestEditRights : undefined,
+ 'onRequestSaveAs': fileInfo.SupportsUpdate && !fileInfo.UserCanNotWriteRelative ? onRequestSaveAs : undefined,
"onError": onError,
"onRequestClose": fileInfo.ClosePostMessage || fileInfo.CloseUrl ? onRequestClose : undefined,
"onRequestRename": fileInfo.SupportsRename && fileInfo.UserCanRename ? onRequestRename : undefined,
@@ -372,9 +390,11 @@ div {
if (window.addEventListener) {
window.addEventListener("load", connectEditor);
window.addEventListener("resize", fixSize);
+ window.addEventListener("orientationchange", fixSize);
} else if (window.attachEvent) {
window.attachEvent("onload", connectEditor);
window.attachEvent("onresize", fixSize);
+ window.attachEvent("orientationchange", fixSize);
}
+
+
+
+
+
diff --git a/apps/common/Gateway.js b/apps/common/Gateway.js
index e2efd153d8..fa6733af22 100644
--- a/apps/common/Gateway.js
+++ b/apps/common/Gateway.js
@@ -47,6 +47,10 @@ if (window.Common === undefined) {
$me.trigger('opendocument', data);
},
+ 'openDocumentFromBinary': function(data) {
+ $me.trigger('opendocumentfrombinary', data);
+ },
+
'showMessage': function(data) {
$me.trigger('showmessage', data);
},
@@ -156,11 +160,11 @@ if (window.Common === undefined) {
}
};
- var _postMessage = function(msg) {
+ var _postMessage = function(msg, buffer) {
// TODO: specify explicit origin
if (window.parent && window.JSON) {
msg.frameEditorId = window.frameEditorId;
- window.parent.postMessage(window.JSON.stringify(msg), "*");
+ buffer ? window.parent.postMessage(msg, "*", [buffer]) : window.parent.postMessage(window.JSON.stringify(msg), "*");
}
};
@@ -169,6 +173,14 @@ if (window.Common === undefined) {
if (msg.origin !== window.parentOrigin && msg.origin !== window.location.origin && !(msg.origin==="null" && (window.parentOrigin==="file://" || window.location.origin==="file://"))) return;
var data = msg.data;
+ if (data && data.command === 'openDocumentFromBinary') {
+ handler = commandMap[data.command];
+ if (handler) {
+ handler.call(this, data.data);
+ }
+ return;
+ }
+
if (Object.prototype.toString.apply(data) !== '[object String]' || !window.JSON) {
return;
}
@@ -386,6 +398,13 @@ if (window.Common === undefined) {
_postMessage({ event: 'onPluginsReady' });
},
+ saveDocument: function(data) {
+ data && _postMessage({
+ event: 'onSaveDocument',
+ data: data.buffer
+ }, data.buffer);
+ },
+
on: function(event, handler){
var localHandler = function(event, data){
handler.call(me, data)
diff --git a/apps/common/index.html b/apps/common/index.html
new file mode 100644
index 0000000000..0a15bcbaab
--- /dev/null
+++ b/apps/common/index.html
@@ -0,0 +1,62 @@
+
+
+