Commit ab420147 authored by Roque's avatar Roque

erp5_officejs: migrate notebook app to use latest officejs approach

parent 9bbbf3d6
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Action Information" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/object_jio_search</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>notebook_editor_view</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Action Information</string> </value>
</item>
<item>
<key> <string>reference</string> </key>
<value> <string>notebook_editor_view</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>View</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Expression" module="Products.CMFCore.Expression"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:${object_url}/NotebookModule_viewNotebookListAsJioForNotebookEditor</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Action Information" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>action_permission</string> </key>
<value>
<tuple>
<string>Add portal content</string>
</tuple>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/object_jio_js_script</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>notebook_upload</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Action Information</string> </value>
</item>
<item>
<key> <string>reference</string> </key>
<value> <string>notebook_upload</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Upload</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Expression" module="Products.CMFCore.Expression"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:${object_url}/Base_uploadDialogForNotebookEditor</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Action Information" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>action_permission</string> </key>
<value>
<tuple>
<string>Add portal content</string>
</tuple>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/object_jio_js_script</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>notebook_download</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Action Information</string> </value>
</item>
<item>
<key> <string>reference</string> </key>
<value> <string>notebook_download</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Download</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Expression" module="Products.CMFCore.Expression"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:${object_url}/Base_downloadDialogForNotebookEditor</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Action Information" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>action_permission</string> </key>
<value>
<tuple>
<string>Add portal content</string>
</tuple>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/object_jio_js_script</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>notebook_editor_clone</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Action Information</string> </value>
</item>
<item>
<key> <string>reference</string> </key>
<value> <string>notebook_editor_clone</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Clone</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Expression" module="Products.CMFCore.Expression"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:${object_url}/Base_cloneNotebookForNotebookEditor</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Action Information" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/object_jio_view</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>notebook_editor_view</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Action Information</string> </value>
</item>
<item>
<key> <string>reference</string> </key>
<value> <string>notebook_editor_view</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>View</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Expression" module="Products.CMFCore.Expression"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:${object_url}/Notebook_viewAsJioForNotebookEditor</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -14,12 +14,18 @@
</head>
<body>
<script data-renderjs-configuration="configuration_manifest" type="text/x-renderjs-configuration">gadget_officejs_notebook_editor.configuration</script>
<script data-renderjs-configuration="portal_type" type="text/x-renderjs-configuration">Notebook</script>
<script data-renderjs-configuration="document_title" type="text/x-renderjs-configuration">Notebook</script>
<script data-renderjs-configuration="document_title_plural" type="text/x-renderjs-configuration">Notebooks</script>
<script data-renderjs-configuration="parent_portal_type" type="text/x-renderjs-configuration">Notebook Module</script>
<script data-renderjs-configuration="parent_relative_url" type="text/x-renderjs-configuration">notebook_module</script>
<script data-renderjs-configuration="erp5_attachment_synchro" type="text/x-renderjs-configuration"></script>
<script data-renderjs-configuration="portal_skin_folder" type="text/x-renderjs-configuration">erp5_officejs_notebook</script>
<script data-renderjs-configuration="app_view_reference" type="text/x-renderjs-configuration">notebook_editor_view</script>
<script data-renderjs-configuration="app_actions" type="text/x-renderjs-configuration">('Notebook | notebook_editor_view', 'Notebook | notebook_editor_clone', 'Notebook | notebook_download', 'Notebook Module | notebook_editor_view', 'Notebook Module | notebook_upload')</script>
<script data-renderjs-configuration="app_allowed_sub_types" type="text/x-renderjs-configuration">('Notebook Module | Notebook',)</script>
<script data-renderjs-configuration="notebook_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": "Notebooks", "hide_listbox_buttons": 1, "blob_type": "", "blob_create_object_url": 0}</script>
<script data-renderjs-configuration="notebook_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": "Notebook", "hide_listbox_buttons": 1, "blob_type": "", "blob_create_object_url": 0}</script>
<script data-renderjs-configuration="upload_dict" type="text/x-renderjs-configuration">{"txt": "txt", "html": "html"}</script>
<script data-renderjs-configuration="erp5_attachment_synchro" type="text/x-renderjs-configuration"></script>
<script data-renderjs-configuration="dropbox_app_key" type="text/x-renderjs-configuration">82g9eir551nhovs</script>
<div data-gadget-url="gadget_erp5_router.html" data-gadget-scope="erp5_router"></div>
</body>
......
......@@ -284,7 +284,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>970.52955.27100.34065</string> </value>
<value> <string>986.55916.60780.2082</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -302,7 +302,7 @@
</tuple>
<state>
<tuple>
<float>1539094329.81</float>
<float>1601070525.42</float>
<string>UTC</string>
</tuple>
</state>
......
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>OfficeJS Notebook Download Action</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="notebook_download_action.js"></script>
</head>
<body>
</body>
</html>
\ No newline at end of file
/*global window, rJS, RSVP, Blob */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Blob) {
"use strict";
function downloadFromTextContent(gadget, text_content, title) {
var element = gadget.element,
a = window.document.createElement("a"),
url = window.URL.createObjectURL(new Blob([text_content], {type: 'text/plain'})),
name_list = [title, "txt"];
element.appendChild(a);
a.style = "display: none";
a.href = url;
a.download = name_list.join('.');
a.click();
element.removeChild(a);
window.URL.revokeObjectURL(url);
}
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_get", "jio_get")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod('preRenderDocument', function (parent_options) {
return { title: parent_options.form_definition.title,
skip_action_form: true };
})
.declareMethod('handleSubmit', function (content_dict, parent_options) {
var gadget = this,
return_submit_dict = {};
return gadget.jio_get(parent_options.action_options.jio_key)
.push(function (document) {
return downloadFromTextContent(gadget, document.text_content, document.title);
})
.push(function (jio_key) {
return_submit_dict.redirect = {
command: 'display',
options: {
jio_key: parent_options.action_options.jio_key,
editable: true
}
};
return return_submit_dict;
}, function (error) {
return_submit_dict.notify = {
message: "Failure downloading document",
status: "error"
};
return return_submit_dict;
});
});
}(window, rJS, RSVP, 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 Notebook Upload Action</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="notebook_upload_action.js"></script>
</head>
<body>
</body>
</html>
\ No newline at end of file
/*global window, rJS, RSVP, jIO, DOMParser */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, jIO, DOMParser) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getSettingList", "getSettingList")
/////////////////////////////////////////////////////////////////
// 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) {
var gadget = this,
return_submit_dict = {},
document = parent_options.doc,
all_attachments,
promise_list = [],
parent_jio_key = parent_options.action_options.jio_key,
property,
jio_key;
delete content_dict.dialog_method;
for (property in content_dict) {
if (content_dict.hasOwnProperty(property)) {
document[property] = content_dict[property];
}
}
return gadget.getSettingList(['portal_type',
'content_type',
'upload_dict',
'parent_relative_url'])
.push(function (result_list) {
var file_name_list, data, filename, queue, filetype;
if (document.file !== undefined) {
file_name_list = document.file.file_name.split('.');
filetype = file_name_list.pop();
if (filetype in window.JSON.parse(result_list[2])) {
filename = file_name_list.join('.');
data = jIO.util.dataURItoBlob(document.file.url);
return new RSVP.Queue()
.push(function () {
return jIO.util.readBlobAsText(data);
})
.push(function (evt) {
return evt.target.result;
})
.push(function (data_content) {
if (filetype === 'html') {
// In case the filetype is html, try looking for an elemnt
// with id `jsmd`, because iodide notebook saves the jsmd
// data in it.
var parser, htmlDoc;
parser = new DOMParser();
htmlDoc = parser.parseFromString(data_content, "text/html");
data_content = htmlDoc.getElementById('jsmd').textContent;
}
return gadget.jio_post({
title: filename,
portal_type: result_list[0],
content_type: result_list[1],
parent_relative_url: result_list[3],
text_content: data_content
});
})
.push(function (jio_key) {
return_submit_dict.redirect = {
command: 'display',
options: {
jio_key: jio_key,
editable: true
}
};
return return_submit_dict;
}, function (error) {
if (error instanceof jIO.util.jIOError) {
return_submit_dict.notify = {
message: "Failure uploading document",
status: "error"
};
return return_submit_dict;
}
throw error;
});
}
return_submit_dict.notify.message = "Wrong format, use format : " +
window.Object.keys(window.JSON.parse(result_list[2])).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, RSVP, jIO, DOMParser));
\ No newline at end of file
......@@ -463,7 +463,9 @@
</item>
<item>
<key> <string>configuration_webapp_manifest_url</string> </key>
<value> <string>gadget_officejs_notebook.json</string> </value>
<value>
<none/>
</value>
</item>
<item>
<key> <string>configuration_x_frame_options</string> </key>
......@@ -710,7 +712,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>985.55188.13524.39168</string> </value>
<value> <string>986.55673.4976.21401</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -728,7 +730,7 @@
</tuple>
<state>
<tuple>
<float>1600960361.5</float>
<float>1601046041.86</float>
<string>UTC</string>
</tuple>
</state>
......