2021-02-08 17:59:31 +01:00
|
|
|
(function() {
|
|
|
|
var OnlyOffice;
|
|
|
|
|
|
|
|
OnlyOffice = class OnlyOffice extends this.OS.application.BaseApplication {
|
|
|
|
constructor(args) {
|
|
|
|
super("OnlyOffice", args);
|
2021-02-09 19:41:47 +01:00
|
|
|
this.eid = `id${Math.random().toString(36).replace(".", "")}`;
|
2021-02-08 17:59:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
|
|
|
var placeholder;
|
2021-02-09 19:41:47 +01:00
|
|
|
this.currfile = void 0;
|
|
|
|
if (this.args && this.args.length > 0) {
|
|
|
|
this.currfile = this.args[0].path.asFileHandle();
|
|
|
|
}
|
2021-02-08 17:59:31 +01:00
|
|
|
placeholder = this.find("editor-area");
|
2021-02-09 19:41:47 +01:00
|
|
|
placeholder.id = this.eid;
|
|
|
|
if (this.currfile) {
|
|
|
|
return this.open();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
open() {
|
|
|
|
if (!this.currfile) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
console.log(this.currfile);
|
|
|
|
return this.exec("token", {
|
|
|
|
file: this.currfile.path
|
|
|
|
}).then((d) => {
|
|
|
|
if (d.error) {
|
|
|
|
return this.error(d.error);
|
|
|
|
}
|
|
|
|
this.access_token = d.result;
|
|
|
|
return this.currfile.onready().then((meta) => {
|
|
|
|
if (this.editor) {
|
|
|
|
//@scheme.apptitle = @currfile.path
|
|
|
|
this.editor.destroyEditor();
|
|
|
|
}
|
|
|
|
return this.editor = new DocsAPI.DocEditor(this.eid, {
|
|
|
|
events: {
|
|
|
|
onRequestCreateNew: () => {
|
|
|
|
return this.newDocument();
|
|
|
|
},
|
|
|
|
onRequestSaveAs: (e) => {
|
|
|
|
return console.log(e);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
document: {
|
|
|
|
fileType: this.currfile.ext,
|
|
|
|
key: meta.mtime.hash().toString(),
|
|
|
|
title: this.currfile.path,
|
|
|
|
url: this.currfile.getlink() + "?" + this.access_token
|
|
|
|
},
|
|
|
|
documentType: this.getDocType(this.currfile.ext),
|
|
|
|
editorConfig: {
|
|
|
|
user: {
|
|
|
|
id: this.systemsetting.user.id.toString(),
|
|
|
|
name: this.systemsetting.user.username
|
|
|
|
},
|
|
|
|
customization: {
|
|
|
|
compactHeader: false
|
|
|
|
},
|
|
|
|
//autosave: false,
|
|
|
|
//forcesave: true
|
|
|
|
callbackUrl: this.uapi("save")
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}).catch((e) => {
|
|
|
|
return this.error(e.toString(), e);
|
2021-02-08 17:59:31 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-09 19:41:47 +01:00
|
|
|
getDocType(ext) {
|
|
|
|
if ("doc,docx,epub,odt".split(",").includes(ext)) {
|
|
|
|
return "word";
|
|
|
|
}
|
|
|
|
if ("csv,ods,xls,xlsx".split(",").includes(ext)) {
|
|
|
|
return "cell";
|
|
|
|
}
|
|
|
|
if ("odp,ppt,pptx".split(",").includes(ext)) {
|
|
|
|
return "slide";
|
|
|
|
}
|
|
|
|
return "none";
|
|
|
|
}
|
|
|
|
|
|
|
|
saveAs(e) {
|
|
|
|
return console.log(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
newDocument() {
|
|
|
|
console.log("create document");
|
|
|
|
return this.error(__("Unable to create document"));
|
|
|
|
}
|
|
|
|
|
|
|
|
uapi(action) {
|
|
|
|
return `${this._api.REST}/system/apigateway?ws=0&path=${this.path()}/api.lua&action=${action}&file=${this.currfile.path}&${this.access_token}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
exec(action, args) {
|
|
|
|
var cmd;
|
|
|
|
cmd = {
|
|
|
|
path: `${this.path()}/api.lua`,
|
|
|
|
parameters: {
|
|
|
|
action: action,
|
|
|
|
args: args
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return this.call(cmd);
|
|
|
|
}
|
|
|
|
|
2021-02-08 17:59:31 +01:00
|
|
|
cleanup() {
|
|
|
|
if (this.editor) {
|
|
|
|
this.editor.destroyEditor();
|
|
|
|
}
|
|
|
|
return this.editor = void 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2021-02-09 19:41:47 +01:00
|
|
|
OnlyOffice.dependencies = ["https://office.iohub.dev/web-apps/apps/api/documents/api.js"];
|
2021-02-08 17:59:31 +01:00
|
|
|
|
|
|
|
this.OS.register("OnlyOffice", OnlyOffice);
|
|
|
|
|
2021-02-09 19:41:47 +01:00
|
|
|
this.extensionParams = {
|
|
|
|
url: "https://office.iohub.dev/web-apps/"
|
|
|
|
};
|
|
|
|
|
2021-02-08 17:59:31 +01:00
|
|
|
}).call(this);
|