Commit 593276bd authored by Roque's avatar Roque

erp5_officejs: general code cleanup and refactorign

parent 8d3a3b52
......@@ -2,7 +2,7 @@
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Action Information" module="erp5.portal_type"/>
<global name="ActionInformation" module="Products.CMFCore.ActionInformation"/>
</pickle>
<pickle>
<dictionary>
......@@ -13,20 +13,20 @@
</value>
</item>
<item>
<key> <string>action_permission</string> </key>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>Add portal content</string>
<string>action_type/object_view</string>
</tuple>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/object_jio_js_script</string>
</tuple>
</value>
<key> <string>category</string> </key>
<value> <string>object_view</string> </value>
</item>
<item>
<key> <string>condition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
......@@ -35,17 +35,19 @@
</value>
</item>
<item>
<key> <string>float_index</string> </key>
<value> <float>35.0</float> </value>
<key> <string>icon</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>text_editor_clone</string> </value>
<value> <string>definition_view</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<key> <string>permissions</string> </key>
<value>
<none/>
<tuple>
<string>View</string>
</tuple>
</value>
</item>
<item>
......@@ -53,12 +55,12 @@
<value> <string>Action Information</string> </value>
</item>
<item>
<key> <string>reference</string> </key>
<value> <string>text_editor_clone</string> </value>
<key> <string>priority</string> </key>
<value> <float>1.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Clone</string> </value>
<value> <string>View</string> </value>
</item>
<item>
<key> <string>visible</string> </key>
......@@ -75,7 +77,7 @@
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:${object_url}/TextEditor_cloneDocument</string> </value>
<value> <string>string:${object_url}/ActionInformation_view</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -2,7 +2,7 @@
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Action Information" module="erp5.portal_type"/>
<global name="ActionInformation" module="Products.CMFCore.ActionInformation"/>
</pickle>
<pickle>
<dictionary>
......@@ -13,20 +13,20 @@
</value>
</item>
<item>
<key> <string>action_permission</string> </key>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>View</string>
<string>action_type/object_view</string>
</tuple>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/object_jio_view</string>
</tuple>
</value>
<key> <string>category</string> </key>
<value> <string>object_view</string> </value>
</item>
<item>
<key> <string>condition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
......@@ -35,17 +35,19 @@
</value>
</item>
<item>
<key> <string>float_index</string> </key>
<value> <float>35.0</float> </value>
<key> <string>icon</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>text_editor_view</string> </value>
<value> <string>definition_view</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<key> <string>permissions</string> </key>
<value>
<none/>
<tuple>
<string>View</string>
</tuple>
</value>
</item>
<item>
......@@ -53,8 +55,8 @@
<value> <string>Action Information</string> </value>
</item>
<item>
<key> <string>reference</string> </key>
<value> <string>text_editor_view</string> </value>
<key> <string>priority</string> </key>
<value> <float>1.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
......@@ -75,7 +77,7 @@
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:${object_url}/WebPage_viewAsTextDocument</string> </value>
<value> <string>string:${object_url}/BaseType_view</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -2,7 +2,7 @@
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Action Information" module="erp5.portal_type"/>
<global name="ActionInformation" module="Products.CMFCore.ActionInformation"/>
</pickle>
<pickle>
<dictionary>
......@@ -12,14 +12,6 @@
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>action_permission</string> </key>
<value>
<tuple>
<string>View</string>
</tuple>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
......@@ -28,6 +20,14 @@
</tuple>
</value>
</item>
<item>
<key> <string>category</string> </key>
<value> <string>object_jio_view</string> </value>
</item>
<item>
<key> <string>condition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
......@@ -35,12 +35,12 @@
</value>
</item>
<item>
<key> <string>float_index</string> </key>
<value> <float>35.0</float> </value>
<key> <string>icon</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>jio_view</string> </value>
<value> <string>definition_view</string> </value>
</item>
<item>
<key> <string>language</string> </key>
......@@ -48,17 +48,25 @@
<none/>
</value>
</item>
<item>
<key> <string>permissions</string> </key>
<value>
<tuple>
<string>View</string>
</tuple>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Action Information</string> </value>
</item>
<item>
<key> <string>reference</string> </key>
<value> <string>jio_view</string> </value>
<key> <string>priority</string> </key>
<value> <float>1.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>View</string> </value>
<value> <string>Definition View</string> </value>
</item>
<item>
<key> <string>visible</string> </key>
......@@ -75,7 +83,7 @@
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:${object_url}/WebPage_viewAsJio</string> </value>
<value> <string>string:${object_url}/ERP5Form_viewAsDefinition</string> </value>
</item>
</dictionary>
</pickle>
......
<?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>View</string>
</tuple>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/object_list</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>float_index</string> </key>
<value> <float>10.0</float> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>text_editor_view</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>reference</string> </key>
<value> <string>text_editor_view</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>View</string> </value>
</item>
<item>
<key> <string>visible</string> </key>
<value> <int>1</int> </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}/WebPageModule_viewWebPageListAsJio</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -9,7 +9,7 @@
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="gadget_officejs_common_utils.js"></script>
<script src="gadget_officejs_common_util.js"></script>
</head>
......
......@@ -87,7 +87,7 @@
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>gadget_officejs_common_utils.html</string> </value>
<value> <string>gadget_officejs_common_util.html</string> </value>
</item>
<item>
<key> <string>description</string> </key>
......@@ -97,7 +97,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>gadget_officejs_common_utils_html</string> </value>
<value> <string>gadget_officejs_common_util_html</string> </value>
</item>
<item>
<key> <string>language</string> </key>
......@@ -136,7 +136,7 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Gadget OfficeJS Common Utils</string> </value>
<value> <string>Gadget OfficeJS Common Util</string> </value>
</item>
<item>
<key> <string>url_string</string> </key>
......@@ -273,7 +273,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>975.50798.33418.15411</string> </value>
<value> <string>977.16290.38883.28228</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -291,7 +291,7 @@
</tuple>
<state>
<tuple>
<float>1563365949.47</float>
<float>1563811367.37</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -83,7 +83,7 @@
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>gadget_officejs_common_utils.js</string> </value>
<value> <string>gadget_officejs_common_util.js</string> </value>
</item>
<item>
<key> <string>description</string> </key>
......@@ -93,7 +93,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>gadget_officejs_common_utils_js</string> </value>
<value> <string>gadget_officejs_common_util_js</string> </value>
</item>
<item>
<key> <string>language</string> </key>
......@@ -132,7 +132,7 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Gadget OfficeJS Common Utils JS</string> </value>
<value> <string>Gadget OfficeJS Common Util JS</string> </value>
</item>
<item>
<key> <string>url_string</string> </key>
......@@ -269,7 +269,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>977.8828.22214.8772</string> </value>
<value> <string>977.16294.5398.40106</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -287,7 +287,7 @@
</tuple>
<state>
<tuple>
<float>1563365942.38</float>
<float>1563811574.1</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -83,7 +83,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>gadget_officejs_page_local_controller_html</string> </value>
<value> <string>gadget_officejs_controller_page_local_controller_html</string> </value>
</item>
<item>
<key> <string>language</string> </key>
......@@ -232,7 +232,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>976.52707.23546.23773</string> </value>
<value> <string>977.15823.10779.36625</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -250,7 +250,7 @@
</tuple>
<state>
<tuple>
<float>1563366544.73</float>
<float>1563811084.56</float>
<string>UTC</string>
</tuple>
</state>
......
/*global document, window, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3 */
/*jslint nomen: true, indent: 2, maxerr: 10, maxlen: 80 */
(function (document, window, rJS, RSVP) {
"use strict";
......@@ -10,16 +10,9 @@
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("isDesktopMedia", "isDesktopMedia")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getUrlForList", "getUrlForList")
.declareAcquiredMethod('getUrlParameter', 'getUrlParameter')
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("redirect", "redirect")
/////////////////////////////////////////////////////////////////
// declared methods
......@@ -30,24 +23,25 @@
default_view,
app_view,
form_definition,
gadget_utils,
gadget_util,
jio_document,
portal_type,
front_page;
return RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.declareGadget("gadget_officejs_common_utils.html"),
gadget.declareGadget("gadget_officejs_common_util.html"),
gadget.getSetting('app_view_reference'),
gadget.getSetting('default_view_reference'),
gadget.getSetting('documents_editable')
]);
})
.push(function (result_list) {
gadget_utils = result_list[0];
gadget_util = result_list[0];
app_view = options.action || result_list[1];
default_view = result_list[2];
options.editable = ((result_list[3] == "1") ? true : options.editable);
options.editable = ((result_list[3] == "1") ?
true : options.editable);
return gadget.jio_get(options.jio_key);
})
.push(function (result) {
......@@ -71,19 +65,19 @@
portal_type = parent_portal_type;
}
front_page = portal_type === parent_portal_type;
return gadget_utils.getFormDefinition(portal_type, app_view);
return gadget_util.getFormDefinition(portal_type, app_view);
})
.push(function (result) {
return result;
}, function (error) {
if (error.status_code === 400) {
return gadget_utils.getFormDefinition(portal_type, default_view);
return gadget_util.getFormDefinition(portal_type, default_view);
}
throw error;
})
.push(function (result) {
form_definition = result;
return gadget_utils.getFormInfo(form_definition);
return gadget_util.getFormInfo(form_definition);
})
.push(function (form_info) {
var form_type = form_info[0],
......@@ -109,8 +103,8 @@
this.element.removeChild(this.element.firstChild);
}
this.element.appendChild(fragment);
return gadget.declareGadget("gadget_officejs_form_view.html", {element: fragment,
scope: 'form_view'})
return gadget.declareGadget("gadget_officejs_form_view.html",
{element: fragment, scope: 'form_view'})
.push(function (form_view_gadget) {
return form_view_gadget.render(gadget.state);
});
......@@ -137,7 +131,8 @@
return gadget.notifySubmitting();
})
.push(function () {
return gadget.notifySubmitted({message: 'Data Updated', status: 'success'});
return gadget.notifySubmitted({message: 'Data Updated',
status: 'success'});
});
})
......
/*global window, window, rJS, jIO, RSVP, document, URLSearchParams, UriTemplate, console */
/*jslint indent: 2, maxerr: 3 */
(function (window, rJS, jIO, RSVP, document, URLSearchParams, UriTemplate, console) {
/*jslint indent: 2, maxerr: 10, maxlen: 80 */
(function (window, rJS, jIO, RSVP, document, URLSearchParams, UriTemplate,
console) {
"use strict";
// jIO call wrapper for redirection to authentication page if needed
function wrapJioCall(gadget, method_name, argument_list) {
var storage = gadget.state_parameter_dict.jio_storage;
if (storage === undefined) {
return gadget.redirect({command: 'display', options: {page: 'ojs_configurator'}});
return gadget.redirect({command: 'display',
options: {page: 'ojs_configurator'}});
}
return storage[method_name].apply(storage, argument_list)
.push(undefined, function (error) {
......@@ -27,7 +29,8 @@
return gadget.redirect({
command: 'raw',
options: {
url: UriTemplate.parse(regexp.exec(login_page)[1]).expand({came_from: came_from})
url: UriTemplate.parse(regexp.exec(login_page)[1])
.expand({came_from: came_from})
}
});
});
......@@ -50,7 +53,8 @@
}
// User entered wrong password ?
// Notify
return gadget.notifySubmitted({message: 'Unauthorized storage access', status: 'error'})
return gadget.notifySubmitted({message: 'Unauthorized storage access',
status: 'error'})
.push(function () {
return gadget.redirect({command: 'display',
options: {page: 'ojs_configurator'}});
......@@ -61,19 +65,21 @@
}
function processHateoasDict(raw_dict) {
var raw_fields, type, parent, field_key, field_id, return_dict = {};
var raw_field_list, type, parent, field_key, field_id, return_dict = {};
return_dict.raw_dict = raw_dict;
/*jslint nomen: true*/
if (raw_dict.hasOwnProperty("_embedded") && raw_dict._embedded.hasOwnProperty("_view")) {
raw_fields = raw_dict._embedded._view;
if (raw_dict.hasOwnProperty("_embedded") &&
raw_dict._embedded.hasOwnProperty("_view")) {
raw_field_list = raw_dict._embedded._view;
type = raw_dict._links.type.name;
parent = raw_dict._links.parent.name;
return_dict.parent_relative_url = "portal_types/" + parent;
return_dict.portal_type = type;
for (field_key in raw_fields) {
if (raw_fields.hasOwnProperty(field_key)) {
for (field_key in raw_field_list) {
if (raw_field_list.hasOwnProperty(field_key)) {
field_id = "";
if (raw_fields[field_key]["default"] !== undefined && raw_fields[field_key]["default"] !== "") {
if (raw_field_list[field_key]["default"] !== undefined &&
raw_field_list[field_key]["default"] !== "") {
if (field_key.startsWith("my_")) {
field_id = field_key.replace("my_", "");
} else if (field_key.startsWith("your_")) {
......@@ -81,7 +87,7 @@
} else {
field_id = field_key;
}
return_dict[field_id] = raw_fields[field_key]["default"];
return_dict[field_id] = raw_field_list[field_key]["default"];
}
}
}
......@@ -109,7 +115,8 @@
var appcache_storage,
origin_url = window.location.href,
hateoas_script = "hateoas_appcache/ERP5Document_getHateoas",
// TODO manifest should come from gadget.props.cache_file -add script in html body
// TODO manifest should come from gadget.props.cache_file
// add script in html body
manifest = "gadget_officejs_text_editor.configuration",
jio_appchache_options = {
type: "replicate",
......@@ -144,7 +151,8 @@
if (jio_options === undefined) {
return;
}
jio_appchache_options.local_sub_storage = JSON.parse(JSON.stringify(jio_options));
jio_appchache_options.local_sub_storage = JSON.parse(
JSON.stringify(jio_options));
jio_options = {
type: 'dateupdater',
sub_storage: jio_options,
......@@ -173,9 +181,13 @@
for (id in attachment_dict) {
if (attachment_dict.hasOwnProperty(id)) {
if (id.indexOf(hateoas_script) === -1) {
promise_list.push(appcache_storage.getAttachment(origin_url, id));
promise_list.push(appcache_storage
.getAttachment(origin_url, id));
} else {
promise_list.push(appcache_storage.getAttachment(origin_url, id, {"format": "json"}));
promise_list.push(
appcache_storage
.getAttachment(origin_url, id,
{"format": "json"}));
}
configuration_ids_list[i] = id;
i += 1;
......@@ -203,9 +215,12 @@
.push(undefined);
});
}, function (error) {
console.log("Error while appcache-local storage synchronization");
if (error && error.currentTarget && error.currentTarget.status === "401") {
console.log("Unauthorized access to storage, sync cancelled");
console.log("Error while appcache-local " +
"storage synchronization");
if (error && error.currentTarget &&
error.currentTarget.status === "401") {
console.log("Unauthorized access to storage," +
"sync cancelled");
return;
}
throw error;
......
/*global window, rJS, RSVP, Handlebars */
/*jslint nomen: true, indent: 2, maxerr: 3 */
/*jslint nomen: true, indent: 2, maxerr: 10, maxlen: 80 */
(function (window, rJS, RSVP, Handlebars) {
"use strict";
......@@ -36,52 +36,50 @@
);
}
function getHTMLElementList(gadget, element_list) {
var i = 0,
element_info_list = [],
url_for_parameter_list = [],
element_info,
key;
for (key in element_list) {
if (element_list.hasOwnProperty(key)) {
element_info = element_list[key];
url_for_parameter_list.push({ command: 'change',
options: element_info });
element_info_list[i] = { reference: element_info.reference,
title: element_info.title};
i += 1;
}
}
return gadget.getUrlForList(url_for_parameter_list)
.push(function (url_list) {
var html_element_list = [], j, element;
for (j = 0; j < url_list.length; j += 1) {
element = { href: url_list[j],
icon: null,
name: element_info_list[j].reference,
title: element_info_list[j].title };
html_element_list.push(element);
}
return html_element_list;
});
}
gadget_klass
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("getUrlForList", "getUrlForList")
.declareAcquiredMethod("getUrlParameter", "getUrlParameter")
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getSetting", "getSetting")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("getHTMLElementList", function (element_list) {
var gadget = this,
i = 0,
element_info_list = [],
url_for_parameter_list = [],
element_info,
key;
for (key in element_list) {
if (element_list.hasOwnProperty(key)) {
element_info = element_list[key];
url_for_parameter_list.push({ command: 'change', options: element_info });
element_info_list[i] = { reference: element_info.reference, title: element_info.title};
i += 1;
}
}
return gadget.getUrlForList(url_for_parameter_list)
.push(function (url_list) {
var html_element_list = [], j, element;
for (j = 0; j < url_list.length; j += 1) {
element = { href: url_list[j],
icon: null,
name: element_info_list[j].reference,
title: element_info_list[j].title };
html_element_list.push(element);
}
return html_element_list;
});
})
.declareMethod("render", function (options) {
var gadget = this,
portal_type,
......@@ -96,20 +94,20 @@
})
.push(function (result) {
portal_type = result;
return gadget.declareGadget("gadget_officejs_common_utils.html");
return gadget.declareGadget("gadget_officejs_common_util.html");
})
.push(function (gadget_utils) {
// TODO views are also listed here
// should views be handled in another gadget like "..tab_office.js" ?
return gadget_utils.getAllViewsAndActions(portal_type, options.jio_key);
return gadget_utils.getViewAndActionDict(portal_type,
options.jio_key);
})
.push(function (action_info_dict) {
return RSVP.all([
gadget.getHTMLElementList(action_info_dict.views),
gadget.getHTMLElementList(action_info_dict.actions)
getHTMLElementList(gadget, action_info_dict.view_list),
getHTMLElementList(gadget, action_info_dict.action_list)
]);
})
// check other lists like clone or delete? NO. For now, they will be actions
.push(function (all_html_elements) {
return RSVP.all([
renderLinkList(gadget, "Views", "eye", all_html_elements[0]),
......@@ -118,7 +116,8 @@
})
.push(function (translated_html_link_list) {
gadget.element.innerHTML = translated_html_link_list.join("\n");
return gadget.getUrlFor({command: 'change', options: {page: undefined}});
return gadget.getUrlFor({command: 'change',
options: {page: undefined}});
})
.push(function (back_url) {
return gadget.updateHeader({
......
/*global window, document, rJS */
/*jslint nomen: true, indent: 2, maxerr: 13 */
/*jslint nomen: true, indent: 2, maxerr: 10, maxlen: 80 */
(function (window, document, rJS) {
"use strict";
......@@ -8,12 +8,6 @@
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("getUrlForList", "getUrlForList")
.declareAcquiredMethod("getUrlParameter", "getUrlParameter")
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("jio_post", "jio_post")
......@@ -22,7 +16,8 @@
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("createDocument", function (portal_type, parent_portal_type) {
.declareMethod("createDocument", function (portal_type,
parent_portal_type) {
var gadget = this,
doc = {
title: "Untitled Document",
......@@ -58,13 +53,21 @@
})
.push(function (portal_type_result) {
portal_type = portal_type_result;
// TODO: somehow (a generic action?) get the path string:${object_url}/Base_viewNewContentDialog
return gadget.jio_get("portal_skins/erp5_hal_json_style/Base_viewNewContentDialog");
return gadget.getSetting("new_content_action");
})
.push(function (new_content_action) {
if (!new_content_action) {
throw new Error("Missing site configuration 'new_content_action'");
}
return gadget.jio_get(new_content_action);
})
.push(function (form_result) {
form_definition = form_result.raw_dict._embedded._view._embedded.form_definition;
form_definition.fields_raw_properties = form_result.raw_dict._embedded._view.my_fields_raw_properties["default"];
form_definition._actions = form_result.raw_dict._embedded._view._actions;
form_definition = form_result.raw_dict._embedded._view
._embedded.form_definition;
form_definition.fields_raw_properties = form_result.raw_dict._embedded
._view.my_fields_raw_properties["default"];
form_definition._actions = form_result.raw_dict._embedded
._view._actions;
form_definition.group_list = form_result.raw_dict.group_list;
form_definition.title = "Create Document";
return gadget.changeState({
......@@ -88,15 +91,17 @@
this.element.removeChild(this.element.firstChild);
}
this.element.appendChild(fragment);
return gadget.declareGadget("gadget_officejs_form_view.html", {element: fragment,
scope: 'fg'})
return gadget.declareGadget("gadget_officejs_form_view.html",
{element: fragment, scope: 'fg'})
.push(function (form_view_gadget) {
return form_view_gadget.render(gadget.state);
});
} else {
// if there is only one sub portal type, skip create document dialog rendering
// if there is only one sub portal type
// skip create document dialog rendering
return gadget.createDocument(gadget.state.doc.portal_type[0],
gadget.state.parent_portal_type.replace(/ /g, '_').toLowerCase());
gadget.state.parent_portal_type
.replace(/ /g, '_').toLowerCase());
}
})
......@@ -104,7 +109,8 @@
var gadget = this,
content_dict = options[2];
return gadget.createDocument(content_dict.portal_type,
gadget.state.parent_portal_type.replace(/ /g, '_').toLowerCase());
gadget.state.parent_portal_type
.replace(/ /g, '_').toLowerCase());
});
}(window, document, rJS));
\ No newline at end of file
/*global window, document, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3 */
/*jslint nomen: true, indent: 2, maxerr: 10, maxlen: 80 */
(function (window, document, rJS, RSVP) {
"use strict";
......@@ -8,7 +8,6 @@
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getUrlParameter", "getUrlParameter")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
......@@ -24,46 +23,51 @@
.push(function () {
return RSVP.all([
gadget.getUrlParameter("parent_portal_type"),
gadget.declareGadget("gadget_officejs_common_utils.html")
gadget.declareGadget("gadget_officejs_common_util.html")
]);
})
.push(function (result) {
parent_portal_type = result[0];
return result[1].getFormDefinition(parent_portal_type, action_reference);
return result[1].getFormDefinition(parent_portal_type,
action_reference);
});
})
.declareMethod("render", function (options) {
var gadget = this, action_reference, gadget_utils, form_definition;
var gadget = this, action_reference, gadget_util, form_definition;
return RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getUrlParameter('portal_type'),
gadget.getUrlParameter('parent_relative_url'),
gadget.getUrlParameter("action"),
gadget.declareGadget("gadget_officejs_common_utils.html")
gadget.declareGadget("gadget_officejs_common_util.html")
]);
})
.push(function (result) {
if (result[0] !== undefined) { options.portal_type = result[0]; }
if (result[1] !== undefined) { options.parent_relative_url = result[1]; }
if (result[1] !== undefined) {
options.parent_relative_url = result[1];
}
action_reference = result[2];
gadget_utils = result[3];
gadget_util = result[3];
return gadget.getActionFormDefinition(action_reference);
})
.push(function (result) {
form_definition = result;
return gadget_utils.getFormInfo(form_definition);
return gadget_util.getFormInfo(form_definition);
})
.push(function (form_info) {
var fragment = document.createElement('div'),
action_gadget_url,
form_type = form_info[0],
child_gadget_url = form_info[1],
//an action form must have a GadgetField called "gadget_field_new_action_js_script"
//an action form must have a GadgetField called
//"gadget_field_new_action_js_script"
//this gadget will point the custom action gadget
valid_action = form_definition.action_type === "object_jio_js_script" &&
form_definition.fields_raw_properties.hasOwnProperty("gadget_field_action_js_script"),
valid_action = form_definition.action_type ===
"object_jio_js_script" && form_definition.fields_raw_properties
.hasOwnProperty("gadget_field_action_js_script"),
state_options = {
doc: {},
action_options: options,
......@@ -74,9 +78,12 @@
valid_action: valid_action
};
if (valid_action) {
action_gadget_url = form_definition.fields_raw_properties.gadget_field_action_js_script.values.gadget_url;
// as custom gadget render is being done here, avoid to child gadget to render it
delete form_definition.fields_raw_properties.gadget_field_action_js_script;
action_gadget_url = form_definition.fields_raw_properties
.gadget_field_action_js_script.values.gadget_url;
// as custom gadget render is being done here
// avoid to child gadget to render it
delete form_definition.fields_raw_properties
.gadget_field_action_js_script;
gadget.element.appendChild(fragment);
return gadget.declareGadget(action_gadget_url, {
scope: "action_field",
......@@ -103,8 +110,8 @@
this.element.removeChild(this.element.firstChild);
}
this.element.appendChild(fragment);
return gadget.declareGadget("gadget_officejs_form_view.html", {element: fragment,
scope: 'fg'})
return gadget.declareGadget("gadget_officejs_form_view.html",
{element: fragment, scope: 'fg'})
.push(function (form_view_gadget) {
return form_view_gadget.render(gadget.state);
});
......@@ -137,7 +144,8 @@
return gadget.notifySubmitting();
})
.push(function () {
return gadget.notifySubmitted({message: 'Data Updated', status: 'success'});
return gadget.notifySubmitted({message: 'Data Updated',
status: 'success'});
})
.push(function () {
return gadget.redirect({
......@@ -149,7 +157,9 @@
});
});
} else {
return gadget.notifySubmitted({message: 'Could not perform this action: configuration error', status: 'fail'});
return gadget.notifySubmitted(
{message: 'Could not perform this action: configuration error',
status: 'fail'});
}
});
......
......@@ -230,8 +230,8 @@ gadget_officejs_form_view.html\n
gadget_officejs_form_view.js\n
gadget_erp5_page_handle_action.html\n
gadget_erp5_page_handle_action.js\n
gadget_officejs_common_utils.html\n
gadget_officejs_common_utils.js\n
gadget_officejs_common_util.html\n
gadget_officejs_common_util.js\n
gadget_erp5_page_create_document.html\n
gadget_erp5_page_create_document.js\n
\n
......@@ -746,7 +746,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>977.10238.57791.10683</string> </value>
<value> <string>977.8821.29343.5888</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -764,7 +764,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1563448279.94</float>
<float>1563363682.11</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -134,7 +134,7 @@ NETWORK:\n
</item>
<item>
<key> <string>title</string> </key>
<value> <string>OfficeJS Configuration</string> </value>
<value> <string>OfficeJS Text Editor Configuration</string> </value>
</item>
<item>
<key> <string>url_string</string> </key>
......@@ -271,7 +271,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>977.10238.54043.341</string> </value>
<value> <string>976.64206.22853.836</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -289,7 +289,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1563448274.75</float>
<float>1563193388.95</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -21,6 +21,14 @@
<script data-renderjs-configuration="parent_relative_url" type="text/x-renderjs-configuration">web_page_module</script>
<script data-renderjs-configuration="hide_listbox_buttons" type="text/x-renderjs-configuration">1</script>
<script data-renderjs-configuration="documents_editable" type="text/x-renderjs-configuration">1</script>
<script data-renderjs-configuration="portal_skin_folder" type="text/x-renderjs-configuration">erp5_web_officejs_ui</script>
<!-- TODO: somehow (a generic action?) get the path string:${object_url}/Base_viewNewContentDialog. For now it's in new_content_action -->
<script data-renderjs-configuration="new_content_action" type="text/x-renderjs-configuration">portal_skins/erp5_hal_json_style/Base_viewNewContentDialog</script>
<script data-renderjs-configuration="app_view_reference" type="text/x-renderjs-configuration">text_editor_view</script>
<script data-renderjs-configuration="app_actions" type="text/x-renderjs-configuration">('Web Page | text_editor_view', 'Web Page | text_editor_clone')</script>
<script data-renderjs-configuration="app_allowed_sub_types" type="text/x-renderjs-configuration">('Web Page Module | Web Page',)</script>
<script data-renderjs-configuration="hide_header_add_button" type="text/x-renderjs-configuration">0</script>
<script data-renderjs-configuration="header_jump_button" type="text/x-renderjs-configuration">0</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">n692ixxhyg9zhqs</script>
<div data-gadget-url="gadget_erp5_router.html" data-gadget-scope="erp5_router"></div>
......
......@@ -787,7 +787,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>976.64179.17400.52480</string> </value>
<value> <string>977.15998.30713.4488</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -805,7 +805,7 @@
</tuple>
<state>
<tuple>
<float>1563192454.2</float>
<float>1563801605.23</float>
<string>UTC</string>
</tuple>
</state>
......
<registered_skin_selection>
<skin_folder_selection>
<skin_folder>erp5_web_officejs_ui</skin_folder>
<skin_selection>RJS,View</skin_selection>
<skin_selection>Hal,RJS,View</skin_selection>
</skin_folder_selection>
</registered_skin_selection>
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ERP5 Form" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>action</string> </key>
<value> <string>Base_edit</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>Base ERP5 Form view for rendering in renderjs UI</string> </value>
</item>
<item>
<key> <string>edit_order</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>enctype</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>group_list</string> </key>
<value>
<list>
<string>left</string>
<string>right</string>
<string>center</string>
<string>bottom</string>
<string>hidden</string>
</list>
</value>
</item>
<item>
<key> <string>groups</string> </key>
<value>
<dictionary>
<item>
<key> <string>bottom</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>center</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>hidden</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>left</string> </key>
<value>
<list>
<string>my_fields_raw_properties</string>
</list>
</value>
</item>
<item>
<key> <string>right</string> </key>
<value>
<list/>
</value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Form_viewAsDefinition</string> </value>
</item>
<item>
<key> <string>method</string> </key>
<value> <string>POST</string> </value>
</item>
<item>
<key> <string>name</string> </key>
<value> <string>ERP5Form_viewAsJio</string> </value>
</item>
<item>
<key> <string>pt</string> </key>
<value> <string>form_view</string> </value>
</item>
<item>
<key> <string>row_length</string> </key>
<value> <int>4</int> </value>
</item>
<item>
<key> <string>stored_encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>unicode_mode</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>update_action</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>update_action_title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from Products.ERP5Type.Log import log
def getRealRelativeUrl(document):
return '/'.join(context.getPortalObject().portal_url.getRelativeContentPath(document))
def getFieldRawProperties(field, meta_type=None, key=None, key_prefix=None):
""" Return the raw properties of the field """
if meta_type is None:
meta_type = field.meta_type
if key is None:
key = field.generate_field_key(key_prefix=key_prefix)
if meta_type == "ProxyField":
meta_type = field.getRecursiveTemplateField().meta_type
result = {
"type": meta_type,
"key": key,
"values": {},
"overrides": field.overrides,
"message_values": field.message_values
}
# these patchs change the field property names as are required by js rendering
form_list_patch = False
gadget_field_patch = False
for key in field.values.keys():
# sometimes, field.values returns a key as string and also as a tuple
if type(key) is str:
result["values"][key] = field.values[key]
if key == "columns":
form_list_patch = True
if key == "gadget_url":
gadget_field_patch = True
if form_list_patch:
try:
result["values"]["column_list"] = result["values"]["columns"]
result["values"]["sort_column_list"] = result["values"]["sort_columns"]
result["values"]["search_column_list"] = result["values"]["search_columns"]
portal_type = result["values"]["portal_types"][0][0] if "portal_types" in result["values"] else False
if not portal_type:
portal_type = result["values"]["portal_type"][0][0] if "portal_type" in result["values"] else False
query = "portal_type%3A%22" + portal_type + "%22" if portal_type else ""
full_query = "urn:jio:allDocs?query=" + query
result["values"]["query"] = full_query
except KeyError:
log("error while patching form list definition")
if gadget_field_patch:
try:
result["values"]["url"] = result["values"]["gadget_url"]
result["values"]["renderjs_extra"] = result["values"]["renderjs_extra"][0][0]
except (ValueError, KeyError, IndexError):
log("error while patching form gadget list definition")
return result
if REQUEST.get("view") == "definition_view":
traversed_document = context
traversed_document_portal_type = traversed_document.getPortalType()
fields_raw_properties = {}
if traversed_document_portal_type in ("ERP5 Form", "ERP5 Report"):
custom_action_script = False
for group in traversed_document.Form_getGroupTitleAndId():
if 'hidden' in group["gid"]:
for field in traversed_document.get_fields_in_group(group["goid"]):
if field.id == "gadget_field_action_js_script":
custom_action_script = True
fields_raw_properties[field.id] = getFieldRawProperties(field, key_prefix=None)
continue
for field in traversed_document.get_fields_in_group(group["goid"]):
if field.id == "gadget_field_action_js_script":
custom_action_script = True
fields_raw_properties[field.id] = getFieldRawProperties(field, key_prefix=None)
if custom_action_script:
fields_raw_properties['_actions'] = {
'put': {
"href": "%(traversed_document_url)s/%(action_id)s" % {
"traversed_document_url": context.getPortalObject().absolute_url() + "/" + getRealRelativeUrl(traversed_document),
"action_id": "Base_edit"
},
"action": "Base_edit",
"method": "POST",
}
}
if fields_raw_properties:
return fields_raw_properties
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Form_getFieldsRawProperties</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
Action Information | definition_view
Base Type | definition_view
ERP5 Form | definition_view
Web Page Module | text_editor_view
Web Page | text_editor_clone
Web Page | text_editor_view
\ No newline at end of file
......@@ -40,5 +40,4 @@ web_site_module/officejs_todomvc
web_site_module/officejs_wallsearch
web_site_module/officejs_wallsearch/**
web_site_module/officejs_whiteboard
web_site_module/officejs_media_player/**
web_site_module/hateoas_appcache
\ No newline at end of file
web_site_module/officejs_media_player/**
\ No newline at end of file
......@@ -40,5 +40,4 @@ web_site_module/officejs_todomvc
web_site_module/officejs_wallsearch
web_site_module/officejs_wallsearch/**
web_site_module/officejs_whiteboard
web_site_module/officejs_media_player/**
web_site_module/hateoas_appcache
\ No newline at end of file
web_site_module/officejs_media_player/**
\ No newline at end of file
......@@ -5,10 +5,6 @@ image_module/hr_logo_svg
image_module/officejs_audioplayer_*
image_module/officejs_todomvc_*
image_module/wallsearch_icon_svg
portal_types/Web Page Module/text_editor_view
portal_types/Web Page/jio_view
portal_types/Web Page/text_editor_clone
portal_types/Web Page/text_editor_view
web_page_module/dhtmlx_gantt_*
web_page_module/fb_sdk_js
web_page_module/gadget_field_*
......@@ -18,7 +14,6 @@ web_page_module/officejs_audioplayer_*
web_page_module/officejs_todomvc_*
web_page_module/ojs_*
web_page_module/wallsearch_privacy_policy_html
web_site_module/hateoas_appcache
web_site_module/officejs_audioplayer
web_site_module/officejs_audioplayer/**
web_site_module/officejs_bookmark_manager
......
erp5_web_officejs_ui | Hal
erp5_web_officejs_ui | RJS
erp5_web_officejs_ui | View
\ No newline at end of file
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