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

erp5_officejs: refactoring to speed up page loading

/reviewed-on nexedi/erp5!965
parent cf632afb
Pipeline #6312 passed with stage
in 0 seconds
...@@ -120,6 +120,7 @@ ...@@ -120,6 +120,7 @@
// Acquired methods // Acquired methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareAcquiredMethod("getSetting", "getSetting") .declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getSettingList", "getSettingList")
.declareAcquiredMethod("jio_get", "jio_get") .declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs") .declareAcquiredMethod("jio_allDocs", "jio_allDocs")
...@@ -134,14 +135,9 @@ ...@@ -134,14 +135,9 @@
app_actions, app_actions,
app_view, app_view,
default_view; default_view;
return RSVP.Queue() return gadget.getSettingList(['app_view_reference',
.push(function () { 'default_view_reference',
return RSVP.all([ 'app_actions'])
gadget.getSetting('app_view_reference'),
gadget.getSetting('default_view_reference'),
gadget.getSetting('app_actions')
]);
})
.push(function (result_list) { .push(function (result_list) {
app_view = result_list[0]; app_view = result_list[0];
default_view = result_list[1]; default_view = result_list[1];
...@@ -240,14 +236,9 @@ ...@@ -240,14 +236,9 @@
app_allowed_sub_types, app_allowed_sub_types,
form_info, form_info,
error; error;
return RSVP.Queue() return gadget.getSettingList([portal_type_dict_setting,
.push(function () { 'portal_skin_folder',
return RSVP.all([ 'app_allowed_sub_types'])
gadget.getSetting(portal_type_dict_setting),
gadget.getSetting("portal_skin_folder"),
gadget.getSetting("app_allowed_sub_types")
]);
})
.push(function (result_list) { .push(function (result_list) {
app_allowed_sub_types = result_list[2]; app_allowed_sub_types = result_list[2];
if (!result_list[1]) { if (!result_list[1]) {
......
...@@ -269,7 +269,7 @@ ...@@ -269,7 +269,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>978.26807.33358.5717</string> </value> <value> <string>979.7531.30512.46370</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -287,7 +287,7 @@ ...@@ -287,7 +287,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1568651276.38</float> <float>1571065275.72</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -12,6 +12,11 @@ ...@@ -12,6 +12,11 @@
<!-- custom script --> <!-- custom script -->
<script src="gadget_erp5_page_ojs_local_controller.js" type="text/javascript"></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> </head>
<body> <body>
</body> </body>
......
...@@ -232,7 +232,7 @@ ...@@ -232,7 +232,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>977.15823.10779.36625</string> </value> <value> <string>979.7467.57626.53282</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -250,7 +250,7 @@ ...@@ -250,7 +250,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1563811084.56</float> <float>1571061400.65</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -3,6 +3,46 @@ ...@@ -3,6 +3,46 @@
(function (document, window, rJS, RSVP, jIO, console) { (function (document, window, rJS, RSVP, jIO, console) {
"use strict"; "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) rJS(window)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
...@@ -11,7 +51,7 @@ ...@@ -11,7 +51,7 @@
.declareAcquiredMethod("jio_get", "jio_get") .declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_put", "jio_put") .declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("redirect", "redirect") .declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("getSetting", "getSetting") .declareAcquiredMethod("getSettingList", "getSettingList")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted') .declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.declareAcquiredMethod("notifySubmitting", "notifySubmitting") .declareAcquiredMethod("notifySubmitting", "notifySubmitting")
...@@ -25,15 +65,20 @@ ...@@ -25,15 +65,20 @@
gadget_util, gadget_util,
jio_document, jio_document,
portal_type, portal_type,
parent_portal_type,
current_version, current_version,
index; index;
current_version = window.location.href.replace(window.location.hash, ""); current_version = window.location.href.replace(window.location.hash, "");
index = current_version.indexOf(window.location.host) + index = current_version.indexOf(window.location.host) +
window.location.host.length; window.location.host.length;
current_version = current_version.substr(index); current_version = current_version.substr(index);
return gadget.getSetting("migration_version") return gadget.getSettingList(["migration_version",
.push(function (migration_version) { "app_view_reference",
if (migration_version !== current_version) { "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 //if app version has changed, force storage selection
return gadget.redirect({ return gadget.redirect({
'command': 'display', 'command': 'display',
...@@ -45,14 +90,14 @@ ...@@ -45,14 +90,14 @@
} }
}) })
.push(function () { .push(function () {
return RSVP.all([ if (!warmup_gadget_done) {
gadget.declareGadget("gadget_officejs_common_util.html"), warmupGadgetList(gadget, warmup_list);
gadget.getSetting('app_view_reference') warmup_gadget_done = true;
]); }
return gadget.getDeclaredGadget("common_util");
}) })
.push(function (result_list) { .push(function (result) {
gadget_util = result_list[0]; gadget_util = result;
app_view = options.action || result_list[1];
return gadget.jio_get(options.jio_key); return gadget.jio_get(options.jio_key);
}) })
.push(function (result) { .push(function (result) {
...@@ -63,7 +108,7 @@ ...@@ -63,7 +108,7 @@
}, function (error) { }, function (error) {
// instaceof error is Object, so use status_code and undefined jio_key // instaceof error is Object, so use status_code and undefined jio_key
if (error.status_code === 400 && !options.jio_key) { if (error.status_code === 400 && !options.jio_key) {
return gadget.getSetting('parent_portal_type'); return parent_portal_type;
} }
throw error; throw error;
}) })
......
...@@ -228,7 +228,7 @@ ...@@ -228,7 +228,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>978.57300.17773.6331</string> </value> <value> <string>979.7618.39284.59767</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1570117898.93</float> <float>1571070879.6</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -175,6 +175,13 @@ ...@@ -175,6 +175,13 @@
// declared methods // 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) { .declareMethod("triggerSubmit", function (argument_list) {
var gadget = this, child_gadget, content_dict; var gadget = this, child_gadget, content_dict;
return gadget.getDeclaredGadget('erp5_pt_gadget') return gadget.getDeclaredGadget('erp5_pt_gadget')
...@@ -306,13 +313,10 @@ ...@@ -306,13 +313,10 @@
}} }}
]; ];
erp5_document = form_json.erp5_document; erp5_document = form_json.erp5_document;
return RSVP.all([ return gadget.getUrlForList(url_for_parameter_list);
gadget.getUrlForList(url_for_parameter_list)
]);
}) })
.push(function (result_list) { .push(function (url_list) {
var url_list = result_list[0], var header_dict = { "page_title": page_title };
header_dict = { "page_title": page_title };
if (options.form_type === 'dialog') { if (options.form_type === 'dialog') {
//TODO: find correct url //TODO: find correct url
header_dict.cancel_url = url_list[6]; header_dict.cancel_url = url_list[6];
......
...@@ -269,7 +269,7 @@ ...@@ -269,7 +269,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>978.63202.6561.35293</string> </value> <value> <string>979.7520.54247.47189</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -287,7 +287,7 @@ ...@@ -287,7 +287,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1570539644.03</float> <float>1571065315.5</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -86,13 +86,14 @@ ...@@ -86,13 +86,14 @@
.declareAcquiredMethod("notifySubmitted", "notifySubmitted") .declareAcquiredMethod("notifySubmitted", "notifySubmitted")
.declareAcquiredMethod("redirect", "redirect") .declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("getSetting", "getSetting") .declareAcquiredMethod("getSettingList", "getSettingList")
.declareAcquiredMethod("setSetting", "setSetting") .declareAcquiredMethod("setSetting", "setSetting")
.declareAcquiredMethod('getUrlFor', 'getUrlFor') .declareAcquiredMethod('getUrlFor', 'getUrlFor')
.declareMethod('updateConfiguration', function (appcache_storage, origin_url, .declareMethod('updateConfiguration', function (jio_appchache_options, origin_url,
migration_version, current_version, migration_version, current_version,
storage_name) { storage_name) {
var appcache_storage = jIO.createJIO(jio_appchache_options);
if (!appcache_storage) { return; } if (!appcache_storage) { return; }
var gadget = this, var gadget = this,
document_id_list = [origin_url, document_id_list = [origin_url,
...@@ -142,15 +143,10 @@ ...@@ -142,15 +143,10 @@
previous_storage_name, previous_storage_name,
index, index,
origin_url = window.location.href; origin_url = window.location.href;
return RSVP.Queue() return gadget.getSettingList(['configuration_manifest',
.push(function () { 'jio_storage_name',
return RSVP.all([ 'previous_storage_name',
gadget.getSetting('configuration_manifest'), 'migration_version'])
gadget.getSetting('jio_storage_name'),
gadget.getSetting('previous_storage_name'),
gadget.getSetting('migration_version')
]);
})
.push(function (result_list) { .push(function (result_list) {
selected_storage_name = result_list[1]; selected_storage_name = result_list[1];
previous_storage_name = result_list[2]; previous_storage_name = result_list[2];
...@@ -204,14 +200,14 @@ ...@@ -204,14 +200,14 @@
if (result_list[0] === undefined) { return; } if (result_list[0] === undefined) { return; }
if (selected_storage_name === undefined) { return; } if (selected_storage_name === undefined) { return; }
gadget.state_parameter_dict.jio_storage_name = selected_storage_name; 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, ""); current_version = window.location.href.replace(window.location.hash, "");
index = current_version.indexOf(window.location.host) + window.location.host.length; index = current_version.indexOf(window.location.host) + window.location.host.length;
current_version = current_version.substr(index); current_version = current_version.substr(index);
if (migration_version !== current_version || if (migration_version !== current_version ||
previous_storage_name !== selected_storage_name) { previous_storage_name !== selected_storage_name) {
return gadget.updateConfiguration(appcache_storage, origin_url, migration_version, return gadget.updateConfiguration(jio_appchache_options, origin_url,
current_version, selected_storage_name); migration_version, current_version,
selected_storage_name);
} }
}) })
.push(undefined, function (error) { .push(undefined, function (error) {
......
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>979.3132.57631.22818</string> </value> <value> <string>979.7652.21916.23961</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -252,7 +252,7 @@ ...@@ -252,7 +252,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1570799816.86</float> <float>1571071046.04</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </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