Commit 4c25f638 authored by Roque's avatar Roque Committed by Roque

erp5_officejs: refactoring to speed up page loading

/reviewed-on !965
parent cf632afb
Pipeline #6312 passed with stage
in 0 seconds
......@@ -120,6 +120,7 @@
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getSettingList", "getSettingList")
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
......@@ -134,14 +135,9 @@
app_actions,
app_view,
default_view;
return RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getSetting('app_view_reference'),
gadget.getSetting('default_view_reference'),
gadget.getSetting('app_actions')
]);
})
return gadget.getSettingList(['app_view_reference',
'default_view_reference',
'app_actions'])
.push(function (result_list) {
app_view = result_list[0];
default_view = result_list[1];
......@@ -240,14 +236,9 @@
app_allowed_sub_types,
form_info,
error;
return RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getSetting(portal_type_dict_setting),
gadget.getSetting("portal_skin_folder"),
gadget.getSetting("app_allowed_sub_types")
]);
})
return gadget.getSettingList([portal_type_dict_setting,
'portal_skin_folder',
'app_allowed_sub_types'])
.push(function (result_list) {
app_allowed_sub_types = result_list[2];
if (!result_list[1]) {
......
......@@ -269,7 +269,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>978.26807.33358.5717</string> </value>
<value> <string>979.7531.30512.46370</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -287,7 +287,7 @@
</tuple>
<state>
<tuple>
<float>1568651276.38</float>
<float>1571065275.72</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -12,6 +12,11 @@
<!-- custom script -->
<script src="gadget_erp5_page_ojs_local_controller.js" type="text/javascript"></script>
<div data-gadget-url="gadget_officejs_common_util.html"
data-gadget-scope="common_util"
data-gadget-sandbox="public">
</div>
</head>
<body>
</body>
......
......@@ -232,7 +232,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>977.15823.10779.36625</string> </value>
<value> <string>979.7467.57626.53282</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -250,7 +250,7 @@
</tuple>
<state>
<tuple>
<float>1563811084.56</float>
<float>1571061400.65</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -3,6 +3,46 @@
(function (document, window, rJS, RSVP, jIO, console) {
"use strict";
var warmup_gadget_done = false,
warmup_list = [
//officejs gadgets
'gadget_officejs_form_view.html',
'gadget_officejs_common_util.html',
'gadget_erp5_label_field.html',
'gadget_html5_element.html',
'gadget_erp5_field_datetime.html',
'gadget_erp5_field_string.html',
'gadget_erp5_form.html',
'gadget_erp5_field_float.html',
'gadget_erp5_field_listbox.html',
// Used in panel
'gadget_translation.html',
'gadget_erp5_panel.html',
'gadget_erp5_header.html',
'gadget_erp5_searchfield.html',
'gadget_erp5_field_multicheckbox.html',
'gadget_html5_input.html',
//following elements should be split in at list 2 groups (doclist and doc)
'gadget_erp5_pt_form_list',
'gadget_erp5_pt_form_view.html',
//
'gadget_erp5_pt_form_view_editable.html',
'gadget_erp5_field_textarea.html',
'gadget_erp5_field_gadget.html',
'gadget_html5_textarea.html',
'gadget_editor.html'
];
function warmupGadgetList(gadget, url_list) {
var i;
for (i = 0; i < url_list.length; i += 1) {
// No need to check the result, as it will fail later
// when rJS will try to instanciate one of this gadget
rJS.declareGadgetKlass(rJS.getAbsoluteURL(url_list[i],
gadget.__path));
}
}
rJS(window)
/////////////////////////////////////////////////////////////////
......@@ -11,7 +51,7 @@
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getSettingList", "getSettingList")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
......@@ -25,15 +65,20 @@
gadget_util,
jio_document,
portal_type,
parent_portal_type,
current_version,
index;
current_version = window.location.href.replace(window.location.hash, "");
index = current_version.indexOf(window.location.host) +
window.location.host.length;
current_version = current_version.substr(index);
return gadget.getSetting("migration_version")
.push(function (migration_version) {
if (migration_version !== current_version) {
return gadget.getSettingList(["migration_version",
"app_view_reference",
"parent_portal_type"])
.push(function (setting_list) {
app_view = options.action || setting_list[1];
parent_portal_type = setting_list[2];
if (setting_list[0] !== current_version) {
//if app version has changed, force storage selection
return gadget.redirect({
'command': 'display',
......@@ -45,14 +90,14 @@
}
})
.push(function () {
return RSVP.all([
gadget.declareGadget("gadget_officejs_common_util.html"),
gadget.getSetting('app_view_reference')
]);
if (!warmup_gadget_done) {
warmupGadgetList(gadget, warmup_list);
warmup_gadget_done = true;
}
return gadget.getDeclaredGadget("common_util");
})
.push(function (result_list) {
gadget_util = result_list[0];
app_view = options.action || result_list[1];
.push(function (result) {
gadget_util = result;
return gadget.jio_get(options.jio_key);
})
.push(function (result) {
......@@ -63,7 +108,7 @@
}, function (error) {
// instaceof error is Object, so use status_code and undefined jio_key
if (error.status_code === 400 && !options.jio_key) {
return gadget.getSetting('parent_portal_type');
return parent_portal_type;
}
throw error;
})
......
......@@ -228,7 +228,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>978.57300.17773.6331</string> </value>
<value> <string>979.7618.39284.59767</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -246,7 +246,7 @@
</tuple>
<state>
<tuple>
<float>1570117898.93</float>
<float>1571070879.6</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -175,6 +175,13 @@
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("getContent", function (argument_list) {
return this.getDeclaredGadget('erp5_pt_gadget')
.push(function (child_gadget) {
return child_gadget.getContent();
});
})
.declareMethod("triggerSubmit", function (argument_list) {
var gadget = this, child_gadget, content_dict;
return gadget.getDeclaredGadget('erp5_pt_gadget')
......@@ -306,13 +313,10 @@
}}
];
erp5_document = form_json.erp5_document;
return RSVP.all([
gadget.getUrlForList(url_for_parameter_list)
]);
return gadget.getUrlForList(url_for_parameter_list);
})
.push(function (result_list) {
var url_list = result_list[0],
header_dict = { "page_title": page_title };
.push(function (url_list) {
var header_dict = { "page_title": page_title };
if (options.form_type === 'dialog') {
//TODO: find correct url
header_dict.cancel_url = url_list[6];
......
......@@ -269,7 +269,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>978.63202.6561.35293</string> </value>
<value> <string>979.7520.54247.47189</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -287,7 +287,7 @@
</tuple>
<state>
<tuple>
<float>1570539644.03</float>
<float>1571065315.5</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -86,13 +86,14 @@
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getSettingList", "getSettingList")
.declareAcquiredMethod("setSetting", "setSetting")
.declareAcquiredMethod('getUrlFor', 'getUrlFor')
.declareMethod('updateConfiguration', function (appcache_storage, origin_url,
.declareMethod('updateConfiguration', function (jio_appchache_options, origin_url,
migration_version, current_version,
storage_name) {
var appcache_storage = jIO.createJIO(jio_appchache_options);
if (!appcache_storage) { return; }
var gadget = this,
document_id_list = [origin_url,
......@@ -142,15 +143,10 @@
previous_storage_name,
index,
origin_url = window.location.href;
return RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getSetting('configuration_manifest'),
gadget.getSetting('jio_storage_name'),
gadget.getSetting('previous_storage_name'),
gadget.getSetting('migration_version')
]);
})
return gadget.getSettingList(['configuration_manifest',
'jio_storage_name',
'previous_storage_name',
'migration_version'])
.push(function (result_list) {
selected_storage_name = result_list[1];
previous_storage_name = result_list[2];
......@@ -204,14 +200,14 @@
if (result_list[0] === undefined) { return; }
if (selected_storage_name === undefined) { return; }
gadget.state_parameter_dict.jio_storage_name = selected_storage_name;
appcache_storage = jIO.createJIO(jio_appchache_options);
current_version = window.location.href.replace(window.location.hash, "");
index = current_version.indexOf(window.location.host) + window.location.host.length;
current_version = current_version.substr(index);
if (migration_version !== current_version ||
previous_storage_name !== selected_storage_name) {
return gadget.updateConfiguration(appcache_storage, origin_url, migration_version,
current_version, selected_storage_name);
return gadget.updateConfiguration(jio_appchache_options, origin_url,
migration_version, current_version,
selected_storage_name);
}
})
.push(undefined, function (error) {
......
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>979.3132.57631.22818</string> </value>
<value> <string>979.7652.21916.23961</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1570799816.86</float>
<float>1571071046.04</float>
<string>UTC</string>
</tuple>
</state>
......
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