Commit aad0686b authored by Thomas Lechauve's avatar Thomas Lechauve

Instance page have stop/start/destroy button

parent 0d0d73ad
......@@ -59,28 +59,22 @@ $.vifib.softwareList = function (context) {
list.append(row);
});
list.listview('refresh');
}
},
statusCode: $.extend(false, $.vifib.statuscode, {})
});
});
}
$.vifib.instanceList = function (context) {
var list,
countRequest = 0;
var list;
return context.each(function () {
list = $(this).find('ul');
$(this).slapos('instanceList', {
success: function (response) {
$(this).ajaxSend(function () { ++countRequest; });
$(this).ajaxComplete(function () {
if (countRequest-- == 0) {
console.log("the end")
list.listview('refresh');
} else {
console.log(countRequest)
}
$.each(response.list, function (i, e) {
$.vifib.fillRowInstance(list, $('<li></li>'), e);
});
$.vifib.fillRowInstance(list, $('<li></li>'), '');
},
statusCode: $.extend(false, $.vifib.statuscode, {})
});
});
}
......@@ -91,9 +85,9 @@ $.vifib.fillRowInstance = function (list, row, instid) {
$(this).html(Mustache.render($.vifib.panel.rowinstance, response));
},
complete: function (jqxhr, textstatus) {
console.log("complete")
list.append($(this));
}
list.append($(this)).listview('refresh');
},
statusCode: $.extend(false, $.vifib.statuscode, {})
});
}
$.vifib.computerList = function (context) {
......@@ -107,7 +101,8 @@ $.vifib.computerList = function (context) {
list.append(row);
});
list.listview('refresh');
}
},
statusCode: $.extend(false, $.vifib.statuscode, {})
});
});
}
......@@ -117,7 +112,8 @@ $.vifib.fillRowSoftware = function (context, softid) {
success: function (response) {
$.extend(response, {softurl: '#/library/software/id' + softid});
$(this).html(Mustache.render($.vifib.panel.rowsoftware, response));
}
},
statusCode: $.extend(false, $.vifib.statuscode, {})
});
})
}
......@@ -127,7 +123,8 @@ $.vifib.fillRowComputer = function (context, compid) {
success: function (response) {
$.extend(response, {compurl: '#/dashboard/computer/id/' + compid});
$(this).html(Mustache.render($.vifib.panel.rowcomputer, response));
}
},
statusCode: $.extend(false, $.vifib.statuscode, {})
});
})
}
......@@ -88,6 +88,15 @@ $.vifib.mobile = {
$('body')
.route('add', '/dashboard/instance/id<path:instid>', 1)
.done($.vifib.mobile.dashboard.instance);
$('body')
.route('add', '/dashboard/instance/start<path:instid>', 1)
.done($.vifib.mobile.dashboard.instancestart);
$('body')
.route('add', '/dashboard/instance/stop<path:instid>', 1)
.done($.vifib.mobile.dashboard.instancestop);
$('body')
.route('add', '/dashboard/instance/destroy<path:instid>', 1)
.done($.vifib.mobile.dashboard.instancedestroy);
$('body')
.route('add', '/dashboard/computer/list', 1)
.done($.vifib.mobile.dashboard.computerlist);
......@@ -150,12 +159,58 @@ $.vifib.mobile = {
var page;
$(this).slapos('instanceInfo', instid, {
success: function (response) {
response[response.status] = true;
response.stop_url = '#/dashboard/instance/stop' + instid;
response.start_url = '#/dashboard/instance/start' + instid;
response.destroy_url = '#/dashboard/instance/destroy' + instid;
page = $.vifib.onepanel($.vifib.panel.instance, response);
page.prepend(Mustache.render($.vifib.header.default, {title: 'Instance'}));
$.vifib.changepage($(page));
}
});
},
instancestart: function (instid) {
$(this).slapos('instanceInfo', instid, {
success: function (response) {
if (response.status === 'stop_requested') {
response.status = 'started';
$(this).slapos('instanceRequest', {
data: response,
success: function (response) {
$.url.redirect('/dashboard/instance/id' + instid);
},
statusCode: $.extend(false, $.vifib.statuscode, {})
})
}
},
statusCode: $.extend(false, $.vifib.statuscode, {})
});
},
instancestop: function (instid) {
$(this).slapos('instanceInfo', instid, {
success: function (response) {
if (response.status === 'start_requested') {
response.status = 'stopped';
$(this).slapos('instanceRequest', {
data: response,
success: function (response) {
$.url.redirect('/dashboard/instance/id' + instid);
},
statusCode: $.extend(false, $.vifib.statuscode, {})
})
}
},
statusCode: $.extend(false, $.vifib.statuscode, {})
});
},
instancedestroy: function (instid) {
$(this).slapos('instanceDelete', instid, {
success: function (response) {
$.url.redirect('/dashboard/instance/id' + instid);
},
statusCode: $.extend(false, $.vifib.statuscode, {})
})
},
computerlist: function (route) {
var page = $.vifib.onepanel($.vifib.panel.allcomputer);
page.prepend(Mustache.render($.vifib.header.default, {title: 'Computers'}));
......
......@@ -130,10 +130,30 @@ $.vifib.panel = {
'</article>',
instance:
'<article>' +
'{{# image_url }}' +
'<img src="{{ image_url }}">' +
'{{/ image_url }}' +
'<h2>{{ instance_id }}</h2>' +
'<center><h3>{{ title }}</h3></center>' +
'<ul data-role="listview">' +
'<li class="ui-li-static">' +
'<p class="ui-li-desc"><i>Software release</i></p>' +
'<h3 class="ui-li-heading"><a href="{{ software_release }}">{{ software_release }}</a></h3>' +
'</li>' +
'<li class="ui-li-static">' +
'<p class="ui-li-desc"><i>Software type</i></p>' +
'<h3 class="ui-li-heading">{{ software_type }}</h3>' +
'</li>' +
'<li class="ui-li-static">' +
'<p class="ui-li-desc"><i>Status</i></p>' +
'<h3 class="ui-li-heading">{{ status }}</h3>' +
'</li>' +
'</ul>' +
'{{# start_requested }}' +
'<a data-role="button" href="{{ stop_url }}">Stop</a>' +
'<a data-role="button" href="{{ destroy_url }}">Destroy</a>' +
'{{/ start_requested }}' +
'{{# stop_requested }}' +
'<a data-role="button" href="{{ start_url }}">Start</a>' +
'<a data-role="button" href="{{ destroy_url }}">Destroy</a>' +
'{{/ stop_requested }}' +
'' +
'</article>',
instancelist:
'<article>' +
......@@ -142,7 +162,7 @@ $.vifib.panel = {
'</ul>' +
'</article>',
rowinstance:
'<a href="{{ insturl }}">{{ title }}</a>',
'<a href="{{ insturl }}">{{ instance_id }}</a>',
computer:
'<article>' +
'<h2>{{ computer_id }}</h2>' +
......
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