Commit af3fb549 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_gadget_interface_validator] JSLint

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