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 @@
.allowPublicAcquisition("getUrlFor", function (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) {
var gadget = this;
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>967.30869.341.45038</string> </value>
<value> <string>967.30869.54828.19677</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1526055710.14</float>
<float>1526293842.78</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -169,10 +169,7 @@
return options.url;
}
if (command === COMMAND_CHANGE_LANGUAGE) {
return new RSVP.Queue()
.push(function () {
return gadget.getSetting("website_url_set");
})
return gadget.getSetting("website_url_set")
.push(function (result) {
var param_list = window.location.hash.split('#')[1],
new_url = JSON.parse(result)[options.language];
......@@ -220,6 +217,34 @@
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) {
var prefix = '?',
result,
......@@ -946,32 +971,16 @@
});
})
.declareMethod('getCommandUrlFor', function (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(this, command, args);
} else {
hash = getCommandUrlFor(this, 'error', options);
}
if (absolute_url) {
hash = new URL(hash, window.location.href).href;
.declareMethod('getCommandUrlForList', function (options_list) {
var i,
result_list = [];
for (i = 0; i < options_list.length; i += 1) {
result_list.push(getCommandUrlForMethod(this, options_list[i]));
}
return hash;
return result_list;
})
.declareMethod('getCommandUrlFor', function (options) {
return getCommandUrlForMethod(this, options);
})
.declareMethod('redirect', function (options, push_history) {
......
......@@ -232,7 +232,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>966.2649.17362.11178</string> </value>
<value> <string>967.34846.62513.42240</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -250,8 +250,8 @@
</tuple>
<state>
<tuple>
<float>1520516819.75</float>
<string>GMT+1</string>
<float>1526294815.82</float>
<string>UTC</string>
</tuple>
</state>
</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