Commit af3fb549 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_gadget_interface_validator] JSLint

parent fe9a9c94
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>946.46289.58152.58624</string> </value> <value> <string>968.15557.27071.42905</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>1446475754.4</float> <float>1529069154.34</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*global window, rJS, RSVP, Handlebars */ /*global window, rJS, RSVP, Handlebars, $, loopEventListener */
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80 */
(function (window, rJS, RSVP, Handlebars) { (function (window, rJS, RSVP, Handlebars, $, loopEventListener) {
"use strict"; "use strict";
var INTERFACE_GADGET_SCOPE = "interface_gadget"; var INTERFACE_GADGET_SCOPE = "interface_gadget",
/////////////////////////////////////////////////////////////////
// Handlebars
/////////////////////////////////////////////////////////////////
// Precompile the templates while loading the first gadget instance
gadget_klass = rJS(window),
source = gadget_klass.__template_element
.getElementById("interface-validator-template")
.innerHTML,
interface_validator_template = Handlebars.compile(source);
function fetchPageType(gadget_url) { function fetchPageType(gadget_url) {
var page_type = '', var page_type = '',
key = '_page_'; key = '_page_';
if(gadget_url.indexOf(key) > -1) { if (gadget_url.indexOf(key) > -1) {
page_type = gadget_url.substring(gadget_url.indexOf(key) + key.length, page_type = gadget_url.substring(gadget_url.indexOf(key) + key.length,
gadget_url.lastIndexOf('.')); gadget_url.lastIndexOf('.'));
} }
return page_type; return page_type;
} }
/////////////////////////////////////////////////////////////////
// Handlebars
/////////////////////////////////////////////////////////////////
// Precompile the templates while loading the first gadget instance
var gadget_klass = rJS(window),
source = gadget_klass.__template_element
.getElementById("interface-validator-template")
.innerHTML,
interface_validator_template = Handlebars.compile(source);
gadget_klass gadget_klass
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// ready // ready
...@@ -38,7 +37,7 @@ ...@@ -38,7 +37,7 @@
.ready(function (g) { .ready(function (g) {
return g.getElement() return g.getElement()
.push(function (element) { .push(function (element) {
g.props.element = element, g.props.element = element;
g.props.content_element = element.querySelector('.appcache_form'); g.props.content_element = element.querySelector('.appcache_form');
}); });
}) })
...@@ -56,10 +55,11 @@ ...@@ -56,10 +55,11 @@
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this; var gadget = this;
return new RSVP.Queue() return new RSVP.Queue()
.push(function() { .push(function () {
var error_message = ''; var error_message = '';
if(options.found !== undefined && options.found === 'false') { if (options.found !== undefined && options.found === 'false') {
error_message = "Error: Cannot load the appcache file. Please check and try again."; error_message = "Error: Cannot load the appcache file. " +
"Please check and try again.";
} }
gadget.props.content_element.innerHTML = gadget.props.content_element.innerHTML =
interface_validator_template({ interface_validator_template({
...@@ -76,7 +76,9 @@ ...@@ -76,7 +76,9 @@
.declareService(function () { .declareService(function () {
//////////////////////////////////// ////////////////////////////////////
// Form submit listening. Prevent browser to automatically handle the form submit in case of a bug // Form submit listening.
// Prevent browser to automatically handle the form submit in
// case of a bug
//////////////////////////////////// ////////////////////////////////////
var gadget = this; var gadget = this;
function formSubmit(submit_event) { function formSubmit(submit_event) {
...@@ -88,37 +90,42 @@ ...@@ -88,37 +90,42 @@
.disabled = true; .disabled = true;
return submit_event.target[0].value; return submit_event.target[0].value;
}) })
.push(function(submit_url) { .push(function (submit_url) {
appcache_url = submit_url; appcache_url = submit_url;
return gadget.getDeclaredGadget(INTERFACE_GADGET_SCOPE); return gadget.getDeclaredGadget(INTERFACE_GADGET_SCOPE);
}) })
.push(function(i_gadget) { .push(function (i_gadget) {
var required_interface = 'gadget_interface_validator_reportpage_interface.html', var required_interface =
'gadget_interface_validator_reportpage_interface.html',
gadget_source_url = 'gadget_interface_validator.appcache'; gadget_source_url = 'gadget_interface_validator.appcache';
interface_gadget = i_gadget; interface_gadget = i_gadget;
return interface_gadget.getGadgetListImplementingInterface(required_interface, gadget_source_url); return interface_gadget.getGadgetListImplementingInterface(
required_interface,
gadget_source_url
);
}) })
.push(function(gadget_list) { .push(function (gadget_list) {
if(gadget_list.length > 0) { if (gadget_list.length > 0) {
var page_type = fetchPageType(gadget_list[0]); var page_type = fetchPageType(gadget_list[0]);
return gadget.redirect({ return gadget.redirect({
page: page_type, page: page_type,
appcache_url: appcache_url appcache_url: appcache_url
}); });
} else {
return gadget.redirect({
found: false
});
} }
return gadget.redirect({
found: false
});
}); });
} }
// Listen to form submit // Listen to form submit
return loopEventListener( return loopEventListener(
gadget.props.content_element.querySelector('form.interface-validation-form'), gadget.props.content_element.querySelector(
'form.interface-validation-form'
),
'submit', 'submit',
false, false,
formSubmit formSubmit
); );
}); });
}(window, rJS, RSVP, Handlebars)); }(window, rJS, RSVP, Handlebars, $, loopEventListener));
\ No newline at end of file \ No newline at end of file
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>946.54877.22908.40635</string> </value> <value> <string>968.15277.3815.5239</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>1446717901.46</float> <float>1529052317.55</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>946.54878.32293.23654</string> </value> <value> <string>968.15263.39947.11758</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>1446717974.43</float> <float>1529051525.57</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*global window, rJS */ /*global window, rJS, document, loopEventListener, RSVP */
/*jslint nomen: true, indent: 2 */ /*jslint nomen: true, indent: 2, maxlen: 80 */
(function (window, rJS) { (function (window, rJS, document, loopEventListener, RSVP) {
"use strict"; "use strict";
var MAIN_PAGE_PREFIX = "gadget_interface_validator_", var MAIN_PAGE_PREFIX = "gadget_interface_validator_",
DEFAULT_PAGE = "form", DEFAULT_PAGE = "form",
REDIRECT_TIMEOUT = 5000; REDIRECT_TIMEOUT = 5000;
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
if (subhash !== '') { if (subhash !== '') {
keyvalue = subhash.split('='); keyvalue = subhash.split('=');
if (keyvalue.length === 2) { if (keyvalue.length === 2) {
args[decodeURIComponent(keyvalue[0])] = decodeURIComponent(keyvalue[1]); args[decodeURIComponent(keyvalue[0])] =
decodeURIComponent(keyvalue[1]);
} }
} }
} }
...@@ -52,7 +53,7 @@ ...@@ -52,7 +53,7 @@
}; };
}) })
.declareMethod("getCommandUrlFor", function(options) { .declareMethod("getCommandUrlFor", function (options) {
var prefix = '', var prefix = '',
result, result,
key; key;
...@@ -60,7 +61,8 @@ ...@@ -60,7 +61,8 @@
for (key in options) { for (key in options) {
if (options.hasOwnProperty(key) && options[key] !== undefined) { if (options.hasOwnProperty(key) && options[key] !== undefined) {
// Don't keep empty values // Don't keep empty values
result += prefix + encodeURIComponent(key) + "=" + encodeURIComponent(options[key]); result += prefix + encodeURIComponent(key) + "=" +
encodeURIComponent(options[key]);
prefix = '&'; prefix = '&';
} }
} }
...@@ -79,8 +81,7 @@ ...@@ -79,8 +81,7 @@
}) })
.declareMethod('route', function (options) { .declareMethod('route', function (options) {
var gadget = this, var args = options.args,
args = options.args,
page; page;
page = args.page || DEFAULT_PAGE; page = args.page || DEFAULT_PAGE;
...@@ -105,4 +106,4 @@ ...@@ -105,4 +106,4 @@
}); });
}); });
}(window, rJS)); }(window, rJS, document, loopEventListener, RSVP));
\ No newline at end of file \ No newline at end of file
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>946.58912.52724.48776</string> </value> <value> <string>968.15281.35451.28142</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>1446805302.57</float> <float>1529052586.11</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