Commit b88a0489 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_gadget_interface_validator] Do not reimplement jio ajax

parent 29224500
......@@ -7,6 +7,7 @@
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<script src="jiodev.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_interface.js" type="text/javascript"></script>
......
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>946.45949.24044.35191</string> </value>
<value> <string>968.5552.51560.44322</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1445940328.05</float>
<float>1529075051.25</float>
<string>UTC</string>
</tuple>
</state>
......
/*jslint nomen: true, indent: 2, maxerr: 30, maxlen: 80 */
/*global DOMParser, document, XMLHttpRequest, rJS, renderJS, RSVP, window*/
/*global DOMParser, document, rJS, renderJS, RSVP, window,
jIO*/
/*
* DOMParser HTML extension
* 2012-09-04
......@@ -45,52 +46,19 @@
};
}(DOMParser, document));
(function (window, rJS, RSVP, DOMParser, XMLHttpRequest, renderJS) {
(function (window, rJS, RSVP, DOMParser, renderJS, jIO) {
"use strict";
function ajax(url) {
var xhr;
function resolver(resolve, reject) {
function handler() {
try {
if (xhr.readyState === 0) {
// UNSENT
reject(xhr);
} else if (xhr.readyState === 4) {
// DONE
if ((xhr.status < 200) || (xhr.status >= 300)) {
reject(xhr);
} else {
resolve(xhr);
}
}
} catch (e) {
reject(e);
}
}
xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.onreadystatechange = handler;
xhr.setRequestHeader('Accept', 'text/html');
xhr.withCredentials = true;
xhr.send();
}
function canceller() {
if ((xhr !== undefined) && (xhr.readyState !== xhr.DONE)) {
xhr.abort();
}
}
return new RSVP.Promise(resolver, canceller);
}
function fetchAppcacheData(appcache_url) {
return new RSVP.Queue()
.push(function () {
return ajax(appcache_url);
return jIO.util.ajax({
url: appcache_url,
dataType: 'text'
});
})
.push(function (xhr) {
return xhr.responseText.split('\n');
.push(function (evt) {
return evt.target.responseText.split('\n');
});
}
......@@ -133,11 +101,14 @@
function getInterfaceListFromURL(gadget_url) {
return new RSVP.Queue()
.push(function () {
return ajax(gadget_url);
return jIO.util.ajax({
url: gadget_url,
dataType: 'text'
});
})
.push(function (xhr) {
.push(function (evt) {
var document_element = (new DOMParser()).parseFromString(
xhr.responseText,
evt.target.responseText,
'text/html'
),
interface_list = [],
......@@ -169,10 +140,13 @@
"One or more required tags are missing.";
return new RSVP.Queue()
.push(function () {
return ajax(interface_url);
return jIO.util.ajax({
url: interface_url,
dataType: 'text'
});
})
.push(function (xhr) {
var doc = (new DOMParser()).parseFromString(xhr.responseText,
.push(function (evt) {
var doc = (new DOMParser()).parseFromString(evt.target.responseText,
'text/html').body,
dl_list = doc.getElementsByTagName('dl'),
next_element = dl_list[0].firstElementChild,
......@@ -413,10 +387,13 @@
};
return new RSVP.Queue()
.push(function () {
return ajax(interface_url);
return jIO.util.ajax({
url: interface_url,
dataType: 'text'
});
})
.push(function (xhr) {
var doc = (new DOMParser()).parseFromString(xhr.responseText,
.push(function (evt) {
var doc = (new DOMParser()).parseFromString(evt.target.responseText,
'text/html').body,
dl_list = doc.querySelectorAll('dl'),
dt_list = doc.querySelectorAll('dt'),
......@@ -658,4 +635,4 @@
});
});
}(window, rJS, RSVP, DOMParser, XMLHttpRequest, renderJS));
\ No newline at end of file
}(window, rJS, RSVP, DOMParser, renderJS, jIO));
\ No newline at end of file
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>968.15557.27071.42905</string> </value>
<value> <string>968.15689.53377.56541</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1529069154.34</float>
<float>1529077165.39</float>
<string>UTC</string>
</tuple>
</state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment