Commit a3c6df2f authored by Romain Courteaud's avatar Romain Courteaud

[erp5_web_renderjs_ui] Launcher: factorize some code

parent 206a30ad
...@@ -38,10 +38,7 @@ ...@@ -38,10 +38,7 @@
} }
function route(my_root_gadget, my_scope, my_method, argument_list) { function route(my_root_gadget, my_scope, my_method, argument_list) {
return RSVP.Queue() return my_root_gadget.getDeclaredGadget(my_scope)
.push(function () {
return my_root_gadget.getDeclaredGadget(my_scope);
})
.push(function (my_gadget) { .push(function (my_gadget) {
if (argument_list) { if (argument_list) {
return my_gadget[my_method].apply(my_gadget, argument_list); return my_gadget[my_method].apply(my_gadget, argument_list);
...@@ -310,10 +307,7 @@ ...@@ -310,10 +307,7 @@
var gadget = this, var gadget = this,
key = argument_list[0], key = argument_list[0],
default_value = argument_list[1]; default_value = argument_list[1];
return gadget.getDeclaredGadget("setting_gadget") return route(gadget, 'setting_gadget', 'get', [gadget.props.setting_id])
.push(function (jio_gadget) {
return jio_gadget.get(gadget.props.setting_id);
})
.push(function (doc) { .push(function (doc) {
return doc[key] || default_value; return doc[key] || default_value;
}, function (error) { }, function (error) {
...@@ -345,10 +339,7 @@ ...@@ -345,10 +339,7 @@
}); });
}) })
.allowPublicAcquisition("translateHtml", function (argument_list) { .allowPublicAcquisition("translateHtml", function (argument_list) {
return this.getDeclaredGadget("translation_gadget") return route(this, 'translation_gadget', 'translateHtml', argument_list);
.push(function (translation_gadget) {
return translation_gadget.translateHtml(argument_list[0]);
});
}) })
// XXX Those methods may be directly integrated into the header, // XXX Those methods may be directly integrated into the header,
...@@ -391,33 +382,20 @@ ...@@ -391,33 +382,20 @@
}) })
.allowPublicAcquisition("translate", function (argument_list) { .allowPublicAcquisition("translate", function (argument_list) {
return this.getDeclaredGadget("translation_gadget") return route(this, 'translation_gadget', 'translate', argument_list);
.push(function (translation_gadget) {
return translation_gadget.translate(argument_list[0]);
});
}) })
.allowPublicAcquisition("redirect", function (param_list) { .allowPublicAcquisition("redirect", function (param_list) {
return this.getDeclaredGadget('router') return route(this, 'router', 'redirect', param_list);
.push(function (router_gadget) {
return router_gadget.redirect.apply(router_gadget, param_list);
});
}) })
.allowPublicAcquisition('reload', function () { .allowPublicAcquisition('reload', function () {
return location.reload(); return location.reload();
}) })
.allowPublicAcquisition("getUrlParameter", function (param_list) { .allowPublicAcquisition("getUrlParameter", function (param_list) {
return this.getDeclaredGadget('router') return route(this, 'router', 'getUrlParameter', param_list);
.push(function (router_gadget) {
return router_gadget.getUrlParameter.apply(router_gadget, param_list);
});
}) })
.allowPublicAcquisition("getUrlFor", function (param_list) { .allowPublicAcquisition("getUrlFor", function (param_list) {
return this.getDeclaredGadget('router') return route(this, 'router', 'getCommandUrlFor', param_list);
.push(function (router_gadget) {
return router_gadget.getCommandUrlFor.apply(router_gadget,
param_list);
});
}) })
.allowPublicAcquisition("updateHeader", function (param_list) { .allowPublicAcquisition("updateHeader", function (param_list) {
......
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>966.11431.6711.50466</string> </value> <value> <string>967.30869.341.45038</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>1521043696.52</float> <float>1526055710.14</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