Commit da7cc548 authored by Thomas Lechauve's avatar Thomas Lechauve

Manually linted (clean) javascript files

parent f4fad40f
$(document).bind("mobileinit", function () {
var spinOptions = {color: "#FFFFFF", lines:30, length:0, width:5, radius:7, rotate:0, trail:60, speed:1.6};
$(document).bind('mobileinit', function () {
'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
$(document).slapos({
......@@ -15,9 +18,9 @@ $(document).bind("mobileinit", function () {
// show loading during ajax request
$(document).ajaxStart(function () {
$("#loading").spin(spinOptions);
$('#loading').spin(spinOptions);
}).ajaxStop(function () {
$("#loading").spin(false);
$('#loading').spin(false);
});
//$(document).slapos('store', 'host', '/fake');
......
......@@ -65,7 +65,7 @@
},
request: function (type, method, args) {
var statusCode, data;
var statusCode, data, ajaxOptions;
if (args.hasOwnProperty('statusCode')) {
statusCode = args.statusCode || methods.statusDefault();
} else {
......@@ -78,7 +78,7 @@
}
delete args.data;
$.extend(args, {statusCode: statusCode});
var ajaxOptions = {
ajaxOptions = {
type: type,
url: $(this).slapos('host') + method,
contentType: 'application/json',
......@@ -138,16 +138,17 @@
$.extend(args, {url: url});
return $(this).slapos('request', 'GET', '', args);
}
};
$.fn.slapos = function (method) {
var r;
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) {
return methods.init.apply(this, arguments);
r = methods.init.apply(this, arguments);
} else {
$.error('Method ' + method + ' does not exist on jQuery.slapos');
}
return r;
};
}(jQuery));
'use strict';
var getDevice = function (w) {
(function (window, $) {
'use strict';
var getDevice = function (w) {
if (w < 500) {
return 'mobile';
}
......@@ -7,12 +8,11 @@ var getDevice = function (w) {
return 'tablet';
}
return 'desktop';
},
device = getDevice($(window).width());
var body = $("body");
},
body = $("body");
$.vifib.devices = {
$.vifib.device = getDevice($(window).width());
$.vifib.devices = {
"mobile": function (url) {
$('body')
.route('add', '')
......@@ -69,44 +69,31 @@ $.vifib.devices = {
.route('add', '<path:url>')
.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') {
}
return false;
}
$.vifib.startrouter = function () {
$.vifib.startrouter = function () {
$('body')
.route('go', $.url.getPath())
.fail($.vifib.mobile.nopage);
}
};
/* Thanks to Ben Alman
/* Thanks to Ben Alman
* https://raw.github.com/cowboy/jquery-misc/master/jquery.ba-serializeobject.js
*/
$.fn.serializeObject = function(){
$.fn.serializeObject = function () {
var obj = {};
$.each( this.serializeArray(), function(i,o){
$.each(this.serializeArray(), function (i, o) {
var n = o.name,
v = o.value;
obj[n] = obj[n] === undefined ? v
: $.isArray( obj[n] ) ? obj[n].concat( v )
: [ obj[n], v ];
: $.isArray(obj[n]) ? obj[n].concat(v)
: [obj[n], v];
});
return obj;
}
};
$.fn.spin = function(opts) {
this.each(function() {
$.fn.spin = function (opts) {
this.each(function () {
var $this = $(this),
data = $this.data();
if (data.spinner) {
......@@ -118,17 +105,17 @@ $.fn.spin = function(opts) {
}
});
return this;
}
};
$(document).ready(function () {
$(document).ready(function () {
// bind on resize screen event
$(window).resize(function () {
setTimeout(function () {
var curdevice = getDevice($(window).width());
if (device !== curdevice) {
device = curdevice;
if ($.vifib.device !== curdevice) {
$.vifib.device = curdevice;
$.routereset();
$.vifib.devices[device]();
$.vifib.devices[$.vifib.device]();
$.vifib.startrouter();
}
}, 800);
......@@ -140,7 +127,8 @@ $(document).ready(function () {
if (options.hasOwnProperty('access_token')) {
$(document).slapos('access_token', options.access_token);
}
$.vifib.devices[device]();
$.vifib.devices[$.vifib.device]();
$.vifib.startrouter();
});
});
});
}(window, jQuery));
$.vifib.desktop = {
(function (window, $) {
'use strict';
$.vifib.desktop = {
redirect: function (route) {
$.url.go('/overview');
},
......@@ -14,7 +16,7 @@ $.vifib.desktop = {
]}
]);
// header
page.prepend(Mustache.render($.vifib.header.default, {title: 'SlapOs'}));
page.prepend(Mustache.render($.vifib.header.main, {title: 'SlapOs'}));
// rendering
$.vifib.changepage($(page));
$('#panel-1')
......@@ -38,7 +40,7 @@ $.vifib.desktop = {
.done($.vifib.login.googleRedirect);
$('#panel-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) {
$.vifib.replacepanel($(this), $.vifib.panel.carousel);
......@@ -74,12 +76,12 @@ $.vifib.desktop = {
.done($.vifib.desktop.library.all);
$('#panel-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) {
$.vifib.replacepanel($(this), $.vifib.panel.library, {
most: [
{url: '#/library/software/id/fake/software_info/Kvm', name: 'Kvm'},
{url: '#/library/software/id/fake/software_info/Kvm', name: 'Kvm'}
],
newest: [
{url: '#/library/software/id/fake/software_info/Html5as', name: 'html5 AS'}
......@@ -102,7 +104,7 @@ $.vifib.desktop = {
dispatch: function (route) {
$.vifib.replacepanel($(this), $.vifib.panel.simplelist, {
links: [
{url: '#/dashboard/instance/list', name: 'Instances'},
{url: '#/dashboard/instance/list', name: 'Instances'}
]
});
$('#panel-2')
......@@ -128,7 +130,7 @@ $.vifib.desktop = {
.done($.vifib.desktop.dashboard.instancedestroy);
$('#panel-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) {
$.vifib.replacepanel($(this), $.vifib.panel.instancelist);
......@@ -140,7 +142,7 @@ $.vifib.desktop = {
var data = {
"status": "start_requested",
"slave": false,
"software_type": "type_provided_by_the_software",
"software_type": "type_provided_by_the_software"
};
$.extend(data, $(this).serializeObject());
$(this).slapos('instanceRequest', {
......@@ -175,7 +177,7 @@ $.vifib.desktop = {
$.url.redirect('/dashboard/instance/id' + instid);
},
statusCode: $.extend(false, $.vifib.statuscode, {})
})
});
}
},
statusCode: $.extend(false, $.vifib.statuscode, {})
......@@ -192,11 +194,12 @@ $.vifib.desktop = {
$.url.redirect('/dashboard/instance/id' + instid);
},
statusCode: $.extend(false, $.vifib.statuscode, {})
})
});
}
},
statusCode: $.extend(false, $.vifib.statuscode, {})
});
},
}
};
}
};
}(window, jQuery));
$.vifib.login = {
(function (window, $) {
'use strict';
$.vifib.login = {
facebook: function (params) {
var redirect = location.protocol + '//' + location.host + location.pathname + '#/dashboard/' + '?',
fburl = 'https://www.facebook.com/dialog/oauth?' +
......@@ -30,13 +32,13 @@ $.vifib.login = {
});
$.url.redirect('/dashboard/', options);
}
}
$.vifib.statuscode = {
};
$.vifib.statuscode = {
400: function (jqxhr, textstatus) {
var page;
if(device === 'mobile') {
if ($.vifib.device === 'mobile') {
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);
$.vifib.changepage($(page));
} else {
......@@ -48,9 +50,9 @@ $.vifib.statuscode = {
},
402: function (jqxhr, textstatus) {
var page;
if(device === 'mobile') {
if ($.vifib.device === 'mobile') {
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);
$.vifib.changepage($(page));
} else {
......@@ -59,9 +61,9 @@ $.vifib.statuscode = {
},
404: function (jqxhr, textstatus) {
var page;
if(device === 'mobile') {
if ($.vifib.device === 'mobile') {
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);
$.vifib.changepage($(page));
} else {
......@@ -70,17 +72,17 @@ $.vifib.statuscode = {
},
500: function (jqxhr, textstatus) {
var page;
if(device === 'mobile') {
if ($.vifib.device === 'mobile') {
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);
$.vifib.changepage($(page));
} else {
$.vifib.replacepanel($(this), $.vifib.panel.internalerror);
}
},
}
$.vifib.softwareList = function (context) {
}
};
$.vifib.softwareList = function (context) {
var list;
return context.each(function () {
list = $(this).find('ul');
......@@ -95,8 +97,8 @@ $.vifib.softwareList = function (context) {
statusCode: $.extend(false, $.vifib.statuscode, {})
});
});
}
$.vifib.instanceList = function (context) {
};
$.vifib.instanceList = function (context) {
var list;
return context.each(function () {
list = $(this).find('ul');
......@@ -109,8 +111,8 @@ $.vifib.instanceList = function (context) {
statusCode: $.extend(false, $.vifib.statuscode, {})
});
});
}
$.vifib.fillRowInstance = function (list, row, instid) {
};
$.vifib.fillRowInstance = function (list, row, instid) {
return row.slapos('instanceInfo', instid, {
success: function (response) {
$.extend(response, {insturl: '#/dashboard/instance/id' + instid});
......@@ -121,8 +123,8 @@ $.vifib.fillRowInstance = function (list, row, instid) {
},
statusCode: $.extend(false, $.vifib.statuscode, {})
});
}
$.vifib.computerList = function (context) {
};
$.vifib.computerList = function (context) {
var list;
return context.each(function () {
list = $(this).find('ul');
......@@ -137,8 +139,8 @@ $.vifib.computerList = function (context) {
statusCode: $.extend(false, $.vifib.statuscode, {})
});
});
}
$.vifib.fillRowSoftware = function (context, softid) {
};
$.vifib.fillRowSoftware = function (context, softid) {
return context.each(function () {
$(this).slapos('softwareInfo', softid, {
success: function (response) {
......@@ -147,9 +149,9 @@ $.vifib.fillRowSoftware = function (context, softid) {
},
statusCode: $.extend(false, $.vifib.statuscode, {})
});
})
}
$.vifib.fillRowComputer = function (context, compid) {
});
};
$.vifib.fillRowComputer = function (context, compid) {
return context.each(function () {
$(this).slapos('computerInfo', compid, {
success: function (response) {
......@@ -158,5 +160,6 @@ $.vifib.fillRowComputer = function (context, compid) {
},
statusCode: $.extend(false, $.vifib.statuscode, {})
});
})
}
});
};
}(window, jQuery));
$.vifib.mobile = {
(function (window, $) {
'use strict';
$.vifib.mobile = {
nopage: function () {
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));
},
overview: function (route) {
......@@ -9,7 +11,7 @@ $.vifib.mobile = {
// rendering
page = $.vifib.onepanel($.vifib.panel.login);
// header
page.prepend(Mustache.render($.vifib.header.default, {title: 'SlapOs'}));
page.prepend(Mustache.render($.vifib.header.main, {title: 'SlapOs'}));
// footer navbar
page.append($.vifib.footer.overview);
// rendering
......@@ -31,16 +33,16 @@ $.vifib.mobile = {
.fail($.vifib.mobile.nopage);
},
overview: function () {
page = $.vifib.onepanel($.vifib.panel.library, {
var page = $.vifib.onepanel($.vifib.panel.library, {
most: [
{url: '#/library/software/id/fake/software_info/Kvm', name: 'Kvm'},
{url: '#/library/software/id/fake/software_info/Kvm', name: 'Kvm'}
],
newest: [
{url: '#/library/software/id/fake/software_info/Html5', name: 'Html5as'}
]
});
// 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, {
links: [
{url: '#/library/all', name: 'See all softwares'},
......@@ -58,7 +60,7 @@ $.vifib.mobile = {
var page;
page = $.vifib.onepanel($.vifib.panel.software, response);
// header
page.prepend(Mustache.render($.vifib.header.default, {title: response.name}));
page.prepend(Mustache.render($.vifib.header.main, {title: response.name}));
// footer navbar
page.append($.vifib.footer.overview);
// rendering
......@@ -70,7 +72,7 @@ $.vifib.mobile = {
all: function () {
var page = $.vifib.onepanel($.vifib.panel.allsoftware);
$.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);
$.vifib.changepage($(page));
}
......@@ -109,24 +111,24 @@ $.vifib.mobile = {
{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));
},
instancelist: function (route) {
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.instanceList($(page));
},
instancerequest: function (route) {
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));
$("#instancerequest").submit(function () {
var data = {
"status": "start_requested",
"slave": false,
"software_type": "type_provided_by_the_software",
"software_type": "type_provided_by_the_software"
};
$.extend(data, $(this).serializeObject());
$(this).slapos('instanceRequest', {
......@@ -148,7 +150,7 @@ $.vifib.mobile = {
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'}));
page.prepend(Mustache.render($.vifib.header.main, {title: 'Instance'}));
$.vifib.changepage($(page));
}
});
......@@ -164,7 +166,7 @@ $.vifib.mobile = {
$.url.redirect('/dashboard/instance/id' + instid);
},
statusCode: $.extend(false, $.vifib.statuscode, {})
})
});
}
},
statusCode: $.extend(false, $.vifib.statuscode, {})
......@@ -181,7 +183,7 @@ $.vifib.mobile = {
$.url.redirect('/dashboard/instance/id' + instid);
},
statusCode: $.extend(false, $.vifib.statuscode, {})
})
});
}
},
statusCode: $.extend(false, $.vifib.statuscode, {})
......@@ -193,11 +195,11 @@ $.vifib.mobile = {
$.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'}));
page.prepend(Mustache.render($.vifib.header.main, {title: 'Computers'}));
$.vifib.changepage($(page));
$.vifib.computerList($(page));
},
......@@ -206,10 +208,11 @@ $.vifib.mobile = {
$(this).slapos('computerInfo', compid, {
success: function (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));
}
});
}
}
};
};
}(window, jQuery));
$.vifib.tablet = {
(function (window, $) {
'use strict';
$.vifib.tablet = {
overview: function (route) {
var page = $.vifib.twopanel([
$.vifib.panel.sidemenu.main,
......@@ -10,7 +12,7 @@ $.vifib.tablet = {
]}
]);
// header
page.prepend(Mustache.render($.vifib.header.default, {title: 'SlapOs'}));
page.prepend(Mustache.render($.vifib.header.main, {title: 'SlapOs'}));
// rendering
$.vifib.changepage($(page));
},
......@@ -23,13 +25,13 @@ $.vifib.tablet = {
{links: [
{url: '#/library/', name: 'Overview'},
{url: '#/library/all', name: 'See all softwares'}
],categories: [
], categories: [
{url: '#/library/categorie/vm', name: 'Virtual Machine'},
{url: '#/library/categorie/db', name: 'Database'}
]}
]);
// header
page.prepend(Mustache.render($.vifib.header.default, {title: 'Library'}));
page.prepend(Mustache.render($.vifib.header.main, {title: 'Library'}));
// rendering
$.vifib.changepage($(page));
$('#panel-1')
......@@ -43,11 +45,11 @@ $.vifib.tablet = {
.done($.vifib.tablet.library.all);
$('#panel-1')
.route('go', $.url.getPath(), 1)
.fail(function () { $.vifib.replacepanel($(this), $.vifib.panel.failed)});
.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'},],
most: [{url: '#/library/software/id/fake/software_info/Kvm', name: 'Kvm'}],
newest: [{url: '#/library/software/id/fake/software_info/Html5as', name: 'html5 AS'}]
});
},
......@@ -77,10 +79,10 @@ $.vifib.tablet = {
{links: [
{url: '#/library/', name: 'Library'},
{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));
$('#panel-1')
.route('add', '/dashboard/', 1)
......@@ -105,7 +107,7 @@ $.vifib.tablet = {
.done($.vifib.tablet.dashboard.instancedestroy);
$('#panel-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) {
$.vifib.replacepanel($(this), $.vifib.panel.instancelist);
......@@ -133,7 +135,7 @@ $.vifib.tablet = {
var data = {
"status": "start_requested",
"slave": false,
"software_type": "type_provided_by_the_software",
"software_type": "type_provided_by_the_software"
};
$.extend(data, $(this).serializeObject());
$(this).slapos('instanceRequest', {
......@@ -157,7 +159,7 @@ $.vifib.tablet = {
$.url.redirect('/dashboard/instance/id' + instid);
},
statusCode: $.extend(false, $.vifib.statuscode, {})
})
});
}
},
statusCode: $.extend(false, $.vifib.statuscode, {})
......@@ -174,11 +176,12 @@ $.vifib.tablet = {
$.url.redirect('/dashboard/instance/id' + instid);
},
statusCode: $.extend(false, $.vifib.statuscode, {})
})
});
}
},
statusCode: $.extend(false, $.vifib.statuscode, {})
});
},
}
};
}
};
}(window, jQuery));
$.vifib.panel = {
(function (window, $) {
'use strict';
$.vifib.panel = {
carousel:
'<article id="slider">' +
'<ul>' +
......@@ -41,7 +43,6 @@ $.vifib.panel = {
'</li>' +
'</ul>' +
'</article>',
simplelist:
'<article>' +
'<ul data-role="listview">' +
......@@ -110,7 +111,7 @@ $.vifib.panel = {
rowsoftware:
'<a href="{{ softurl }}">' +
'{{# thumb_url }}' +
'<img src="{{ thumb_url }}">'+
'<img src="{{ thumb_url }}">' +
'{{/ thumb_url }}' +
'<h3>{{ name }}</h3>' +
'</a>',
......@@ -153,7 +154,6 @@ $.vifib.panel = {
'<a data-role="button" href="{{ start_url }}">Start</a>' +
'<a data-role="button" href="{{ destroy_url }}">Destroy</a>' +
'{{/ stop_requested }}' +
'' +
'</article>',
instancelist:
'<article>' +
......@@ -203,13 +203,14 @@ $.vifib.panel = {
nocomputer:
'<article>' +
'<h4>The computer you are looking for, named "{{ name }}", does not exist</h4>' +
'</article>',
}
'</article>'
};
$.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>'
}
$.vifib.header = {
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>'
}
};
}(window, jQuery));
$.vifib.onepanel = function (panel, data) {
var page = $('<div data-role="page"></div>')
(function (window, $) {
'use strict';
$.vifib.onepanel = function (panel, data) {
var page = $('<div data-role="page"></div>'),
content = $('<div data-role="content"></div>')
.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>')
.append($.vifib.makecontent(panels, data));
return $(page);
}
};
$.vifib.threepanel = function (panels, data) {
$.vifib.threepanel = function (panels, data) {
var page = $('<div data-role="page"></div>')
.append($.vifib.makecontent(panels, data));
return $(page);
}
};
$.vifib.replacepanel = function (context, panel, data) {
$.vifib.replacepanel = function (context, panel, data) {
context.html(Mustache.render(panel, data));
$(':jqmData(role=page)').trigger('pagecreate');
}
};
$.vifib.makecontent = function (panels, data) {
$.vifib.makecontent = function (panels, data) {
var i = 0,
pandata,
gridname = {
2: 'ui-grid-a',
3: 'ui-grid-b',
4: 'ui-grid-c',
5: 'ui-grid-d',
5: 'ui-grid-d'
},
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];
divcontent.append($.vifib.makepanel(panels[i], pandata, i));
}
return divcontent;
}
};
$.vifib.makepanel = function (panel, data, index) {
$.vifib.makepanel = function (panel, data, index) {
var blockname = [
'ui-block-a',
'ui-block-b',
'ui-block-c',
'ui-block-d',
'ui-block-e',
'ui-block-e'
],
divpane = $('<div class="' + blockname[index] + '">')
.append('<section id="panel-' + index + '">' + Mustache.render(panel, data) + '</section>');
return divpane;
}
};
$.vifib.changepage = function (page) {
$.vifib.changepage = function (page) {
$('[id^=panel]').remove();
$('#slider').remove();
$('#loading').remove();
......@@ -62,4 +64,5 @@ $.vifib.changepage = function (page) {
changeHash: false,
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 */
var storejs = {
(function (window, $) {
'use strict';
/* Tools to store js object in sessionStorage */
var storejs = {
add: function (key, js) {
window.sessionStorage.setItem(key, JSON.stringify(js));
},
......@@ -11,13 +13,13 @@ var storejs = {
$.extend(data, object);
storejs.add(key, data);
}
}
}
/*************
/*************
* RESOURCES
*************/
// INSTANCE
storejs.add('instances', {
// INSTANCE
storejs.add('instances', {
Kvm: {
status: "start_requested",
connection: {},
......@@ -40,15 +42,15 @@ storejs.add('instances', {
computer_id: "COMP-0"
}
}
});
// SOFTWARE
storejs.add('softwares', {
});
// 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',
price: '1'
},
Html5as : {
name: 'Html5as',
......@@ -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.',
price: '1337'
}
});
// Resources lists
storejs.add('software_list', {
});
// Resources lists
storejs.add('software_list', {
list: [
'/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
*********************/
// ******* INSTANCE
var instance_list = function () {
// ******* INSTANCE
instance_list = function () {
var response = {list: []};
$.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;
};
// list
fakeserver.respondWith('GET', '/fake/instance', function (xhr) {
};
// 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)
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) {
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) {
});
// Request instance
fakeserver.respondWith("POST", '/fake/instance', function (xhr) {
var instances = storejs.get('instances'),
inst = JSON.parse(xhr.requestBody),
iadd = {},
......@@ -109,30 +112,30 @@ fakeserver.respondWith("POST", '/fake/instance', function (xhr) {
title: inst.title,
status: inst.status
}));
});
});
//********** SOFTWARE
// Get softwares list
fakeserver.respondWith('GET', '/fake/software', [
//********** 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) {
]);
// 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
if (url.hasOwnProperty('cache')) { url.cache = true; }
var result = tmp(url, options);
fakeserver.respond();
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