Commit af3fb549 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_gadget_interface_validator] JSLint

parent fe9a9c94
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 30, maxlen: 80 */
/*global DOMParser, document, XMLHttpRequest, rJS, renderJS, RSVP, window*/
/* /*
* DOMParser HTML extension * DOMParser HTML extension
* 2012-09-04 * 2012-09-04
...@@ -8,7 +9,7 @@ ...@@ -8,7 +9,7 @@
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. * NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
*/ */
/*! @source https://gist.github.com/1129031 */ /*! @source https://gist.github.com/1129031 */
(function (DOMParser) { (function (DOMParser, document) {
"use strict"; "use strict";
var DOMParser_proto = DOMParser.prototype, var DOMParser_proto = DOMParser.prototype,
real_parseFromString = DOMParser_proto.parseFromString; real_parseFromString = DOMParser_proto.parseFromString;
...@@ -42,11 +43,9 @@ ...@@ -42,11 +43,9 @@
} }
return result; return result;
}; };
}(DOMParser)); }(DOMParser, document));
/*global window, rJS, RSVP */ (function (window, rJS, RSVP, DOMParser, XMLHttpRequest, renderJS) {
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, DOMParser) {
"use strict"; "use strict";
function ajax(url) { function ajax(url) {
var xhr; var xhr;
...@@ -88,13 +87,13 @@ ...@@ -88,13 +87,13 @@
function fetchAppcacheData(appcache_url) { function fetchAppcacheData(appcache_url) {
var defer = RSVP.defer(); var defer = RSVP.defer();
return new RSVP.Queue() return new RSVP.Queue()
.push(function() { .push(function () {
return ajax(appcache_url); return ajax(appcache_url);
}) })
.push(function(xhr) { .push(function (xhr) {
var filename_list = xhr.responseText.split('\n'); var filename_list = xhr.responseText.split('\n');
return filename_list; return filename_list;
}, function(error) { }, function (error) {
defer.reject(error); defer.reject(error);
return defer.promise; return defer.promise;
}); });
...@@ -107,20 +106,20 @@ ...@@ -107,20 +106,20 @@
ext, ext,
file_name, file_name,
last_index, last_index,
item; i;
for(item in filename_list) { for (i = 0; i < filename_list.length; i += 1) {
last_index = filename_list[item].lastIndexOf('.'); last_index = filename_list[i].lastIndexOf('.');
file_name = filename_list[item].substr(0,last_index); file_name = filename_list[i].substr(0, last_index);
ext = filename_list[item].substr(last_index+1); ext = filename_list[i].substr(last_index + 1);
if(ext === "html") { if (ext === "html") {
html_list.push(file_name); html_list.push(file_name);
} else if(ext === "js") { } else if (ext === "js") {
js_list.push(file_name); js_list.push(file_name);
} }
} }
for(item in html_list) { for (i = 0; i < html_list.length; i += 1) {
if (js_list.indexOf(html_list[item]) > -1) { if (js_list.indexOf(html_list[i]) > -1) {
gadget_list.push(html_list[item] + ".html"); gadget_list.push(html_list[i] + ".html");
} }
} }
return gadget_list; return gadget_list;
...@@ -128,37 +127,42 @@ ...@@ -128,37 +127,42 @@
function generateErrorMessage(error) { function generateErrorMessage(error) {
var error_message = ''; var error_message = '';
error_message = error_message error_message = error_message +
+ error.toString() error.toString() +
+ (error.message !== undefined ? error.message : '') (error.message !== undefined ? error.message : '') +
+ (error.status ? error.status.toString() + ' ' : '') (error.status ? error.status.toString() + ' ' : '') +
+ (error.statusText !== undefined ? error.statusText : ''); (error.statusText !== undefined ? error.statusText : '');
return error_message; return error_message;
} }
function getInterfaceListFromURL(gadget_url) { function getInterfaceListFromURL(gadget_url) {
var defer = RSVP.defer(); var defer = RSVP.defer();
return new RSVP.Queue() return new RSVP.Queue()
.push(function() { .push(function () {
return ajax(gadget_url); return ajax(gadget_url);
}) })
.push(function(xhr) { .push(function (xhr) {
var document_element = (new DOMParser()).parseFromString(xhr.responseText, 'text/html'), var document_element = (new DOMParser()).parseFromString(
xhr.responseText,
'text/html'
),
interface_list = [], interface_list = [],
element, element,
i; i;
if (document_element.nodeType === 9 && document_element.head !== null) { if (document_element.nodeType === 9 && document_element.head !== null) {
for (i = 0; i < document_element.head.children.length; i += 1) { for (i = 0; i < document_element.head.children.length; i += 1) {
element = document_element.head.children[i]; element = document_element.head.children[i];
if (element.href !== null && element.rel === "http://www.renderjs.org/rel/interface") { if (element.href !== null &&
element.rel === "http://www.renderjs.org/rel/interface") {
interface_list.push( interface_list.push(
renderJS.getAbsoluteURL(element.getAttribute("href"), window.location.href) renderJS.getAbsoluteURL(element.getAttribute("href"),
window.location.href)
); );
} }
} }
} }
return interface_list; return interface_list;
}, function(error) { }, function (error) {
var message = "Error with loading the gadget data.\n"; var message = "Error with loading the gadget data.\n";
error.message = message + generateErrorMessage(error); error.message = message + generateErrorMessage(error);
defer.reject(error); defer.reject(error);
...@@ -168,37 +172,54 @@ ...@@ -168,37 +172,54 @@
function verifyInterfaceDefinition(interface_url) { function verifyInterfaceDefinition(interface_url) {
//to verify if interface definition follows the correct template. //to verify if interface definition follows the correct template.
var error_message = "Interface definition is incorrect: One or more required tags are missing.", var error_message = "Interface definition is incorrect: " +
"One or more required tags are missing.",
defer = RSVP.defer(); defer = RSVP.defer();
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return ajax(interface_url); return ajax(interface_url);
}) })
.push(function(xhr) { .push(function (xhr) {
var doc = (new DOMParser()).parseFromString(xhr.responseText, 'text/html').body, var doc = (new DOMParser()).parseFromString(xhr.responseText,
'text/html').body,
dl_list = doc.getElementsByTagName('dl'), dl_list = doc.getElementsByTagName('dl'),
next_element = dl_list[0].firstElementChild, next_element = dl_list[0].firstElementChild,
method_len = dl_list.length - 1, method_len = dl_list.length - 1,
i; argument_len,
if (dl_list[0].childElementCount !== 3*method_len) { next_child_element,
i,
j;
if (dl_list[0].childElementCount !== 3 * method_len) {
throw new Error(error_message); throw new Error(error_message);
} }
try { try {
for (i = 0; i < method_len; i += 1) { for (i = 0; i < method_len; i += 1) {
if ((!next_element || next_element.localName.toLowerCase() !== 'dt') || if ((next_element === null) ||
(!(next_element = next_element.nextElementSibling) || next_element.localName.toLowerCase() !== 'dd') || (next_element.localName.toLowerCase() !== 'dt')) {
(!(next_element = next_element.nextElementSibling) || next_element.localName.toLowerCase() !== 'dl')) {
throw new Error(error_message); throw new Error(error_message);
} }
if(next_element.getElementsByTagName('dt').length !== next_element.getElementsByTagName('dd').length) { next_element = next_element.nextElementSibling;
if (next_element.localName.toLowerCase() !== 'dd') {
throw new Error(error_message); throw new Error(error_message);
} }
var argument_len = next_element.getElementsByTagName('dt').length, next_element = next_element.nextElementSibling;
next_child_element = next_element.firstElementChild, if (next_element.localName.toLowerCase() !== 'dl') {
j; throw new Error(error_message);
}
if (next_element.getElementsByTagName('dt').length !==
next_element.getElementsByTagName('dd').length) {
throw new Error(error_message);
}
argument_len = next_element.getElementsByTagName('dt').length;
next_child_element = next_element.firstElementChild;
for (j = 0; j < argument_len; j += 1) { for (j = 0; j < argument_len; j += 1) {
if ((!next_child_element || next_child_element.localName.toLowerCase() !== 'dt') || if ((next_child_element === null) ||
(!(next_child_element = next_child_element.nextElementSibling) || next_child_element.localName.toLowerCase() !== 'dd')) { (next_child_element.localName.toLowerCase() !== 'dt')) {
throw new Error(error_message);
}
next_child_element = next_child_element.nextElementSibling;
if (next_child_element.localName.toLowerCase() !== 'dd') {
throw new Error(error_message); throw new Error(error_message);
} }
next_child_element = next_child_element.nextElementSibling; next_child_element = next_child_element.nextElementSibling;
...@@ -206,11 +227,11 @@ ...@@ -206,11 +227,11 @@
next_element = next_element.nextElementSibling; next_element = next_element.nextElementSibling;
} }
defer.resolve("Success"); defer.resolve("Success");
} catch(error) { } catch (error) {
defer.reject(error); defer.reject(error);
} }
return defer.promise; return defer.promise;
}, function(error) { }, function (error) {
var message = "Error with loading the interface data.\n"; var message = "Error with loading the interface data.\n";
error.message = message + generateErrorMessage(error); error.message = message + generateErrorMessage(error);
defer.reject(error); defer.reject(error);
...@@ -227,119 +248,135 @@ ...@@ -227,119 +248,135 @@
} else { } else {
throw new Error("Interface is not declared."); throw new Error("Interface is not declared.");
} }
} catch(error) { } catch (error) {
defer.reject(error); defer.reject(error);
} }
return defer.promise; return defer.promise;
} }
function verifyAllMethod(interface_method_list, gadget_method_list) { /*
//to verify all methods of gadget and interface. function verifyMethodSignature(interface_method, gadget_method) {
var defer = RSVP.defer(); //to verify if two methods have the same signature
return new RSVP.Queue() var max_arg_len = interface_method.argument_list.length,
.push(function() { min_arg_len = 0,
return verifyAllMethodDeclared(interface_method_list, gadget_method_list[0]); i,
}) argument_list;
/* Commented till figure out the way to fetch the argument length of a defined function. if (max_arg_len) {
.push(function() { argument_list = interface_method.argument_list;
return verifyAllMethodSignature(interface_method_list, gadget_method_list[1]); for (i = 0; i < argument_list.length; i += 1) {
}) if (argument_list[i].required) {
*/ min_arg_len += 1;
.push (function() { }
defer.resolve("Success"); }
return defer.promise; }
}, function(error) { return (gadget_method.arg_len >= min_arg_len &&
defer.reject(error); gadget_method.arg_len <= max_arg_len);
return defer.promise;
});
} }
function verifyAllMethodDeclared(interface_method_list, gadget_method_list) { function verifyAllMethodSignature(interface_method_list, gadget_method_list) {
//to verify if all the interface methods are declared by the gadget. //to verify if all the declared methods match the signature
// of the interface methods.
var defer = RSVP.defer(), var defer = RSVP.defer(),
gadget_method_name_list = gadget_method_list, interface_method_dict = {},
interface_method_name_list = [], gadget_method_name_list = [],
i, j, index,
item,
i,
j,
failed = false, failed = false,
failed_methods = []; failed_methods = [];
for (i = 0; i < interface_method_list.length; i += 1) { for (i = 0; i < interface_method_list.length; i += 1) {
interface_method_name_list.push(interface_method_list[i].name); interface_method_dict[interface_method_list[i].name] =
interface_method_list[i];
}
for (j = 0; j < gadget_method_list.length; j += 1) {
gadget_method_name_list.push(gadget_method_list[j].name);
} }
try { try {
for (j = 0; j < interface_method_name_list.length; j += 1) { for (item in interface_method_dict) {
if(gadget_method_name_list.indexOf(interface_method_name_list[j]) < 0) { index = gadget_method_name_list.lastIndexOf(item);
if (!verifyMethodSignature(interface_method_dict[item],
gadget_method_list[index])) {
failed = true; failed = true;
failed_methods.push(interface_method_name_list[j]); failed_methods.push(item);
} }
} }
if(failed) { if (failed) {
var error_message = "Following required methods are not declared in the gadget: ", var error_message =
"Following methods have missing/mismatched arguments: ",
method; method;
for(method in failed_methods) { for (method in failed_methods) {
error_message += ("\n" + failed_methods[method]); error_message += ("\n" + failed_methods[method]);
} }
throw new Error(error_message); throw new Error(error_message);
} }
defer.resolve("Success"); defer.resolve("Success");
} catch(error) { } catch (error) {
defer.reject(error); defer.reject(error);
} }
return defer.promise; return defer.promise;
} }
*/
function verifyAllMethodSignature(interface_method_list, gadget_method_list) { function verifyAllMethodDeclared(interface_method_list, gadget_method_list) {
//to verify if all the declared methods match the signature of the interface methods. //to verify if all the interface methods are declared by the gadget.
var defer = RSVP.defer(), var defer = RSVP.defer(),
interface_method_dict = {}, gadget_method_name_list = gadget_method_list,
gadget_method_name_list = [], interface_method_name_list = [],
index, i,
item, j,
i, j,
failed = false, failed = false,
failed_methods = []; failed_methods = [],
for(i = 0; i < interface_method_list.length; i += 1) { error_message;
interface_method_dict[interface_method_list[i].name] = interface_method_list[i]; for (i = 0; i < interface_method_list.length; i += 1) {
} interface_method_name_list.push(interface_method_list[i].name);
for(j = 0; j < gadget_method_list.length; j += 1) {
gadget_method_name_list.push(gadget_method_list[j].name);
} }
try { try {
for(item in interface_method_dict) { for (j = 0; j < interface_method_name_list.length; j += 1) {
index = gadget_method_name_list.lastIndexOf(item); if (gadget_method_name_list.indexOf(
if(!verifyMethodSignature(interface_method_dict[item], gadget_method_list[index])) { interface_method_name_list[j]
) < 0) {
failed = true; failed = true;
failed_methods.push(item); failed_methods.push(interface_method_name_list[j]);
} }
} }
if(failed) { if (failed) {
var error_message = "Following methods have missing/mismatched arguments: ", error_message =
method; "Following required methods are not declared in the gadget: ";
for(method in failed_methods) { for (i = 0; i < failed_methods.length; i += 1) {
error_message += ("\n" + failed_methods[method]); error_message += ("\n" + failed_methods[i]);
} }
throw new Error(error_message); throw new Error(error_message);
} }
defer.resolve("Success"); defer.resolve("Success");
} catch(error) { } catch (error) {
defer.reject(error); defer.reject(error);
} }
return defer.promise; return defer.promise;
} }
function verifyMethodSignature(interface_method, gadget_method) { function verifyAllMethod(interface_method_list, gadget_method_list) {
//to verify if two methods have the same signature //to verify all methods of gadget and interface.
var max_arg_len = interface_method.argument_list.length, var defer = RSVP.defer();
min_arg_len = 0, return new RSVP.Queue()
i; .push(function () {
if (max_arg_len) { return verifyAllMethodDeclared(interface_method_list,
var argument_list = interface_method.argument_list; gadget_method_list[0]);
for (i = 0; i < argument_list.length; i += 1) { })
if (argument_list[i].required) { /* Commented till figure out the way to fetch the argument length of a
min_arg_len += 1; defined function.
} .push(function() {
} return verifyAllMethodSignature(interface_method_list,
} gadget_method_list[1]);
return (gadget_method.arg_len >= min_arg_len && gadget_method.arg_len <= max_arg_len); })
*/
.push(function () {
defer.resolve("Success");
return defer.promise;
}, function (error) {
defer.reject(error);
return defer.promise;
});
} }
rJS(window) rJS(window)
...@@ -358,7 +395,7 @@ ...@@ -358,7 +395,7 @@
}) })
.push(function () { .push(function () {
return interface_gadget.getDeclaredGadget(gadget_url); return interface_gadget.getDeclaredGadget(gadget_url);
}, function(error) { }, function (error) {
var message = "Error with loading the gadget.\n"; var message = "Error with loading the gadget.\n";
error.message = message + error.message; error.message = message + error.message;
defer.reject(error); defer.reject(error);
...@@ -367,19 +404,17 @@ ...@@ -367,19 +404,17 @@
}) })
.declareMethod("getDeclaredGadgetInterfaceList", function (gadget_data) { .declareMethod("getDeclaredGadgetInterfaceList", function (gadget_data) {
var interface_gadget = this, var defer = RSVP.defer();
defer = RSVP.defer();
return new RSVP.Queue() return new RSVP.Queue()
.push(function() { .push(function () {
if(gadget_data.constructor === String) { if (gadget_data.constructor === String) {
return getInterfaceListFromURL(gadget_data); return getInterfaceListFromURL(gadget_data);
} else {
return gadget_data.getInterfaceList();
} }
return gadget_data.getInterfaceList();
}) })
.push(function(interface_list) { .push(function (interface_list) {
return interface_list; return interface_list;
}, function(error) { }, function (error) {
defer.reject(error); defer.reject(error);
return defer.promise; return defer.promise;
}); });
...@@ -389,14 +424,18 @@ ...@@ -389,14 +424,18 @@
var declared_method_dict = {}, var declared_method_dict = {},
declared_method_list = [], declared_method_list = [],
item; item;
for (item in gadget) { for (item in gadget.constructor.prototype) {
if (gadget.constructor.prototype.hasOwnProperty(item)) {
if (!(/__/).test(item)) { if (!(/__/).test(item)) {
declared_method_dict[item] = gadget[item]; declared_method_dict[item] = gadget[item];
} }
} }
for(item in declared_method_dict) { }
for (item in declared_method_dict) {
if (declared_method_dict.hasOwnProperty(item)) {
declared_method_list.push(item); declared_method_list.push(item);
} }
}
return RSVP.all([ return RSVP.all([
declared_method_list //, declared_method_list //,
// gadget.getDeclaredMethodList() // gadget.getDeclaredMethodList()
...@@ -406,15 +445,15 @@ ...@@ -406,15 +445,15 @@
.declareMethod("getGadgetListFromAppcache", function (appcache_url) { .declareMethod("getGadgetListFromAppcache", function (appcache_url) {
var defer = RSVP.defer(); var defer = RSVP.defer();
return new RSVP.Queue() return new RSVP.Queue()
.push(function() { .push(function () {
return fetchAppcacheData(appcache_url); return fetchAppcacheData(appcache_url);
}) })
.push(function(filename_list) { .push(function (filename_list) {
return filterGadgetList(filename_list); return filterGadgetList(filename_list);
}) })
.push(function(filtered_gadget_list) { .push(function (filtered_gadget_list) {
return filtered_gadget_list; return filtered_gadget_list;
}, function(error) { }, function (error) {
defer.reject(error); defer.reject(error);
return defer.promise; return defer.promise;
}); });
...@@ -422,10 +461,10 @@ ...@@ -422,10 +461,10 @@
.declareMethod("getAbsoluteURL", function (gadget, url) { .declareMethod("getAbsoluteURL", function (gadget, url) {
return new RSVP.Queue() return new RSVP.Queue()
.push(function() { .push(function () {
return gadget.getPath(); return gadget.getPath();
}) })
.push(function(base_url) { .push(function (base_url) {
return rJS.getAbsoluteURL(url, base_url); return rJS.getAbsoluteURL(url, base_url);
}); });
}) })
...@@ -438,35 +477,42 @@ ...@@ -438,35 +477,42 @@
}, },
defer = RSVP.defer(); defer = RSVP.defer();
return new RSVP.Queue() return new RSVP.Queue()
.push(function() { .push(function () {
return ajax(interface_url); return ajax(interface_url);
}) })
.push(function(xhr) { .push(function (xhr) {
var doc = (new DOMParser()).parseFromString(xhr.responseText, 'text/html').body, var doc = (new DOMParser()).parseFromString(xhr.responseText,
'text/html').body,
dl_list = doc.getElementsByTagName('dl'), dl_list = doc.getElementsByTagName('dl'),
dt_list = doc.getElementsByTagName('dt'), dt_list = doc.getElementsByTagName('dt'),
dd_list = doc.getElementsByTagName('dd'), dd_list = doc.getElementsByTagName('dd'),
method_len = dl_list.length - 1, method_len = dl_list.length - 1,
dt_count = 0, dt_count = 0,
dl_count = 1, dl_count = 1,
i; i,
method,
argument_len,
j,
argument_item;
interface_data.name = doc.getElementsByTagName('h1')[0].innerHTML; interface_data.name = doc.getElementsByTagName('h1')[0].innerHTML;
interface_data.description = doc.getElementsByTagName('h3')[0].innerHTML; interface_data.description =
doc.getElementsByTagName('h3')[0].innerHTML;
for (i = 0; i < method_len; i += 1) { for (i = 0; i < method_len; i += 1) {
var method = { method = {
name: dt_list[dt_count].innerHTML, name: dt_list[dt_count].innerHTML,
description: dd_list[dt_count].innerHTML, description: dd_list[dt_count].innerHTML,
argument_list: [] argument_list: []
}, };
argument_len = dl_list[dl_count].getElementsByTagName('dt').length, argument_len = dl_list[dl_count].getElementsByTagName('dt')
j; .length;
dt_count += 1; dt_count += 1;
dl_count += 1; dl_count += 1;
for (j = 0; j < argument_len; j += 1) { for (j = 0; j < argument_len; j += 1) {
var argument_item = { argument_item = {
name: dt_list[dt_count].innerHTML, name: dt_list[dt_count].innerHTML,
description: dd_list[dt_count].innerHTML, description: dd_list[dt_count].innerHTML,
required: dt_list[dt_count].getAttribute("data-parameter-required") === "optional" ? false:true, required: dt_list[dt_count]
.getAttribute("data-parameter-required") !== "optional",
type: dt_list[dt_count].getAttribute("data-parameter-type") type: dt_list[dt_count].getAttribute("data-parameter-type")
}; };
dt_count += 1; dt_count += 1;
...@@ -475,7 +521,7 @@ ...@@ -475,7 +521,7 @@
interface_data.method_list.push(method); interface_data.method_list.push(method);
} }
return interface_data; return interface_data;
}, function(error) { }, function (error) {
var message = "Error with loading the interface data.\n"; var message = "Error with loading the interface data.\n";
error.message = message + generateErrorMessage(error); error.message = message + generateErrorMessage(error);
defer.reject(error); defer.reject(error);
...@@ -486,68 +532,85 @@ ...@@ -486,68 +532,85 @@
.declareMethod("getDefinedInterfaceMethodList", function (interface_url) { .declareMethod("getDefinedInterfaceMethodList", function (interface_url) {
var defer = RSVP.defer(); var defer = RSVP.defer();
return this.getInterfaceData(interface_url) return this.getInterfaceData(interface_url)
.push(function(interface_data) { .push(function (interface_data) {
return interface_data.method_list; return interface_data.method_list;
}, function(error) { }, function (error) {
defer.reject(error); defer.reject(error);
return defer.promise; return defer.promise;
}); });
}) })
.declareMethod("getGadgetListImplementingInterface", function (interface_data, gadget_source_data) { .declareMethod("getGadgetListImplementingInterface",
function (interface_data, gadget_source_data) {
var interface_gadget = this, var interface_gadget = this,
interface_list, interface_list,
gadget_list; gadget_list;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
var required_interface_list = []; var required_interface_list = [];
if(!interface_data) { if (!interface_data) {
throw new Error("Invalid input: No interface data is provided."); throw new Error("Invalid input: No interface data is provided.");
} else if(interface_data.constructor === Array) { }
if (interface_data.constructor === Array) {
required_interface_list = interface_data; required_interface_list = interface_data;
} else if(interface_data.constructor === String) { } else if (interface_data.constructor === String) {
required_interface_list.push(interface_data); required_interface_list.push(interface_data);
} else { } else {
throw new Error("Invalid input: Invalid interface data is provided."); throw new Error(
"Invalid input: Invalid interface data is provided."
);
} }
return required_interface_list; return required_interface_list;
}) })
.push(function (i_list) { .push(function (i_list) {
var source_gadget_list = []; var source_gadget_list = [];
interface_list = i_list; interface_list = i_list;
if(!gadget_source_data) { if (!gadget_source_data) {
throw new Error("Invalid input: No gadget source information is provided."); throw new Error(
} else if(gadget_source_data.constructor === Array) { "Invalid input: No gadget source information is provided."
);
}
if (gadget_source_data.constructor === Array) {
source_gadget_list = gadget_source_data; source_gadget_list = gadget_source_data;
} else if(gadget_source_data.constructor === String) { } else if (gadget_source_data.constructor === String) {
source_gadget_list = interface_gadget.getGadgetListFromAppcache(gadget_source_data); source_gadget_list = interface_gadget.getGadgetListFromAppcache(
gadget_source_data
);
} else { } else {
throw new Error("Invalid input: Invalid gadget source information is provided."); throw new Error(
"Invalid input: Invalid gadget source information is provided."
);
} }
return source_gadget_list; return source_gadget_list;
}) })
.push(function (g_list) { .push(function (g_list) {
var item, var i,
result_list = []; result_list = [];
gadget_list = g_list; gadget_list = g_list;
for (item in gadget_list) { for (i = 0; i < gadget_list.length; i += 1) {
result_list.push(interface_gadget.verifyGadgetInterfaceImplementation(gadget_list[item], interface_list)); result_list.push(
interface_gadget.verifyGadgetInterfaceImplementation(
gadget_list[i],
interface_list
)
);
} }
return RSVP.all(result_list); return RSVP.all(result_list);
}) })
.push(function(result_list) { .push(function (result_list) {
var item, var i,
result_gadget_list = []; result_gadget_list = [];
for(item in result_list) { for (i = 0; i < result_list.length; i += 1) {
if (result_list[item].result === true) { if (result_list[i].result) {
result_gadget_list.push(gadget_list[item]); result_gadget_list.push(gadget_list[i]);
} }
} }
return result_gadget_list; return result_gadget_list;
}); });
}) })
.declareMethod("verifyGadgetSingleInterfaceImplementation", function (verify_gadget, interface_url) { .declareMethod("verifyGadgetSingleInterfaceImplementation",
function (verify_gadget, interface_url) {
var interface_gadget = this, var interface_gadget = this,
absolute_interface_url, absolute_interface_url,
verify_result = {}; verify_result = {};
...@@ -561,48 +624,53 @@ ...@@ -561,48 +624,53 @@
.push(function (interface_detail) { .push(function (interface_detail) {
var declared_interface_list = interface_detail[0]; var declared_interface_list = interface_detail[0];
absolute_interface_url = interface_detail[1]; absolute_interface_url = interface_detail[1];
return verifyInterfaceDeclaration(absolute_interface_url, declared_interface_list); return verifyInterfaceDeclaration(absolute_interface_url,
declared_interface_list);
}) })
.push(function () { .push(function () {
return verifyInterfaceDefinition(absolute_interface_url); return verifyInterfaceDefinition(absolute_interface_url);
}) })
.push(function () { .push(function () {
return RSVP.all([ return RSVP.all([
interface_gadget.getDefinedInterfaceMethodList(absolute_interface_url), interface_gadget.getDefinedInterfaceMethodList(
absolute_interface_url
),
interface_gadget.getDeclaredGadgetMethodList(verify_gadget) interface_gadget.getDeclaredGadgetMethodList(verify_gadget)
]); ]);
}) })
.push(function(method_list) { .push(function (method_list) {
return verifyAllMethod(method_list[0], method_list[1]); return verifyAllMethod(method_list[0], method_list[1]);
}) })
.push(function() { .push(function () {
verify_result.result = true; verify_result.result = true;
return verify_result; return verify_result;
}, function(error) { }, function (error) {
var interface_name = absolute_interface_url.substr(absolute_interface_url.lastIndexOf('/')+1), var interface_name = absolute_interface_url.substr(
absolute_interface_url.lastIndexOf('/') + 1
),
error_message; error_message;
error_message = "Interface Name: " + interface_name + "\n" error_message = "Interface Name: " + interface_name + "\n" +
+ "Error Details : \n" + error.message + "\n"; "Error Details : \n" + error.message + "\n";
verify_result.result = false; verify_result.result = false;
verify_result.details = error_message; verify_result.details = error_message;
return verify_result; return verify_result;
}); });
}) })
.declareMethod("verifyGadgetInterfaceImplementation", function (gadget_data, interface_data) { .declareMethod("verifyGadgetInterfaceImplementation",
function (gadget_data, interface_data) {
var interface_gadget = this, var interface_gadget = this,
verify_gadget, verify_gadget,
interface_list, interface_list,
verify_result = {}, verify_result = {};
declared_gadget = false;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
var required_gadget; var required_gadget;
if(!gadget_data) { if (!gadget_data) {
throw new Error("Invalid input: No gadget data is provided."); throw new Error("Invalid input: No gadget data is provided.");
} else if(gadget_data.constructor === String) { }
if (gadget_data.constructor === String) {
verify_result.gadget_url = gadget_data; verify_result.gadget_url = gadget_data;
declared_gadget = true;
required_gadget = interface_gadget.getVerifyGadget(gadget_data); required_gadget = interface_gadget.getVerifyGadget(gadget_data);
} else { } else {
required_gadget = gadget_data; required_gadget = gadget_data;
...@@ -612,48 +680,52 @@ ...@@ -612,48 +680,52 @@
.push(function (required_gadget) { .push(function (required_gadget) {
var required_interface_list = []; var required_interface_list = [];
verify_gadget = required_gadget; verify_gadget = required_gadget;
if(!interface_data) { if (!interface_data) {
required_interface_list = interface_gadget.getDeclaredGadgetInterfaceList(verify_gadget); required_interface_list =
} else if(interface_data.constructor === Array) { interface_gadget.getDeclaredGadgetInterfaceList(verify_gadget);
} else if (interface_data.constructor === Array) {
required_interface_list = interface_data; required_interface_list = interface_data;
} else if(interface_data.constructor === String) { } else if (interface_data.constructor === String) {
required_interface_list.push(interface_data); required_interface_list.push(interface_data);
} }
return required_interface_list; return required_interface_list;
}) })
.push(function (required_interface_list) { .push(function (required_interface_list) {
var interface_url, var result_list = [],
result_list = [], i;
item;
interface_list = required_interface_list; interface_list = required_interface_list;
for (item in interface_list) { for (i = 0; i < interface_list.length; i += 1) {
interface_url = interface_list[item]; result_list.push(
result_list.push(interface_gadget.verifyGadgetSingleInterfaceImplementation(verify_gadget, interface_url)); interface_gadget.verifyGadgetSingleInterfaceImplementation(
verify_gadget,
interface_list[i]
)
);
} }
return RSVP.all(result_list); return RSVP.all(result_list);
}) })
.push(function(result_list) { .push(function (result_list) {
var item, var i,
failed = false, failed = false,
error_message = ''; error_message = '';
for(item in result_list) { for (i = 0; i < result_list.length; i += 1) {
if (!result_list[item].result) { if (!result_list[i].result) {
failed = true; failed = true;
error_message += (result_list[item].details + '\n'); error_message += (result_list[i].details + '\n');
} }
} }
if(failed) { if (failed) {
throw new Error(error_message); throw new Error(error_message);
} }
}) })
.push (function() { .push(function () {
verify_result.result = true; verify_result.result = true;
return verify_result; return verify_result;
}, function(error) { }, function (error) {
verify_result.result = false; verify_result.result = false;
verify_result.details = error.message; verify_result.details = error.message;
return verify_result; return verify_result;
}); });
}); });
}(window, rJS, RSVP, DOMParser)); }(window, rJS, RSVP, DOMParser, XMLHttpRequest, renderJS));
\ 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.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({ return gadget.redirect({
found: false 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>
......
/*global window, rJS, RSVP, Handlebars */ /*global window, rJS, RSVP, Handlebars, loopEventListener, $, document */
/*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, $, document) {
"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),
templater = gadget_klass.__template_element,
report_widget_table = Handlebars.compile(
templater.getElementById("report-widget-table").innerHTML
);
function renderInitialReport(gadget, gadget_list) { function renderInitialReport(gadget, gadget_list) {
var gadget_info_list = [], var row_list = [],
row_list = [],
column_list = ['Gadget Name', 'Declared Interfaces', 'Validation Status'], column_list = ['Gadget Name', 'Declared Interfaces', 'Validation Status'],
cell_list, cell_list,
default_status = "In Progress", default_status = "In Progress",
content = '', content = '',
item; i;
for(item in gadget_list) { for (i = 0; i < gadget_list.length; i += 1) {
cell_list = []; cell_list = [{
cell_list.push({
default_class: "gadget_name", default_class: "gadget_name",
value: gadget_list[item] value: gadget_list[i]
}); }, {
cell_list.push({
default_class: "interface_list", default_class: "interface_list",
value: default_status value: default_status
}); }, {
cell_list.push({
default_class: "validation_status", default_class: "validation_status",
value: default_status value: default_status
}); }];
row_list.push({ row_list.push({
"cell_list": cell_list, "cell_list": cell_list,
"default_id": gadget_list[item].substr(0, gadget_list[item].indexOf('.')) "default_id": gadget_list[i].substr(0, gadget_list[i].indexOf('.'))
}); });
} }
content += report_widget_table({ content += report_widget_table({
...@@ -40,55 +45,33 @@ ...@@ -40,55 +45,33 @@
$(gadget.props.element).trigger("create"); $(gadget.props.element).trigger("create");
} }
function validateAppGadgetList(gadget, gadget_list){
var item;
for(item in gadget_list) {
updateGadgetData(gadget, gadget_list[item]);
}
}
function updateGadgetData(gadget, verify_gadget_url) {
return RSVP.Queue()
.push(function() {
return verifyGadgetImplementation(gadget, verify_gadget_url);
})
.push(function(verify_result) {
var result_dict = {
id: verify_gadget_url.substr(0, verify_gadget_url.indexOf('.')),
gadget_name: verify_gadget_url,
interface_list: verify_result[0],
validation_status: verify_result[1].result,
validation_message: verify_result[1].result_message,
error_detail: verify_result[1].details
};
return updateReportData(gadget, result_dict);
});
}
function verifyGadgetImplementation(gadget, verify_gadget_url) { function verifyGadgetImplementation(gadget, verify_gadget_url) {
var interface_gadget, var interface_gadget,
interface_list = [], interface_list = [],
default_validation_status = {result:"N/A"}; default_validation_status = {result: "N/A"};
return new RSVP.Queue() return new RSVP.Queue()
.push(function() { .push(function () {
return gadget.getDeclaredGadget(INTERFACE_GADGET_SCOPE); return gadget.getDeclaredGadget(INTERFACE_GADGET_SCOPE);
}) })
.push(function(i_gadget) { .push(function (i_gadget) {
interface_gadget = i_gadget; interface_gadget = i_gadget;
return interface_gadget.getDeclaredGadgetInterfaceList(verify_gadget_url); return interface_gadget.getDeclaredGadgetInterfaceList(
verify_gadget_url
);
}) })
.push(function(temp_interface_list) { .push(function (temp_interface_list) {
interface_list = temp_interface_list; interface_list = temp_interface_list;
if(interface_list.length > 0) { if (interface_list.length > 0) {
return interface_gadget.verifyGadgetInterfaceImplementation(verify_gadget_url); return interface_gadget.verifyGadgetInterfaceImplementation(
verify_gadget_url
);
} }
else {
return default_validation_status; return default_validation_status;
}
}) })
.push(function(validation_status) { .push(function (validation_status) {
return [interface_list, validation_status]; return [interface_list, validation_status];
}, function(error) { }, function (error) {
default_validation_status.result = false; default_validation_status.result = false;
default_validation_status.result_message = "Error with gadget loading"; default_validation_status.result_message = "Error with gadget loading";
default_validation_status.details = error.message; default_validation_status.details = error.message;
...@@ -97,62 +80,85 @@ ...@@ -97,62 +80,85 @@
} }
function updateReportData(gadget, report_data) { function updateReportData(gadget, report_data) {
var id = "#" + report_data.id.replace('/','\\/'), var id = "#" + report_data.id.replace('/', '\\/'),
update_element = gadget.props.content_element.querySelector(id), update_element = gadget.props.content_element.querySelector(id),
interface_data = '', interface_data = '',
validation_status = report_data.validation_status, validation_status = report_data.validation_status,
validation_message = report_data.validation_message; validation_message = report_data.validation_message,
if (report_data.interface_list.length) { i,
var item,
interface_name; interface_name;
for (item in report_data.interface_list) { if (report_data.interface_list.length) {
interface_name = report_data.interface_list[item].substr(report_data.interface_list[item].lastIndexOf('/') + 1); for (i = 0; i < report_data.interface_list.length; i += 1) {
interface_name = report_data.interface_list[i].substr(
report_data.interface_list[i].lastIndexOf('/') + 1
);
interface_data += (interface_name + '<br />'); interface_data += (interface_name + '<br />');
} }
} else { } else {
interface_data = 'None'; interface_data = 'None';
} }
if(report_data.validation_status === true) { if (report_data.validation_status === true) {
validation_status = "Success"; validation_status = "Success";
update_element.setAttribute('style', 'color: green'); update_element.setAttribute('style', 'color: green');
} }
if(report_data.validation_status === false) { if (report_data.validation_status === false) {
validation_status = (validation_message !== undefined? validation_message : "Failure"); validation_status =
(validation_message !== undefined ? validation_message : "Failure");
update_element.setAttribute('style', 'cursor: pointer; color: red'); update_element.setAttribute('style', 'cursor: pointer; color: red');
update_element.className += "error expand"; update_element.className += "error expand";
} }
gadget.props.error_data[report_data.id] = report_data.error_detail; gadget.props.error_data[report_data.id] = report_data.error_detail;
update_element.querySelector(".validation_status").innerHTML = validation_status; update_element.querySelector(".validation_status").innerHTML =
validation_status;
update_element.querySelector(".validation_status").className += " final"; update_element.querySelector(".validation_status").className += " final";
update_element.querySelector(".interface_list").innerHTML = interface_data; update_element.querySelector(".interface_list").innerHTML = interface_data;
} }
function updateGadgetData(gadget, verify_gadget_url) {
return RSVP.Queue()
.push(function () {
return verifyGadgetImplementation(gadget, verify_gadget_url);
})
.push(function (verify_result) {
var result_dict = {
id: verify_gadget_url.substr(0, verify_gadget_url.indexOf('.')),
gadget_name: verify_gadget_url,
interface_list: verify_result[0],
validation_status: verify_result[1].result,
validation_message: verify_result[1].result_message,
error_detail: verify_result[1].details
};
return updateReportData(gadget, result_dict);
});
}
function validateAppGadgetList(gadget, gadget_list) {
var i;
for (i = 0; i < gadget_list.length; i += 1) {
updateGadgetData(gadget, gadget_list[i]);
}
}
function toggleErrorRow(gadget, source_element) { function toggleErrorRow(gadget, source_element) {
if(source_element.className.indexOf("expand") > -1) { if (source_element.className.indexOf("expand") > -1) {
var error_tr = document.createElement('tr'), var error_tr = document.createElement('tr'),
error_td = error_tr.insertCell(0); error_td = error_tr.insertCell(0);
error_tr.id = source_element.id + '_errordata'; error_tr.id = source_element.id + '_errordata';
error_td.className = 'errordata'; error_td.className = 'errordata';
error_td.colSpan = "3"; error_td.colSpan = "3";
error_td.innerText = gadget.props.error_data[source_element.id]; error_td.innerText = gadget.props.error_data[source_element.id];
source_element.parentNode.insertBefore(error_tr, source_element.nextSibling); source_element.parentNode.insertBefore(error_tr,
source_element.className = source_element.className.replace("expand","shrink"); source_element.nextSibling);
} else if(source_element.className.indexOf("shrink") > -1) { source_element.className = source_element.className.replace("expand",
"shrink");
} else if (source_element.className.indexOf("shrink") > -1) {
source_element.parentNode.removeChild(source_element.nextSibling); source_element.parentNode.removeChild(source_element.nextSibling);
source_element.className = source_element.className.replace("shrink","expand"); source_element.className = source_element.className.replace("shrink",
"expand");
} }
return; return;
} }
/////////////////////////////////////////////////////////////////
// Handlebars
/////////////////////////////////////////////////////////////////
// Precompile the templates while loading the first gadget instance
var gadget_klass = rJS(window),
templater = gadget_klass.__template_element,
report_widget_table = Handlebars.compile(
templater.getElementById("report-widget-table").innerHTML
);
Handlebars.registerPartial( Handlebars.registerPartial(
"report-widget-table-partial", "report-widget-table-partial",
templater.getElementById("report-widget-table-partial").innerHTML templater.getElementById("report-widget-table-partial").innerHTML
...@@ -172,7 +178,7 @@ ...@@ -172,7 +178,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('.validation_report'); g.props.content_element = element.querySelector('.validation_report');
}); });
}) })
...@@ -182,26 +188,26 @@ ...@@ -182,26 +188,26 @@
appcache_url = options.appcache_url, appcache_url = options.appcache_url,
gadget_list; gadget_list;
return new RSVP.Queue() return new RSVP.Queue()
.push(function() { .push(function () {
return gadget.getDeclaredGadget(INTERFACE_GADGET_SCOPE); return gadget.getDeclaredGadget(INTERFACE_GADGET_SCOPE);
}) })
.push(function(interface_gadget) { .push(function (interface_gadget) {
return interface_gadget.getGadgetListFromAppcache(appcache_url); return interface_gadget.getGadgetListFromAppcache(appcache_url);
}) })
.push(function(filtered_gadget_list) { .push(function (filtered_gadget_list) {
gadget_list = filtered_gadget_list; gadget_list = filtered_gadget_list;
return renderInitialReport(gadget, gadget_list); return renderInitialReport(gadget, gadget_list);
}) })
.push(function() { .push(function () {
return validateAppGadgetList(gadget, gadget_list); return validateAppGadgetList(gadget, gadget_list);
}, function(error) { }, function () {
return gadget.redirect({ return gadget.redirect({
found: false found: false
}); });
}); });
}) })
.declareMethod("reportPageDummyMethod1", function(param1) { .declareMethod("reportPageDummyMethod1", function () {
// A dummy method to fulfil the interface implementation requirement. // A dummy method to fulfil the interface implementation requirement.
return; return;
}) })
...@@ -219,7 +225,7 @@ ...@@ -219,7 +225,7 @@
function rowSubmit(submit_data) { function rowSubmit(submit_data) {
var parent_element = submit_data.target.parentElement; var parent_element = submit_data.target.parentElement;
if(parent_element.className.indexOf("error") > -1) { if (parent_element.className.indexOf("error") > -1) {
return toggleErrorRow(gadget, parent_element); return toggleErrorRow(gadget, parent_element);
} }
} }
...@@ -232,4 +238,4 @@ ...@@ -232,4 +238,4 @@
); );
}); });
}(window, rJS, RSVP, Handlebars)); }(window, rJS, RSVP, Handlebars, loopEventListener, $, document));
\ 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.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_",
...@@ -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