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({
...@@ -12,12 +15,12 @@ $(document).bind("mobileinit", function () { ...@@ -12,12 +15,12 @@ $(document).bind("mobileinit", function () {
// Google application id // Google application id
'ggappid': '380290002359.apps.googleusercontent.com' 'ggappid': '380290002359.apps.googleusercontent.com'
}); });
// 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,24 +78,24 @@ ...@@ -78,24 +78,24 @@
} }
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',
data: JSON.stringify(data), data: JSON.stringify(data),
datatype: 'json', datatype: 'json',
context: $(this), context: $(this),
headers: { headers: {
'Accept': 'application/json', 'Accept': 'application/json',
}, },
beforeSend: function (xhr) { beforeSend: function (xhr) {
if ($(this).slapos('access_token')) { if ($(this).slapos('access_token')) {
xhr.setRequestHeader('Authorization', $(this).slapos('store', 'token_type') + ' ' + $(this).slapos('access_token')); xhr.setRequestHeader('Authorization', $(this).slapos('store', 'token_type') + ' ' + $(this).slapos('access_token'));
} }
} }
}; };
$.extend(ajaxOptions, args); $.extend(ajaxOptions, args);
return $.ajax(ajaxOptions); return $.ajax(ajaxOptions);
}, },
instanceList: function (args) { instanceList: function (args) {
...@@ -110,7 +110,7 @@ ...@@ -110,7 +110,7 @@
instanceRequest: function (args) { instanceRequest: function (args) {
return $(this).slapos('request', 'POST', '/instance', args); return $(this).slapos('request', 'POST', '/instance', args);
}, },
instanceBang: function (url, args) { instanceBang: function (url, args) {
$.extend(args, {url: url + '/bang'}); $.extend(args, {url: url + '/bang'});
return $(this).slapos('request', 'POST', '', args); return $(this).slapos('request', 'POST', '', args);
...@@ -129,7 +129,7 @@ ...@@ -129,7 +129,7 @@
$.extend(args, {url: url}); $.extend(args, {url: url});
return $(this).slapos('request', 'GET', '', args); return $(this).slapos('request', 'GET', '', args);
}, },
computerList: function (args) { computerList: function (args) {
return $(this).slapos('request', '', args); return $(this).slapos('request', '', args);
}, },
...@@ -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';
if (w < 500) { var getDevice = function (w) {
return 'mobile'; if (w < 500) {
} return 'mobile';
if (w < 900) { }
return 'tablet'; if (w < 900) {
} return 'tablet';
return 'desktop'; }
}, return 'desktop';
device = getDevice($(window).width());
var body = $("body");
$.vifib.devices = {
"mobile": function (url) {
$('body')
.route('add', '')
.done($.vifib.mobile.overview);
$('body')
.route('add', '/login/facebook')
.done($.vifib.login.facebook);
$('body')
.route('add', '/login/google')
.done($.vifib.login.google);
// when Google send back the token, it reset hashtag from url
$('body')
.route('add', 'access_token=<path:path>')
.done($.vifib.login.googleRedirect);
$('body')
.route('add', '/overview')
.done($.vifib.mobile.overview);
$('body')
.route('add', '/library<path:url>')
.done($.vifib.mobile.library.dispatch);
$('body')
.route('add', '/dashboard<path:url>')
.done($.vifib.mobile.dashboard.dispatch);
},
"tablet": function () {
$('body')
.route('add', '')
.done($.vifib.tablet.overview);
$('body')
.route('add', '/login/facebook')
.done($.vifib.login.facebook);
$('body')
.route('add', '/login/google')
.done($.vifib.login.google);
// when Google send back the token, it reset hashtag from url
$('body')
.route('add', 'access_token=<path:path>')
.done($.vifib.login.googleRedirect);
$('body')
.route('add', '/overview')
.done($.vifib.tablet.overview);
$('body')
.route('add', '/library<path:url>')
.done($.vifib.tablet.library.dispatch);
$('body')
.route('add', '/dashboard<path:url>')
.done($.vifib.tablet.dashboard.dispatch);
}, },
"desktop": function () { body = $("body");
$('body')
.route('add', '')
.done($.vifib.desktop.redirect);
$('body')
.route('add', '<path:url>')
.done($.vifib.desktop.dispatch);
}
}
$.vifib.isauthenticated = function () { $.vifib.device = getDevice($(window).width());
var token_type = $(document).slapos('store', 'token_type'); $.vifib.devices = {
if ($(document).slapos('access_token') === undefined || token_type === undefined) { "mobile": function (url) {
return false; $('body')
} .route('add', '')
if (token_type === 'Google') { .done($.vifib.mobile.overview);
$('body')
} else if (token_type === 'Facebook') { .route('add', '/login/facebook')
.done($.vifib.login.facebook);
} $('body')
return false; .route('add', '/login/google')
} .done($.vifib.login.google);
// when Google send back the token, it reset hashtag from url
$('body')
.route('add', 'access_token=<path:path>')
.done($.vifib.login.googleRedirect);
$('body')
.route('add', '/overview')
.done($.vifib.mobile.overview);
$('body')
.route('add', '/library<path:url>')
.done($.vifib.mobile.library.dispatch);
$('body')
.route('add', '/dashboard<path:url>')
.done($.vifib.mobile.dashboard.dispatch);
},
"tablet": function () {
$('body')
.route('add', '')
.done($.vifib.tablet.overview);
$('body')
.route('add', '/login/facebook')
.done($.vifib.login.facebook);
$('body')
.route('add', '/login/google')
.done($.vifib.login.google);
// when Google send back the token, it reset hashtag from url
$('body')
.route('add', 'access_token=<path:path>')
.done($.vifib.login.googleRedirect);
$('body')
.route('add', '/overview')
.done($.vifib.tablet.overview);
$('body')
.route('add', '/library<path:url>')
.done($.vifib.tablet.library.dispatch);
$('body')
.route('add', '/dashboard<path:url>')
.done($.vifib.tablet.dashboard.dispatch);
},
"desktop": function () {
$('body')
.route('add', '')
.done($.vifib.desktop.redirect);
$('body')
.route('add', '<path:url>')
.done($.vifib.desktop.dispatch);
}
};
$.vifib.startrouter = function () { $.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) {
this.each(function() {
var $this = $(this),
data = $this.data();
if (data.spinner) {
data.spinner.stop();
delete data.spinner;
}
if (opts !== false) {
data.spinner = new Spinner($.extend({color: $this.css('color')}, opts)).spin(this);
}
});
return this;
}
$(document).ready(function () { $.fn.spin = function (opts) {
// bind on resize screen event this.each(function () {
$(window).resize(function () { var $this = $(this),
setTimeout(function () { data = $this.data();
var curdevice = getDevice($(window).width()); if (data.spinner) {
if (device !== curdevice) { data.spinner.stop();
device = curdevice; delete data.spinner;
$.routereset();
$.vifib.devices[device]();
$.vifib.startrouter();
} }
}, 800); if (opts !== false) {
}); data.spinner = new Spinner($.extend({color: $this.css('color')}, opts)).spin(this);
}
});
return this;
};
// Url change event $(document).ready(function () {
$.url.onhashchange(function () { // bind on resize screen event
var options = $.url.getOptions(); $(window).resize(function () {
if (options.hasOwnProperty('access_token')) { setTimeout(function () {
$(document).slapos('access_token', options.access_token); var curdevice = getDevice($(window).width());
} if ($.vifib.device !== curdevice) {
$.vifib.devices[device](); $.vifib.device = curdevice;
$.vifib.startrouter(); $.routereset();
$.vifib.devices[$.vifib.device]();
$.vifib.startrouter();
}
}, 800);
});
// Url change event
$.url.onhashchange(function () {
var options = $.url.getOptions();
if (options.hasOwnProperty('access_token')) {
$(document).slapos('access_token', options.access_token);
}
$.vifib.devices[$.vifib.device]();
$.vifib.startrouter();
});
}); });
}); }(window, jQuery));
$.vifib.desktop = { (function (window, $) {
redirect: function (route) { 'use strict';
$.url.go('/overview'); $.vifib.desktop = {
}, redirect: function (route) {
dispatch: function (route) { $.url.go('/overview');
var page = $.vifib.threepanel([ },
$.vifib.panel.sidemenu.main,
$.vifib.panel.blank,
$.vifib.panel.blank
], [
{links: [
{url: '#/library/', name: 'Library'},
{url: 'http://packages.python.org/slapos.core/', name: 'Documentation'}
]}
]);
// header
page.prepend(Mustache.render($.vifib.header.default, {title: 'SlapOs'}));
// rendering
$.vifib.changepage($(page));
$('#panel-1')
.route('add', '/library<path:url>', 1)
.done($.vifib.desktop.library.dispatch);
$('#panel-1')
.route('add', '/overview', 1)
.done($.vifib.desktop.overview);
$('#panel-1')
.route('add', '/dashboard<path:url>', 1)
.done($.vifib.desktop.dashboard.dispatch);
$('#panel-1')
.route('add', '/login/facebook', 1)
.done($.vifib.login.facebook);
$('#panel-1')
.route('add', '/login/google', 1)
.done($.vifib.login.google);
// when Google send back the token, it reset hashtag from url
$('#panel-1')
.route('add', 'access_token=<path:path>', 1)
.done($.vifib.login.googleRedirect);
$('#panel-1')
.route('go', $.url.getPath(), 1)
.fail(function () { $.vifib.replacepanel($(this), $.vifib.panel.failed)});
},
overview: function (route) {
$.vifib.replacepanel($(this), $.vifib.panel.carousel);
if (Modernizr.csstransforms) {
window.mySwipe = new Swipe(document.getElementById('slider'), {
speed: 800,
auto: 4000,
continous: true
});
}
$.vifib.replacepanel($('#panel-2'), $.vifib.panel.login);
},
library: {
dispatch: function (route) { dispatch: function (route) {
$.vifib.replacepanel($(this), $.vifib.panel.sidemenu.library, { var page = $.vifib.threepanel([
links: [ $.vifib.panel.sidemenu.main,
{url: '#/library/', name: 'Overview'}, $.vifib.panel.blank,
{url: '#/library/all', name: 'See all softwares'} $.vifib.panel.blank
], ], [
categories: [ {links: [
{url: '#/library/categorie/vm', name: 'Virtual Machine'}, {url: '#/library/', name: 'Library'},
{url: '#/library/categorie/db', name: 'Database'} {url: 'http://packages.python.org/slapos.core/', name: 'Documentation'}
] ]}
}); ]);
$('#panel-2') // header
.route('add', '/library/', 2) page.prepend(Mustache.render($.vifib.header.main, {title: 'SlapOs'}));
.done($.vifib.desktop.library.overview); // rendering
$('#panel-2') $.vifib.changepage($(page));
.route('add', '/library/software/id<path:softid>', 2) $('#panel-1')
.done($.vifib.desktop.library.software); .route('add', '/library<path:url>', 1)
$('#panel-2') .done($.vifib.desktop.library.dispatch);
.route('add', '/library/all', 2) $('#panel-1')
.done($.vifib.desktop.library.all); .route('add', '/overview', 1)
$('#panel-2') .done($.vifib.desktop.overview);
.route('go', $.url.getPath(), 2) $('#panel-1')
.fail(function () { $.vifib.replacepanel($(this), $.vifib.panel.failed)}); .route('add', '/dashboard<path:url>', 1)
.done($.vifib.desktop.dashboard.dispatch);
$('#panel-1')
.route('add', '/login/facebook', 1)
.done($.vifib.login.facebook);
$('#panel-1')
.route('add', '/login/google', 1)
.done($.vifib.login.google);
// when Google send back the token, it reset hashtag from url
$('#panel-1')
.route('add', 'access_token=<path:path>', 1)
.done($.vifib.login.googleRedirect);
$('#panel-1')
.route('go', $.url.getPath(), 1)
.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.carousel);
most: [ if (Modernizr.csstransforms) {
{url: '#/library/software/id/fake/software_info/Kvm', name: 'Kvm'}, window.mySwipe = new Swipe(document.getElementById('slider'), {
], speed: 800,
newest: [ auto: 4000,
{url: '#/library/software/id/fake/software_info/Html5as', name: 'html5 AS'} continous: true
] });
}); }
}, $.vifib.replacepanel($('#panel-2'), $.vifib.panel.login);
software: function (softid) {
$(this).slapos('softwareInfo', softid, {
success: function (response) {
$.vifib.replacepanel($(this), $.vifib.panel.software, response);
}
});
},
all: function () {
$.vifib.replacepanel($(this), $.vifib.panel.allsoftware);
$.vifib.softwareList($(this));
}
},
dashboard: {
dispatch: function (route) {
$.vifib.replacepanel($(this), $.vifib.panel.simplelist, {
links: [
{url: '#/dashboard/instance/list', name: 'Instances'},
]
});
$('#panel-2')
.route('add', '/dashboard/', 2)
.done($.vifib.desktop.dashboard.instancelist);
$('#panel-2')
.route('add', '/dashboard/instance/list', 2)
.done($.vifib.desktop.dashboard.instancelist);
$('#panel-2')
.route('add', '/dashboard/instance/request', 2)
.done($.vifib.desktop.dashboard.instancerequest);
$('#panel-2')
.route('add', '/dashboard/instance/id<path:instid>', 2)
.done($.vifib.desktop.dashboard.instance);
$('#panel-2')
.route('add', '/dashboard/instance/start<path:instid>', 2)
.done($.vifib.desktop.dashboard.instancestart);
$('#panel-2')
.route('add', '/dashboard/instance/stop<path:instid>', 2)
.done($.vifib.desktop.dashboard.instancestop);
$('#panel-2')
.route('add', '/dashboard/instance/destroy<path:instid>', 2)
.done($.vifib.desktop.dashboard.instancedestroy);
$('#panel-2')
.route('go', $.url.getPath(), 2)
.fail(function () { $.vifib.replacepanel($(this), $.vifib.panel.failed)});
}, },
instancelist: function (route) { library: {
$.vifib.replacepanel($(this), $.vifib.panel.instancelist); dispatch: function (route) {
$.vifib.instanceList($(this)); $.vifib.replacepanel($(this), $.vifib.panel.sidemenu.library, {
links: [
{url: '#/library/', name: 'Overview'},
{url: '#/library/all', name: 'See all softwares'}
],
categories: [
{url: '#/library/categorie/vm', name: 'Virtual Machine'},
{url: '#/library/categorie/db', name: 'Database'}
]
});
$('#panel-2')
.route('add', '/library/', 2)
.done($.vifib.desktop.library.overview);
$('#panel-2')
.route('add', '/library/software/id<path:softid>', 2)
.done($.vifib.desktop.library.software);
$('#panel-2')
.route('add', '/library/all', 2)
.done($.vifib.desktop.library.all);
$('#panel-2')
.route('go', $.url.getPath(), 2)
.fail(function () { $.vifib.replacepanel($(this), $.vifib.panel.failed); });
},
overview: function (route) {
$.vifib.replacepanel($(this), $.vifib.panel.library, {
most: [
{url: '#/library/software/id/fake/software_info/Kvm', name: 'Kvm'}
],
newest: [
{url: '#/library/software/id/fake/software_info/Html5as', name: 'html5 AS'}
]
});
},
software: function (softid) {
$(this).slapos('softwareInfo', softid, {
success: function (response) {
$.vifib.replacepanel($(this), $.vifib.panel.software, response);
}
});
},
all: function () {
$.vifib.replacepanel($(this), $.vifib.panel.allsoftware);
$.vifib.softwareList($(this));
}
}, },
instancerequest: function (route) { dashboard: {
$.vifib.replacepanel($(this), $.vifib.panel.instancerequest); dispatch: function (route) {
$("#instancerequest").submit(function () { $.vifib.replacepanel($(this), $.vifib.panel.simplelist, {
var data = { links: [
"status": "start_requested", {url: '#/dashboard/instance/list', name: 'Instances'}
"slave": false, ]
"software_type": "type_provided_by_the_software", });
}; $('#panel-2')
$.extend(data, $(this).serializeObject()); .route('add', '/dashboard/', 2)
$(this).slapos('instanceRequest', { .done($.vifib.desktop.dashboard.instancelist);
data: data, $('#panel-2')
.route('add', '/dashboard/instance/list', 2)
.done($.vifib.desktop.dashboard.instancelist);
$('#panel-2')
.route('add', '/dashboard/instance/request', 2)
.done($.vifib.desktop.dashboard.instancerequest);
$('#panel-2')
.route('add', '/dashboard/instance/id<path:instid>', 2)
.done($.vifib.desktop.dashboard.instance);
$('#panel-2')
.route('add', '/dashboard/instance/start<path:instid>', 2)
.done($.vifib.desktop.dashboard.instancestart);
$('#panel-2')
.route('add', '/dashboard/instance/stop<path:instid>', 2)
.done($.vifib.desktop.dashboard.instancestop);
$('#panel-2')
.route('add', '/dashboard/instance/destroy<path:instid>', 2)
.done($.vifib.desktop.dashboard.instancedestroy);
$('#panel-2')
.route('go', $.url.getPath(), 2)
.fail(function () { $.vifib.replacepanel($(this), $.vifib.panel.failed); });
},
instancelist: function (route) {
$.vifib.replacepanel($(this), $.vifib.panel.instancelist);
$.vifib.instanceList($(this));
},
instancerequest: function (route) {
$.vifib.replacepanel($(this), $.vifib.panel.instancerequest);
$("#instancerequest").submit(function () {
var data = {
"status": "start_requested",
"slave": false,
"software_type": "type_provided_by_the_software"
};
$.extend(data, $(this).serializeObject());
$(this).slapos('instanceRequest', {
data: data,
success: function (response) {
$.url.redirect('/dashboard/instance/list');
},
statusCode: $.extend(false, $.vifib.statuscode, {})
});
return false;
});
},
instance: function (instid) {
$(this).slapos('instanceInfo', instid, {
success: function (response) { success: function (response) {
$.url.redirect('/dashboard/instance/list'); 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;
$.vifib.replacepanel($(this), $.vifib.panel.instance, response);
}
});
},
instancestop: function (instid) {
$(this).slapos('instanceInfo', instid, {
success: function (response) {
if (response.status === 'start_requested') {
response.status = 'stop_requested';
$(this).slapos('instanceRequest', {
data: response,
success: function (response) {
$.url.redirect('/dashboard/instance/id' + instid);
},
statusCode: $.extend(false, $.vifib.statuscode, {})
});
}
}, },
statusCode: $.extend(false, $.vifib.statuscode, {}) statusCode: $.extend(false, $.vifib.statuscode, {})
}); });
return false; },
}); instancestart: function (instid) {
}, $(this).slapos('instanceInfo', instid, {
instance: function (instid) { success: function (response) {
$(this).slapos('instanceInfo', instid, { if (response.status === 'stop_requested') {
success: function (response) { response.status = 'start_requested';
response[response.status] = true; $(this).slapos('instanceRequest', {
response.stop_url = '#/dashboard/instance/stop' + instid; data: response,
response.start_url = '#/dashboard/instance/start' + instid; success: function (response) {
response.destroy_url = '#/dashboard/instance/destroy' + instid; $.url.redirect('/dashboard/instance/id' + instid);
$.vifib.replacepanel($(this), $.vifib.panel.instance, response); },
} statusCode: $.extend(false, $.vifib.statuscode, {})
}); });
}, }
instancestop: function (instid) { },
$(this).slapos('instanceInfo', instid, { statusCode: $.extend(false, $.vifib.statuscode, {})
success: function (response) { });
if (response.status === 'start_requested') { }
response.status = 'stop_requested'; }
$(this).slapos('instanceRequest', { };
data: response, }(window, jQuery));
success: function (response) {
$.url.redirect('/dashboard/instance/id' + instid);
},
statusCode: $.extend(false, $.vifib.statuscode, {})
})
}
},
statusCode: $.extend(false, $.vifib.statuscode, {})
});
},
instancestart: function (instid) {
$(this).slapos('instanceInfo', instid, {
success: function (response) {
if (response.status === 'stop_requested') {
response.status = 'start_requested';
$(this).slapos('instanceRequest', {
data: response,
success: function (response) {
$.url.redirect('/dashboard/instance/id' + instid);
},
statusCode: $.extend(false, $.vifib.statuscode, {})
})
}
},
statusCode: $.extend(false, $.vifib.statuscode, {})
});
},
}
};
$.vifib.login = { (function (window, $) {
facebook: function (params) { 'use strict';
var redirect = location.protocol + '//' + location.host + location.pathname + '#/dashboard/' + '?', $.vifib.login = {
fburl = 'https://www.facebook.com/dialog/oauth?' + facebook: function (params) {
'client_id=' + $(document).slapos('store', 'fbappid') + var redirect = location.protocol + '//' + location.host + location.pathname + '#/dashboard/' + '?',
'&redirect_uri=' + encodeURIComponent(redirect) + fburl = 'https://www.facebook.com/dialog/oauth?' +
'&scope=email' + 'client_id=' + $(document).slapos('store', 'fbappid') +
'&response_type=token'; '&redirect_uri=' + encodeURIComponent(redirect) +
// set token type to Facebook for js library '&scope=email' +
$(document).slapos('store', 'token_type', 'Facebook'); '&response_type=token';
window.location.href = fburl; // set token type to Facebook for js library
}, $(document).slapos('store', 'token_type', 'Facebook');
google: function (params) { window.location.href = fburl;
var redirect = location.protocol + '//' + location.host + location.pathname, },
ggurl = 'https://accounts.google.com/o/oauth2/auth?' + google: function (params) {
'client_id=' + $(document).slapos('store', 'ggappid') + var redirect = location.protocol + '//' + location.host + location.pathname,
'&redirect_uri=' + encodeURIComponent(redirect) + ggurl = 'https://accounts.google.com/o/oauth2/auth?' +
'&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email++https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile' + 'client_id=' + $(document).slapos('store', 'ggappid') +
'&response_type=token'; '&redirect_uri=' + encodeURIComponent(redirect) +
$(document).slapos('store', 'token_type', 'Google'); '&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email++https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile' +
window.location.href = ggurl; '&response_type=token';
}, $(document).slapos('store', 'token_type', 'Google');
googleRedirect: function (response) { window.location.href = ggurl;
var options = {}, },
option; googleRedirect: function (response) {
response = 'access_token=' + response; var options = {},
$.each(response.split('&'), function (i, e) { option;
option = e.split('='); response = 'access_token=' + response;
options[option[0]] = option[1]; $.each(response.split('&'), function (i, e) {
}); option = e.split('=');
$.url.redirect('/dashboard/', options); options[option[0]] = option[1];
} });
} $.url.redirect('/dashboard/', options);
$.vifib.statuscode = {
400: function (jqxhr, textstatus) {
var page;
if(device === 'mobile') {
page = $.vifib.onepanel($.vifib.panel.badrequest);
page.prepend(Mustache.render($.vifib.header.default, {title: 'An error as occured'}));
page.append($.vifib.footer.overview);
$.vifib.changepage($(page));
} else {
$.vifib.replacepanel($(this), $.vifib.panel.badrequest);
}
},
401: function (jqxhr, textstatus) {
$.url.redirect('/overview');
},
402: function (jqxhr, textstatus) {
var page;
if(device === 'mobile') {
page = $.vifib.onepanel($.vifib.panel.payment);
page.prepend(Mustache.render($.vifib.header.default, {title: 'An error as occured'}));
page.append($.vifib.footer.overview);
$.vifib.changepage($(page));
} else {
$.vifib.replacepanel($(this), $.vifib.panel.payment);
}
},
404: function (jqxhr, textstatus) {
var page;
if(device === 'mobile') {
page = $.vifib.onepanel($.vifib.panel.notfound);
page.prepend(Mustache.render($.vifib.header.default, {title: 'An error as occured'}));
page.append($.vifib.footer.overview);
$.vifib.changepage($(page));
} else {
$.vifib.replacepanel($(this), $.vifib.panel.notfound);
} }
}, };
500: function (jqxhr, textstatus) { $.vifib.statuscode = {
var page; 400: function (jqxhr, textstatus) {
if(device === 'mobile') { var page;
page = $.vifib.onepanel($.vifib.panel.internalerror); if ($.vifib.device === 'mobile') {
page.prepend(Mustache.render($.vifib.header.default, {title: 'An error as occured'})); page = $.vifib.onepanel($.vifib.panel.badrequest);
page.append($.vifib.footer.overview); page.prepend(Mustache.render($.vifib.header.main, {title: 'An error as occured'}));
$.vifib.changepage($(page)); page.append($.vifib.footer.overview);
} else { $.vifib.changepage($(page));
$.vifib.replacepanel($(this), $.vifib.panel.internalerror); } else {
$.vifib.replacepanel($(this), $.vifib.panel.badrequest);
}
},
401: function (jqxhr, textstatus) {
$.url.redirect('/overview');
},
402: function (jqxhr, textstatus) {
var page;
if ($.vifib.device === 'mobile') {
page = $.vifib.onepanel($.vifib.panel.payment);
page.prepend(Mustache.render($.vifib.header.main, {title: 'An error as occured'}));
page.append($.vifib.footer.overview);
$.vifib.changepage($(page));
} else {
$.vifib.replacepanel($(this), $.vifib.panel.payment);
}
},
404: function (jqxhr, textstatus) {
var page;
if ($.vifib.device === 'mobile') {
page = $.vifib.onepanel($.vifib.panel.notfound);
page.prepend(Mustache.render($.vifib.header.main, {title: 'An error as occured'}));
page.append($.vifib.footer.overview);
$.vifib.changepage($(page));
} else {
$.vifib.replacepanel($(this), $.vifib.panel.notfound);
}
},
500: function (jqxhr, textstatus) {
var page;
if ($.vifib.device === 'mobile') {
page = $.vifib.onepanel($.vifib.panel.internalerror);
page.prepend(Mustache.render($.vifib.header.main, {title: 'An error as occured'}));
page.append($.vifib.footer.overview);
$.vifib.changepage($(page));
} else {
$.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'); $(this).slapos('softwareList', {
$(this).slapos('softwareList', { success: function (response) {
success: function (response) { $.each(response.list, function (index, soft) {
$.each(response.list, function (index, soft) { var row = $.vifib.fillRowSoftware($('<li></li>'), soft);
var row = $.vifib.fillRowSoftware($('<li></li>'), soft); list.append(row);
list.append(row); });
}); list.listview('refresh');
list.listview('refresh'); },
}, 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'); $(this).slapos('instanceList', {
$(this).slapos('instanceList', { success: function (response) {
success: function (response) { $.each(response.list, function (i, e) {
$.each(response.list, function (i, e) { $.vifib.fillRowInstance(list, $('<li></li>'), e);
$.vifib.fillRowInstance(list, $('<li></li>'), e); });
}); },
}, 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) {
$.extend(response, {insturl: '#/dashboard/instance/id' + instid});
$(this).html(Mustache.render($.vifib.panel.rowinstance, response));
},
complete: function (jqxhr, textstatus) {
list.append($(this)).listview('refresh');
},
statusCode: $.extend(false, $.vifib.statuscode, {})
});
}
$.vifib.computerList = function (context) {
var list;
return context.each(function () {
list = $(this).find('ul');
$(this).slapos('computerList', {
success: function (response) { success: function (response) {
$.each(response.list, function (index, comp) { $.extend(response, {insturl: '#/dashboard/instance/id' + instid});
var row = $.vifib.fillRowComputer($('<li></li>'), comp); $(this).html(Mustache.render($.vifib.panel.rowinstance, response));
list.append(row);
});
list.listview('refresh');
}, },
statusCode: $.extend(false, $.vifib.statuscode, {}) complete: function (jqxhr, textstatus) {
}); list.append($(this)).listview('refresh');
});
}
$.vifib.fillRowSoftware = function (context, softid) {
return context.each(function () {
$(this).slapos('softwareInfo', softid, {
success: function (response) {
$.extend(response, {softurl: '#/library/software/id' + softid});
$(this).html(Mustache.render($.vifib.panel.rowsoftware, response));
}, },
statusCode: $.extend(false, $.vifib.statuscode, {}) statusCode: $.extend(false, $.vifib.statuscode, {})
}); });
}) };
} $.vifib.computerList = function (context) {
$.vifib.fillRowComputer = function (context, compid) { var list;
return context.each(function () { return context.each(function () {
$(this).slapos('computerInfo', compid, { list = $(this).find('ul');
success: function (response) { $(this).slapos('computerList', {
$.extend(response, {compurl: '#/dashboard/computer/id/' + compid}); success: function (response) {
$(this).html(Mustache.render($.vifib.panel.rowcomputer, response)); $.each(response.list, function (index, comp) {
}, var row = $.vifib.fillRowComputer($('<li></li>'), comp);
statusCode: $.extend(false, $.vifib.statuscode, {}) list.append(row);
});
list.listview('refresh');
},
statusCode: $.extend(false, $.vifib.statuscode, {})
});
});
};
$.vifib.fillRowSoftware = function (context, softid) {
return context.each(function () {
$(this).slapos('softwareInfo', softid, {
success: function (response) {
$.extend(response, {softurl: '#/library/software/id' + softid});
$(this).html(Mustache.render($.vifib.panel.rowsoftware, response));
},
statusCode: $.extend(false, $.vifib.statuscode, {})
});
});
};
$.vifib.fillRowComputer = function (context, compid) {
return context.each(function () {
$(this).slapos('computerInfo', compid, {
success: function (response) {
$.extend(response, {compurl: '#/dashboard/computer/id/' + compid});
$(this).html(Mustache.render($.vifib.panel.rowcomputer, response));
},
statusCode: $.extend(false, $.vifib.statuscode, {})
});
}); });
}) };
} }(window, jQuery));
$.vifib.mobile = { (function (window, $) {
nopage: function () { 'use strict';
var page = $.vifib.onepanel($.vifib.panel.failed); $.vifib.mobile = {
page.prepend(Mustache.render($.vifib.header.default, {title: 'Oops'})); nopage: function () {
$.vifib.changepage($(page)); var page = $.vifib.onepanel($.vifib.panel.failed);
}, page.prepend(Mustache.render($.vifib.header.main, {title: 'Oops'}));
overview: function (route) { $.vifib.changepage($(page));
var page;
// rendering
page = $.vifib.onepanel($.vifib.panel.login);
// header
page.prepend(Mustache.render($.vifib.header.default, {title: 'SlapOs'}));
// footer navbar
page.append($.vifib.footer.overview);
// rendering
$.vifib.changepage($(page));
},
library: {
dispatch: function (route) {
$('body')
.route('add', '/library/', 1)
.done($.vifib.mobile.library.overview);
$('body')
.route('add', '/library/software/id<path:softid>', 1)
.done($.vifib.mobile.library.software);
$('body')
.route('add', '/library/all', 1)
.done($.vifib.mobile.library.all);
$('body')
.route('go', $.url.getPath(), 1)
.fail($.vifib.mobile.nopage);
}, },
overview: function () { overview: function (route) {
page = $.vifib.onepanel($.vifib.panel.library, { var page;
most: [ // rendering
{url: '#/library/software/id/fake/software_info/Kvm', name: 'Kvm'}, page = $.vifib.onepanel($.vifib.panel.login);
],
newest: [
{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: 'SlapOs'}));
page.append(Mustache.render($.vifib.panel.simplelist, {
links: [
{url: '#/library/all', name: 'See all softwares'},
{url: '#/library/categories', name: 'See categories'}
]
}));
// footer navbar // footer navbar
page.append($.vifib.footer.overview); page.append($.vifib.footer.overview);
// rendering // rendering
$.vifib.changepage($(page)); $.vifib.changepage($(page));
}, },
software: function (softid) { library: {
$('body').slapos('softwareInfo', softid, { dispatch: function (route) {
success: function (response) { $('body')
var page; .route('add', '/library/', 1)
page = $.vifib.onepanel($.vifib.panel.software, response); .done($.vifib.mobile.library.overview);
// header $('body')
page.prepend(Mustache.render($.vifib.header.default, {title: response.name})); .route('add', '/library/software/id<path:softid>', 1)
// footer navbar .done($.vifib.mobile.library.software);
page.append($.vifib.footer.overview); $('body')
// rendering .route('add', '/library/all', 1)
$.vifib.changepage($(page)); .done($.vifib.mobile.library.all);
}, $('body')
statusCode: $.extend(false, $.vifib.statuscode, {}) .route('go', $.url.getPath(), 1)
}); .fail($.vifib.mobile.nopage);
}, },
all: function () { overview: function () {
var page = $.vifib.onepanel($.vifib.panel.allsoftware); var page = $.vifib.onepanel($.vifib.panel.library, {
$.vifib.softwareList($(page)); most: [
page.prepend(Mustache.render($.vifib.header.default, {title: 'All softwares'})); {url: '#/library/software/id/fake/software_info/Kvm', name: 'Kvm'}
page.append($.vifib.footer.overview); ],
$.vifib.changepage($(page)); newest: [
} {url: '#/library/software/id/fake/software_info/Html5', name: 'Html5as'}
}, ]
dashboard: { });
dispatch: function (route) { // header
$('body') page.prepend(Mustache.render($.vifib.header.main, {title: 'Library'}));
.route('add', '/dashboard/', 1) page.append(Mustache.render($.vifib.panel.simplelist, {
.done($.vifib.mobile.dashboard.home); links: [
$('body') {url: '#/library/all', name: 'See all softwares'},
.route('add', '/dashboard/instance/list', 1) {url: '#/library/categories', name: 'See categories'}
.done($.vifib.mobile.dashboard.instancelist); ]
$('body') }));
.route('add', '/dashboard/instance/request', 1) // footer navbar
.done($.vifib.mobile.dashboard.instancerequest); page.append($.vifib.footer.overview);
$('body') // rendering
.route('add', '/dashboard/instance/id<path:instid>', 1) $.vifib.changepage($(page));
.done($.vifib.mobile.dashboard.instance); },
$('body') software: function (softid) {
.route('add', '/dashboard/instance/start<path:instid>', 1) $('body').slapos('softwareInfo', softid, {
.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('go', $.url.getPath(), 1)
.fail($.vifib.mobile.nopage);
},
home: function (route) {
var page = $.vifib.onepanel($.vifib.panel.simplelist, {
links: [
{url: '#/dashboard/instance/list', name: 'Instances'},
{url: '#/dashboard/computer/list', name: 'Computers'}
]
});
page.prepend(Mustache.render($.vifib.header.default, {title: 'Dashboard'}));
$.vifib.changepage($(page));
},
instancelist: function (route) {
var page = $.vifib.onepanel($.vifib.panel.instancelist);
page.prepend(Mustache.render($.vifib.header.default, {title: 'Instances'}));
$.vifib.changepage($(page));
$.vifib.instanceList($(page));
},
instancerequest: function (route) {
var page = $.vifib.onepanel($.vifib.panel.instancerequest);
page.prepend(Mustache.render($.vifib.header.default, {title: 'Request instance'}));
$.vifib.changepage($(page));
$("#instancerequest").submit(function () {
var data = {
"status": "start_requested",
"slave": false,
"software_type": "type_provided_by_the_software",
};
$.extend(data, $(this).serializeObject());
$(this).slapos('instanceRequest', {
data: data,
success: function (response) { success: function (response) {
$.url.redirect('/dashboard/instance/list'); var page;
page = $.vifib.onepanel($.vifib.panel.software, response);
// header
page.prepend(Mustache.render($.vifib.header.main, {title: response.name}));
// footer navbar
page.append($.vifib.footer.overview);
// rendering
$.vifib.changepage($(page));
}, },
statusCode: $.extend(false, $.vifib.statuscode, {}) statusCode: $.extend(false, $.vifib.statuscode, {})
}); });
return false; },
}); all: function () {
}, var page = $.vifib.onepanel($.vifib.panel.allsoftware);
instance: function (instid) { $.vifib.softwareList($(page));
var page; page.prepend(Mustache.render($.vifib.header.main, {title: 'All softwares'}));
$(this).slapos('instanceInfo', instid, { page.append($.vifib.footer.overview);
success: function (response) { $.vifib.changepage($(page));
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) { dashboard: {
$(this).slapos('instanceInfo', instid, { dispatch: function (route) {
success: function (response) { $('body')
if (response.status === 'stop_requested') { .route('add', '/dashboard/', 1)
response.status = 'start_requested'; .done($.vifib.mobile.dashboard.home);
$(this).slapos('instanceRequest', { $('body')
data: response, .route('add', '/dashboard/instance/list', 1)
success: function (response) { .done($.vifib.mobile.dashboard.instancelist);
$.url.redirect('/dashboard/instance/id' + instid); $('body')
}, .route('add', '/dashboard/instance/request', 1)
statusCode: $.extend(false, $.vifib.statuscode, {}) .done($.vifib.mobile.dashboard.instancerequest);
}) $('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('go', $.url.getPath(), 1)
.fail($.vifib.mobile.nopage);
},
home: function (route) {
var page = $.vifib.onepanel($.vifib.panel.simplelist, {
links: [
{url: '#/dashboard/instance/list', name: 'Instances'},
{url: '#/dashboard/computer/list', name: 'Computers'}
]
});
page.prepend(Mustache.render($.vifib.header.main, {title: 'Dashboard'}));
$.vifib.changepage($(page));
},
instancelist: function (route) {
var page = $.vifib.onepanel($.vifib.panel.instancelist);
page.prepend(Mustache.render($.vifib.header.main, {title: 'Instances'}));
$.vifib.changepage($(page));
$.vifib.instanceList($(page));
},
instancerequest: function (route) {
var page = $.vifib.onepanel($.vifib.panel.instancerequest);
page.prepend(Mustache.render($.vifib.header.main, {title: 'Request instance'}));
$.vifib.changepage($(page));
$("#instancerequest").submit(function () {
var data = {
"status": "start_requested",
"slave": false,
"software_type": "type_provided_by_the_software"
};
$.extend(data, $(this).serializeObject());
$(this).slapos('instanceRequest', {
data: data,
success: function (response) {
$.url.redirect('/dashboard/instance/list');
},
statusCode: $.extend(false, $.vifib.statuscode, {})
});
return false;
});
},
instance: function (instid) {
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.main, {title: 'Instance'}));
$.vifib.changepage($(page));
} }
}, });
statusCode: $.extend(false, $.vifib.statuscode, {}) },
}); instancestart: function (instid) {
}, $(this).slapos('instanceInfo', instid, {
instancestop: function (instid) { success: function (response) {
$(this).slapos('instanceInfo', instid, { if (response.status === 'stop_requested') {
success: function (response) { response.status = 'start_requested';
if (response.status === 'start_requested') { $(this).slapos('instanceRequest', {
response.status = 'stop_requested'; data: response,
$(this).slapos('instanceRequest', { success: function (response) {
data: response, $.url.redirect('/dashboard/instance/id' + instid);
success: function (response) { },
$.url.redirect('/dashboard/instance/id' + instid); statusCode: $.extend(false, $.vifib.statuscode, {})
}, });
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 = 'stop_requested';
$(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.main, {title: 'Computers'}));
$.vifib.changepage($(page));
$.vifib.computerList($(page));
},
computer: function (compid) {
var page;
$(this).slapos('computerInfo', compid, {
success: function (response) {
page = $.vifib.onepanel($.vifib.panel.computer, response);
page.prepend(Mustache.render($.vifib.header.main, {title: 'Computer'}));
$.vifib.changepage($(page));
} }
}, });
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'}));
$.vifib.changepage($(page));
$.vifib.computerList($(page));
},
computer: function (compid) {
var page;
$(this).slapos('computerInfo', compid, {
success: function (response) {
page = $.vifib.onepanel($.vifib.panel.computer, response);
page.prepend(Mustache.render($.vifib.header.default, {title: 'Computer'}));
$.vifib.changepage($(page));
}
});
} }
} };
}; }(window, jQuery));
$.vifib.tablet = { (function (window, $) {
overview: function (route) { 'use strict';
var page = $.vifib.twopanel([ $.vifib.tablet = {
$.vifib.panel.sidemenu.main, overview: function (route) {
$.vifib.panel.login
], [
{links: [
{url: '#/library/', name: 'Library'},
{url: 'http://packages.python.org/slapos.core/', name: 'Documentation'}
]}
]);
// header
page.prepend(Mustache.render($.vifib.header.default, {title: 'SlapOs'}));
// rendering
$.vifib.changepage($(page));
},
library: {
dispatch: function (route) {
var page = $.vifib.twopanel([ var page = $.vifib.twopanel([
$.vifib.panel.sidemenu.library, $.vifib.panel.sidemenu.main,
$.vifib.panel.blank $.vifib.panel.login
], [ ], [
{links: [ {links: [
{url: '#/library/', name: 'Overview'}, {url: '#/library/', name: 'Library'},
{url: '#/library/all', name: 'See all softwares'} {url: 'http://packages.python.org/slapos.core/', name: 'Documentation'}
],categories: [
{url: '#/library/categorie/vm', name: 'Virtual Machine'},
{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: 'SlapOs'}));
// rendering // rendering
$.vifib.changepage($(page)); $.vifib.changepage($(page));
$('#panel-1')
.route('add', '/library/', 1)
.done($.vifib.tablet.library.overview);
$('#panel-1')
.route('add', '/library/software/id<path:softid>', 1)
.done($.vifib.tablet.library.software);
$('#panel-1')
.route('add', '/library/all', 1)
.done($.vifib.tablet.library.all);
$('#panel-1')
.route('go', $.url.getPath(), 1)
.fail(function () { $.vifib.replacepanel($(this), $.vifib.panel.failed)});
},
overview: function () {
$.vifib.replacepanel($(this), $.vifib.panel.library, {
most: [{url: '#/library/software/id/fake/software_info/Kvm', name: 'Kvm'},],
newest: [{url: '#/library/software/id/fake/software_info/Html5as', name: 'html5 AS'}]
});
}, },
software: function (softid) { library: {
$(this).slapos('softwareInfo', softid, { dispatch: function (route) {
success: function (response) { var page = $.vifib.twopanel([
$.vifib.replacepanel($(this), $.vifib.panel.software, response); $.vifib.panel.sidemenu.library,
}, $.vifib.panel.blank
statusCode: $.extend(false, $.vifib.statuscode, { ], [
404: function (jqxhr, textstatus) { {links: [
$.vifib.replacepanel($(this), $.vifib.panel.nosoftware, {name: softid}); {url: '#/library/', name: 'Overview'},
} {url: '#/library/all', name: 'See all softwares'}
}) ], categories: [
}); {url: '#/library/categorie/vm', name: 'Virtual Machine'},
}, {url: '#/library/categorie/db', name: 'Database'}
all: function (softid) { ]}
$.vifib.replacepanel($(this), $.vifib.panel.allsoftware); ]);
$.vifib.softwareList($(this)); // header
} page.prepend(Mustache.render($.vifib.header.main, {title: 'Library'}));
}, // rendering
dashboard: { $.vifib.changepage($(page));
dispatch: function (route) { $('#panel-1')
var page = $.vifib.twopanel([ .route('add', '/library/', 1)
$.vifib.panel.simplelist, .done($.vifib.tablet.library.overview);
$.vifib.panel.blank $('#panel-1')
], [ .route('add', '/library/software/id<path:softid>', 1)
{links: [ .done($.vifib.tablet.library.software);
{url: '#/library/', name: 'Library'}, $('#panel-1')
{url: 'http://packages.python.org/slapos.core/', name: 'Documentation'}, .route('add', '/library/all', 1)
{url: '#/dashboard/instance/list', name: 'Instances'}, .done($.vifib.tablet.library.all);
]} $('#panel-1')
]); .route('go', $.url.getPath(), 1)
page.prepend(Mustache.render($.vifib.header.default, {title: 'Dashboard'})); .fail(function () { $.vifib.replacepanel($(this), $.vifib.panel.failed); });
$.vifib.changepage($(page)); },
$('#panel-1') overview: function () {
.route('add', '/dashboard/', 1) $.vifib.replacepanel($(this), $.vifib.panel.library, {
.done($.vifib.tablet.dashboard.instancelist); most: [{url: '#/library/software/id/fake/software_info/Kvm', name: 'Kvm'}],
$('#panel-1') newest: [{url: '#/library/software/id/fake/software_info/Html5as', name: 'html5 AS'}]
.route('add', '/dashboard/instance/list', 1) });
.done($.vifib.tablet.dashboard.instancelist); },
$('#panel-1') software: function (softid) {
.route('add', '/dashboard/instance/request', 1) $(this).slapos('softwareInfo', softid, {
.done($.vifib.tablet.dashboard.instancerequest); success: function (response) {
$('#panel-1') $.vifib.replacepanel($(this), $.vifib.panel.software, response);
.route('add', '/dashboard/instance/id<path:instid>', 1) },
.done($.vifib.tablet.dashboard.instance); statusCode: $.extend(false, $.vifib.statuscode, {
$('#panel-1') 404: function (jqxhr, textstatus) {
.route('add', '/dashboard/instance/start<path:instid>', 1) $.vifib.replacepanel($(this), $.vifib.panel.nosoftware, {name: softid});
.done($.vifib.tablet.dashboard.instancestart); }
$('#panel-1') })
.route('add', '/dashboard/instance/stop<path:instid>', 1) });
.done($.vifib.tablet.dashboard.instancestop); },
$('#panel-1') all: function (softid) {
.route('add', '/dashboard/instance/destroy<path:instid>', 1) $.vifib.replacepanel($(this), $.vifib.panel.allsoftware);
.done($.vifib.tablet.dashboard.instancedestroy); $.vifib.softwareList($(this));
$('#panel-1') }
.route('go', $.url.getPath(), 1)
.fail(function () { $.vifib.replacepanel($(this), $.vifib.panel.failed)});
},
instancelist: function (route) {
$.vifib.replacepanel($(this), $.vifib.panel.instancelist);
$.vifib.instanceList($(this));
},
instance: function (instid) {
$(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;
$.vifib.replacepanel($(this), $.vifib.panel.instance, response);
},
statusCode: $.extend(false, $.vifib.statuscode, {
404: function (jqxhr, textstatus) {
$.vifib.replacepanel($(this), $.vifib.panel.noinstance, {name: instid});
}
})
});
}, },
instancerequest: function (route) { dashboard: {
$.vifib.replacepanel($(this), $.vifib.panel.instancerequest); dispatch: function (route) {
$("#instancerequest").submit(function () { var page = $.vifib.twopanel([
var data = { $.vifib.panel.simplelist,
"status": "start_requested", $.vifib.panel.blank
"slave": false, ], [
"software_type": "type_provided_by_the_software", {links: [
}; {url: '#/library/', name: 'Library'},
$.extend(data, $(this).serializeObject()); {url: 'http://packages.python.org/slapos.core/', name: 'Documentation'},
$(this).slapos('instanceRequest', { {url: '#/dashboard/instance/list', name: 'Instances'}
data: data, ]}
]);
page.prepend(Mustache.render($.vifib.header.main, {title: 'Dashboard'}));
$.vifib.changepage($(page));
$('#panel-1')
.route('add', '/dashboard/', 1)
.done($.vifib.tablet.dashboard.instancelist);
$('#panel-1')
.route('add', '/dashboard/instance/list', 1)
.done($.vifib.tablet.dashboard.instancelist);
$('#panel-1')
.route('add', '/dashboard/instance/request', 1)
.done($.vifib.tablet.dashboard.instancerequest);
$('#panel-1')
.route('add', '/dashboard/instance/id<path:instid>', 1)
.done($.vifib.tablet.dashboard.instance);
$('#panel-1')
.route('add', '/dashboard/instance/start<path:instid>', 1)
.done($.vifib.tablet.dashboard.instancestart);
$('#panel-1')
.route('add', '/dashboard/instance/stop<path:instid>', 1)
.done($.vifib.tablet.dashboard.instancestop);
$('#panel-1')
.route('add', '/dashboard/instance/destroy<path:instid>', 1)
.done($.vifib.tablet.dashboard.instancedestroy);
$('#panel-1')
.route('go', $.url.getPath(), 1)
.fail(function () { $.vifib.replacepanel($(this), $.vifib.panel.failed); });
},
instancelist: function (route) {
$.vifib.replacepanel($(this), $.vifib.panel.instancelist);
$.vifib.instanceList($(this));
},
instance: function (instid) {
$(this).slapos('instanceInfo', instid, {
success: function (response) { success: function (response) {
$.url.redirect('/dashboard/instance/list'); 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;
$.vifib.replacepanel($(this), $.vifib.panel.instance, response);
},
statusCode: $.extend(false, $.vifib.statuscode, {
404: function (jqxhr, textstatus) {
$.vifib.replacepanel($(this), $.vifib.panel.noinstance, {name: instid});
}
})
});
},
instancerequest: function (route) {
$.vifib.replacepanel($(this), $.vifib.panel.instancerequest);
$("#instancerequest").submit(function () {
var data = {
"status": "start_requested",
"slave": false,
"software_type": "type_provided_by_the_software"
};
$.extend(data, $(this).serializeObject());
$(this).slapos('instanceRequest', {
data: data,
success: function (response) {
$.url.redirect('/dashboard/instance/list');
},
statusCode: $.extend(false, $.vifib.statuscode, {})
});
return false;
});
},
instancestop: function (instid) {
$(this).slapos('instanceInfo', instid, {
success: function (response) {
if (response.status === 'start_requested') {
response.status = 'stop_requested';
$(this).slapos('instanceRequest', {
data: response,
success: function (response) {
$.url.redirect('/dashboard/instance/id' + instid);
},
statusCode: $.extend(false, $.vifib.statuscode, {})
});
}
}, },
statusCode: $.extend(false, $.vifib.statuscode, {}) statusCode: $.extend(false, $.vifib.statuscode, {})
}); });
return false; },
}); instancestart: function (instid) {
}, $(this).slapos('instanceInfo', instid, {
instancestop: function (instid) { success: function (response) {
$(this).slapos('instanceInfo', instid, { if (response.status === 'stop_requested') {
success: function (response) { response.status = 'start_requested';
if (response.status === 'start_requested') { $(this).slapos('instanceRequest', {
response.status = 'stop_requested'; data: response,
$(this).slapos('instanceRequest', { success: function (response) {
data: response, $.url.redirect('/dashboard/instance/id' + instid);
success: function (response) { },
$.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, {}) }
}); }
}, };
instancestart: function (instid) { }(window, jQuery));
$(this).slapos('instanceInfo', instid, {
success: function (response) {
if (response.status === 'stop_requested') {
response.status = 'start_requested';
$(this).slapos('instanceRequest', {
data: response,
success: function (response) {
$.url.redirect('/dashboard/instance/id' + instid);
},
statusCode: $.extend(false, $.vifib.statuscode, {})
})
}
},
statusCode: $.extend(false, $.vifib.statuscode, {})
});
},
}
};
$.vifib.panel = { (function (window, $) {
carousel: 'use strict';
'<article id="slider">' + $.vifib.panel = {
'<ul>' + carousel:
'<li style="display: block">' + '<article id="slider">' +
'<h2>Paas Without limit</h2>' + '<ul>' +
'<p>c c++ java javascript perl php python</p><p>kumofs mysql mariadb memcached</p><p>apache nodejs flask tomcat zope</p>' + '<li style="display: block">' +
'</li>' + '<h2>Paas Without limit</h2>' +
'<li style="display: none">' + '<p>c c++ java javascript perl php python</p><p>kumofs mysql mariadb memcached</p><p>apache nodejs flask tomcat zope</p>' +
'<h2>Iaas broker</h2>' + '</li>' +
'<p>xen kvm hyperv vmware openstack</p><p>opennebula amazon eucalyptus</p><p> niftyname gandi rackspace</p>' + '<li style="display: none">' +
'</li>' + '<h2>Iaas broker</h2>' +
'<li style="display: none">' + '<p>xen kvm hyperv vmware openstack</p><p>opennebula amazon eucalyptus</p><p> niftyname gandi rackspace</p>' +
'<h2>Resilient Cloud Computing</h2>' + '</li>' +
'<fieldset class="ui-grid-a">' + '<li style="display: none">' +
'<div class="ui-block-a">' + '<h2>Resilient Cloud Computing</h2>' +
'<ul>' + '<fieldset class="ui-grid-a">' +
'<li>decentralized</li>' + '<div class="ui-block-a">' +
'<li>open-source</li>' + '<ul>' +
'</ul>' + '<li>decentralized</li>' +
'</div>' + '<li>open-source</li>' +
'<div class="ui-block-b">' + '</ul>' +
'<ul>' + '</div>' +
'<li>10x cost efficient</li>' + '<div class="ui-block-b">' +
'<li>tremendously simpler</li>' + '<ul>' +
'</ul>' + '<li>10x cost efficient</li>' +
'</div>' + '<li>tremendously simpler</li>' +
'</fieldset>' + '</ul>' +
'</li>' + '</div>' +
'<li style="display: none">' + '</fieldset>' +
'<h2>Mobile Edge Computing</h2>' + '</li>' +
'<p>bsd linux macos windows android tizen</p>' + '<li style="display: none">' +
'</li>' + '<h2>Mobile Edge Computing</h2>' +
'<li style="display: none">' + '<p>bsd linux macos windows android tizen</p>' +
'<h2>Billing</h2>' + '</li>' +
'<p>accoutning billing charging crm portal market</p>' + '<li style="display: none">' +
'</li>' + '<h2>Billing</h2>' +
'<li style="display: none">' + '<p>accoutning billing charging crm portal market</p>' +
'<h2>Saas for free</h2>' + '</li>' +
'<p>wordpress drupal erp5 prestashop joomla</p><p>xwiki mediawiki oscommerce sugarcrm</p><p>phpbb facturalux zabbix</p>' + '<li style="display: none">' +
'</li>' + '<h2>Saas for free</h2>' +
'</ul>' + '<p>wordpress drupal erp5 prestashop joomla</p><p>xwiki mediawiki oscommerce sugarcrm</p><p>phpbb facturalux zabbix</p>' +
'</article>', '</li>' +
'</ul>' +
simplelist: '</article>',
'<article>' + simplelist:
'<ul data-role="listview">' + '<article>' +
'{{# links }}' + '<ul data-role="listview">' +
'<li><a href="{{ url }}">{{ name }}</a></li>' +
'{{/ links }}' +
'</ul>' +
'</article>',
failed:
'<article>' +
'<center><h4>This page does not exist</h4></center>' +
'</article>',
blank:
'<article></article>',
login:
'<article>' +
'<h2>Sign in with</h2>' +
'<a data-role="button" href="#/login/facebook">Facebook</a><br/>' +
'<a data-role="button" href="#/login/google">Google</a>' +
'</article>',
sidemenu: {
main: '<aside><nav><ul data-role="listview">{{# links }}<li><a href="{{ url }}">{{ name }}</a></li>{{/ links }}</ul></nav></aside>',
library:
'<aside><nav>' +
'<ul data-role="listview" data-theme="d">' +
'{{# links }}' + '{{# links }}' +
'<li><a href="{{ url }}">{{ name }}</a></li>' + '<li><a href="{{ url }}">{{ name }}</a></li>' +
'{{/ links }}' + '{{/ links }}' +
'<li data-role="divider">Categories</li>' + '</ul>' +
'{{# categories }}' + '</article>',
'<li><a href="{{ url }}">{{ name }}</a></li>' + failed:
'{{/ categories }}' + '<article>' +
'</ul></nav></aside>' '<center><h4>This page does not exist</h4></center>' +
}, '</article>',
categories: blank:
'<article><ul data-role="listview"><li data-role="divider">Categories</li>{{# categories }}<li><a href="{{ url }}">{{ name }}</a></li>{{/ categories }}</ul></article>', '<article></article>',
library: login:
'<article>' + '<article>' +
'<form id="search-library">' + '<h2>Sign in with</h2>' +
'<div data-role="fieldcontain" class="ui-hide-label">' + '<a data-role="button" href="#/login/facebook">Facebook</a><br/>' +
'<label for="search"></label>' + '<a data-role="button" href="#/login/google">Google</a>' +
'<input type="search" name="search" placeholder="Search"/>' + '</article>',
'</div>' + sidemenu: {
'</form>' + main: '<aside><nav><ul data-role="listview">{{# links }}<li><a href="{{ url }}">{{ name }}</a></li>{{/ links }}</ul></nav></aside>',
'<ul data-role="listview" data-inset="true">' + library:
'<li data-role="list-divider">Most downloaded</li>' + '<aside><nav>' +
'{{# most }}' + '<ul data-role="listview" data-theme="d">' +
'<li><a href="{{ url }}"><h4>{{ name }}</h4></a></li>' + '{{# links }}' +
'{{/ most }}' + '<li><a href="{{ url }}">{{ name }}</a></li>' +
'<li data-role="list-divider">Brand new</li>' + '{{/ links }}' +
'{{# newest }}' + '<li data-role="divider">Categories</li>' +
'<li><a href="{{ url }}"><h4>{{ name }}</h4></a></li>' + '{{# categories }}' +
'{{/ newest }}' + '<li><a href="{{ url }}">{{ name }}</a></li>' +
'</ul></article>', '{{/ categories }}' +
software: '</ul></nav></aside>'
'<article>' + },
'<img src="{{ image_url }}">' + categories:
'<p><b>{{ description }}</b></p>' + '<article><ul data-role="listview"><li data-role="divider">Categories</li>{{# categories }}<li><a href="{{ url }}">{{ name }}</a></li>{{/ categories }}</ul></article>',
'<a data-role="button" href="#/login">Buy it for {{ price }}&euro;</a>' + library:
'</article>', '<article>' +
allsoftware: '<form id="search-library">' +
'<article>' + '<div data-role="fieldcontain" class="ui-hide-label">' +
'<ul data-role="listview">' + '<label for="search"></label>' +
'</ul>' + '<input type="search" name="search" placeholder="Search"/>' +
'</article>', '</div>' +
rowsoftware: '</form>' +
'<a href="{{ softurl }}">' + '<ul data-role="listview" data-inset="true">' +
'{{# thumb_url }}' + '<li data-role="list-divider">Most downloaded</li>' +
'<img src="{{ thumb_url }}">'+ '{{# most }}' +
'{{/ thumb_url }}' + '<li><a href="{{ url }}"><h4>{{ name }}</h4></a></li>' +
'<h3>{{ name }}</h3>' + '{{/ most }}' +
'</a>', '<li data-role="list-divider">Brand new</li>' +
instancerequest: '{{# newest }}' +
'<article>' + '<li><a href="{{ url }}"><h4>{{ name }}</h4></a></li>' +
'<form id="instancerequest">' + '{{/ newest }}' +
'<div data-role="fieldcontain">' + '</ul></article>',
'<label for="title" class="ui-input-text">Title:</label>' + software:
'<input type="text" name="title" required/>' + '<article>' +
'</div>' + '<img src="{{ image_url }}">' +
'<div data-role="fieldcontain">' + '<p><b>{{ description }}</b></p>' +
'<label for="software_release" class="ui-input-text">Software release:</label>' + '<a data-role="button" href="#/login">Buy it for {{ price }}&euro;</a>' +
'<input type="text" name="software_release" value="http://example.com/example.cfg"/>' + '</article>',
'</div>' + allsoftware:
'<button value="Submit" type="submit">Submit</button>' + '<article>' +
'</form>' + '<ul data-role="listview">' +
'</article>', '</ul>' +
instance: '</article>',
'<article>' + rowsoftware:
'<center><h3>{{ title }}</h3></center>' + '<a href="{{ softurl }}">' +
'<ul data-role="listview">' + '{{# thumb_url }}' +
'<li class="ui-li-static">' + '<img src="{{ thumb_url }}">' +
'<p class="ui-li-desc"><i>Software release</i></p>' + '{{/ thumb_url }}' +
'<h3 class="ui-li-heading"><a href="{{ software_release }}">{{ software_release }}</a></h3>' + '<h3>{{ name }}</h3>' +
'</li>' + '</a>',
'<li class="ui-li-static">' + instancerequest:
'<p class="ui-li-desc"><i>Software type</i></p>' + '<article>' +
'<h3 class="ui-li-heading">{{ software_type }}</h3>' + '<form id="instancerequest">' +
'</li>' + '<div data-role="fieldcontain">' +
'<li class="ui-li-static">' + '<label for="title" class="ui-input-text">Title:</label>' +
'<p class="ui-li-desc"><i>Status</i></p>' + '<input type="text" name="title" required/>' +
'<h3 class="ui-li-heading">{{ status }}</h3>' + '</div>' +
'</li>' + '<div data-role="fieldcontain">' +
'</ul>' + '<label for="software_release" class="ui-input-text">Software release:</label>' +
'{{# start_requested }}' + '<input type="text" name="software_release" value="http://example.com/example.cfg"/>' +
'<a data-role="button" href="{{ stop_url }}">Stop</a>' + '</div>' +
'<a data-role="button" href="{{ destroy_url }}">Destroy</a>' + '<button value="Submit" type="submit">Submit</button>' +
'{{/ start_requested }}' + '</form>' +
'{{# stop_requested }}' + '</article>',
'<a data-role="button" href="{{ start_url }}">Start</a>' + instance:
'<a data-role="button" href="{{ destroy_url }}">Destroy</a>' + '<article>' +
'{{/ stop_requested }}' + '<center><h3>{{ title }}</h3></center>' +
'' + '<ul data-role="listview">' +
'</article>', '<li class="ui-li-static">' +
instancelist: '<p class="ui-li-desc"><i>Software release</i></p>' +
'<article>' + '<h3 class="ui-li-heading"><a href="{{ software_release }}">{{ software_release }}</a></h3>' +
'<a href="#/dashboard/instance/request" data-role="button">Create a new instance</a>' + '</li>' +
'<ul data-role="listview">' + '<li class="ui-li-static">' +
'</ul>' + '<p class="ui-li-desc"><i>Software type</i></p>' +
'</article>', '<h3 class="ui-li-heading">{{ software_type }}</h3>' +
rowinstance: '</li>' +
'<a href="{{ insturl }}">{{ title }}</a>', '<li class="ui-li-static">' +
computer: '<p class="ui-li-desc"><i>Status</i></p>' +
'<article>' + '<h3 class="ui-li-heading">{{ status }}</h3>' +
'<h2>{{ computer_id }}</h2>' + '</li>' +
'</article>', '</ul>' +
allcomputer: '{{# start_requested }}' +
'<article>' + '<a data-role="button" href="{{ stop_url }}">Stop</a>' +
'<ul data-role="listview">' + '<a data-role="button" href="{{ destroy_url }}">Destroy</a>' +
'</ul>' + '{{/ start_requested }}' +
'</article>', '{{# stop_requested }}' +
rowcomputer: '<a data-role="button" href="{{ start_url }}">Start</a>' +
'<a href="{{ compurl }}">' + '<a data-role="button" href="{{ destroy_url }}">Destroy</a>' +
'{{ computer_id }}' + '{{/ stop_requested }}' +
'</a>', '</article>',
notfound: instancelist:
'<article>' + '<article>' +
'<center><h4>This resource could not be found</h4></center>' + '<a href="#/dashboard/instance/request" data-role="button">Create a new instance</a>' +
'</article>', '<ul data-role="listview">' +
badrequest: '</ul>' +
'<article>' + '</article>',
'<center><h4>Something went wrong, the server receive an incorrect request</h4></center>' + rowinstance:
'</article>', '<a href="{{ insturl }}">{{ title }}</a>',
payment: computer:
'<article>' + '<article>' +
'<center><h4>Your account is locked because of non payment/h4></center>' + '<h2>{{ computer_id }}</h2>' +
'</article>', '</article>',
internalerror: allcomputer:
'<article>' + '<article>' +
'<center><h4>This resource could not be found</h4></center>' + '<ul data-role="listview">' +
'</article>', '</ul>' +
nosoftware: '</article>',
'<article>' + rowcomputer:
'<h4>The software you are looking for, named "{{ name }}", does not exist</h4>' + '<a href="{{ compurl }}">' +
'</article>', '{{ computer_id }}' +
noinstance: '</a>',
'<article>' + notfound:
'<h4>The instance you are looking for, named "{{ name }}", does not exist</h4>' + '<article>' +
'</article>', '<center><h4>This resource could not be found</h4></center>' +
nocomputer: '</article>',
'<article>' + badrequest:
'<h4>The computer you are looking for, named "{{ name }}", does not exist</h4>' + '<article>' +
'</article>', '<center><h4>Something went wrong, the server receive an incorrect request</h4></center>' +
} '</article>',
payment:
'<article>' +
'<center><h4>Your account is locked because of non payment/h4></center>' +
'</article>',
internalerror:
'<article>' +
'<center><h4>This resource could not be found</h4></center>' +
'</article>',
nosoftware:
'<article>' +
'<h4>The software you are looking for, named "{{ name }}", does not exist</h4>' +
'</article>',
noinstance:
'<article>' +
'<h4>The instance you are looking for, named "{{ name }}", does not exist</h4>' +
'</article>',
nocomputer:
'<article>' +
'<h4>The computer you are looking for, named "{{ name }}", does not exist</h4>' +
'</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';
content = $('<div data-role="content"></div>') $.vifib.onepanel = function (panel, data) {
.append(Mustache.render(panel, data)); var page = $('<div data-role="page"></div>'),
page.append(content); content = $('<div data-role="content"></div>')
return $(page); .append(Mustache.render(panel, data));
} page.append(content);
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();
$('body').append($(page)); $('body').append($(page));
$.mobile.changePage($(page), { $.mobile.changePage($(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';
add: function (key, js) { /* Tools to store js object in sessionStorage */
window.sessionStorage.setItem(key, JSON.stringify(js)); var storejs = {
}, add: function (key, js) {
get: function (key) { window.sessionStorage.setItem(key, JSON.stringify(js));
return JSON.parse(window.sessionStorage.getItem(key)); },
}, get: function (key) {
extend: function (key, object) { return JSON.parse(window.sessionStorage.getItem(key));
var data = storejs.get(key); },
$.extend(data, object); extend: function (key, object) {
storejs.add(key, data); var data = storejs.get(key);
} $.extend(data, object);
} storejs.add(key, data);
}
/*************
* RESOURCES
*************/
// INSTANCE
storejs.add('instances', {
Kvm: {
status: "start_requested",
connection: {},
partition: {
public_ip: [],
tap_interface: "",
private_ip: []
},
slave: false,
children_list: [],
title: "Kvm",
software_type: "Virtual machine",
parameter: {
Custom1: "one string",
Custom2: "one float",
Custom3: "[u'abc', u'def']"
},
software_release: "http://example.com/example.cfg",
sla: {
computer_id: "COMP-0"
} }
}
});
// SOFTWARE
storejs.add('softwares', {
Kvm: {
name: 'Kvm',
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',
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae metus a est convallis pretium. Pellentesque habitant morbi tristique senectus.',
price: '1',
},
Html5as : {
name: 'Html5as',
image_url: 'http://7.mshcdn.com/wp-content/uploads/2011/01/html5-logo-1.jpg',
thumb_url: 'http://www.w3.org/html/logo/downloads/HTML5_Badge_512.png',
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae metus a est convallis pretium. Pellentesque habitant morbi tristique senectus.',
price: '1337'
}
});
// Resources lists
storejs.add('software_list', {
list: [
'/fake/software_info/Kvm',
'/fake/software_info/Html5as',
]
});
var fakeserver = sinon.fakeServer.create(); /*************
* RESOURCES
*************/
// INSTANCE
storejs.add('instances', {
Kvm: {
status: "start_requested",
connection: {},
partition: {
public_ip: [],
tap_interface: "",
private_ip: []
},
slave: false,
children_list: [],
title: "Kvm",
software_type: "Virtual machine",
parameter: {
Custom1: "one string",
Custom2: "one float",
Custom3: "[u'abc', u'def']"
},
software_release: "http://example.com/example.cfg",
sla: {
computer_id: "COMP-0"
}
}
});
// SOFTWARE
storejs.add('softwares', {
Kvm: {
name: 'Kvm',
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',
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae metus a est convallis pretium. Pellentesque habitant morbi tristique senectus.',
price: '1'
},
Html5as : {
name: 'Html5as',
image_url: 'http://7.mshcdn.com/wp-content/uploads/2011/01/html5-logo-1.jpg',
thumb_url: 'http://www.w3.org/html/logo/downloads/HTML5_Badge_512.png',
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae metus a est convallis pretium. Pellentesque habitant morbi tristique senectus.',
price: '1337'
}
});
// Resources lists
storejs.add('software_list', {
list: [
'/fake/software_info/Kvm',
'/fake/software_info/Html5as'
]
});
/********************* var fakeserver = sinon.fakeServer.create(),
* RESPONSE tmp = $.ajax,
*********************/
// ******* INSTANCE /*********************
var instance_list = function () { * RESPONSE
var response = {list: []}; *********************/
$.each(storejs.get('instances'), function (i, e) {
response.list.push('/fake/instance_info/' + e.title)
});
return response;
};
// list
fakeserver.respondWith('GET', '/fake/instance', function (xhr) {
var response = {list: []};
$.each(storejs.get('instances'), function (i, e) {
response.list.push('/fake/instance_info/' + e.title)
});
xhr.respond(200, {'Content-Type': 'application/json'}, JSON.stringify(response))
});
// Get instance info
fakeserver.respondWith("GET", /\/fake\/instance_info\/(.*)/, function (xhr, instid) {
var instances = storejs.get('instances');
if (instances.hasOwnProperty(instid)) {
xhr.respond(200, {'Content-Type': 'application/json'}, JSON.stringify(instances[instid]));
} else {
xhr.respond(404, { 'Content-Type': 'application/json'}, 'Not found');
}
});
// Request instance
fakeserver.respondWith("POST", '/fake/instance', function (xhr) {
var instances = storejs.get('instances'),
inst = JSON.parse(xhr.requestBody),
iadd = {},
ilist = instance_list();
iadd[inst.title] = inst;
storejs.extend('instances', iadd);
xhr.respond(201, {'Content-Type': 'application/json'}, JSON.stringify({
title: inst.title,
status: inst.status
}));
});
//********** SOFTWARE // ******* INSTANCE
// Get softwares list instance_list = function () {
fakeserver.respondWith('GET', '/fake/software', [ var response = {list: []};
200, {'Content-Type': 'application/json'}, JSON.stringify(storejs.get('software_list')) $.each(storejs.get('instances'), function (i, e) {
]); response.list.push('/fake/instance_info/' + e.title);
// Get software info });
fakeserver.respondWith("GET", /\/fake\/software_info\/(.*)/, function (xhr, softid) { return response;
var softwares = storejs.get('softwares'); };
if (softwares.hasOwnProperty(softid)) { // list
xhr.respond(200, {'Content-Type': 'application/json'}, JSON.stringify(softwares[softid])); fakeserver.respondWith('GET', '/fake/instance', function (xhr) {
} else { var response = {list: []};
xhr.respond(404, { 'Content-Type': 'application/json'}, 'Not found'); $.each(storejs.get('instances'), function (i, e) {
} response.list.push('/fake/instance_info/' + e.title);
}); });
xhr.respond(200, {'Content-Type': 'application/json'}, JSON.stringify(response));
});
// Get instance info
fakeserver.respondWith("GET", /\/fake\/instance_info\/(.*)/, function (xhr, instid) {
var instances = storejs.get('instances');
if (instances.hasOwnProperty(instid)) {
xhr.respond(200, {'Content-Type': 'application/json'}, JSON.stringify(instances[instid]));
} else {
xhr.respond(404, { 'Content-Type': 'application/json'}, 'Not found');
}
});
// Request instance
fakeserver.respondWith("POST", '/fake/instance', function (xhr) {
var instances = storejs.get('instances'),
inst = JSON.parse(xhr.requestBody),
iadd = {},
ilist = instance_list();
iadd[inst.title] = inst;
storejs.extend('instances', iadd);
xhr.respond(201, {'Content-Type': 'application/json'}, JSON.stringify({
title: inst.title,
status: inst.status
}));
});
//********** SOFTWARE
// Get softwares list
fakeserver.respondWith('GET', '/fake/software', [
200, {'Content-Type': 'application/json'}, JSON.stringify(storejs.get('software_list'))
]);
// Get software info
fakeserver.respondWith("GET", /\/fake\/software_info\/(.*)/, function (xhr, softid) {
var softwares = storejs.get('softwares');
if (softwares.hasOwnProperty(softid)) {
xhr.respond(200, {'Content-Type': 'application/json'}, JSON.stringify(softwares[softid]));
} else {
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