Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Titouan Soulard
erp5
Commits
af3fb549
Commit
af3fb549
authored
Jun 15, 2018
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[erp5_gadget_interface_validator] JSLint
parent
fe9a9c94
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
550 additions
and
464 deletions
+550
-464
bt5/erp5_gadget_interface_validator/PathTemplateItem/web_page_module/gadget_interface_js.js
...r/PathTemplateItem/web_page_module/gadget_interface_js.js
+397
-325
bt5/erp5_gadget_interface_validator/PathTemplateItem/web_page_module/gadget_interface_js.xml
.../PathTemplateItem/web_page_module/gadget_interface_js.xml
+2
-2
bt5/erp5_gadget_interface_validator/PathTemplateItem/web_page_module/gadget_interface_validator_page_form_js.js
...eb_page_module/gadget_interface_validator_page_form_js.js
+40
-33
bt5/erp5_gadget_interface_validator/PathTemplateItem/web_page_module/gadget_interface_validator_page_form_js.xml
...b_page_module/gadget_interface_validator_page_form_js.xml
+2
-2
bt5/erp5_gadget_interface_validator/PathTemplateItem/web_page_module/gadget_interface_validator_page_report_js.js
..._page_module/gadget_interface_validator_page_report_js.js
+93
-87
bt5/erp5_gadget_interface_validator/PathTemplateItem/web_page_module/gadget_interface_validator_page_report_js.xml
...page_module/gadget_interface_validator_page_report_js.xml
+2
-2
bt5/erp5_gadget_interface_validator/PathTemplateItem/web_page_module/gadget_interface_validator_router_js.js
...m/web_page_module/gadget_interface_validator_router_js.js
+12
-11
bt5/erp5_gadget_interface_validator/PathTemplateItem/web_page_module/gadget_interface_validator_router_js.xml
.../web_page_module/gadget_interface_validator_router_js.xml
+2
-2
No files found.
bt5/erp5_gadget_interface_validator/PathTemplateItem/web_page_module/gadget_interface_js.js
View file @
af3fb549
/*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
* 2012-09-04
...
...
@@ -8,7 +9,7 @@
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
*/
/*! @source https://gist.github.com/1129031 */
(
function
(
DOMParser
)
{
(
function
(
DOMParser
,
document
)
{
"
use strict
"
;
var
DOMParser_proto
=
DOMParser
.
prototype
,
real_parseFromString
=
DOMParser_proto
.
parseFromString
;
...
...
@@ -42,11 +43,9 @@
}
return
result
;
};
}(
DOMParser
));
}(
DOMParser
,
document
));
/*global window, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(
function
(
window
,
rJS
,
RSVP
,
DOMParser
)
{
(
function
(
window
,
rJS
,
RSVP
,
DOMParser
,
XMLHttpRequest
,
renderJS
)
{
"
use strict
"
;
function
ajax
(
url
)
{
var
xhr
;
...
...
@@ -88,13 +87,13 @@
function
fetchAppcacheData
(
appcache_url
)
{
var
defer
=
RSVP
.
defer
();
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
.
push
(
function
()
{
return
ajax
(
appcache_url
);
})
.
push
(
function
(
xhr
)
{
.
push
(
function
(
xhr
)
{
var
filename_list
=
xhr
.
responseText
.
split
(
'
\n
'
);
return
filename_list
;
},
function
(
error
)
{
},
function
(
error
)
{
defer
.
reject
(
error
);
return
defer
.
promise
;
});
...
...
@@ -107,20 +106,20 @@
ext
,
file_name
,
last_index
,
i
tem
;
for
(
item
in
filename_list
)
{
last_index
=
filename_list
[
i
tem
].
lastIndexOf
(
'
.
'
);
file_name
=
filename_list
[
i
tem
].
substr
(
0
,
last_index
);
ext
=
filename_list
[
i
tem
].
substr
(
last_index
+
1
);
if
(
ext
===
"
html
"
)
{
i
;
for
(
i
=
0
;
i
<
filename_list
.
length
;
i
+=
1
)
{
last_index
=
filename_list
[
i
].
lastIndexOf
(
'
.
'
);
file_name
=
filename_list
[
i
].
substr
(
0
,
last_index
);
ext
=
filename_list
[
i
].
substr
(
last_index
+
1
);
if
(
ext
===
"
html
"
)
{
html_list
.
push
(
file_name
);
}
else
if
(
ext
===
"
js
"
)
{
}
else
if
(
ext
===
"
js
"
)
{
js_list
.
push
(
file_name
);
}
}
for
(
item
in
html_list
)
{
if
(
js_list
.
indexOf
(
html_list
[
i
tem
])
>
-
1
)
{
gadget_list
.
push
(
html_list
[
i
tem
]
+
"
.html
"
);
for
(
i
=
0
;
i
<
html_list
.
length
;
i
+=
1
)
{
if
(
js_list
.
indexOf
(
html_list
[
i
])
>
-
1
)
{
gadget_list
.
push
(
html_list
[
i
]
+
"
.html
"
);
}
}
return
gadget_list
;
...
...
@@ -128,77 +127,99 @@
function
generateErrorMessage
(
error
)
{
var
error_message
=
''
;
error_message
=
error_message
+
error
.
toString
()
+
(
error
.
message
!==
undefined
?
error
.
message
:
''
)
+
(
error
.
status
?
error
.
status
.
toString
()
+
'
'
:
''
)
+
(
error
.
statusText
!==
undefined
?
error
.
statusText
:
''
);
error_message
=
error_message
+
error
.
toString
()
+
(
error
.
message
!==
undefined
?
error
.
message
:
''
)
+
(
error
.
status
?
error
.
status
.
toString
()
+
'
'
:
''
)
+
(
error
.
statusText
!==
undefined
?
error
.
statusText
:
''
);
return
error_message
;
}
function
getInterfaceListFromURL
(
gadget_url
)
{
var
defer
=
RSVP
.
defer
();
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
.
push
(
function
()
{
return
ajax
(
gadget_url
);
})
.
push
(
function
(
xhr
)
{
var
document_element
=
(
new
DOMParser
()).
parseFromString
(
xhr
.
responseText
,
'
text/html
'
),
.
push
(
function
(
xhr
)
{
var
document_element
=
(
new
DOMParser
()).
parseFromString
(
xhr
.
responseText
,
'
text/html
'
),
interface_list
=
[],
element
,
i
;
if
(
document_element
.
nodeType
===
9
&&
document_element
.
head
!==
null
)
{
for
(
i
=
0
;
i
<
document_element
.
head
.
children
.
length
;
i
+=
1
)
{
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
(
renderJS
.
getAbsoluteURL
(
element
.
getAttribute
(
"
href
"
),
window
.
location
.
href
)
renderJS
.
getAbsoluteURL
(
element
.
getAttribute
(
"
href
"
),
window
.
location
.
href
)
);
}
}
}
return
interface_list
;
},
function
(
error
)
{
var
message
=
"
Error with loading the gadget data.
\n
"
;
error
.
message
=
message
+
generateErrorMessage
(
error
);
defer
.
reject
(
error
);
return
defer
.
promise
;
});
return
interface_list
;
},
function
(
error
)
{
var
message
=
"
Error with loading the gadget data.
\n
"
;
error
.
message
=
message
+
generateErrorMessage
(
error
);
defer
.
reject
(
error
);
return
defer
.
promise
;
});
}
function
verifyInterfaceDefinition
(
interface_url
)
{
//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
();
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
ajax
(
interface_url
);
})
.
push
(
function
(
xhr
)
{
var
doc
=
(
new
DOMParser
()).
parseFromString
(
xhr
.
responseText
,
'
text/html
'
).
body
,
.
push
(
function
(
xhr
)
{
var
doc
=
(
new
DOMParser
()).
parseFromString
(
xhr
.
responseText
,
'
text/html
'
).
body
,
dl_list
=
doc
.
getElementsByTagName
(
'
dl
'
),
next_element
=
dl_list
[
0
].
firstElementChild
,
method_len
=
dl_list
.
length
-
1
,
i
;
if
(
dl_list
[
0
].
childElementCount
!==
3
*
method_len
)
{
argument_len
,
next_child_element
,
i
,
j
;
if
(
dl_list
[
0
].
childElementCount
!==
3
*
method_len
)
{
throw
new
Error
(
error_message
);
}
try
{
for
(
i
=
0
;
i
<
method_len
;
i
+=
1
)
{
if
((
!
next_element
||
next_element
.
localName
.
toLowerCase
()
!==
'
dt
'
)
||
(
!
(
next_element
=
next_element
.
nextElementSibling
)
||
next_element
.
localName
.
toLowerCase
()
!==
'
dd
'
)
||
(
!
(
next_element
=
next_element
.
nextElementSibling
)
||
next_element
.
localName
.
toLowerCase
()
!==
'
dl
'
))
{
if
((
next_element
===
null
)
||
(
next_element
.
localName
.
toLowerCase
()
!==
'
dt
'
))
{
throw
new
Error
(
error_message
);
}
next_element
=
next_element
.
nextElementSibling
;
if
(
next_element
.
localName
.
toLowerCase
()
!==
'
dd
'
)
{
throw
new
Error
(
error_message
);
}
next_element
=
next_element
.
nextElementSibling
;
if
(
next_element
.
localName
.
toLowerCase
()
!==
'
dl
'
)
{
throw
new
Error
(
error_message
);
}
if
(
next_element
.
getElementsByTagName
(
'
dt
'
).
length
!==
next_element
.
getElementsByTagName
(
'
dd
'
).
length
)
{
if
(
next_element
.
getElementsByTagName
(
'
dt
'
).
length
!==
next_element
.
getElementsByTagName
(
'
dd
'
).
length
)
{
throw
new
Error
(
error_message
);
}
var
argument_len
=
next_element
.
getElementsByTagName
(
'
dt
'
).
length
,
next_child_element
=
next_element
.
firstElementChild
,
j
;
argument_len
=
next_element
.
getElementsByTagName
(
'
dt
'
).
length
;
next_child_element
=
next_element
.
firstElementChild
;
for
(
j
=
0
;
j
<
argument_len
;
j
+=
1
)
{
if
((
!
next_child_element
||
next_child_element
.
localName
.
toLowerCase
()
!==
'
dt
'
)
||
(
!
(
next_child_element
=
next_child_element
.
nextElementSibling
)
||
next_child_element
.
localName
.
toLowerCase
()
!==
'
dd
'
))
{
if
((
next_child_element
===
null
)
||
(
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
);
}
next_child_element
=
next_child_element
.
nextElementSibling
;
...
...
@@ -206,11 +227,11 @@
next_element
=
next_element
.
nextElementSibling
;
}
defer
.
resolve
(
"
Success
"
);
}
catch
(
error
)
{
}
catch
(
error
)
{
defer
.
reject
(
error
);
}
return
defer
.
promise
;
},
function
(
error
)
{
},
function
(
error
)
{
var
message
=
"
Error with loading the interface data.
\n
"
;
error
.
message
=
message
+
generateErrorMessage
(
error
);
defer
.
reject
(
error
);
...
...
@@ -227,119 +248,135 @@
}
else
{
throw
new
Error
(
"
Interface is not declared.
"
);
}
}
catch
(
error
)
{
}
catch
(
error
)
{
defer
.
reject
(
error
);
}
return
defer
.
promise
;
}
function
verifyAllMethod
(
interface_method_list
,
gadget_method_list
)
{
//to verify all methods of gadget and interface.
var
defer
=
RSVP
.
defer
();
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
verifyAllMethodDeclared
(
interface_method_list
,
gadget_method_list
[
0
]);
})
/* Commented till figure out the way to fetch the argument length of a defined function.
.push(function() {
return verifyAllMethodSignature(interface_method_list, gadget_method_list[1]);
})
*/
.
push
(
function
()
{
defer
.
resolve
(
"
Success
"
);
return
defer
.
promise
;
},
function
(
error
)
{
defer
.
reject
(
error
);
return
defer
.
promise
;
});
/*
function verifyMethodSignature(interface_method, gadget_method) {
//to verify if two methods have the same signature
var max_arg_len = interface_method.argument_list.length,
min_arg_len = 0,
i,
argument_list;
if (max_arg_len) {
argument_list = interface_method.argument_list;
for (i = 0; i < argument_list.length; i += 1) {
if (argument_list[i].required) {
min_arg_len += 1;
}
}
}
return (gadget_method.arg_len >= min_arg_len &&
gadget_method.arg_len <= max_arg_len);
}
function
verifyAllMethodDeclared
(
interface_method_list
,
gadget_method_list
)
{
//to verify if all the interface methods are declared by the gadget.
function verifyAllMethodSignature(interface_method_list, gadget_method_list) {
//to verify if all the declared methods match the signature
// of the interface methods.
var defer = RSVP.defer(),
gadget_method_name_list
=
gadget_method_list
,
interface_method_name_list
=
[],
i
,
j
,
interface_method_dict = {},
gadget_method_name_list = [],
index,
item,
i,
j,
failed = false,
failed_methods = [];
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 {
for
(
j
=
0
;
j
<
interface_method_name_list
.
length
;
j
+=
1
)
{
if
(
gadget_method_name_list
.
indexOf
(
interface_method_name_list
[
j
])
<
0
)
{
for (item in interface_method_dict) {
index = gadget_method_name_list.lastIndexOf(item);
if (!verifyMethodSignature(interface_method_dict[item],
gadget_method_list[index])) {
failed = true;
failed_methods
.
push
(
i
nterface_method_name_list
[
j
]
);
failed_methods.push(i
tem
);
}
}
if
(
failed
)
{
var
error_message
=
"
Following required methods are not declared in the gadget:
"
,
if (failed) {
var error_message =
"Following methods have missing/mismatched arguments: ",
method;
for
(
method
in
failed_methods
)
{
for
(method in failed_methods) {
error_message += ("\n" + failed_methods[method]);
}
throw new Error(error_message);
}
defer.resolve("Success");
}
catch
(
error
)
{
} catch
(error) {
defer.reject(error);
}
return defer.promise;
}
*/
function
verifyAllMethod
Signature
(
interface_method_list
,
gadget_method_list
)
{
//to verify if all the
declared methods match the signature of the interface methods
.
function
verifyAllMethod
Declared
(
interface_method_list
,
gadget_method_list
)
{
//to verify if all the
interface methods are declared by the gadget
.
var
defer
=
RSVP
.
defer
(),
interface_method_dict
=
{},
gadget_method_name_list
=
[],
index
,
item
,
i
,
j
,
gadget_method_name_list
=
gadget_method_list
,
interface_method_name_list
=
[],
i
,
j
,
failed
=
false
,
failed_methods
=
[];
for
(
i
=
0
;
i
<
interface_method_list
.
length
;
i
+=
1
)
{
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
);
failed_methods
=
[],
error_message
;
for
(
i
=
0
;
i
<
interface_method_list
.
length
;
i
+=
1
)
{
interface_method_name_list
.
push
(
interface_method_list
[
i
].
name
);
}
try
{
for
(
item
in
interface_method_dict
)
{
index
=
gadget_method_name_list
.
lastIndexOf
(
item
);
if
(
!
verifyMethodSignature
(
interface_method_dict
[
item
],
gadget_method_list
[
index
]))
{
for
(
j
=
0
;
j
<
interface_method_name_list
.
length
;
j
+=
1
)
{
if
(
gadget_method_name_list
.
indexOf
(
interface_method_name_list
[
j
]
)
<
0
)
{
failed
=
true
;
failed_methods
.
push
(
i
tem
);
failed_methods
.
push
(
i
nterface_method_name_list
[
j
]
);
}
}
if
(
failed
)
{
var
error_message
=
"
Following methods have missing/mismatched arguments:
"
,
method
;
for
(
method
in
failed_methods
)
{
error_message
+=
(
"
\n
"
+
failed_methods
[
method
]);
if
(
failed
)
{
error_message
=
"
Following required methods are not declared in the gadget:
"
;
for
(
i
=
0
;
i
<
failed_methods
.
length
;
i
+=
1
)
{
error_message
+=
(
"
\n
"
+
failed_methods
[
i
]);
}
throw
new
Error
(
error_message
);
}
defer
.
resolve
(
"
Success
"
);
}
catch
(
error
)
{
}
catch
(
error
)
{
defer
.
reject
(
error
);
}
return
defer
.
promise
;
}
function
verifyMethodSignature
(
interface_method
,
gadget_method
)
{
//to verify if two methods have the same signature
var
max_arg_len
=
interface_method
.
argument_list
.
length
,
min_arg_len
=
0
,
i
;
if
(
max_arg_len
)
{
var
argument_list
=
interface_method
.
argument_list
;
for
(
i
=
0
;
i
<
argument_list
.
length
;
i
+=
1
)
{
if
(
argument_list
[
i
].
required
)
{
min_arg_len
+=
1
;
}
}
}
return
(
gadget_method
.
arg_len
>=
min_arg_len
&&
gadget_method
.
arg_len
<=
max_arg_len
);
function
verifyAllMethod
(
interface_method_list
,
gadget_method_list
)
{
//to verify all methods of gadget and interface.
var
defer
=
RSVP
.
defer
();
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
verifyAllMethodDeclared
(
interface_method_list
,
gadget_method_list
[
0
]);
})
/* Commented till figure out the way to fetch the argument length of a
defined function.
.push(function() {
return verifyAllMethodSignature(interface_method_list,
gadget_method_list[1]);
})
*/
.
push
(
function
()
{
defer
.
resolve
(
"
Success
"
);
return
defer
.
promise
;
},
function
(
error
)
{
defer
.
reject
(
error
);
return
defer
.
promise
;
});
}
rJS
(
window
)
...
...
@@ -358,7 +395,7 @@
})
.
push
(
function
()
{
return
interface_gadget
.
getDeclaredGadget
(
gadget_url
);
},
function
(
error
)
{
},
function
(
error
)
{
var
message
=
"
Error with loading the gadget.
\n
"
;
error
.
message
=
message
+
error
.
message
;
defer
.
reject
(
error
);
...
...
@@ -367,19 +404,17 @@
})
.
declareMethod
(
"
getDeclaredGadgetInterfaceList
"
,
function
(
gadget_data
)
{
var
interface_gadget
=
this
,
defer
=
RSVP
.
defer
();
var
defer
=
RSVP
.
defer
();
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
if
(
gadget_data
.
constructor
===
String
)
{
.
push
(
function
()
{
if
(
gadget_data
.
constructor
===
String
)
{
return
getInterfaceListFromURL
(
gadget_data
);
}
else
{
return
gadget_data
.
getInterfaceList
();
}
return
gadget_data
.
getInterfaceList
();
})
.
push
(
function
(
interface_list
)
{
.
push
(
function
(
interface_list
)
{
return
interface_list
;
},
function
(
error
)
{
},
function
(
error
)
{
defer
.
reject
(
error
);
return
defer
.
promise
;
});
...
...
@@ -389,32 +424,36 @@
var
declared_method_dict
=
{},
declared_method_list
=
[],
item
;
for
(
item
in
gadget
)
{
if
(
!
(
/__/
).
test
(
item
))
{
declared_method_dict
[
item
]
=
gadget
[
item
];
for
(
item
in
gadget
.
constructor
.
prototype
)
{
if
(
gadget
.
constructor
.
prototype
.
hasOwnProperty
(
item
))
{
if
(
!
(
/__/
).
test
(
item
))
{
declared_method_dict
[
item
]
=
gadget
[
item
];
}
}
}
for
(
item
in
declared_method_dict
)
{
if
(
declared_method_dict
.
hasOwnProperty
(
item
))
{
declared_method_list
.
push
(
item
);
}
}
for
(
item
in
declared_method_dict
)
{
declared_method_list
.
push
(
item
);
}
return
RSVP
.
all
([
declared_method_list
//,
// gadget.getDeclaredMethodList()
]);
]);
})
.
declareMethod
(
"
getGadgetListFromAppcache
"
,
function
(
appcache_url
)
{
var
defer
=
RSVP
.
defer
();
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
.
push
(
function
()
{
return
fetchAppcacheData
(
appcache_url
);
})
.
push
(
function
(
filename_list
)
{
.
push
(
function
(
filename_list
)
{
return
filterGadgetList
(
filename_list
);
})
.
push
(
function
(
filtered_gadget_list
)
{
.
push
(
function
(
filtered_gadget_list
)
{
return
filtered_gadget_list
;
},
function
(
error
)
{
},
function
(
error
)
{
defer
.
reject
(
error
);
return
defer
.
promise
;
});
...
...
@@ -422,10 +461,10 @@
.
declareMethod
(
"
getAbsoluteURL
"
,
function
(
gadget
,
url
)
{
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
gadget
.
getPath
();
.
push
(
function
()
{
return
gadget
.
getPath
();
})
.
push
(
function
(
base_url
)
{
.
push
(
function
(
base_url
)
{
return
rJS
.
getAbsoluteURL
(
url
,
base_url
);
});
})
...
...
@@ -438,222 +477,255 @@
},
defer
=
RSVP
.
defer
();
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
.
push
(
function
()
{
return
ajax
(
interface_url
);
})
.
push
(
function
(
xhr
)
{
var
doc
=
(
new
DOMParser
()).
parseFromString
(
xhr
.
responseText
,
'
text/html
'
).
body
,
.
push
(
function
(
xhr
)
{
var
doc
=
(
new
DOMParser
()).
parseFromString
(
xhr
.
responseText
,
'
text/html
'
).
body
,
dl_list
=
doc
.
getElementsByTagName
(
'
dl
'
),
dt_list
=
doc
.
getElementsByTagName
(
'
dt
'
),
dd_list
=
doc
.
getElementsByTagName
(
'
dd
'
),
method_len
=
dl_list
.
length
-
1
,
dt_count
=
0
,
dl_count
=
1
,
i
;
i
,
method
,
argument_len
,
j
,
argument_item
;
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
)
{
var
method
=
{
name
:
dt_list
[
dt_count
].
innerHTML
,
description
:
dd_list
[
dt_count
].
innerHTML
,
argument_list
:
[]
},
argument_len
=
dl_list
[
dl_count
].
getElementsByTagName
(
'
dt
'
).
length
,
j
;
method
=
{
name
:
dt_list
[
dt_count
].
innerHTML
,
description
:
dd_list
[
dt_count
].
innerHTML
,
argument_list
:
[]
};
argument_len
=
dl_list
[
dl_count
].
getElementsByTagName
(
'
dt
'
)
.
length
;
dt_count
+=
1
;
dl_count
+=
1
;
for
(
j
=
0
;
j
<
argument_len
;
j
+=
1
)
{
var
argument_item
=
{
name
:
dt_list
[
dt_count
].
innerHTML
,
description
:
dd_list
[
dt_count
].
innerHTML
,
required
:
dt_list
[
dt_count
].
getAttribute
(
"
data-parameter-required
"
)
===
"
optional
"
?
false
:
true
,
type
:
dt_list
[
dt_count
].
getAttribute
(
"
data-parameter-type
"
)
};
argument_item
=
{
name
:
dt_list
[
dt_count
].
innerHTML
,
description
:
dd_list
[
dt_count
].
innerHTML
,
required
:
dt_list
[
dt_count
]
.
getAttribute
(
"
data-parameter-required
"
)
!==
"
optional
"
,
type
:
dt_list
[
dt_count
].
getAttribute
(
"
data-parameter-type
"
)
};
dt_count
+=
1
;
method
.
argument_list
.
push
(
argument_item
);
}
interface_data
.
method_list
.
push
(
method
);
}
return
interface_data
;
},
function
(
error
)
{
},
function
(
error
)
{
var
message
=
"
Error with loading the interface data.
\n
"
;
error
.
message
=
message
+
generateErrorMessage
(
error
);
defer
.
reject
(
error
);
return
defer
.
promise
;
});
});
})
.
declareMethod
(
"
getDefinedInterfaceMethodList
"
,
function
(
interface_url
)
{
var
defer
=
RSVP
.
defer
();
return
this
.
getInterfaceData
(
interface_url
)
.
push
(
function
(
interface_data
)
{
.
push
(
function
(
interface_data
)
{
return
interface_data
.
method_list
;
},
function
(
error
)
{
},
function
(
error
)
{
defer
.
reject
(
error
);
return
defer
.
promise
;
});
})
.
declareMethod
(
"
getGadgetListImplementingInterface
"
,
function
(
interface_data
,
gadget_source_data
)
{
var
interface_gadget
=
this
,
interface_list
,
gadget_list
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
var
required_interface_list
=
[];
if
(
!
interface_data
)
{
throw
new
Error
(
"
Invalid input: No interface data is provided.
"
);
}
else
if
(
interface_data
.
constructor
===
Array
)
{
required_interface_list
=
interface_data
;
}
else
if
(
interface_data
.
constructor
===
String
)
{
required_interface_list
.
push
(
interface_data
);
}
else
{
throw
new
Error
(
"
Invalid input: Invalid interface data is provided.
"
);
}
return
required_interface_list
;
})
.
push
(
function
(
i_list
)
{
var
source_gadget_list
=
[];
interface_list
=
i_list
;
if
(
!
gadget_source_data
)
{
throw
new
Error
(
"
Invalid input: No gadget source information is provided.
"
);
}
else
if
(
gadget_source_data
.
constructor
===
Array
)
{
source_gadget_list
=
gadget_source_data
;
}
else
if
(
gadget_source_data
.
constructor
===
String
)
{
source_gadget_list
=
interface_gadget
.
getGadgetListFromAppcache
(
gadget_source_data
);
}
else
{
throw
new
Error
(
"
Invalid input: Invalid gadget source information is provided.
"
);
}
return
source_gadget_list
;
})
.
push
(
function
(
g_list
)
{
var
item
,
result_list
=
[];
gadget_list
=
g_list
;
for
(
item
in
gadget_list
)
{
result_list
.
push
(
interface_gadget
.
verifyGadgetInterfaceImplementation
(
gadget_list
[
item
],
interface_list
));
}
return
RSVP
.
all
(
result_list
);
})
.
push
(
function
(
result_list
)
{
var
item
,
result_gadget_list
=
[];
for
(
item
in
result_list
)
{
if
(
result_list
[
item
].
result
===
true
)
{
result_gadget_list
.
push
(
gadget_list
[
item
]);
.
declareMethod
(
"
getGadgetListImplementingInterface
"
,
function
(
interface_data
,
gadget_source_data
)
{
var
interface_gadget
=
this
,
interface_list
,
gadget_list
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
var
required_interface_list
=
[];
if
(
!
interface_data
)
{
throw
new
Error
(
"
Invalid input: No interface data is provided.
"
);
}
}
return
result_gadget_list
;
});
})
if
(
interface_data
.
constructor
===
Array
)
{
required_interface_list
=
interface_data
;
}
else
if
(
interface_data
.
constructor
===
String
)
{
required_interface_list
.
push
(
interface_data
);
}
else
{
throw
new
Error
(
"
Invalid input: Invalid interface data is provided.
"
);
}
return
required_interface_list
;
})
.
push
(
function
(
i_list
)
{
var
source_gadget_list
=
[];
interface_list
=
i_list
;
if
(
!
gadget_source_data
)
{
throw
new
Error
(
"
Invalid input: No gadget source information is provided.
"
);
}
if
(
gadget_source_data
.
constructor
===
Array
)
{
source_gadget_list
=
gadget_source_data
;
}
else
if
(
gadget_source_data
.
constructor
===
String
)
{
source_gadget_list
=
interface_gadget
.
getGadgetListFromAppcache
(
gadget_source_data
);
}
else
{
throw
new
Error
(
"
Invalid input: Invalid gadget source information is provided.
"
);
}
return
source_gadget_list
;
})
.
push
(
function
(
g_list
)
{
var
i
,
result_list
=
[];
gadget_list
=
g_list
;
for
(
i
=
0
;
i
<
gadget_list
.
length
;
i
+=
1
)
{
result_list
.
push
(
interface_gadget
.
verifyGadgetInterfaceImplementation
(
gadget_list
[
i
],
interface_list
)
);
}
return
RSVP
.
all
(
result_list
);
})
.
push
(
function
(
result_list
)
{
var
i
,
result_gadget_list
=
[];
for
(
i
=
0
;
i
<
result_list
.
length
;
i
+=
1
)
{
if
(
result_list
[
i
].
result
)
{
result_gadget_list
.
push
(
gadget_list
[
i
]);
}
}
return
result_gadget_list
;
});
})
.
declareMethod
(
"
verifyGadgetSingleInterfaceImplementation
"
,
function
(
verify_gadget
,
interface_url
)
{
var
interface_gadget
=
this
,
absolute_interface_url
,
verify_result
=
{};
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
RSVP
.
all
([
interface_gadget
.
getDeclaredGadgetInterfaceList
(
verify_gadget
),
interface_gadget
.
getAbsoluteURL
(
verify_gadget
,
interface_url
)
]);
})
.
push
(
function
(
interface_detail
)
{
var
declared_interface_list
=
interface_detail
[
0
];
absolute_interface_url
=
interface_detail
[
1
];
return
verifyInterfaceDeclaration
(
absolute_interface_url
,
declared_interface_list
);
})
.
push
(
function
()
{
return
verifyInterfaceDefinition
(
absolute_interface_url
);
})
.
push
(
function
()
{
return
RSVP
.
all
([
interface_gadget
.
getDefinedInterfaceMethodList
(
absolute_interface_url
),
interface_gadget
.
getDeclaredGadgetMethodList
(
verify_gadget
)
]);
})
.
push
(
function
(
method_list
)
{
return
verifyAllMethod
(
method_list
[
0
],
method_list
[
1
]);
})
.
push
(
function
()
{
verify_result
.
result
=
true
;
return
verify_result
;
},
function
(
error
)
{
var
interface_name
=
absolute_interface_url
.
substr
(
absolute_interface_url
.
lastIndexOf
(
'
/
'
)
+
1
),
error_message
;
error_message
=
"
Interface Name:
"
+
interface_name
+
"
\n
"
+
"
Error Details :
\n
"
+
error
.
message
+
"
\n
"
;
verify_result
.
result
=
false
;
verify_result
.
details
=
error_message
;
return
verify_result
;
});
})
.
declareMethod
(
"
verifyGadgetSingleInterfaceImplementation
"
,
function
(
verify_gadget
,
interface_url
)
{
var
interface_gadget
=
this
,
absolute_interface_url
,
verify_result
=
{};
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
RSVP
.
all
([
interface_gadget
.
getDeclaredGadgetInterfaceList
(
verify_gadget
),
interface_gadget
.
getAbsoluteURL
(
verify_gadget
,
interface_url
)
]);
})
.
push
(
function
(
interface_detail
)
{
var
declared_interface_list
=
interface_detail
[
0
];
absolute_interface_url
=
interface_detail
[
1
];
return
verifyInterfaceDeclaration
(
absolute_interface_url
,
declared_interface_list
);
})
.
push
(
function
()
{
return
verifyInterfaceDefinition
(
absolute_interface_url
);
})
.
push
(
function
()
{
return
RSVP
.
all
([
interface_gadget
.
getDefinedInterfaceMethodList
(
absolute_interface_url
),
interface_gadget
.
getDeclaredGadgetMethodList
(
verify_gadget
)
]);
})
.
push
(
function
(
method_list
)
{
return
verifyAllMethod
(
method_list
[
0
],
method_list
[
1
]);
})
.
push
(
function
()
{
verify_result
.
result
=
true
;
return
verify_result
;
},
function
(
error
)
{
var
interface_name
=
absolute_interface_url
.
substr
(
absolute_interface_url
.
lastIndexOf
(
'
/
'
)
+
1
),
error_message
;
error_message
=
"
Interface Name:
"
+
interface_name
+
"
\n
"
+
"
Error Details :
\n
"
+
error
.
message
+
"
\n
"
;
verify_result
.
result
=
false
;
verify_result
.
details
=
error_message
;
return
verify_result
;
});
})
.
declareMethod
(
"
verifyGadgetInterfaceImplementation
"
,
function
(
gadget_data
,
interface_data
)
{
var
interface_gadget
=
this
,
verify_gadget
,
interface_list
,
verify_result
=
{},
declared_gadget
=
false
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
var
required_gadget
;
if
(
!
gadget_data
)
{
throw
new
Error
(
"
Invalid input: No gadget data is provided.
"
);
}
else
if
(
gadget_data
.
constructor
===
String
)
{
verify_result
.
gadget_url
=
gadget_data
;
declared_gadget
=
true
;
required_gadget
=
interface_gadget
.
getVerifyGadget
(
gadget_data
);
}
else
{
required_gadget
=
gadget_data
;
}
return
required_gadget
;
})
.
push
(
function
(
required_gadget
)
{
var
required_interface_list
=
[];
verify_gadget
=
required_gadget
;
if
(
!
interface_data
)
{
required_interface_list
=
interface_gadget
.
getDeclaredGadgetInterfaceList
(
verify_gadget
);
}
else
if
(
interface_data
.
constructor
===
Array
)
{
required_interface_list
=
interface_data
;
}
else
if
(
interface_data
.
constructor
===
String
)
{
required_interface_list
.
push
(
interface_data
);
}
return
required_interface_list
;
})
.
push
(
function
(
required_interface_list
)
{
var
interface_url
,
result_list
=
[],
item
;
interface_list
=
required_interface_list
;
for
(
item
in
interface_list
)
{
interface_url
=
interface_list
[
item
];
result_list
.
push
(
interface_gadget
.
verifyGadgetSingleInterfaceImplementation
(
verify_gadget
,
interface_url
));
}
return
RSVP
.
all
(
result_list
);
})
.
push
(
function
(
result_list
)
{
var
item
,
failed
=
false
,
error_message
=
''
;
for
(
item
in
result_list
)
{
if
(
!
result_list
[
item
].
result
)
{
failed
=
true
;
error_message
+=
(
result_list
[
item
].
details
+
'
\n
'
);
.
declareMethod
(
"
verifyGadgetInterfaceImplementation
"
,
function
(
gadget_data
,
interface_data
)
{
var
interface_gadget
=
this
,
verify_gadget
,
interface_list
,
verify_result
=
{};
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
var
required_gadget
;
if
(
!
gadget_data
)
{
throw
new
Error
(
"
Invalid input: No gadget data is provided.
"
);
}
}
if
(
failed
)
{
throw
new
Error
(
error_message
);
}
})
.
push
(
function
()
{
verify_result
.
result
=
true
;
return
verify_result
;
},
function
(
error
)
{
verify_result
.
result
=
false
;
verify_result
.
details
=
error
.
message
;
return
verify_result
;
});
});
if
(
gadget_data
.
constructor
===
String
)
{
verify_result
.
gadget_url
=
gadget_data
;
required_gadget
=
interface_gadget
.
getVerifyGadget
(
gadget_data
);
}
else
{
required_gadget
=
gadget_data
;
}
return
required_gadget
;
})
.
push
(
function
(
required_gadget
)
{
var
required_interface_list
=
[];
verify_gadget
=
required_gadget
;
if
(
!
interface_data
)
{
required_interface_list
=
interface_gadget
.
getDeclaredGadgetInterfaceList
(
verify_gadget
);
}
else
if
(
interface_data
.
constructor
===
Array
)
{
required_interface_list
=
interface_data
;
}
else
if
(
interface_data
.
constructor
===
String
)
{
required_interface_list
.
push
(
interface_data
);
}
return
required_interface_list
;
})
.
push
(
function
(
required_interface_list
)
{
var
result_list
=
[],
i
;
interface_list
=
required_interface_list
;
for
(
i
=
0
;
i
<
interface_list
.
length
;
i
+=
1
)
{
result_list
.
push
(
interface_gadget
.
verifyGadgetSingleInterfaceImplementation
(
verify_gadget
,
interface_list
[
i
]
)
);
}
return
RSVP
.
all
(
result_list
);
})
.
push
(
function
(
result_list
)
{
var
i
,
failed
=
false
,
error_message
=
''
;
for
(
i
=
0
;
i
<
result_list
.
length
;
i
+=
1
)
{
if
(
!
result_list
[
i
].
result
)
{
failed
=
true
;
error_message
+=
(
result_list
[
i
].
details
+
'
\n
'
);
}
}
if
(
failed
)
{
throw
new
Error
(
error_message
);
}
})
.
push
(
function
()
{
verify_result
.
result
=
true
;
return
verify_result
;
},
function
(
error
)
{
verify_result
.
result
=
false
;
verify_result
.
details
=
error
.
message
;
return
verify_result
;
});
});
}(
window
,
rJS
,
RSVP
,
DOMParser
));
\ No newline at end of file
}(
window
,
rJS
,
RSVP
,
DOMParser
,
XMLHttpRequest
,
renderJS
));
\ No newline at end of file
bt5/erp5_gadget_interface_validator/PathTemplateItem/web_page_module/gadget_interface_js.xml
View file @
af3fb549
...
...
@@ -230,7 +230,7 @@
</item>
<item>
<key>
<string>
serial
</string>
</key>
<value>
<string>
9
46.46289.58152.58624
</string>
</value>
<value>
<string>
9
68.15557.27071.42905
</string>
</value>
</item>
<item>
<key>
<string>
state
</string>
</key>
...
...
@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>
1
446475754.
4
</float>
<float>
1
529069154.3
4
</float>
<string>
UTC
</string>
</tuple>
</state>
...
...
bt5/erp5_gadget_interface_validator/PathTemplateItem/web_page_module/gadget_interface_validator_page_form_js.js
View file @
af3fb549
/*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
(
'
.
'
));
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
});
}
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
bt5/erp5_gadget_interface_validator/PathTemplateItem/web_page_module/gadget_interface_validator_page_form_js.xml
View file @
af3fb549
...
...
@@ -230,7 +230,7 @@
</item>
<item>
<key>
<string>
serial
</string>
</key>
<value>
<string>
9
46.54877.22908.40635
</string>
</value>
<value>
<string>
9
68.15277.3815.5239
</string>
</value>
</item>
<item>
<key>
<string>
state
</string>
</key>
...
...
@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>
1
446717901.46
</float>
<float>
1
529052317.55
</float>
<string>
UTC
</string>
</tuple>
</state>
...
...
bt5/erp5_gadget_interface_validator/PathTemplateItem/web_page_module/gadget_interface_validator_page_report_js.js
View file @
af3fb549
/*global window, rJS, RSVP, Handlebars */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(
function
(
window
,
rJS
,
RSVP
,
Handlebars
)
{
/*global window, rJS, RSVP, Handlebars
, loopEventListener, $, document
*/
/*jslint nomen: true, indent: 2, maxerr: 3
, maxlen: 80
*/
(
function
(
window
,
rJS
,
RSVP
,
Handlebars
,
loopEventListener
,
$
,
document
)
{
"
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
)
{
var
gadget_info_list
=
[],
row_list
=
[],
var
row_list
=
[],
column_list
=
[
'
Gadget Name
'
,
'
Declared Interfaces
'
,
'
Validation Status
'
],
cell_list
,
default_status
=
"
In Progress
"
,
content
=
''
,
item
;
for
(
item
in
gadget_list
)
{
cell_list
=
[];
cell_list
.
push
({
i
;
for
(
i
=
0
;
i
<
gadget_list
.
length
;
i
+=
1
)
{
cell_list
=
[{
default_class
:
"
gadget_name
"
,
value
:
gadget_list
[
item
]
});
cell_list
.
push
({
value
:
gadget_list
[
i
]
},
{
default_class
:
"
interface_list
"
,
value
:
default_status
});
cell_list
.
push
({
},
{
default_class
:
"
validation_status
"
,
value
:
default_status
}
)
;
}
]
;
row_list
.
push
({
"
cell_list
"
:
cell_list
,
"
default_id
"
:
gadget_list
[
i
tem
].
substr
(
0
,
gadget_list
[
item
].
indexOf
(
'
.
'
))
});
"
default_id
"
:
gadget_list
[
i
].
substr
(
0
,
gadget_list
[
i
].
indexOf
(
'
.
'
))
});
}
content
+=
report_widget_table
({
column_list
:
column_list
,
...
...
@@ -40,55 +45,33 @@
$
(
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
)
{
var
interface_gadget
,
interface_list
=
[],
default_validation_status
=
{
result
:
"
N/A
"
};
default_validation_status
=
{
result
:
"
N/A
"
};
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
.
push
(
function
()
{
return
gadget
.
getDeclaredGadget
(
INTERFACE_GADGET_SCOPE
);
})
.
push
(
function
(
i_gadget
)
{
.
push
(
function
(
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
;
if
(
interface_list
.
length
>
0
)
{
return
interface_gadget
.
verifyGadgetInterfaceImplementation
(
verify_gadget_url
);
}
else
{
return
default_validation_status
;
if
(
interface_list
.
length
>
0
)
{
return
interface_gadget
.
verifyGadgetInterfaceImplementation
(
verify_gadget_url
);
}
return
default_validation_status
;
})
.
push
(
function
(
validation_status
)
{
.
push
(
function
(
validation_status
)
{
return
[
interface_list
,
validation_status
];
},
function
(
error
)
{
},
function
(
error
)
{
default_validation_status
.
result
=
false
;
default_validation_status
.
result_message
=
"
Error with gadget loading
"
;
default_validation_status
.
details
=
error
.
message
;
...
...
@@ -97,62 +80,85 @@
}
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
),
interface_data
=
''
,
validation_status
=
report_data
.
validation_status
,
validation_message
=
report_data
.
validation_message
;
validation_message
=
report_data
.
validation_message
,
i
,
interface_name
;
if
(
report_data
.
interface_list
.
length
)
{
var
item
,
interface_name
;
for
(
item
in
report_data
.
interface_list
)
{
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 />
'
);
}
}
else
{
interface_data
=
'
None
'
;
}
if
(
report_data
.
validation_status
===
true
)
{
if
(
report_data
.
validation_status
===
true
)
{
validation_status
=
"
Success
"
;
update_element
.
setAttribute
(
'
style
'
,
'
color: green
'
);
}
if
(
report_data
.
validation_status
===
false
)
{
validation_status
=
(
validation_message
!==
undefined
?
validation_message
:
"
Failure
"
);
if
(
report_data
.
validation_status
===
false
)
{
validation_status
=
(
validation_message
!==
undefined
?
validation_message
:
"
Failure
"
);
update_element
.
setAttribute
(
'
style
'
,
'
cursor: pointer; color: red
'
);
update_element
.
className
+=
"
error expand
"
;
}
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
(
"
.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
)
{
if
(
source_element
.
className
.
indexOf
(
"
expand
"
)
>
-
1
)
{
if
(
source_element
.
className
.
indexOf
(
"
expand
"
)
>
-
1
)
{
var
error_tr
=
document
.
createElement
(
'
tr
'
),
error_td
=
error_tr
.
insertCell
(
0
);
error_tr
.
id
=
source_element
.
id
+
'
_errordata
'
;
error_td
.
className
=
'
errordata
'
;
error_td
.
colSpan
=
"
3
"
;
error_td
.
innerText
=
gadget
.
props
.
error_data
[
source_element
.
id
];
source_element
.
parentNode
.
insertBefore
(
error_tr
,
source_element
.
nextSibling
);
source_element
.
className
=
source_element
.
className
.
replace
(
"
expand
"
,
"
shrink
"
);
}
else
if
(
source_element
.
className
.
indexOf
(
"
shrink
"
)
>
-
1
)
{
source_element
.
parentNode
.
insertBefore
(
error_tr
,
source_element
.
nextSibling
);
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
.
className
=
source_element
.
className
.
replace
(
"
shrink
"
,
"
expand
"
);
source_element
.
className
=
source_element
.
className
.
replace
(
"
shrink
"
,
"
expand
"
);
}
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
(
"
report-widget-table-partial
"
,
templater
.
getElementById
(
"
report-widget-table-partial
"
).
innerHTML
...
...
@@ -172,7 +178,7 @@
.
ready
(
function
(
g
)
{
return
g
.
getElement
()
.
push
(
function
(
element
)
{
g
.
props
.
element
=
element
,
g
.
props
.
element
=
element
;
g
.
props
.
content_element
=
element
.
querySelector
(
'
.validation_report
'
);
});
})
...
...
@@ -182,26 +188,26 @@
appcache_url
=
options
.
appcache_url
,
gadget_list
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
.
push
(
function
()
{
return
gadget
.
getDeclaredGadget
(
INTERFACE_GADGET_SCOPE
);
})
.
push
(
function
(
interface_gadget
)
{
.
push
(
function
(
interface_gadget
)
{
return
interface_gadget
.
getGadgetListFromAppcache
(
appcache_url
);
})
.
push
(
function
(
filtered_gadget_list
)
{
.
push
(
function
(
filtered_gadget_list
)
{
gadget_list
=
filtered_gadget_list
;
return
renderInitialReport
(
gadget
,
gadget_list
);
})
.
push
(
function
()
{
.
push
(
function
()
{
return
validateAppGadgetList
(
gadget
,
gadget_list
);
},
function
(
error
)
{
},
function
(
)
{
return
gadget
.
redirect
({
found
:
false
});
});
})
.
declareMethod
(
"
reportPageDummyMethod1
"
,
function
(
param1
)
{
.
declareMethod
(
"
reportPageDummyMethod1
"
,
function
(
)
{
// A dummy method to fulfil the interface implementation requirement.
return
;
})
...
...
@@ -219,7 +225,7 @@
function
rowSubmit
(
submit_data
)
{
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
);
}
}
...
...
@@ -232,4 +238,4 @@
);
});
}(
window
,
rJS
,
RSVP
,
Handlebars
));
\ No newline at end of file
}(
window
,
rJS
,
RSVP
,
Handlebars
,
loopEventListener
,
$
,
document
));
\ No newline at end of file
bt5/erp5_gadget_interface_validator/PathTemplateItem/web_page_module/gadget_interface_validator_page_report_js.xml
View file @
af3fb549
...
...
@@ -230,7 +230,7 @@
</item>
<item>
<key>
<string>
serial
</string>
</key>
<value>
<string>
9
46.54878.32293.23654
</string>
</value>
<value>
<string>
9
68.15263.39947.11758
</string>
</value>
</item>
<item>
<key>
<string>
state
</string>
</key>
...
...
@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>
1
446717974.43
</float>
<float>
1
529051525.57
</float>
<string>
UTC
</string>
</tuple>
</state>
...
...
bt5/erp5_gadget_interface_validator/PathTemplateItem/web_page_module/gadget_interface_validator_router_js.js
View file @
af3fb549
/*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_
"
,
var
MAIN_PAGE_PREFIX
=
"
gadget_interface_validator_
"
,
DEFAULT_PAGE
=
"
form
"
,
REDIRECT_TIMEOUT
=
5000
;
...
...
@@ -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
bt5/erp5_gadget_interface_validator/PathTemplateItem/web_page_module/gadget_interface_validator_router_js.xml
View file @
af3fb549
...
...
@@ -230,7 +230,7 @@
</item>
<item>
<key>
<string>
serial
</string>
</key>
<value>
<string>
9
46.58912.52724.48776
</string>
</value>
<value>
<string>
9
68.15281.35451.28142
</string>
</value>
</item>
<item>
<key>
<string>
state
</string>
</key>
...
...
@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>
1
446805302.57
</float>
<float>
1
529052586.11
</float>
<string>
UTC
</string>
</tuple>
</state>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment