Commit 85bb91dd authored by Roque's avatar Roque

erp5_officejs_ooffice: refactoring, all only office apps share common gadgets

- document view
- upload and download
parent 1ca655a3
......@@ -23,7 +23,7 @@
<script data-renderjs-configuration="app_allowed_sub_types" type="text/x-renderjs-configuration">('Document Module | Spreadsheet',)</script>
<script data-renderjs-configuration="app_view_reference" type="text/x-renderjs-configuration">ooffice_spreadsheet_view</script>
<script data-renderjs-configuration="document_module_dict" type="text/x-renderjs-configuration">{"front_page": 1, "editable": 0, "hide_add_button": 0, "jump_button": 0, "fast_input_button": 0, "export_button": 0, "filter_action": 1, "panel_action": 1, "previous_next_button": 0, "history_previous_link": 0, "title": "Spreadsheets", "hide_listbox_buttons": 1, "blob_type": "", "blob_create_object_url": 0, "file_extension": "xlsy"}</script>
<script data-renderjs-configuration="spreadsheet_dict" type="text/x-renderjs-configuration"> {"front_page": 0, "editable": 1, "hide_add_button": 0, "jump_button": 0, "fast_input_button": 0, "export_button": 0, "filter_action": 0, "panel_action": 1, "previous_next_button": 1, "history_previous_link": 1, "title": "Spreadsheet", "hide_listbox_buttons": 1, "blob_type": "", "blob_create_object_url": 0, "file_extension": "xlsy", "custom_view_gadget": "only_office_document_view.html"}</script>
<script data-renderjs-configuration="spreadsheet_dict" type="text/x-renderjs-configuration"> {"front_page": 0, "editable": 1, "hide_add_button": 0, "jump_button": 0, "fast_input_button": 0, "export_button": 0, "filter_action": 0, "panel_action": 1, "previous_next_button": 1, "history_previous_link": 1, "title": "Spreadsheet", "hide_listbox_buttons": 1, "blob_type": "application/x-asc-spreadsheet", "blob_create_object_url": 0, "file_extension": "xlsy", "custom_view_gadget": "only_office_document_view.html"}</script>
<script data-renderjs-configuration="erp5_attachment_synchro" type="text/x-renderjs-configuration">/{+id}/Document_downloadForOnlyOfficeApp</script>
<script data-renderjs-configuration="dropbox_app_key" type="text/x-renderjs-configuration">hxq0vjiu9v0r4mu</script>
<script data-renderjs-configuration="content_type" type="text/x-renderjs-configuration">application/x-asc-spreadsheet</script>
......
......@@ -241,7 +241,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>978.36906.26142.38092</string> </value>
<value> <string>978.54003.36064.54033</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -259,7 +259,7 @@
</tuple>
<state>
<tuple>
<float>1569594974.27</float>
<float>1569922449.65</float>
<string>UTC</string>
</tuple>
</state>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Folder" module="OFS.Folder"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_local_properties</string> </key>
<value>
<tuple>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>business_template_skin_layer_priority</string> </value>
</item>
<item>
<key> <string>type</string> </key>
<value> <string>float</string> </value>
</item>
</dictionary>
</tuple>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>business_template_skin_layer_priority</string> </key>
<value> <float>42.0</float> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>erp5_ooffice_common</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -81,7 +81,13 @@
.push(function (result) {
state_dict.data = result.target.result;
state_dict.blob_type = portal_type_dict.blob_type;
if (!state_dict.blob_type) {
state_dict.blob_type = "application/x-asc-ooffice";
}
return form_view_gadget.changeState(state_dict);
}, function (error) {
console.log("ERROR rendering custom view");
throw error;
});
});
})
......
/*global document, window, rJS, RSVP, jIO, Blob */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (document, window, rJS, RSVP, jIO, Blob) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod('render', function (options) {
var gadget = this,
state_dict = {
doc: options.doc,
form_definition: options.form_definition,
child_gadget_url: options.child_gadget_url,
options: options
},
portal_type_dict = options.form_definition.portal_type_dict,
form_view_div = document.createElement('div'),
extension,
blob;
return gadget.getSetting("file_extension")
.push(function (file_extension) {
if (file_extension.substring(file_extension.length - 1) == "y") {
file_extension = file_extension.replace(/.$/, "x");
}
extension = file_extension;
gadget.element.appendChild(form_view_div);
return gadget.declareGadget("gadget_officejs_form_view.html",
{element: form_view_div, scope: 'form_view'});
})
.push(function (form_view_gadget) {
if (!state_dict.doc.filename) {
state_dict.doc.filename = "default." + extension;
}
state_dict.mime_type = portal_type_dict.file_extension;
if (options.doc.action) {
return form_view_gadget.changeState(state_dict);
}
state_dict.content_editable = options.doc.content_type === undefined ||
options.doc.content_type.indexOf("application/x-asc") === 0;
return new RSVP.Queue()
.push(function () {
if (!state_dict.content_editable) {
return gadget.jio_getAttachment(options.jio_key, "data");
}
return gadget.declareGadget("gadget_ojs_cloudooo.html")
.push(function (ojs_cloudooo) {
return ojs_cloudooo.getConvertedBlob({
jio_key: options.jio_key,
format: state_dict.mime_type,
filename: options.doc.filename
});
});
})
.push(undefined, function (error) {
if (error instanceof jIO.util.jIOError &&
error.status_code === 404) {
return new Blob();
}
throw error;
})
.push(function (blob) {
if (state_dict.content_editable) {
return jIO.util.readBlobAsDataURL(blob);
}
return jIO.util.readBlobAsText(blob);
})
.push(function (result) {
state_dict.data = result.target.result;
state_dict.blob_type = portal_type_dict.blob_type;
return form_view_gadget.changeState(state_dict);
});
});
})
.declareMethod("triggerSubmit", function () {
var argument_list = arguments, gadget = this, child_gadget, view_gadget, content_dict, data, name_list;
return gadget.notifySubmitting()
.push(function (view_gadget) {
return gadget.getDeclaredGadget('form_view');
})
.push(function (result) {
view_gadget = result;
return view_gadget.getDeclaredGadget('erp5_pt_gadget');
})
.push(function (result) {
child_gadget = result;
if (!child_gadget.state.editable) {
return child_gadget.triggerSubmit(argument_list);
}
return child_gadget.getContent();
})
.push(function (result) {
content_dict = result;
if (!content_dict) { return; }
data = content_dict.text_content;
delete content_dict.text_content;
name_list = view_gadget.state.doc.filename.split('.');
if (name_list.pop() !== view_gadget.state.mime_type) {
name_list.push(view_gadget.state.mime_type);
content_dict.filename = name_list.join('.');
}
return gadget.getSetting("content_type");
})
.push(function (content_type) {
content_dict.content_type = content_type;
return child_gadget.submitContent(
child_gadget.state.jio_key, undefined, content_dict
);
})
.push(function () {
return gadget
.jio_putAttachment(child_gadget.state.jio_key, 'data',
jIO.util.dataURItoBlob(data))
.push(function () {
return gadget.declareGadget("gadget_ojs_cloudooo.html");
})
.push(function (cloudooo) {
return cloudooo
.putAllCloudoooConvertionOperation({
format: view_gadget.state.mime_type,
jio_key: child_gadget.state.jio_key
});
});
}, function (error) {
console.log(error);
return gadget.notifySubmitted({
message: "Submit failed",
status: "error"
});
});
});
}(document, window, rJS, RSVP, jIO, Blob));
\ No newline at end of file
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>OfficeJS Document View</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="only_office_document_view.js"></script>
</head>
<body>
<form class="save_form ui-body-c" novalidate>
</form>
</body>
</html>
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__name__</string> </key>
<value> <string>only_office_document_view.html</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
/*global document, window, rJS, RSVP, jIO, Blob */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (document, window, rJS, RSVP, jIO, Blob) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod('render', function (options) {
var gadget = this,
state_dict = {
doc: options.doc,
form_definition: options.form_definition,
child_gadget_url: options.child_gadget_url,
options: options
},
portal_type_dict = options.form_definition.portal_type_dict,
form_view_div = document.createElement('div'),
extension,
blob;
return gadget.getSetting("file_extension")
.push(function (file_extension) {
if (file_extension.substring(file_extension.length - 1) == "y") {
file_extension = file_extension.replace(/.$/, "x");
}
extension = file_extension;
gadget.element.appendChild(form_view_div);
return gadget.declareGadget("gadget_officejs_form_view.html",
{element: form_view_div, scope: 'form_view'});
})
.push(function (form_view_gadget) {
if (!state_dict.doc.filename) {
state_dict.doc.filename = "default." + extension;
}
state_dict.mime_type = portal_type_dict.file_extension;
if (options.doc.action) {
return form_view_gadget.changeState(state_dict);
}
state_dict.content_editable = options.doc.content_type === undefined ||
options.doc.content_type.indexOf("application/x-asc") === 0;
return new RSVP.Queue()
.push(function () {
if (!state_dict.content_editable) {
return gadget.jio_getAttachment(options.jio_key, "data");
}
return gadget.declareGadget("gadget_ojs_cloudooo.html")
.push(function (ojs_cloudooo) {
return ojs_cloudooo.getConvertedBlob({
jio_key: options.jio_key,
format: state_dict.mime_type,
filename: options.doc.filename
});
});
})
.push(undefined, function (error) {
if (error instanceof jIO.util.jIOError &&
error.status_code === 404) {
return new Blob();
}
throw error;
})
.push(function (blob) {
if (state_dict.content_editable) {
return jIO.util.readBlobAsDataURL(blob);
}
return jIO.util.readBlobAsText(blob);
})
.push(function (result) {
state_dict.data = result.target.result;
state_dict.blob_type = portal_type_dict.blob_type;
return form_view_gadget.changeState(state_dict);
});
});
})
.declareMethod("triggerSubmit", function () {
var argument_list = arguments, gadget = this, child_gadget, view_gadget, content_dict, data, name_list;
return gadget.notifySubmitting()
.push(function (view_gadget) {
return gadget.getDeclaredGadget('form_view');
})
.push(function (result) {
view_gadget = result;
return view_gadget.getDeclaredGadget('erp5_pt_gadget');
})
.push(function (result) {
child_gadget = result;
if (!child_gadget.state.editable) {
return child_gadget.triggerSubmit(argument_list);
}
return child_gadget.getContent();
})
.push(function (result) {
content_dict = result;
if (!content_dict) { return; }
data = content_dict.text_content;
delete content_dict.text_content;
name_list = view_gadget.state.doc.filename.split('.');
if (name_list.pop() !== view_gadget.state.mime_type) {
name_list.push(view_gadget.state.mime_type);
content_dict.filename = name_list.join('.');
}
return gadget.getSetting("content_type");
})
.push(function (content_type) {
content_dict.content_type = content_type;
return child_gadget.submitContent(
child_gadget.state.jio_key, undefined, content_dict
);
})
.push(function () {
return gadget
.jio_putAttachment(child_gadget.state.jio_key, 'data',
jIO.util.dataURItoBlob(data))
.push(function () {
return gadget.declareGadget("gadget_ojs_cloudooo.html");
})
.push(function (cloudooo) {
return cloudooo
.putAllCloudoooConvertionOperation({
format: view_gadget.state.mime_type,
jio_key: child_gadget.state.jio_key
});
});
}, function (error) {
console.log(error);
return gadget.notifySubmitted({
message: "Submit failed",
status: "error"
});
});
});
}(document, window, rJS, RSVP, jIO, Blob));
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__name__</string> </key>
<value> <string>only_office_document_view.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Only OfficeJS Texteditor Download Action</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="ooffice_download_action.js"></script>
</head>
<body>
</body>
</html>
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__name__</string> </key>
<value> <string>ooffice_download_action.html</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
/*global window, rJS, document, RSVP, jIO */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, document, RSVP, jIO) {
"use strict";
function downloadFromBlob(gadget, parent_options, blob, format) {
var element = gadget.element,
a = window.document.createElement("a"),
url = window.URL.createObjectURL(blob),
name_list;
if (parent_options.download_format) {
return gadget.jio_get(parent_options.jio_key)
.push(function (jio_document) {
name_list = jio_document.filename.split('.');
name_list[name_list.length - 1] = format;
element.appendChild(a);
a.style = "display: none";
a.href = url;
a.download = name_list.join('.');
a.click();
element.removeChild(a);
window.URL.revokeObjectURL(url);
});
}
name_list = parent_options.doc.filename.split('.');
name_list[name_list.length - 1] = format;
element.appendChild(a);
a.style = "display: none";
a.href = url;
a.download = name_list.join('.');
a.click();
element.removeChild(a);
window.URL.revokeObjectURL(url);
}
function downloadFromFormat(gadget, parent_options, format) {
var action_options = parent_options.action_options,
fragment = document.createElement('div'), jio_key;
if (!action_options) {
action_options = parent_options;
}
jio_key = action_options.jio_key;
gadget.element.appendChild(fragment);
return gadget.declareGadget("gadget_ojs_cloudooo.html",
{element: fragment, scope: 'ojs_cloudooo'})
.push(function (ojs_cloudooo) {
action_options.download_format = format;
return ojs_cloudooo.getConvertedBlob({
jio_key: jio_key,
format: format,
redirect: jIO.util.stringify({
'command': 'display',
'options': action_options
})
});
})
.push(function (result) {
return downloadFromBlob(gadget, parent_options, result, format);
});
}
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("preRenderDocument", function (parent_options) {
var gadget = this, format_list, conversion_dict, doc;
return gadget.getSetting('conversion_dict')
.push(function (result) {
conversion_dict = result;
return gadget.getSetting('file_extension');
})
.push(function (format) {
format_list = window.JSON.parse(conversion_dict)[format];
format_list.push(format);
doc = { title: parent_options.form_definition.title,
action: true,
format: format_list };
if (parent_options.download_format) {
return downloadFromFormat(gadget, parent_options, parent_options.download_format);
}
})
.push(function () {
return doc;
});
})
.declareMethod('handleSubmit', function (content_dict, parent_options) {
//must return a dict with:
//notify: options_dict for notifySubmitted
//redirect: options_dict for redirect
var return_submit_dict = {
notify: {
message: "",
status: ""
},
redirect: {
command: 'display',
options: {}
}
}, gadget = this;
return downloadFromFormat(gadget, parent_options, content_dict.format)
.push(function () {
return return_submit_dict;
}, function (error) {
if (error instanceof jIO.util.jIOError) {
return_submit_dict.notify.message = "Conversion Failed";
return_submit_dict.notify.status = "error";
return return_submit_dict;
}
throw error;
});
});
}(window, rJS, document, RSVP, jIO));
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__name__</string> </key>
<value> <string>ooffice_download_action.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Only OfficeJS Texteditor Update Action</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="ooffice_upload_action.js"></script>
</head>
<body>
</body>
</html>
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__name__</string> </key>
<value> <string>ooffice_upload_action.html</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
/*global window, rJS, document, RSVP, jIO */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, document, RSVP, jIO) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("preRenderDocument", function (parent_options) {
return this.getSetting('upload_dict')
.push(function (upload_dict) {
var upload = window.JSON.parse(upload_dict),
doc = { title: parent_options.form_definition.title,
action: true,
format: window.Object.keys(upload).join(', ') };
return doc;
});
})
.declareMethod('handleSubmit', function (content_dict, parent_options) {
//must return a dict with:
//notify: options_dict for notifySubmitted
//redirect: options_dict for redirect
var return_submit_dict = {
notify: {
message: "",
status: ""
},
redirect: {
command: 'display',
options: {}
}
}, gadget = this;
return RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getSetting('portal_type'),
gadget.getSetting('content_type'),
gadget.getSetting('file_extension'),
gadget.getSetting('parent_relative_url'),
gadget.getSetting('upload_dict')
]);
})
.push(function (result) {
var upload = window.JSON.parse(result[4]),
ATT_NAME = "data", file_name_list, from, jio_key, data, to, att_name = ATT_NAME, filename;
if (content_dict.file !== undefined) {
file_name_list = content_dict.file.file_name.split('.');
from = file_name_list.pop();
file_name_list.push(result[2]);
filename = file_name_list.join('.');
data = jIO.util.dataURItoBlob(content_dict.file.url);
if (upload.hasOwnProperty(from)) {
if (result[2] !== from) {
att_name = from;
}
to = upload[from];
return gadget.jio_post({
title: filename,
portal_type: result[0],
content_type: result[1],
filename: filename,
parent_relative_url: result[3]
})
.push(function (doc_id) {
jio_key = doc_id;
return gadget.jio_putAttachment(jio_key, att_name, data);
})
.push(function () {
if (result[2] === from) {
return_submit_dict.notify.message = "Data Updated";
return_submit_dict.notify.status = "success";
return_submit_dict.redirect.options = {
jio_key: jio_key,
editable: true
};
return return_submit_dict;
}
var fragment = document.createElement('div');
gadget.element.appendChild(fragment);
return gadget.declareGadget("gadget_ojs_cloudooo.html",
{element: fragment, scope: 'ojs_cloudooo'})
.push(function (ojs_cloudooo) {
return RSVP.all([
ojs_cloudooo.putCloudoooConvertOperation({
status: "convert",
from: from,
to: to,
id: jio_key,
name: att_name,
to_name: ATT_NAME
}),
ojs_cloudooo.putCloudoooConvertOperation({
status: "converted",
from: to,
to: from,
id: jio_key,
name: ATT_NAME
})
]);
})
.push(function () {
return gadget.redirect({
'command': 'display',
'options': {
'page': 'ojs_sync',
'auto_repair': true
}
});
});
})
.push(function () {
return_submit_dict.notify.message = "Data Updated";
return_submit_dict.notify.status = "success";
return_submit_dict.redirect.options = {
'command': 'display',
'options': {
'jio_key': jio_key
}
};
return return_submit_dict;
});
}
return_submit_dict.notify.message = "Can not convert, use format : " +
window.Object.keys(upload).join(', ');
return_submit_dict.notify.status = "error";
return return_submit_dict;
}
return_submit_dict.notify.message = "File is required";
return_submit_dict.notify.status = "error";
return return_submit_dict;
});
});
}(window, rJS, document, RSVP, jIO));
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__name__</string> </key>
<value> <string>ooffice_upload_action.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>OfficeJS Document View</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="only_office_document_view.js"></script>
</head>
<body>
<form class="save_form ui-body-c" novalidate>
</form>
</body>
</html>
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__name__</string> </key>
<value> <string>only_office_document_view.html</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__name__</string> </key>
<value> <string>only_office_document_view.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Only OfficeJS Texteditor Download Action</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="ooffice_download_action.js"></script>
</head>
<body>
</body>
</html>
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__name__</string> </key>
<value> <string>ooffice_download_action.html</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
/*global window, rJS, document, RSVP, jIO */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, document, RSVP, jIO) {
"use strict";
function downloadFromBlob(gadget, parent_options, blob, format) {
var element = gadget.element,
a = window.document.createElement("a"),
url = window.URL.createObjectURL(blob),
name_list;
if (parent_options.download_format) {
return gadget.jio_get(parent_options.jio_key)
.push(function (jio_document) {
name_list = jio_document.filename.split('.');
name_list[name_list.length - 1] = format;
element.appendChild(a);
a.style = "display: none";
a.href = url;
a.download = name_list.join('.');
a.click();
element.removeChild(a);
window.URL.revokeObjectURL(url);
});
}
name_list = parent_options.doc.filename.split('.');
name_list[name_list.length - 1] = format;
element.appendChild(a);
a.style = "display: none";
a.href = url;
a.download = name_list.join('.');
a.click();
element.removeChild(a);
window.URL.revokeObjectURL(url);
}
function downloadFromFormat(gadget, parent_options, format) {
var action_options = parent_options.action_options,
fragment = document.createElement('div'), jio_key;
if (!action_options) {
action_options = parent_options;
}
jio_key = action_options.jio_key;
gadget.element.appendChild(fragment);
return gadget.declareGadget("gadget_ojs_cloudooo.html",
{element: fragment, scope: 'ojs_cloudooo'})
.push(function (ojs_cloudooo) {
action_options.download_format = format;
return ojs_cloudooo.getConvertedBlob({
jio_key: jio_key,
format: format,
redirect: jIO.util.stringify({
'command': 'display',
'options': action_options
})
});
})
.push(function (result) {
return downloadFromBlob(gadget, parent_options, result, format);
});
}
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("preRenderDocument", function (parent_options) {
var gadget = this, format_list, conversion_dict, doc;
return gadget.getSetting('conversion_dict')
.push(function (result) {
conversion_dict = result;
return gadget.getSetting('file_extension');
})
.push(function (format) {
format_list = window.JSON.parse(conversion_dict)[format];
format_list.push(format);
doc = { title: parent_options.form_definition.title,
action: true,
format: format_list };
if (parent_options.download_format) {
return downloadFromFormat(gadget, parent_options, parent_options.download_format);
}
})
.push(function () {
return doc;
});
})
.declareMethod('handleSubmit', function (content_dict, parent_options) {
//must return a dict with:
//notify: options_dict for notifySubmitted
//redirect: options_dict for redirect
var return_submit_dict = {
notify: {
message: "",
status: ""
},
redirect: {
command: 'display',
options: {}
}
}, gadget = this;
return downloadFromFormat(gadget, parent_options, content_dict.format)
.push(function () {
return return_submit_dict;
}, function (error) {
if (error instanceof jIO.util.jIOError) {
return_submit_dict.notify.message = "Conversion Failed";
return_submit_dict.notify.status = "error";
return return_submit_dict;
}
throw error;
});
});
}(window, rJS, document, RSVP, jIO));
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__name__</string> </key>
<value> <string>ooffice_download_action.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Only OfficeJS Texteditor Update Action</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="ooffice_upload_action.js"></script>
</head>
<body>
</body>
</html>
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__name__</string> </key>
<value> <string>ooffice_upload_action.html</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
/*global window, rJS, document, RSVP, jIO */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, document, RSVP, jIO) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("preRenderDocument", function (parent_options) {
return this.getSetting('upload_dict')
.push(function (upload_dict) {
var upload = window.JSON.parse(upload_dict),
doc = { title: parent_options.form_definition.title,
action: true,
format: window.Object.keys(upload).join(', ') };
return doc;
});
})
.declareMethod('handleSubmit', function (content_dict, parent_options) {
//must return a dict with:
//notify: options_dict for notifySubmitted
//redirect: options_dict for redirect
var return_submit_dict = {
notify: {
message: "",
status: ""
},
redirect: {
command: 'display',
options: {}
}
}, gadget = this;
return RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getSetting('portal_type'),
gadget.getSetting('content_type'),
gadget.getSetting('file_extension'),
gadget.getSetting('parent_relative_url'),
gadget.getSetting('upload_dict')
]);
})
.push(function (result) {
var upload = window.JSON.parse(result[4]),
ATT_NAME = "data", file_name_list, from, jio_key, data, to, att_name = ATT_NAME, filename;
if (content_dict.file !== undefined) {
file_name_list = content_dict.file.file_name.split('.');
from = file_name_list.pop();
file_name_list.push(result[2]);
filename = file_name_list.join('.');
data = jIO.util.dataURItoBlob(content_dict.file.url);
if (upload.hasOwnProperty(from)) {
if (result[2] !== from) {
att_name = from;
}
to = upload[from];
return gadget.jio_post({
title: filename,
portal_type: result[0],
content_type: result[1],
filename: filename,
parent_relative_url: result[3]
})
.push(function (doc_id) {
jio_key = doc_id;
return gadget.jio_putAttachment(jio_key, att_name, data);
})
.push(function () {
if (result[2] === from) {
return_submit_dict.notify.message = "Data Updated";
return_submit_dict.notify.status = "success";
return_submit_dict.redirect.options = {
jio_key: jio_key,
editable: true
};
return return_submit_dict;
}
var fragment = document.createElement('div');
gadget.element.appendChild(fragment);
return gadget.declareGadget("gadget_ojs_cloudooo.html",
{element: fragment, scope: 'ojs_cloudooo'})
.push(function (ojs_cloudooo) {
return RSVP.all([
ojs_cloudooo.putCloudoooConvertOperation({
status: "convert",
from: from,
to: to,
id: jio_key,
name: att_name,
to_name: ATT_NAME
}),
ojs_cloudooo.putCloudoooConvertOperation({
status: "converted",
from: to,
to: from,
id: jio_key,
name: ATT_NAME
})
]);
})
.push(function () {
return gadget.redirect({
'command': 'display',
'options': {
'page': 'ojs_sync',
'auto_repair': true
}
});
});
})
.push(function () {
return_submit_dict.notify.message = "Data Updated";
return_submit_dict.notify.status = "success";
return_submit_dict.redirect.options = {
'command': 'display',
'options': {
'jio_key': jio_key
}
};
return return_submit_dict;
});
}
return_submit_dict.notify.message = "Can not convert, use format : " +
window.Object.keys(upload).join(', ');
return_submit_dict.notify.status = "error";
return return_submit_dict;
}
return_submit_dict.notify.message = "File is required";
return_submit_dict.notify.status = "error";
return return_submit_dict;
});
});
}(window, rJS, document, RSVP, jIO));
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__name__</string> </key>
<value> <string>ooffice_upload_action.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
erp5_ooffice_common
erp5_ooffice_presentation_editor
erp5_ooffice_spreadsheet_editor
erp5_ooffice_text_editor
erp5_ooffice_text_editor
\ No newline at end of file
......@@ -29,7 +29,7 @@
</tr>
<tr>
<td>open</td>
<td>${base_url}/portal_skins/erp5_officejs_ui_test/gadget_ooffice_upload_erp5.html</td>
<td>${base_url}/portal_skins/erp5_officejs_ui_test/gadget_ooffice_spreadsheet_upload.html</td>
<td></td>
</tr>
<tr>
......@@ -43,7 +43,28 @@
<td>install_url</td>
</tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForOfficejsUi/macros/wait_install" />
<tal:block metal:use-macro="here/Zuite_CommonTemplateForOnlyOffice/macros/choice_erp5_storage"/>
<tr>
<td>waitForElementPresent</td>
<td>//a[@data-i18n="Storages"]</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//a[@data-i18n="Storages"]</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//a[text()='Local is Enough']</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//a[text()='Local is Enough']</td>
<td></td>
</tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_listbox_loaded"/>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForOnlyOffice/macros/open_document_with_title"/>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForOnlyOffice/macros/wait_for_load_spreadsheet"/>
\ No newline at end of file
......@@ -25,7 +25,26 @@
<td>title</td>
</tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForOfficejsUi/macros/wait_install" />
<tal:block metal:use-macro="here/Zuite_CommonTemplateForOnlyOffice/macros/choice_erp5_storage"/>
<tr>
<td>waitForElementPresent</td>
<td>//a[@data-i18n="Storages"]</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//a[@data-i18n="Storages"]</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//a[text()='Local is Enough']</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//a[text()='Local is Enough']</td>
<td></td>
</tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_listbox_loaded"/>
<tr>
<td>open</td>
......@@ -42,8 +61,11 @@
<tal:block metal:use-macro="here/Zuite_CommonTemplateForOnlyOffice/macros/synchronize"/>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_listbox_loaded"/>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForOnlyOffice/macros/open_document_with_title"/>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForOnlyOffice/macros/wait_for_load_spreadsheet"/>
<tr>
<td>waitForTextPresent</td>
<td>not supported format of document</td>
<td></td>
</tr>
</tbody>
</table>
</body>
......
......@@ -7,16 +7,19 @@
.declareService(function () {
var storage = jIO.createJIO({
type: "indexeddb",
database: "officejs-erp5"
database: "local_default"
}),
gadget = this;
return storage.put('bad_document', {
'content_type': "application/x-asc-spreadsheet",
'description': '',
'filename': 'test.xlsx',
'language': '',
'reference': 'bad_document_ooffice_upload',
'title': 'Bad Document',
'filename': 'test.xlsx',
'portal_type': 'Spreadsheet',
'parent_relative_url': "document_module",
'content_type': "application/x-asc-spreadsheet",
'version': '',
'modification_date': 'Fri, 17 Aug 2018 11:21:22 +0000'
})
.push(function (id) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment