Commit 71cbdce1 authored by Thomas Lechauve's avatar Thomas Lechauve

Fix bug (firefox): parse JSON string to object

It seems that on Firefox, data received from an ajax response is not
automatically parse to an object if it's a JSON string
parent 03cfb3d1
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
><label class="control-label">Software release</label> <label class="control-label">Software release</label>
<div class="controls"> <div class="controls">
<input type="text" class="input-xlarge" required name="software_release"/> <input type="text" class="input-xlarge" required name="software_release"/>
</div> </div>
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
pattern = pattern.replace(/:\w+/g, '([^\/]+)'); pattern = pattern.replace(/:\w+/g, '([^\/]+)');
var regex = new RegExp('^' + pattern + '$'), var regex = new RegExp('^' + pattern + '$'),
result = regex.exec(d); result = regex.exec(d);
console.log(d);
if (result) { if (result) {
result.shift(); result.shift();
methods[callback].apply($this, result); methods[callback].apply($this, result);
...@@ -26,21 +27,6 @@ ...@@ -26,21 +27,6 @@
}); });
}, },
/* Based on ben alman code
* https://raw.github.com/cowboy/jquery-misc/master/jquery.ba-serializeobject.js
*/
serializeObject = function () {
var obj = {};
$.each($(this).serializeArray(), function (i, o) {
var k = o.name,
v = o.value;
obj[k] = obj[k] === undefined ? v
: $.isArray(obj[k]) ? obj[k].concat(v)
: [obj[k], v];
});
return obj;
},
getDate = function () { getDate = function () {
var today = new Date(); var today = new Date();
return [today.getFullYear(), today.getMonth(), today.getDay()].join('/') + return [today.getFullYear(), today.getMonth(), today.getDay()].join('/') +
...@@ -164,6 +150,9 @@ ...@@ -164,6 +150,9 @@
}; };
$(this).slapos('instanceInfo', uri, { $(this).slapos('instanceInfo', uri, {
success: function (infos) { success: function (infos) {
if (typeof(infos) !== "object") {
infos = $.parseJSON(infos);
}
infos.status = $(this).vifib('getRender', 'instance.' + infos.status); infos.status = $(this).vifib('getRender', 'instance.' + infos.status);
infos.actions = [ infos.actions = [
{name: "Bang", url: methods.genBangUrl(decodeURIComponent(uri))} {name: "Bang", url: methods.genBangUrl(decodeURIComponent(uri))}
...@@ -192,6 +181,9 @@ ...@@ -192,6 +181,9 @@
var uri = $(this).vifib("extractInstanceURIFromHashtag"); var uri = $(this).vifib("extractInstanceURIFromHashtag");
$(this).slapos('instanceInfo', uri, { $(this).slapos('instanceInfo', uri, {
success: function (data) { success: function (data) {
if (typeof(data) !== "object") {
data = $.parseJSON(data);
}
var status = $(this).vifib('getRender', 'instance.' + data.status) var status = $(this).vifib('getRender', 'instance.' + data.status)
$("[name=software_type]").val(data.software_type); $("[name=software_type]").val(data.software_type);
$("#instanceStatus").html(status); $("#instanceStatus").html(status);
...@@ -268,6 +260,9 @@ ...@@ -268,6 +260,9 @@
return this.each(function () { return this.each(function () {
$(this).slapos('instanceInfo', url, { $(this).slapos('instanceInfo', url, {
success: function (instance) { success: function (instance) {
if (typeof(instance) !== "object") {
instance = $.parseJSON(instance);
}
$.extend(instance, {'url': methods.genInstanceUrl(url)}); $.extend(instance, {'url': methods.genInstanceUrl(url)});
$(this).vifib('render', 'instance.list.elem', instance); $(this).vifib('render', 'instance.list.elem', instance);
} }
...@@ -279,6 +274,9 @@ ...@@ -279,6 +274,9 @@
var currentList = $(this).vifib('getCurrentList'); var currentList = $(this).vifib('getCurrentList');
$(this).slapos('instanceList', { $(this).slapos('instanceList', {
success: function (data) { success: function (data) {
if (typeof(data) !== "object") {
data = $.parseJSON(data);
}
var $this = $(this), var $this = $(this),
newList = substractLists(currentList, data.list), newList = substractLists(currentList, data.list),
oldList = substractLists(data.list, currentList); oldList = substractLists(data.list, currentList);
...@@ -301,13 +299,16 @@ ...@@ -301,13 +299,16 @@
503: serverError 503: serverError
}, },
table = $(this).vifib('render', 'instance.list').find('#instance-table'); table = $(this).vifib('render', 'instance.list').find('#instance-table');
table.vifib('refresh', methods.refreshListInstance, 30); //table.vifib('refresh', methods.refreshListInstance, 30);
$(this).slapos('instanceList', { $(this).slapos('instanceList', {
success: function (data) { success: function (data) {
if (typeof(data) !== "object") {
data = $.parseJSON(data);
}
$.each(data.list, function () { $.each(data.list, function () {
var url = this.toString(), var url = this.toString(),
row = $('<tr></tr>').vifib('fillRowInstance', url); row = $('<tr></tr>').vifib('fillRowInstance', url);
row.vifib('refresh', methods.refreshRowInstance, 30); //row.vifib('refresh', methods.refreshRowInstance, 30);
table.append(row); table.append(row);
}); });
}, },
......
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