Commit da7cc548 authored by Thomas Lechauve's avatar Thomas Lechauve

Manually linted (clean) javascript files

parent f4fad40f
$(document).bind("mobileinit", function () { $(document).bind('mobileinit', function () {
var spinOptions = {color: "#FFFFFF", lines:30, length:0, width:5, radius:7, rotate:0, trail:60, speed:1.6}; 'use strict';
var spinOptions = {color: '#FFFFFF', lines: 30, length: 0, width: 5, radius: 7, rotate: 0, trail: 60, speed: 1.6};
$.vifib = {} || $.vifib; if (!$.vifib) {
$.vifib = {};
}
//SlapOs configuration //SlapOs configuration
$(document).slapos({ $(document).slapos({
...@@ -15,9 +18,9 @@ $(document).bind("mobileinit", function () { ...@@ -15,9 +18,9 @@ $(document).bind("mobileinit", function () {
// show loading during ajax request // show loading during ajax request
$(document).ajaxStart(function () { $(document).ajaxStart(function () {
$("#loading").spin(spinOptions); $('#loading').spin(spinOptions);
}).ajaxStop(function () { }).ajaxStop(function () {
$("#loading").spin(false); $('#loading').spin(false);
}); });
//$(document).slapos('store', 'host', '/fake'); //$(document).slapos('store', 'host', '/fake');
......
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
}, },
request: function (type, method, args) { request: function (type, method, args) {
var statusCode, data; var statusCode, data, ajaxOptions;
if (args.hasOwnProperty('statusCode')) { if (args.hasOwnProperty('statusCode')) {
statusCode = args.statusCode || methods.statusDefault(); statusCode = args.statusCode || methods.statusDefault();
} else { } else {
...@@ -78,7 +78,7 @@ ...@@ -78,7 +78,7 @@
} }
delete args.data; delete args.data;
$.extend(args, {statusCode: statusCode}); $.extend(args, {statusCode: statusCode});
var ajaxOptions = { ajaxOptions = {
type: type, type: type,
url: $(this).slapos('host') + method, url: $(this).slapos('host') + method,
contentType: 'application/json', contentType: 'application/json',
...@@ -138,16 +138,17 @@ ...@@ -138,16 +138,17 @@
$.extend(args, {url: url}); $.extend(args, {url: url});
return $(this).slapos('request', 'GET', '', args); return $(this).slapos('request', 'GET', '', args);
} }
}; };
$.fn.slapos = function (method) { $.fn.slapos = function (method) {
var r;
if (methods[method]) { if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); r = methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) { } else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments); r = methods.init.apply(this, arguments);
} else { } else {
$.error('Method ' + method + ' does not exist on jQuery.slapos'); $.error('Method ' + method + ' does not exist on jQuery.slapos');
} }
return r;
}; };
}(jQuery)); }(jQuery));
'use strict'; (function (window, $) {
var getDevice = function (w) { 'use strict';
var getDevice = function (w) {
if (w < 500) { if (w < 500) {
return 'mobile'; return 'mobile';
} }
...@@ -7,12 +8,11 @@ var getDevice = function (w) { ...@@ -7,12 +8,11 @@ var getDevice = function (w) {
return 'tablet'; return 'tablet';
} }
return 'desktop'; return 'desktop';
}, },
device = getDevice($(window).width()); body = $("body");
var body = $("body");
$.vifib.devices = { $.vifib.device = getDevice($(window).width());
$.vifib.devices = {
"mobile": function (url) { "mobile": function (url) {
$('body') $('body')
.route('add', '') .route('add', '')
...@@ -69,44 +69,31 @@ $.vifib.devices = { ...@@ -69,44 +69,31 @@ $.vifib.devices = {
.route('add', '<path:url>') .route('add', '<path:url>')
.done($.vifib.desktop.dispatch); .done($.vifib.desktop.dispatch);
} }
} };
$.vifib.isauthenticated = function () {
var token_type = $(document).slapos('store', 'token_type');
if ($(document).slapos('access_token') === undefined || token_type === undefined) {
return false;
}
if (token_type === 'Google') {
} else if (token_type === 'Facebook') { $.vifib.startrouter = function () {
}
return false;
}
$.vifib.startrouter = function () {
$('body') $('body')
.route('go', $.url.getPath()) .route('go', $.url.getPath())
.fail($.vifib.mobile.nopage); .fail($.vifib.mobile.nopage);
} };
/* Thanks to Ben Alman /* Thanks to Ben Alman
* https://raw.github.com/cowboy/jquery-misc/master/jquery.ba-serializeobject.js * https://raw.github.com/cowboy/jquery-misc/master/jquery.ba-serializeobject.js
*/ */
$.fn.serializeObject = function(){ $.fn.serializeObject = function () {
var obj = {}; var obj = {};
$.each( this.serializeArray(), function(i,o){ $.each(this.serializeArray(), function (i, o) {
var n = o.name, var n = o.name,
v = o.value; v = o.value;
obj[n] = obj[n] === undefined ? v obj[n] = obj[n] === undefined ? v
: $.isArray( obj[n] ) ? obj[n].concat( v ) : $.isArray(obj[n]) ? obj[n].concat(v)
: [ obj[n], v ]; : [obj[n], v];
}); });
return obj; return obj;
} };
$.fn.spin = function(opts) { $.fn.spin = function (opts) {
this.each(function() { this.each(function () {
var $this = $(this), var $this = $(this),
data = $this.data(); data = $this.data();
if (data.spinner) { if (data.spinner) {
...@@ -118,17 +105,17 @@ $.fn.spin = function(opts) { ...@@ -118,17 +105,17 @@ $.fn.spin = function(opts) {
} }
}); });
return this; return this;
} };
$(document).ready(function () { $(document).ready(function () {
// bind on resize screen event // bind on resize screen event
$(window).resize(function () { $(window).resize(function () {
setTimeout(function () { setTimeout(function () {
var curdevice = getDevice($(window).width()); var curdevice = getDevice($(window).width());
if (device !== curdevice) { if ($.vifib.device !== curdevice) {
device = curdevice; $.vifib.device = curdevice;
$.routereset(); $.routereset();
$.vifib.devices[device](); $.vifib.devices[$.vifib.device]();
$.vifib.startrouter(); $.vifib.startrouter();
} }
}, 800); }, 800);
...@@ -140,7 +127,8 @@ $(document).ready(function () { ...@@ -140,7 +127,8 @@ $(document).ready(function () {
if (options.hasOwnProperty('access_token')) { if (options.hasOwnProperty('access_token')) {
$(document).slapos('access_token', options.access_token); $(document).slapos('access_token', options.access_token);
} }
$.vifib.devices[device](); $.vifib.devices[$.vifib.device]();
$.vifib.startrouter(); $.vifib.startrouter();
}); });
}); });
}(window, jQuery));
$.vifib.desktop = { (function (window, $) {
'use strict';
$.vifib.desktop = {
redirect: function (route) { redirect: function (route) {
$.url.go('/overview'); $.url.go('/overview');
}, },
...@@ -14,7 +16,7 @@ $.vifib.desktop = { ...@@ -14,7 +16,7 @@ $.vifib.desktop = {
]} ]}
]); ]);
// header // header
page.prepend(Mustache.render($.vifib.header.default, {title: 'SlapOs'})); page.prepend(Mustache.render($.vifib.header.main, {title: 'SlapOs'}));
// rendering // rendering
$.vifib.changepage($(page)); $.vifib.changepage($(page));
$('#panel-1') $('#panel-1')
...@@ -38,7 +40,7 @@ $.vifib.desktop = { ...@@ -38,7 +40,7 @@ $.vifib.desktop = {
.done($.vifib.login.googleRedirect); .done($.vifib.login.googleRedirect);
$('#panel-1') $('#panel-1')
.route('go', $.url.getPath(), 1) .route('go', $.url.getPath(), 1)
.fail(function () { $.vifib.replacepanel($(this), $.vifib.panel.failed)}); .fail(function () { $.vifib.replacepanel($(this), $.vifib.panel.failed); });
}, },
overview: function (route) { overview: function (route) {
$.vifib.replacepanel($(this), $.vifib.panel.carousel); $.vifib.replacepanel($(this), $.vifib.panel.carousel);
...@@ -74,12 +76,12 @@ $.vifib.desktop = { ...@@ -74,12 +76,12 @@ $.vifib.desktop = {
.done($.vifib.desktop.library.all); .done($.vifib.desktop.library.all);
$('#panel-2') $('#panel-2')
.route('go', $.url.getPath(), 2) .route('go', $.url.getPath(), 2)
.fail(function () { $.vifib.replacepanel($(this), $.vifib.panel.failed)}); .fail(function () { $.vifib.replacepanel($(this), $.vifib.panel.failed); });
}, },
overview: function (route) { overview: function (route) {
$.vifib.replacepanel($(this), $.vifib.panel.library, { $.vifib.replacepanel($(this), $.vifib.panel.library, {
most: [ most: [
{url: '#/library/software/id/fake/software_info/Kvm', name: 'Kvm'}, {url: '#/library/software/id/fake/software_info/Kvm', name: 'Kvm'}
], ],
newest: [ newest: [
{url: '#/library/software/id/fake/software_info/Html5as', name: 'html5 AS'} {url: '#/library/software/id/fake/software_info/Html5as', name: 'html5 AS'}
...@@ -102,7 +104,7 @@ $.vifib.desktop = { ...@@ -102,7 +104,7 @@ $.vifib.desktop = {
dispatch: function (route) { dispatch: function (route) {
$.vifib.replacepanel($(this), $.vifib.panel.simplelist, { $.vifib.replacepanel($(this), $.vifib.panel.simplelist, {
links: [ links: [
{url: '#/dashboard/instance/list', name: 'Instances'}, {url: '#/dashboard/instance/list', name: 'Instances'}
] ]
}); });
$('#panel-2') $('#panel-2')
...@@ -128,7 +130,7 @@ $.vifib.desktop = { ...@@ -128,7 +130,7 @@ $.vifib.desktop = {
.done($.vifib.desktop.dashboard.instancedestroy); .done($.vifib.desktop.dashboard.instancedestroy);
$('#panel-2') $('#panel-2')
.route('go', $.url.getPath(), 2) .route('go', $.url.getPath(), 2)
.fail(function () { $.vifib.replacepanel($(this), $.vifib.panel.failed)}); .fail(function () { $.vifib.replacepanel($(this), $.vifib.panel.failed); });
}, },
instancelist: function (route) { instancelist: function (route) {
$.vifib.replacepanel($(this), $.vifib.panel.instancelist); $.vifib.replacepanel($(this), $.vifib.panel.instancelist);
...@@ -140,7 +142,7 @@ $.vifib.desktop = { ...@@ -140,7 +142,7 @@ $.vifib.desktop = {
var data = { var data = {
"status": "start_requested", "status": "start_requested",
"slave": false, "slave": false,
"software_type": "type_provided_by_the_software", "software_type": "type_provided_by_the_software"
}; };
$.extend(data, $(this).serializeObject()); $.extend(data, $(this).serializeObject());
$(this).slapos('instanceRequest', { $(this).slapos('instanceRequest', {
...@@ -175,7 +177,7 @@ $.vifib.desktop = { ...@@ -175,7 +177,7 @@ $.vifib.desktop = {
$.url.redirect('/dashboard/instance/id' + instid); $.url.redirect('/dashboard/instance/id' + instid);
}, },
statusCode: $.extend(false, $.vifib.statuscode, {}) statusCode: $.extend(false, $.vifib.statuscode, {})
}) });
} }
}, },
statusCode: $.extend(false, $.vifib.statuscode, {}) statusCode: $.extend(false, $.vifib.statuscode, {})
...@@ -192,11 +194,12 @@ $.vifib.desktop = { ...@@ -192,11 +194,12 @@ $.vifib.desktop = {
$.url.redirect('/dashboard/instance/id' + instid); $.url.redirect('/dashboard/instance/id' + instid);
}, },
statusCode: $.extend(false, $.vifib.statuscode, {}) statusCode: $.extend(false, $.vifib.statuscode, {})
}) });
} }
}, },
statusCode: $.extend(false, $.vifib.statuscode, {}) statusCode: $.extend(false, $.vifib.statuscode, {})
}); });
},
} }
}; }
};
}(window, jQuery));
$.vifib.login = { (function (window, $) {
'use strict';
$.vifib.login = {
facebook: function (params) { facebook: function (params) {
var redirect = location.protocol + '//' + location.host + location.pathname + '#/dashboard/' + '?', var redirect = location.protocol + '//' + location.host + location.pathname + '#/dashboard/' + '?',
fburl = 'https://www.facebook.com/dialog/oauth?' + fburl = 'https://www.facebook.com/dialog/oauth?' +
...@@ -30,13 +32,13 @@ $.vifib.login = { ...@@ -30,13 +32,13 @@ $.vifib.login = {
}); });
$.url.redirect('/dashboard/', options); $.url.redirect('/dashboard/', options);
} }
} };
$.vifib.statuscode = { $.vifib.statuscode = {
400: function (jqxhr, textstatus) { 400: function (jqxhr, textstatus) {
var page; var page;
if(device === 'mobile') { if ($.vifib.device === 'mobile') {
page = $.vifib.onepanel($.vifib.panel.badrequest); page = $.vifib.onepanel($.vifib.panel.badrequest);
page.prepend(Mustache.render($.vifib.header.default, {title: 'An error as occured'})); page.prepend(Mustache.render($.vifib.header.main, {title: 'An error as occured'}));
page.append($.vifib.footer.overview); page.append($.vifib.footer.overview);
$.vifib.changepage($(page)); $.vifib.changepage($(page));
} else { } else {
...@@ -48,9 +50,9 @@ $.vifib.statuscode = { ...@@ -48,9 +50,9 @@ $.vifib.statuscode = {
}, },
402: function (jqxhr, textstatus) { 402: function (jqxhr, textstatus) {
var page; var page;
if(device === 'mobile') { if ($.vifib.device === 'mobile') {
page = $.vifib.onepanel($.vifib.panel.payment); page = $.vifib.onepanel($.vifib.panel.payment);
page.prepend(Mustache.render($.vifib.header.default, {title: 'An error as occured'})); page.prepend(Mustache.render($.vifib.header.main, {title: 'An error as occured'}));
page.append($.vifib.footer.overview); page.append($.vifib.footer.overview);
$.vifib.changepage($(page)); $.vifib.changepage($(page));
} else { } else {
...@@ -59,9 +61,9 @@ $.vifib.statuscode = { ...@@ -59,9 +61,9 @@ $.vifib.statuscode = {
}, },
404: function (jqxhr, textstatus) { 404: function (jqxhr, textstatus) {
var page; var page;
if(device === 'mobile') { if ($.vifib.device === 'mobile') {
page = $.vifib.onepanel($.vifib.panel.notfound); page = $.vifib.onepanel($.vifib.panel.notfound);
page.prepend(Mustache.render($.vifib.header.default, {title: 'An error as occured'})); page.prepend(Mustache.render($.vifib.header.main, {title: 'An error as occured'}));
page.append($.vifib.footer.overview); page.append($.vifib.footer.overview);
$.vifib.changepage($(page)); $.vifib.changepage($(page));
} else { } else {
...@@ -70,17 +72,17 @@ $.vifib.statuscode = { ...@@ -70,17 +72,17 @@ $.vifib.statuscode = {
}, },
500: function (jqxhr, textstatus) { 500: function (jqxhr, textstatus) {
var page; var page;
if(device === 'mobile') { if ($.vifib.device === 'mobile') {
page = $.vifib.onepanel($.vifib.panel.internalerror); page = $.vifib.onepanel($.vifib.panel.internalerror);
page.prepend(Mustache.render($.vifib.header.default, {title: 'An error as occured'})); page.prepend(Mustache.render($.vifib.header.main, {title: 'An error as occured'}));
page.append($.vifib.footer.overview); page.append($.vifib.footer.overview);
$.vifib.changepage($(page)); $.vifib.changepage($(page));
} else { } else {
$.vifib.replacepanel($(this), $.vifib.panel.internalerror); $.vifib.replacepanel($(this), $.vifib.panel.internalerror);
} }
}, }
} };
$.vifib.softwareList = function (context) { $.vifib.softwareList = function (context) {
var list; var list;
return context.each(function () { return context.each(function () {
list = $(this).find('ul'); list = $(this).find('ul');
...@@ -95,8 +97,8 @@ $.vifib.softwareList = function (context) { ...@@ -95,8 +97,8 @@ $.vifib.softwareList = function (context) {
statusCode: $.extend(false, $.vifib.statuscode, {}) statusCode: $.extend(false, $.vifib.statuscode, {})
}); });
}); });
} };
$.vifib.instanceList = function (context) { $.vifib.instanceList = function (context) {
var list; var list;
return context.each(function () { return context.each(function () {
list = $(this).find('ul'); list = $(this).find('ul');
...@@ -109,8 +111,8 @@ $.vifib.instanceList = function (context) { ...@@ -109,8 +111,8 @@ $.vifib.instanceList = function (context) {
statusCode: $.extend(false, $.vifib.statuscode, {}) statusCode: $.extend(false, $.vifib.statuscode, {})
}); });
}); });
} };
$.vifib.fillRowInstance = function (list, row, instid) { $.vifib.fillRowInstance = function (list, row, instid) {
return row.slapos('instanceInfo', instid, { return row.slapos('instanceInfo', instid, {
success: function (response) { success: function (response) {
$.extend(response, {insturl: '#/dashboard/instance/id' + instid}); $.extend(response, {insturl: '#/dashboard/instance/id' + instid});
...@@ -121,8 +123,8 @@ $.vifib.fillRowInstance = function (list, row, instid) { ...@@ -121,8 +123,8 @@ $.vifib.fillRowInstance = function (list, row, instid) {
}, },
statusCode: $.extend(false, $.vifib.statuscode, {}) statusCode: $.extend(false, $.vifib.statuscode, {})
}); });
} };
$.vifib.computerList = function (context) { $.vifib.computerList = function (context) {
var list; var list;
return context.each(function () { return context.each(function () {
list = $(this).find('ul'); list = $(this).find('ul');
...@@ -137,8 +139,8 @@ $.vifib.computerList = function (context) { ...@@ -137,8 +139,8 @@ $.vifib.computerList = function (context) {
statusCode: $.extend(false, $.vifib.statuscode, {}) statusCode: $.extend(false, $.vifib.statuscode, {})
}); });
}); });
} };
$.vifib.fillRowSoftware = function (context, softid) { $.vifib.fillRowSoftware = function (context, softid) {
return context.each(function () { return context.each(function () {
$(this).slapos('softwareInfo', softid, { $(this).slapos('softwareInfo', softid, {
success: function (response) { success: function (response) {
...@@ -147,9 +149,9 @@ $.vifib.fillRowSoftware = function (context, softid) { ...@@ -147,9 +149,9 @@ $.vifib.fillRowSoftware = function (context, softid) {
}, },
statusCode: $.extend(false, $.vifib.statuscode, {}) statusCode: $.extend(false, $.vifib.statuscode, {})
}); });
}) });
} };
$.vifib.fillRowComputer = function (context, compid) { $.vifib.fillRowComputer = function (context, compid) {
return context.each(function () { return context.each(function () {
$(this).slapos('computerInfo', compid, { $(this).slapos('computerInfo', compid, {
success: function (response) { success: function (response) {
...@@ -158,5 +160,6 @@ $.vifib.fillRowComputer = function (context, compid) { ...@@ -158,5 +160,6 @@ $.vifib.fillRowComputer = function (context, compid) {
}, },
statusCode: $.extend(false, $.vifib.statuscode, {}) statusCode: $.extend(false, $.vifib.statuscode, {})
}); });
}) });
} };
}(window, jQuery));
$.vifib.mobile = { (function (window, $) {
'use strict';
$.vifib.mobile = {
nopage: function () { nopage: function () {
var page = $.vifib.onepanel($.vifib.panel.failed); var page = $.vifib.onepanel($.vifib.panel.failed);
page.prepend(Mustache.render($.vifib.header.default, {title: 'Oops'})); page.prepend(Mustache.render($.vifib.header.main, {title: 'Oops'}));
$.vifib.changepage($(page)); $.vifib.changepage($(page));
}, },
overview: function (route) { overview: function (route) {
...@@ -9,7 +11,7 @@ $.vifib.mobile = { ...@@ -9,7 +11,7 @@ $.vifib.mobile = {
// rendering // rendering
page = $.vifib.onepanel($.vifib.panel.login); page = $.vifib.onepanel($.vifib.panel.login);
// header // header
page.prepend(Mustache.render($.vifib.header.default, {title: 'SlapOs'})); page.prepend(Mustache.render($.vifib.header.main, {title: 'SlapOs'}));
// footer navbar // footer navbar
page.append($.vifib.footer.overview); page.append($.vifib.footer.overview);
// rendering // rendering
...@@ -31,16 +33,16 @@ $.vifib.mobile = { ...@@ -31,16 +33,16 @@ $.vifib.mobile = {
.fail($.vifib.mobile.nopage); .fail($.vifib.mobile.nopage);
}, },
overview: function () { overview: function () {
page = $.vifib.onepanel($.vifib.panel.library, { var page = $.vifib.onepanel($.vifib.panel.library, {
most: [ most: [
{url: '#/library/software/id/fake/software_info/Kvm', name: 'Kvm'}, {url: '#/library/software/id/fake/software_info/Kvm', name: 'Kvm'}
], ],
newest: [ newest: [
{url: '#/library/software/id/fake/software_info/Html5', name: 'Html5as'} {url: '#/library/software/id/fake/software_info/Html5', name: 'Html5as'}
] ]
}); });
// header // header
page.prepend(Mustache.render($.vifib.header.default, {title: 'Library'})); page.prepend(Mustache.render($.vifib.header.main, {title: 'Library'}));
page.append(Mustache.render($.vifib.panel.simplelist, { page.append(Mustache.render($.vifib.panel.simplelist, {
links: [ links: [
{url: '#/library/all', name: 'See all softwares'}, {url: '#/library/all', name: 'See all softwares'},
...@@ -58,7 +60,7 @@ $.vifib.mobile = { ...@@ -58,7 +60,7 @@ $.vifib.mobile = {
var page; var page;
page = $.vifib.onepanel($.vifib.panel.software, response); page = $.vifib.onepanel($.vifib.panel.software, response);
// header // header
page.prepend(Mustache.render($.vifib.header.default, {title: response.name})); page.prepend(Mustache.render($.vifib.header.main, {title: response.name}));
// footer navbar // footer navbar
page.append($.vifib.footer.overview); page.append($.vifib.footer.overview);
// rendering // rendering
...@@ -70,7 +72,7 @@ $.vifib.mobile = { ...@@ -70,7 +72,7 @@ $.vifib.mobile = {
all: function () { all: function () {
var page = $.vifib.onepanel($.vifib.panel.allsoftware); var page = $.vifib.onepanel($.vifib.panel.allsoftware);
$.vifib.softwareList($(page)); $.vifib.softwareList($(page));
page.prepend(Mustache.render($.vifib.header.default, {title: 'All softwares'})); page.prepend(Mustache.render($.vifib.header.main, {title: 'All softwares'}));
page.append($.vifib.footer.overview); page.append($.vifib.footer.overview);
$.vifib.changepage($(page)); $.vifib.changepage($(page));
} }
...@@ -109,24 +111,24 @@ $.vifib.mobile = { ...@@ -109,24 +111,24 @@ $.vifib.mobile = {
{url: '#/dashboard/computer/list', name: 'Computers'} {url: '#/dashboard/computer/list', name: 'Computers'}
] ]
}); });
page.prepend(Mustache.render($.vifib.header.default, {title: 'Dashboard'})); page.prepend(Mustache.render($.vifib.header.main, {title: 'Dashboard'}));
$.vifib.changepage($(page)); $.vifib.changepage($(page));
}, },
instancelist: function (route) { instancelist: function (route) {
var page = $.vifib.onepanel($.vifib.panel.instancelist); var page = $.vifib.onepanel($.vifib.panel.instancelist);
page.prepend(Mustache.render($.vifib.header.default, {title: 'Instances'})); page.prepend(Mustache.render($.vifib.header.main, {title: 'Instances'}));
$.vifib.changepage($(page)); $.vifib.changepage($(page));
$.vifib.instanceList($(page)); $.vifib.instanceList($(page));
}, },
instancerequest: function (route) { instancerequest: function (route) {
var page = $.vifib.onepanel($.vifib.panel.instancerequest); var page = $.vifib.onepanel($.vifib.panel.instancerequest);
page.prepend(Mustache.render($.vifib.header.default, {title: 'Request instance'})); page.prepend(Mustache.render($.vifib.header.main, {title: 'Request instance'}));
$.vifib.changepage($(page)); $.vifib.changepage($(page));
$("#instancerequest").submit(function () { $("#instancerequest").submit(function () {
var data = { var data = {
"status": "start_requested", "status": "start_requested",
"slave": false, "slave": false,
"software_type": "type_provided_by_the_software", "software_type": "type_provided_by_the_software"
}; };
$.extend(data, $(this).serializeObject()); $.extend(data, $(this).serializeObject());
$(this).slapos('instanceRequest', { $(this).slapos('instanceRequest', {
...@@ -148,7 +150,7 @@ $.vifib.mobile = { ...@@ -148,7 +150,7 @@ $.vifib.mobile = {
response.start_url = '#/dashboard/instance/start' + instid; response.start_url = '#/dashboard/instance/start' + instid;
response.destroy_url = '#/dashboard/instance/destroy' + instid; response.destroy_url = '#/dashboard/instance/destroy' + instid;
page = $.vifib.onepanel($.vifib.panel.instance, response); page = $.vifib.onepanel($.vifib.panel.instance, response);
page.prepend(Mustache.render($.vifib.header.default, {title: 'Instance'})); page.prepend(Mustache.render($.vifib.header.main, {title: 'Instance'}));
$.vifib.changepage($(page)); $.vifib.changepage($(page));
} }
}); });
...@@ -164,7 +166,7 @@ $.vifib.mobile = { ...@@ -164,7 +166,7 @@ $.vifib.mobile = {
$.url.redirect('/dashboard/instance/id' + instid); $.url.redirect('/dashboard/instance/id' + instid);
}, },
statusCode: $.extend(false, $.vifib.statuscode, {}) statusCode: $.extend(false, $.vifib.statuscode, {})
}) });
} }
}, },
statusCode: $.extend(false, $.vifib.statuscode, {}) statusCode: $.extend(false, $.vifib.statuscode, {})
...@@ -181,7 +183,7 @@ $.vifib.mobile = { ...@@ -181,7 +183,7 @@ $.vifib.mobile = {
$.url.redirect('/dashboard/instance/id' + instid); $.url.redirect('/dashboard/instance/id' + instid);
}, },
statusCode: $.extend(false, $.vifib.statuscode, {}) statusCode: $.extend(false, $.vifib.statuscode, {})
}) });
} }
}, },
statusCode: $.extend(false, $.vifib.statuscode, {}) statusCode: $.extend(false, $.vifib.statuscode, {})
...@@ -193,11 +195,11 @@ $.vifib.mobile = { ...@@ -193,11 +195,11 @@ $.vifib.mobile = {
$.url.redirect('/dashboard/instance/id' + instid); $.url.redirect('/dashboard/instance/id' + instid);
}, },
statusCode: $.extend(false, $.vifib.statuscode, {}) statusCode: $.extend(false, $.vifib.statuscode, {})
}) });
}, },
computerlist: function (route) { computerlist: function (route) {
var page = $.vifib.onepanel($.vifib.panel.allcomputer); var page = $.vifib.onepanel($.vifib.panel.allcomputer);
page.prepend(Mustache.render($.vifib.header.default, {title: 'Computers'})); page.prepend(Mustache.render($.vifib.header.main, {title: 'Computers'}));
$.vifib.changepage($(page)); $.vifib.changepage($(page));
$.vifib.computerList($(page)); $.vifib.computerList($(page));
}, },
...@@ -206,10 +208,11 @@ $.vifib.mobile = { ...@@ -206,10 +208,11 @@ $.vifib.mobile = {
$(this).slapos('computerInfo', compid, { $(this).slapos('computerInfo', compid, {
success: function (response) { success: function (response) {
page = $.vifib.onepanel($.vifib.panel.computer, response); page = $.vifib.onepanel($.vifib.panel.computer, response);
page.prepend(Mustache.render($.vifib.header.default, {title: 'Computer'})); page.prepend(Mustache.render($.vifib.header.main, {title: 'Computer'}));
$.vifib.changepage($(page)); $.vifib.changepage($(page));
} }
}); });
} }
} }
}; };
}(window, jQuery));
$.vifib.tablet = { (function (window, $) {
'use strict';
$.vifib.tablet = {
overview: function (route) { overview: function (route) {
var page = $.vifib.twopanel([ var page = $.vifib.twopanel([
$.vifib.panel.sidemenu.main, $.vifib.panel.sidemenu.main,
...@@ -10,7 +12,7 @@ $.vifib.tablet = { ...@@ -10,7 +12,7 @@ $.vifib.tablet = {
]} ]}
]); ]);
// header // header
page.prepend(Mustache.render($.vifib.header.default, {title: 'SlapOs'})); page.prepend(Mustache.render($.vifib.header.main, {title: 'SlapOs'}));
// rendering // rendering
$.vifib.changepage($(page)); $.vifib.changepage($(page));
}, },
...@@ -23,13 +25,13 @@ $.vifib.tablet = { ...@@ -23,13 +25,13 @@ $.vifib.tablet = {
{links: [ {links: [
{url: '#/library/', name: 'Overview'}, {url: '#/library/', name: 'Overview'},
{url: '#/library/all', name: 'See all softwares'} {url: '#/library/all', name: 'See all softwares'}
],categories: [ ], categories: [
{url: '#/library/categorie/vm', name: 'Virtual Machine'}, {url: '#/library/categorie/vm', name: 'Virtual Machine'},
{url: '#/library/categorie/db', name: 'Database'} {url: '#/library/categorie/db', name: 'Database'}
]} ]}
]); ]);
// header // header
page.prepend(Mustache.render($.vifib.header.default, {title: 'Library'})); page.prepend(Mustache.render($.vifib.header.main, {title: 'Library'}));
// rendering // rendering
$.vifib.changepage($(page)); $.vifib.changepage($(page));
$('#panel-1') $('#panel-1')
...@@ -43,11 +45,11 @@ $.vifib.tablet = { ...@@ -43,11 +45,11 @@ $.vifib.tablet = {
.done($.vifib.tablet.library.all); .done($.vifib.tablet.library.all);
$('#panel-1') $('#panel-1')
.route('go', $.url.getPath(), 1) .route('go', $.url.getPath(), 1)
.fail(function () { $.vifib.replacepanel($(this), $.vifib.panel.failed)}); .fail(function () { $.vifib.replacepanel($(this), $.vifib.panel.failed); });
}, },
overview: function () { overview: function () {
$.vifib.replacepanel($(this), $.vifib.panel.library, { $.vifib.replacepanel($(this), $.vifib.panel.library, {
most: [{url: '#/library/software/id/fake/software_info/Kvm', name: 'Kvm'},], most: [{url: '#/library/software/id/fake/software_info/Kvm', name: 'Kvm'}],
newest: [{url: '#/library/software/id/fake/software_info/Html5as', name: 'html5 AS'}] newest: [{url: '#/library/software/id/fake/software_info/Html5as', name: 'html5 AS'}]
}); });
}, },
...@@ -77,10 +79,10 @@ $.vifib.tablet = { ...@@ -77,10 +79,10 @@ $.vifib.tablet = {
{links: [ {links: [
{url: '#/library/', name: 'Library'}, {url: '#/library/', name: 'Library'},
{url: 'http://packages.python.org/slapos.core/', name: 'Documentation'}, {url: 'http://packages.python.org/slapos.core/', name: 'Documentation'},
{url: '#/dashboard/instance/list', name: 'Instances'}, {url: '#/dashboard/instance/list', name: 'Instances'}
]} ]}
]); ]);
page.prepend(Mustache.render($.vifib.header.default, {title: 'Dashboard'})); page.prepend(Mustache.render($.vifib.header.main, {title: 'Dashboard'}));
$.vifib.changepage($(page)); $.vifib.changepage($(page));
$('#panel-1') $('#panel-1')
.route('add', '/dashboard/', 1) .route('add', '/dashboard/', 1)
...@@ -105,7 +107,7 @@ $.vifib.tablet = { ...@@ -105,7 +107,7 @@ $.vifib.tablet = {
.done($.vifib.tablet.dashboard.instancedestroy); .done($.vifib.tablet.dashboard.instancedestroy);
$('#panel-1') $('#panel-1')
.route('go', $.url.getPath(), 1) .route('go', $.url.getPath(), 1)
.fail(function () { $.vifib.replacepanel($(this), $.vifib.panel.failed)}); .fail(function () { $.vifib.replacepanel($(this), $.vifib.panel.failed); });
}, },
instancelist: function (route) { instancelist: function (route) {
$.vifib.replacepanel($(this), $.vifib.panel.instancelist); $.vifib.replacepanel($(this), $.vifib.panel.instancelist);
...@@ -133,7 +135,7 @@ $.vifib.tablet = { ...@@ -133,7 +135,7 @@ $.vifib.tablet = {
var data = { var data = {
"status": "start_requested", "status": "start_requested",
"slave": false, "slave": false,
"software_type": "type_provided_by_the_software", "software_type": "type_provided_by_the_software"
}; };
$.extend(data, $(this).serializeObject()); $.extend(data, $(this).serializeObject());
$(this).slapos('instanceRequest', { $(this).slapos('instanceRequest', {
...@@ -157,7 +159,7 @@ $.vifib.tablet = { ...@@ -157,7 +159,7 @@ $.vifib.tablet = {
$.url.redirect('/dashboard/instance/id' + instid); $.url.redirect('/dashboard/instance/id' + instid);
}, },
statusCode: $.extend(false, $.vifib.statuscode, {}) statusCode: $.extend(false, $.vifib.statuscode, {})
}) });
} }
}, },
statusCode: $.extend(false, $.vifib.statuscode, {}) statusCode: $.extend(false, $.vifib.statuscode, {})
...@@ -174,11 +176,12 @@ $.vifib.tablet = { ...@@ -174,11 +176,12 @@ $.vifib.tablet = {
$.url.redirect('/dashboard/instance/id' + instid); $.url.redirect('/dashboard/instance/id' + instid);
}, },
statusCode: $.extend(false, $.vifib.statuscode, {}) statusCode: $.extend(false, $.vifib.statuscode, {})
}) });
} }
}, },
statusCode: $.extend(false, $.vifib.statuscode, {}) statusCode: $.extend(false, $.vifib.statuscode, {})
}); });
},
} }
}; }
};
}(window, jQuery));
$.vifib.panel = { (function (window, $) {
'use strict';
$.vifib.panel = {
carousel: carousel:
'<article id="slider">' + '<article id="slider">' +
'<ul>' + '<ul>' +
...@@ -41,7 +43,6 @@ $.vifib.panel = { ...@@ -41,7 +43,6 @@ $.vifib.panel = {
'</li>' + '</li>' +
'</ul>' + '</ul>' +
'</article>', '</article>',
simplelist: simplelist:
'<article>' + '<article>' +
'<ul data-role="listview">' + '<ul data-role="listview">' +
...@@ -110,7 +111,7 @@ $.vifib.panel = { ...@@ -110,7 +111,7 @@ $.vifib.panel = {
rowsoftware: rowsoftware:
'<a href="{{ softurl }}">' + '<a href="{{ softurl }}">' +
'{{# thumb_url }}' + '{{# thumb_url }}' +
'<img src="{{ thumb_url }}">'+ '<img src="{{ thumb_url }}">' +
'{{/ thumb_url }}' + '{{/ thumb_url }}' +
'<h3>{{ name }}</h3>' + '<h3>{{ name }}</h3>' +
'</a>', '</a>',
...@@ -153,7 +154,6 @@ $.vifib.panel = { ...@@ -153,7 +154,6 @@ $.vifib.panel = {
'<a data-role="button" href="{{ start_url }}">Start</a>' + '<a data-role="button" href="{{ start_url }}">Start</a>' +
'<a data-role="button" href="{{ destroy_url }}">Destroy</a>' + '<a data-role="button" href="{{ destroy_url }}">Destroy</a>' +
'{{/ stop_requested }}' + '{{/ stop_requested }}' +
'' +
'</article>', '</article>',
instancelist: instancelist:
'<article>' + '<article>' +
...@@ -203,13 +203,14 @@ $.vifib.panel = { ...@@ -203,13 +203,14 @@ $.vifib.panel = {
nocomputer: nocomputer:
'<article>' + '<article>' +
'<h4>The computer you are looking for, named "{{ name }}", does not exist</h4>' + '<h4>The computer you are looking for, named "{{ name }}", does not exist</h4>' +
'</article>', '</article>'
} };
$.vifib.header = { $.vifib.header = {
default: '<header data-role="header"><a href="#" data-icon="home" data-iconpos="notext"></a><h2>{{ title }}</h2></div></header><div id="loading" style="position: absolute; top: 20px; right: 20px;"></div>' main: '<header data-role="header"><a href="#" data-icon="home" data-iconpos="notext"></a><h2>{{ title }}</h2></div></header><div id="loading" style="position: absolute; top: 20px; right: 20px;"></div>'
} };
$.vifib.footer = { $.vifib.footer = {
overview: '<footer data-role="footer"><div data-role="navbar"><ul><li><a href="#/library/">Library</a></li><li><a href="http://packages.python.org/slapos.core/">Documentation</a></li></ul></div></footer>' overview: '<footer data-role="footer"><div data-role="navbar"><ul><li><a href="#/library/">Library</a></li><li><a href="http://packages.python.org/slapos.core/">Documentation</a></li></ul></div></footer>'
} };
}(window, jQuery));
$.vifib.onepanel = function (panel, data) { (function (window, $) {
var page = $('<div data-role="page"></div>') 'use strict';
$.vifib.onepanel = function (panel, data) {
var page = $('<div data-role="page"></div>'),
content = $('<div data-role="content"></div>') content = $('<div data-role="content"></div>')
.append(Mustache.render(panel, data)); .append(Mustache.render(panel, data));
page.append(content); page.append(content);
return $(page); return $(page);
} };
$.vifib.twopanel = function (panels, data) { $.vifib.twopanel = function (panels, data) {
var page = $('<div data-role="page"></div>') var page = $('<div data-role="page"></div>')
.append($.vifib.makecontent(panels, data)); .append($.vifib.makecontent(panels, data));
return $(page); return $(page);
} };
$.vifib.threepanel = function (panels, data) { $.vifib.threepanel = function (panels, data) {
var page = $('<div data-role="page"></div>') var page = $('<div data-role="page"></div>')
.append($.vifib.makecontent(panels, data)); .append($.vifib.makecontent(panels, data));
return $(page); return $(page);
} };
$.vifib.replacepanel = function (context, panel, data) { $.vifib.replacepanel = function (context, panel, data) {
context.html(Mustache.render(panel, data)); context.html(Mustache.render(panel, data));
$(':jqmData(role=page)').trigger('pagecreate'); $(':jqmData(role=page)').trigger('pagecreate');
} };
$.vifib.makecontent = function (panels, data) { $.vifib.makecontent = function (panels, data) {
var i = 0, var i = 0,
pandata, pandata,
gridname = { gridname = {
2: 'ui-grid-a', 2: 'ui-grid-a',
3: 'ui-grid-b', 3: 'ui-grid-b',
4: 'ui-grid-c', 4: 'ui-grid-c',
5: 'ui-grid-d', 5: 'ui-grid-d'
}, },
divcontent = $('<div data-role="content" class="' + gridname[panels.length] + '"></div>'); divcontent = $('<div data-role="content" class="' + gridname[panels.length] + '"></div>');
for (i; i < panels.length; i ++) { for (i; i < panels.length; i += 1) {
pandata = data === undefined ? undefined : data[i]; pandata = data === undefined ? undefined : data[i];
divcontent.append($.vifib.makepanel(panels[i], pandata, i)); divcontent.append($.vifib.makepanel(panels[i], pandata, i));
} }
return divcontent; return divcontent;
} };
$.vifib.makepanel = function (panel, data, index) { $.vifib.makepanel = function (panel, data, index) {
var blockname = [ var blockname = [
'ui-block-a', 'ui-block-a',
'ui-block-b', 'ui-block-b',
'ui-block-c', 'ui-block-c',
'ui-block-d', 'ui-block-d',
'ui-block-e', 'ui-block-e'
], ],
divpane = $('<div class="' + blockname[index] + '">') divpane = $('<div class="' + blockname[index] + '">')
.append('<section id="panel-' + index + '">' + Mustache.render(panel, data) + '</section>'); .append('<section id="panel-' + index + '">' + Mustache.render(panel, data) + '</section>');
return divpane; return divpane;
} };
$.vifib.changepage = function (page) { $.vifib.changepage = function (page) {
$('[id^=panel]').remove(); $('[id^=panel]').remove();
$('#slider').remove(); $('#slider').remove();
$('#loading').remove(); $('#loading').remove();
...@@ -62,4 +64,5 @@ $.vifib.changepage = function (page) { ...@@ -62,4 +64,5 @@ $.vifib.changepage = function (page) {
changeHash: false, changeHash: false,
transition: $.mobile.defaultPageTransition transition: $.mobile.defaultPageTransition
}); });
} };
}(window, jQuery));
/*global window, jQuery */
/*!
* route.js v1.0.0
*
* Copyright 2012, Romain Courteaud
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* Date: Mon Jul 16 2012
*/
"use strict";
(function (window, $) {
$.extend({
StatelessDeferred: function () {
var doneList = $.Callbacks("memory"),
promise = {
done: doneList.add,
// Get a promise for this deferred
// If obj is provided, the promise aspect is added to the object
promise: function (obj) {
var i,
keys = ['done', 'promise'];
if (obj === undefined) {
obj = promise;
} else {
for (i = 0; i < keys.length; i += 1) {
obj[keys[i]] = promise[keys[i]];
}
}
return obj;
}
},
deferred = promise.promise({});
deferred.resolveWith = doneList.fireWith;
// All done!
return deferred;
}
});
var routes = [],
current_priority = 0,
methods = {
add: function (pattern, priority) {
var i = 0,
inserted = false,
length = routes.length,
dfr = $.StatelessDeferred(),
context = $(this),
escapepattern,
matchingpattern;
if (priority === undefined) {
priority = 0;
}
if (pattern !== undefined) {
// http://simonwillison.net/2006/Jan/20/escape/
escapepattern = pattern.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
matchingpattern = escapepattern
.replace(/<int:\w+>/g, "(\\d+)")
.replace(/<path:\w+>/g, "(.+)")
.replace(/<\w+>/g, "([^/]+)");
while (!inserted) {
if ((i === length) || (priority >= routes[i][2])) {
routes.splice(i, 0, [new RegExp('^' + matchingpattern + '$'), dfr, priority, context]);
inserted = true;
} else {
i += 1;
}
}
}
return dfr.promise();
},
go: function (path, min_priority) {
var dfr = $.Deferred(),
context = $(this),
result;
if (min_priority === undefined) {
min_priority = 0;
}
setTimeout(function () {
var i = 0,
found = false,
slice_index = -1,
slice_priority = -1;
for (i = 0; i < routes.length; i += 1) {
if (slice_priority !== routes[i][2]) {
slice_priority = routes[i][2];
slice_index = i;
}
if (routes[i][2] < min_priority) {
break;
} else if (routes[i][0].test(path)) {
result = routes[i][0].exec(path);
dfr = routes[i][1];
context = routes[i][3];
current_priority = routes[i][2];
found = true;
break;
}
}
if (i === routes.length) {
slice_index = i;
}
if (slice_index > -1) {
routes = routes.slice(slice_index);
}
if (found) {
dfr.resolveWith(
context,
result.slice(1)
);
} else {
dfr.rejectWith(context);
}
});
return dfr.promise();
},
};
$.routereset = function () {
routes = [];
current_priority = 0;
};
$.routepriority = function () {
return current_priority;
};
$.fn.route = function (method) {
var result;
if (methods.hasOwnProperty(method)) {
result = methods[method].apply(
this,
Array.prototype.slice.call(arguments, 1)
);
} else {
$.error('Method ' + method +
' does not exist on jQuery.route');
}
return result;
};
}(window, jQuery));
/*global window, jQuery */
/*!
* url.js v1.0.0
*
* Copyright 2012, Romain Courteaud
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* Date: Mon Jul 16 2012
*/
"use strict";
(function (window, $) {
var hashchangeinitialized = false,
previousurl,
currentcallback,
getRawHash = function () {
return window.location.toString().split('#')[1];
},
callbackwrapper = function () {
if (previousurl !== window.location.hash) {
previousurl = window.location.hash;
if (currentcallback !== undefined) {
currentcallback();
}
}
},
timeoutwrapper = function () {
callbackwrapper();
window.setTimeout(timeoutwrapper, 500);
};
function UrlHandler() {}
UrlHandler.prototype = {
'generateUrl': function (path, options) {
var pathhash,
hash = '#',
key;
if (path !== undefined) {
hash += encodeURIComponent(path);
}
hash = hash.replace(/%2F/g, '/');
pathhash = hash;
for (key in options) {
if (options.hasOwnProperty(key)) {
if (hash === pathhash) {
hash = hash + '?';
} else {
hash = hash + '&';
}
hash += encodeURIComponent(key) +
'=' + encodeURIComponent(options[key]);
}
}
return hash;
},
'go': function (path, options) {
window.location.hash = this.generateUrl(path, options);
},
'redirect': function (path, options) {
var host = window.location.protocol + '//' +
window.location.host +
window.location.pathname +
window.location.search;
window.location.replace(host + this.generateUrl(path, options));
// window.location.replace(window.location.href.replace(/#.*/, ""));
},
'getPath': function () {
var hash = getRawHash(),
result = '';
if (hash !== undefined) {
result = decodeURIComponent(hash.split('?')[0]);
}
return result;
},
'getOptions': function () {
var options = {},
hash = getRawHash(),
subhashes,
subhash,
index,
keyvalue;
if (hash !== undefined) {
hash = hash.split('?')[1];
if (hash !== undefined) {
subhashes = hash.split('&');
for (index in subhashes) {
if (subhashes.hasOwnProperty(index)) {
subhash = subhashes[index];
if (subhash !== '') {
keyvalue = subhash.split('=');
if (keyvalue.length === 2) {
options[decodeURIComponent(keyvalue[0])] =
decodeURIComponent(keyvalue[1]);
}
}
}
}
}
}
return options;
},
'onhashchange': function (callback) {
previousurl = undefined;
currentcallback = callback;
if (!hashchangeinitialized) {
if (window.onhashchange !== undefined) {
$(window).bind('hashchange', callbackwrapper);
window.setTimeout(callbackwrapper);
} else {
timeoutwrapper();
}
hashchangeinitialized = true;
}
},
};
// Expose to the global object
$.url = new UrlHandler();
}(window, jQuery));
/* Tools to store js object in sessionStorage */ (function (window, $) {
var storejs = { 'use strict';
/* Tools to store js object in sessionStorage */
var storejs = {
add: function (key, js) { add: function (key, js) {
window.sessionStorage.setItem(key, JSON.stringify(js)); window.sessionStorage.setItem(key, JSON.stringify(js));
}, },
...@@ -11,13 +13,13 @@ var storejs = { ...@@ -11,13 +13,13 @@ var storejs = {
$.extend(data, object); $.extend(data, object);
storejs.add(key, data); storejs.add(key, data);
} }
} }
/************* /*************
* RESOURCES * RESOURCES
*************/ *************/
// INSTANCE // INSTANCE
storejs.add('instances', { storejs.add('instances', {
Kvm: { Kvm: {
status: "start_requested", status: "start_requested",
connection: {}, connection: {},
...@@ -40,15 +42,15 @@ storejs.add('instances', { ...@@ -40,15 +42,15 @@ storejs.add('instances', {
computer_id: "COMP-0" computer_id: "COMP-0"
} }
} }
}); });
// SOFTWARE // SOFTWARE
storejs.add('softwares', { storejs.add('softwares', {
Kvm: { Kvm: {
name: 'Kvm', name: 'Kvm',
image_url: 'http://www.linux-kvm.org/wiki/skins/kvm/kvmbanner-logo2.png', image_url: 'http://www.linux-kvm.org/wiki/skins/kvm/kvmbanner-logo2.png',
thumb_url: 'http://www.system-linux.eu/public/images/kvm-logo.png', thumb_url: 'http://www.system-linux.eu/public/images/kvm-logo.png',
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae metus a est convallis pretium. Pellentesque habitant morbi tristique senectus.', description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae metus a est convallis pretium. Pellentesque habitant morbi tristique senectus.',
price: '1', price: '1'
}, },
Html5as : { Html5as : {
name: 'Html5as', name: 'Html5as',
...@@ -57,48 +59,49 @@ storejs.add('softwares', { ...@@ -57,48 +59,49 @@ storejs.add('softwares', {
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae metus a est convallis pretium. Pellentesque habitant morbi tristique senectus.', description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae metus a est convallis pretium. Pellentesque habitant morbi tristique senectus.',
price: '1337' price: '1337'
} }
}); });
// Resources lists // Resources lists
storejs.add('software_list', { storejs.add('software_list', {
list: [ list: [
'/fake/software_info/Kvm', '/fake/software_info/Kvm',
'/fake/software_info/Html5as', '/fake/software_info/Html5as'
] ]
}); });
var fakeserver = sinon.fakeServer.create(); var fakeserver = sinon.fakeServer.create(),
tmp = $.ajax,
/********************* /*********************
* RESPONSE * RESPONSE
*********************/ *********************/
// ******* INSTANCE // ******* INSTANCE
var instance_list = function () { instance_list = function () {
var response = {list: []}; var response = {list: []};
$.each(storejs.get('instances'), function (i, e) { $.each(storejs.get('instances'), function (i, e) {
response.list.push('/fake/instance_info/' + e.title) response.list.push('/fake/instance_info/' + e.title);
}); });
return response; return response;
}; };
// list // list
fakeserver.respondWith('GET', '/fake/instance', function (xhr) { fakeserver.respondWith('GET', '/fake/instance', function (xhr) {
var response = {list: []}; var response = {list: []};
$.each(storejs.get('instances'), function (i, e) { $.each(storejs.get('instances'), function (i, e) {
response.list.push('/fake/instance_info/' + e.title) response.list.push('/fake/instance_info/' + e.title);
}); });
xhr.respond(200, {'Content-Type': 'application/json'}, JSON.stringify(response)) xhr.respond(200, {'Content-Type': 'application/json'}, JSON.stringify(response));
}); });
// Get instance info // Get instance info
fakeserver.respondWith("GET", /\/fake\/instance_info\/(.*)/, function (xhr, instid) { fakeserver.respondWith("GET", /\/fake\/instance_info\/(.*)/, function (xhr, instid) {
var instances = storejs.get('instances'); var instances = storejs.get('instances');
if (instances.hasOwnProperty(instid)) { if (instances.hasOwnProperty(instid)) {
xhr.respond(200, {'Content-Type': 'application/json'}, JSON.stringify(instances[instid])); xhr.respond(200, {'Content-Type': 'application/json'}, JSON.stringify(instances[instid]));
} else { } else {
xhr.respond(404, { 'Content-Type': 'application/json'}, 'Not found'); xhr.respond(404, { 'Content-Type': 'application/json'}, 'Not found');
} }
}); });
// Request instance // Request instance
fakeserver.respondWith("POST", '/fake/instance', function (xhr) { fakeserver.respondWith("POST", '/fake/instance', function (xhr) {
var instances = storejs.get('instances'), var instances = storejs.get('instances'),
inst = JSON.parse(xhr.requestBody), inst = JSON.parse(xhr.requestBody),
iadd = {}, iadd = {},
...@@ -109,30 +112,30 @@ fakeserver.respondWith("POST", '/fake/instance', function (xhr) { ...@@ -109,30 +112,30 @@ fakeserver.respondWith("POST", '/fake/instance', function (xhr) {
title: inst.title, title: inst.title,
status: inst.status status: inst.status
})); }));
}); });
//********** SOFTWARE //********** SOFTWARE
// Get softwares list // Get softwares list
fakeserver.respondWith('GET', '/fake/software', [ fakeserver.respondWith('GET', '/fake/software', [
200, {'Content-Type': 'application/json'}, JSON.stringify(storejs.get('software_list')) 200, {'Content-Type': 'application/json'}, JSON.stringify(storejs.get('software_list'))
]); ]);
// Get software info // Get software info
fakeserver.respondWith("GET", /\/fake\/software_info\/(.*)/, function (xhr, softid) { fakeserver.respondWith("GET", /\/fake\/software_info\/(.*)/, function (xhr, softid) {
var softwares = storejs.get('softwares'); var softwares = storejs.get('softwares');
if (softwares.hasOwnProperty(softid)) { if (softwares.hasOwnProperty(softid)) {
xhr.respond(200, {'Content-Type': 'application/json'}, JSON.stringify(softwares[softid])); xhr.respond(200, {'Content-Type': 'application/json'}, JSON.stringify(softwares[softid]));
} else { } else {
xhr.respond(404, { 'Content-Type': 'application/json'}, 'Not found'); xhr.respond(404, { 'Content-Type': 'application/json'}, 'Not found');
} }
}); });
var tmp = $.ajax; $.ajax = function (url, options) {
$.ajax = function(url, options){
// it will not work with cache set to false // it will not work with cache set to false
if (url.hasOwnProperty('cache')) { url.cache = true; } if (url.hasOwnProperty('cache')) { url.cache = true; }
var result = tmp(url, options); var result = tmp(url, options);
fakeserver.respond(); fakeserver.respond();
return result; return result;
}; };
$(document).slapos('store', 'host', '/fake'); $(document).slapos('store', 'host', '/fake');
}(window, jQuery));
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