Commit 4234b52a authored by Romain Courteaud's avatar Romain Courteaud

[erp5_web_renderjs_ui] Add getUrlForList acquired method

Reduce the number of acquired method calls by grouping them.
parent 954f9dee
...@@ -397,6 +397,9 @@ ...@@ -397,6 +397,9 @@
.allowPublicAcquisition("getUrlFor", function (param_list) { .allowPublicAcquisition("getUrlFor", function (param_list) {
return route(this, 'router', 'getCommandUrlFor', param_list); return route(this, 'router', 'getCommandUrlFor', param_list);
}) })
.allowPublicAcquisition("getUrlForList", function (param_list) {
return route(this, 'router', 'getCommandUrlForList', param_list);
})
.allowPublicAcquisition("updateHeader", function (param_list) { .allowPublicAcquisition("updateHeader", function (param_list) {
var gadget = this; var gadget = this;
......
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>967.30869.341.45038</string> </value> <value> <string>967.30869.54828.19677</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -248,7 +248,7 @@ ...@@ -248,7 +248,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1526055710.14</float> <float>1526293842.78</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -169,10 +169,7 @@ ...@@ -169,10 +169,7 @@
return options.url; return options.url;
} }
if (command === COMMAND_CHANGE_LANGUAGE) { if (command === COMMAND_CHANGE_LANGUAGE) {
return new RSVP.Queue() return gadget.getSetting("website_url_set")
.push(function () {
return gadget.getSetting("website_url_set");
})
.push(function (result) { .push(function (result) {
var param_list = window.location.hash.split('#')[1], var param_list = window.location.hash.split('#')[1],
new_url = JSON.parse(result)[options.language]; new_url = JSON.parse(result)[options.language];
...@@ -220,6 +217,34 @@ ...@@ -220,6 +217,34 @@
return result; return result;
} }
function getCommandUrlForMethod(gadget, options) {
var command = options.command,
absolute_url = options.absolute_url,
hash,
args = options.options,
valid = true,
key;
// Only authorize 'command', 'options', 'absolute_url' keys
// Drop all other kind of parameters, to detect issue more easily
for (key in options) {
if (options.hasOwnProperty(key)) {
if ((key !== 'command') && (key !== 'options') && (key !== 'absolute_url')) {
valid = false;
}
}
}
if (valid && (options.command) && (VALID_URL_COMMAND_DICT.hasOwnProperty(options.command))) {
hash = getCommandUrlFor(gadget, command, args);
} else {
hash = getCommandUrlFor(gadget, 'error', options);
}
if (absolute_url) {
hash = new URL(hash, window.location.href).href;
}
return hash;
}
function getDisplayUrlFor(jio_key, options) { function getDisplayUrlFor(jio_key, options) {
var prefix = '?', var prefix = '?',
result, result,
...@@ -946,32 +971,16 @@ ...@@ -946,32 +971,16 @@
}); });
}) })
.declareMethod('getCommandUrlFor', function (options) { .declareMethod('getCommandUrlForList', function (options_list) {
var command = options.command, var i,
absolute_url = options.absolute_url, result_list = [];
hash, for (i = 0; i < options_list.length; i += 1) {
args = options.options, result_list.push(getCommandUrlForMethod(this, options_list[i]));
valid = true,
key;
// Only authorize 'command', 'options', 'absolute_url' keys
// Drop all other kind of parameters, to detect issue more easily
for (key in options) {
if (options.hasOwnProperty(key)) {
if ((key !== 'command') && (key !== 'options') && (key !== 'absolute_url')) {
valid = false;
}
}
}
if (valid && (options.command) && (VALID_URL_COMMAND_DICT.hasOwnProperty(options.command))) {
hash = getCommandUrlFor(this, command, args);
} else {
hash = getCommandUrlFor(this, 'error', options);
}
if (absolute_url) {
hash = new URL(hash, window.location.href).href;
} }
return hash; return result_list;
})
.declareMethod('getCommandUrlFor', function (options) {
return getCommandUrlForMethod(this, options);
}) })
.declareMethod('redirect', function (options, push_history) { .declareMethod('redirect', function (options, push_history) {
......
...@@ -232,7 +232,7 @@ ...@@ -232,7 +232,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>966.2649.17362.11178</string> </value> <value> <string>967.34846.62513.42240</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -250,8 +250,8 @@ ...@@ -250,8 +250,8 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1520516819.75</float> <float>1526294815.82</float>
<string>GMT+1</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
</object> </object>
......
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