Commit 0ed49aff authored by Thomas Lechauve's avatar Thomas Lechauve

Merge mobile, tablet and desktop code together

parent 0de1504e
......@@ -39,14 +39,14 @@ $(DEVDIR)/js/fake.js: js/utils/fake.js
cp $< $@
# Sort files for concatenation
CATJSFILES = $(DEVDIR)/lib/jquery.js $(DEVDIR)/lib/sinon.js $(DEVDIR)/lib/mustache.js $(DEVDIR)/lib/spin.js $(DEVDIR)/lib/modernizr.js $(DEVDIR)/lib/swipe.js $(DEVDIR)/js/jquery.slapos.js $(DEVDIR)/js/init.js $(DEVDIR)/lib/jquery.mobile.js $(DEVDIR)/lib/url.js $(DEVDIR)/lib/route.js $(DEVDIR)/js/main.js $(DEVDIR)/js/render.js $(DEVDIR)/js/panels.js $(DEVDIR)/js/pages.js $(DEVDIR)/js/pages.mobile.js $(DEVDIR)/js/pages.tablet.js $(DEVDIR)/js/pages.desktop.js
CATJSFILES = $(DEVDIR)/lib/jquery.js $(DEVDIR)/lib/sinon.js $(DEVDIR)/lib/mustache.js $(DEVDIR)/lib/spin.js $(DEVDIR)/lib/modernizr.js $(DEVDIR)/lib/swipe.js $(DEVDIR)/js/jquery.slapos.js $(DEVDIR)/js/init.js $(DEVDIR)/lib/jquery.mobile.js $(DEVDIR)/lib/url.js $(DEVDIR)/lib/route.js $(DEVDIR)/js/main.js $(DEVDIR)/js/render.js $(DEVDIR)/js/panels.js $(DEVDIR)/js/pages.js $(DEVDIR)/js/pages/library.js $(DEVDIR)/js/pages/overview.js $(DEVDIR)/js/pages/dashboard.js $(DEVDIR)/js/pages/login.js
CATCSSFILES = $(DEVDIR)/lib/qunit.css $(DEVDIR)/lib/jquery.mobile.css
# List all javascript files except tests files and lib files
JSFILES = $(find $(JSDIR) -name 'tests' -prune -o -name 'lib' -prune -o -name "*.js" -print)
JSFILES = $(find $(JSDIR) -name 'tests' -prune -o -name 'lib' -prune -o -name '*.js' -printf '%p ')
dev: $(DEVDIR)/lib/sinon.js $(DEVDIR)/lib/jquery.js $(DEVDIR)/lib/qunit.js $(DEVDIR)/lib/qunit.css $(DEVDIR)/lib/jquery.mobile.js $(DEVDIR)/lib/jquery.mobile.css $(DEVDIR)/lib/jquery.mobile.zip $(DEVDIR)/lib/modernizr.js $(DEVDIR)/lib/mustache.js $(DEVDIR)/lib/spin.js $(DEVDIR)/lib/swipe.js $(DEVDIR)/lib/route.js $(DEVDIR)/lib/url.js $(patsubst %.js, $(DEVDIR)/js/%.js, $(JSFILES)) $(APPDIR)/index.html $(APPDIR)/$(DEVJS) $(APPDIR)/$(DEVCSS) manifest
dev: $(DEVDIR)/lib/sinon.js $(DEVDIR)/lib/jquery.js $(DEVDIR)/lib/qunit.js $(DEVDIR)/lib/qunit.css $(DEVDIR)/lib/jquery.mobile.js $(DEVDIR)/lib/jquery.mobile.css $(DEVDIR)/lib/jquery.mobile.zip $(DEVDIR)/lib/modernizr.js $(DEVDIR)/lib/mustache.js $(DEVDIR)/lib/spin.js $(DEVDIR)/lib/swipe.js $(DEVDIR)/lib/route.js $(DEVDIR)/lib/url.js $(subst $(JSDIR)/, $(DEVDIR)/, $(JSFILES)) $(APPDIR)/index.html $(APPDIR)/$(DEVJS) $(APPDIR)/$(DEVCSS) manifest
manifest: $(APPDIR)/index.html $(APPDIR)/$(DEVJS) $(APPDIR)/$(DEVCSS)
@if test -f $(MANIFESTNAME); then \
......@@ -54,14 +54,13 @@ manifest: $(APPDIR)/index.html $(APPDIR)/$(DEVJS) $(APPDIR)/$(DEVCSS)
else \
echo "CACHE MANIFEST" > $(MANIFESTNAME); \
echo "#rel 1" >> $(MANIFESTNAME); \
find $(APPDIR) -type f -not -name $(MANIFESTNAME) | sed -e 's#$(APPDIR)/##g' >> $(MANIFESTNAME); \
find $(APPDIR) -type f -not -wholename $(MANIFESTNAME) | sed -e 's#$(APPDIR)/##g' >> $(MANIFESTNAME); \
fi
$(APPDIR)/index.html: index.html
@mkdir -p $(@D)
cp $< $@
# Lint javascript files #
$(DEVDIR)/js/%.js: js/%.js
@mkdir -p $(@D)
@# Prepend jslintrc to defined global variables #
......@@ -101,7 +100,7 @@ $(DEVDIR)/lib/jquery.mobile.zip:
@mkdir -p $(APPDIR)
curl -s -o $@ http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.zip
unzip $@ -d $(DEVDIR) 'jquery.mobile-?.?.?/images/*'
cp -r $(DEVDIR)/jquery.mobile-1.1.0/images $(APPDIR)
cp -r $(DEVDIR)/jquery.mobile-1.1.0/images $(APPDIR)/
rm -rf $(DEVDIR)/jquery.mobile-1.1.0
$(DEVDIR)/lib/mustache.js:
......@@ -171,7 +170,7 @@ $(DEVDIR)/tests/%_test.html.ok: $(DEVDIR)/tests/%_test.html $(DEVDIR)/tests/%_te
#########################################
clean:
@echo soft cleaning
rm -rf $(APPDIR)
rm -rf $(APPDIR)/*.*
cleanall:
@echo cleaning
rm -rf $(DEVDIR) ${RELDIR} $(TARBALL)
<!DOCTYPE HTML>
<html manifest="slapos.manifest">
<!--<html manifest="slapos.manifest">-->
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
......
......@@ -4,8 +4,53 @@ $(document).bind('mobileinit', function () {
if (!$.vifib) {
$.vifib = {};
$.vifib.pages = {};
}
// Initialize routes
$.vifib.initroutes = function () {
// Google redirection
$('body')
.route('add', $.vifib.pages.login.googleRedirect.url)
.done($.vifib.pages.login.googleRedirect.action);
// Authentication
$('body')
.route('add', $.vifib.pages.login.dispatch.url)
.done($.vifib.pages.login.dispatch.action);
// Default
$('body')
.route('add', '')
.done($.vifib.pages.overview.action);
// Overview
$('body')
.route('add', $.vifib.pages.overview.url)
.done($.vifib.pages.overview.action);
// Library
$('body')
.route('add', $.vifib.pages.library.dispatch.url)
.done($.vifib.pages.library.dispatch.action);
$('body')
.route('add', $.vifib.pages.library.menu.url)
.done($.vifib.pages.library.menu.action);
// Dashboard
$('body')
.route('add', $.vifib.pages.dashboard.dispatch.url)
.done($.vifib.pages.dashboard.dispatch.action);
$('body')
.route('add', $.vifib.pages.dashboard.menu.url)
.done($.vifib.pages.dashboard.menu.action);
// Software
$('body')
.route('add', $.vifib.pages.software.dispatch.url)
.done($.vifib.pages.software.dispatch.action);
// Instance
$('body')
.route('add', $.vifib.pages.instance.dispatch.url)
.done($.vifib.pages.instance.dispatch.action);
// Computer
$('body')
.route('add', $.vifib.pages.computer.dispatch.url)
.done($.vifib.pages.computer.dispatch.action);
};
//SlapOs configuration
$(document).slapos({
// REST API url
......
......@@ -131,7 +131,7 @@
},
computerList: function (args) {
return $(this).slapos('request', '', args);
return $(this).slapos('request', 'GET', '/computer', args);
},
computerInfo: function (url, args) {
......
......@@ -15,66 +15,66 @@
$.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);
.route('add', $.vifib.pages.overview.url)
.done($.vifib.pages.overview.action);
//$('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);
//$('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);
.route('add', $.vifib.pages.overview.url)
.done($.vifib.pages.overview.action);
//$('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);
.route('add', $.vifib.pages.overview.url)
.done($.vifib.pages.overview.action);
//$('body')
//.route('add', '<path:url>')
//.done($.vifib.desktop.dispatch);
}
};
$.vifib.startrouter = function () {
$('body')
.route('go', $.url.getPath())
.fail($.vifib.mobile.nopage);
.route('go', $.url.getPath());
//.fail($.vifib.mobile.nopage);
};
/* Thanks to Ben Alman
......@@ -110,15 +110,18 @@
$(document).ready(function () {
// bind on resize screen event
$(window).resize(function () {
setTimeout(function () {
if ($(window).data('resizing')) {
clearTimeout($(window).data('resizing'));
}
$(window).data('resizing', setTimeout(function () {
var curdevice = getDevice($(window).width());
if ($.vifib.device !== curdevice) {
$.vifib.device = curdevice;
$.routereset();
$.vifib.devices[$.vifib.device]();
$.vifib.initroutes();
$.vifib.startrouter();
}
}, 800);
}, 800));
});
// Url change event
......@@ -127,7 +130,7 @@
if (options.hasOwnProperty('access_token')) {
$(document).slapos('access_token', options.access_token);
}
$.vifib.devices[$.vifib.device]();
$.vifib.initroutes();
$.vifib.startrouter();
});
});
......
(function (window, $) {
'use strict';
$.vifib.desktop = {
redirect: function (route) {
$.url.go('/overview');
},
dispatch: function (route) {
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.main, {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) {
$.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));
}
},
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) {
$.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) {
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, {})
});
},
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, {})
});
}
}
};
}(window, jQuery));
(function (window, $) {
'use strict';
$.vifib.login = {
facebook: function (params) {
var redirect = window.location.protocol + '//' + window.location.host + window.location.pathname + '#/dashboard/' + '?',
fburl = 'https://www.facebook.com/dialog/oauth?' +
'client_id=' + $(document).slapos('store', 'fbappid') +
'&redirect_uri=' + encodeURIComponent(redirect) +
'&scope=email' +
'&response_type=token';
// set token type to Facebook for js library
$(document).slapos('store', 'token_type', 'Facebook');
window.location.href = fburl;
},
google: function (params) {
var redirect = window.location.protocol + '//' + window.location.host + window.location.pathname,
ggurl = 'https://accounts.google.com/o/oauth2/auth?' +
'client_id=' + $(document).slapos('store', 'ggappid') +
'&redirect_uri=' + encodeURIComponent(redirect) +
'&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email++https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile' +
'&response_type=token';
$(document).slapos('store', 'token_type', 'Google');
window.location.href = ggurl;
},
googleRedirect: function (response) {
var options = {},
option;
response = 'access_token=' + response;
$.each(response.split('&'), function (i, e) {
option = e.split('=');
options[option[0]] = option[1];
});
$.url.redirect('/dashboard/', options);
}
};
$.vifib.statuscode = {
400: function (jqxhr, textstatus) {
var page;
......@@ -115,7 +82,7 @@
$.vifib.fillRowInstance = function (list, row, instid) {
return row.slapos('instanceInfo', instid, {
success: function (response) {
$.extend(response, {insturl: '#/dashboard/instance/id' + instid});
$.extend(response, {insturl: '#/instance/show' + instid});
$(this).html(Mustache.render($.vifib.panel.rowinstance, response));
},
complete: function (jqxhr, textstatus) {
......@@ -144,7 +111,7 @@
return context.each(function () {
$(this).slapos('softwareInfo', softid, {
success: function (response) {
$.extend(response, {softurl: '#/library/software/id' + softid});
$.extend(response, {softurl: '#/software/show' + softid});
$(this).html(Mustache.render($.vifib.panel.rowsoftware, response));
},
statusCode: $.extend(false, $.vifib.statuscode, {})
......@@ -155,11 +122,14 @@
return context.each(function () {
$(this).slapos('computerInfo', compid, {
success: function (response) {
$.extend(response, {compurl: '#/dashboard/computer/id/' + compid});
$.extend(response, {compurl: '#/computer/show' + compid});
$(this).html(Mustache.render($.vifib.panel.rowcomputer, response));
},
statusCode: $.extend(false, $.vifib.statuscode, {})
});
});
};
$.vifib.buildurl = function (panel) {
return '#' + panel.url;
};
}(window, jQuery));
(function (window, $) {
'use strict';
$.vifib.mobile = {
nopage: function () {
var page = $.vifib.onepanel($.vifib.panel.failed);
page.prepend(Mustache.render($.vifib.header.main, {title: 'Oops'}));
$.vifib.changepage($(page));
},
overview: function (route) {
var page;
// rendering
page = $.vifib.onepanel($.vifib.panel.login);
// header
page.prepend(Mustache.render($.vifib.header.main, {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 () {
var page = $.vifib.onepanel($.vifib.panel.library, {
most: [
{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.main, {title: 'Library'}));
page.append(Mustache.render($.vifib.panel.simplelist, {
links: [
{url: '#/library/all', name: 'See all softwares'},
{url: '#/library/categories', name: 'See categories'}
]
}));
// footer navbar
page.append($.vifib.footer.overview);
// rendering
$.vifib.changepage($(page));
},
software: function (softid) {
$('body').slapos('softwareInfo', softid, {
success: function (response) {
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, {})
});
},
all: function () {
var page = $.vifib.onepanel($.vifib.panel.allsoftware);
$.vifib.softwareList($(page));
page.prepend(Mustache.render($.vifib.header.main, {title: 'All softwares'}));
page.append($.vifib.footer.overview);
$.vifib.changepage($(page));
}
},
dashboard: {
dispatch: function (route) {
$('body')
.route('add', '/dashboard/', 1)
.done($.vifib.mobile.dashboard.home);
$('body')
.route('add', '/dashboard/instance/list', 1)
.done($.vifib.mobile.dashboard.instancelist);
$('body')
.route('add', '/dashboard/instance/request', 1)
.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));
}
});
},
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, {})
});
},
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));
}
});
}
}
};
}(window, jQuery));
(function (window, $) {
'use strict';
$.vifib.tablet = {
overview: function (route) {
var page = $.vifib.twopanel([
$.vifib.panel.sidemenu.main,
$.vifib.panel.login
], [
{links: [
{url: '#/library/', name: 'Library'},
{url: 'http://packages.python.org/slapos.core/', name: 'Documentation'}
]}
]);
// header
page.prepend(Mustache.render($.vifib.header.main, {title: 'SlapOs'}));
// rendering
$.vifib.changepage($(page));
},
library: {
dispatch: function (route) {
var page = $.vifib.twopanel([
$.vifib.panel.sidemenu.library,
$.vifib.panel.blank
], [
{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'}
]}
]);
// header
page.prepend(Mustache.render($.vifib.header.main, {title: 'Library'}));
// rendering
$.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) {
$(this).slapos('softwareInfo', softid, {
success: function (response) {
$.vifib.replacepanel($(this), $.vifib.panel.software, response);
},
statusCode: $.extend(false, $.vifib.statuscode, {
404: function (jqxhr, textstatus) {
$.vifib.replacepanel($(this), $.vifib.panel.nosoftware, {name: softid});
}
})
});
},
all: function (softid) {
$.vifib.replacepanel($(this), $.vifib.panel.allsoftware);
$.vifib.softwareList($(this));
}
},
dashboard: {
dispatch: function (route) {
var page = $.vifib.twopanel([
$.vifib.panel.simplelist,
$.vifib.panel.blank
], [
{links: [
{url: '#/library/', name: 'Library'},
{url: 'http://packages.python.org/slapos.core/', name: 'Documentation'},
{url: '#/dashboard/instance/list', name: 'Instances'}
]}
]);
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) {
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, {})
});
},
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, {})
});
}
}
};
}(window, jQuery));
(function (window, $) {
'use strict';
var mainmenudata, dashboardmenudata;
$.vifib.pages.dashboard = {
dispatch: {
url: '/dashboard<path:url>',
action: function (args) {
var p,
mainpanel = function () {
p = $.routepriority() + 1;
$(this)
.route('add', $.vifib.pages.dashboard.instancelist.url, p)
.done($.vifib.pages.dashboard.instancelist.action);
$(this)
.route('add', $.vifib.pages.dashboard.instancerequest.url, p)
.done($.vifib.pages.dashboard.instancerequest.action);
$(this)
.route('add', $.vifib.pages.dashboard.computerlist.url, p)
.done($.vifib.pages.dashboard.computerlist.action);
$(this)
.route('go', $.url.getPath(), p);
};
$.vifib.render($(this), [
{template: $.vifib.panel.blank, callback: mainpanel},
{template: $.vifib.panel.menu.main, data: dashboardmenudata},
{template: $.vifib.panel.menu.main, data: mainmenudata}
], {template: $.vifib.header.main, data: {title: 'SlapOs'}});
}
},
menu: {
url: '/dashboard',
action: function (args) {
$.vifib.render($(this), [
{template: $.vifib.panel.menu.main, data: dashboardmenudata},
{template: $.vifib.panel.menu.main, data: mainmenudata}
], {template: $.vifib.header.main, data: {title: 'SlapOs'}});
}
},
instancelist: {
url: '/dashboard/instance/list',
action: function (args) {
var instlist = function () {
$.vifib.instanceList($(this));
};
$.vifib.render($(this), [
{template: $.vifib.panel.instancelist, callback: instlist, data: {requesturl: '#/dashboard/instance/request'}},
], {template: $.vifib.header.main, data: {title: 'SlapOs'}});
}
},
instancerequest: {
url: '/dashboard/instance/request',
action: function (args) {
var instreq = function () {
$("#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($.vifib.pages.dashboard.instancelist.url);
},
statusCode: $.extend(false, $.vifib.statuscode, {})
});
return false;
});
};
$.vifib.render($(this), [
{template: $.vifib.panel.instancerequest, callback: instreq},
], {template: $.vifib.header.main, data: {title: 'SlapOs'}});
}
},
computerlist: {
url: '/dashboard/computer/list',
action: function (args) {
var complist = function () {
$.vifib.computerList($(this));
};
$.vifib.render($(this), [
{template: $.vifib.panel.computerlist, callback: complist},
], {template: $.vifib.header.main, data: {title: 'SlapOs'}});
}
}
};
$.vifib.pages.instance = {
dispatch: {
url: '/instance<path:url>',
action: function (args) {
var p,
mainpanel = function () {
p = $.routepriority() + 1;
$(this)
.route('add', $.vifib.pages.instance.show.url, p)
.done($.vifib.pages.instance.show.action);
$(this)
.route('go', $.url.getPath(), p);
},
instancelist = function () {
var instlist = function () {
$.vifib.instanceList($(this));
};
$.vifib.render($(this), [
{template: $.vifib.panel.instancelist, callback: instlist, data: {requesturl: '#/dashboard/instance/request'}},
]);
};
$.vifib.render($(this), [
{template: $.vifib.panel.blank, callback: mainpanel},
{template: $.vifib.panel.instancelist, callback: instancelist},
{template: $.vifib.panel.menu.main, data: dashboardmenudata}
], {template: $.vifib.header.main, data: {title: 'SlapOs'}});
}
},
show: {
url: '/instance/show<path:instid>',
action: function (instid) {
$(this).slapos('instanceInfo', instid, {
success: function (response) {
$.vifib.render($(this), [
{template: $.vifib.panel.instance, data: response}
], {template: $.vifib.header.main, data: {title: 'SlapOs'}});
}
});
}
}
};
$.vifib.pages.computer = {
dispatch: {
url: '/computer<path:url>',
action: function (args) {
var p,
mainpanel = function () {
p = $.routepriority() + 1;
$(this)
.route('add', $.vifib.pages.computer.show.url, p)
.done($.vifib.pages.computer.show.action);
$(this)
.route('go', $.url.getPath(), p);
},
computerlist = function () {
var complist = function () {
$.vifib.computerList($(this));
};
$.vifib.render($(this), [
{template: $.vifib.panel.computerlist, callback: complist},
]);
};
$.vifib.render($(this), [
{template: $.vifib.panel.blank, callback: mainpanel},
{template: $.vifib.panel.computerlist, callback: computerlist},
{template: $.vifib.panel.menu.main, data: dashboardmenudata}
], {template: $.vifib.header.main, data: {title: 'SlapOs'}});
}
},
show: {
url: '/computer/show<path:compid>',
action: function (compid) {
$(this).slapos('computerInfo', compid, {
success: function (response) {
$.vifib.render($(this), [
{template: $.vifib.panel.computer, data: response}
], {template: $.vifib.header.main, data: {title: 'SlapOs'}});
}
});
}
}
};
mainmenudata = {
links: [
{url: $.vifib.buildurl($.vifib.pages.library.overview), name: 'Library'},
{url: $.vifib.buildurl($.vifib.pages.library.overview), name: 'Dashboard'}
]
};
dashboardmenudata = {
links: [
{url: $.vifib.buildurl($.vifib.pages.dashboard.instancelist), name: 'Instances'},
{url: $.vifib.buildurl($.vifib.pages.dashboard.computerlist), name: 'Computers'}
]
};
}(window, jQuery));
(function (window, $) {
'use strict';
var mainmenudata, librarymenudata;
$.vifib.pages.library = {
dispatch: {
url: '/library<path:url>',
action: function (args) {
var p,
mainpanel = function () {
p = $.routepriority() + 1;
$(this)
.route('add', $.vifib.pages.library.overview.url, p)
.done($.vifib.pages.library.overview.action);
$(this)
.route('add', $.vifib.pages.library.softwarelist.url, p)
.done($.vifib.pages.library.softwarelist.action);
$(this)
.route('go', $.url.getPath(), p);
};
$.vifib.render($(this), [
{template: $.vifib.panel.blank, callback: mainpanel},
{template: $.vifib.panel.menu.main, data: librarymenudata},
{template: $.vifib.panel.menu.main, data: mainmenudata}
], {template: $.vifib.header.main, data: {title: 'SlapOs'}});
}
},
overview: {
url: '/library/overview',
action: function (args) {
$.vifib.render($(this), [
{template: $.vifib.panel.library},
]);
}
},
menu: {
url: '/library',
action: function (args) {
$.vifib.render($(this), [
{template: $.vifib.panel.menu.main, data: librarymenudata},
{template: $.vifib.panel.menu.main, data: mainmenudata}
], {template: $.vifib.header.main, data: {title: 'SlapOs'}});
}
},
softwarelist: {
url: '/library/software/list',
action: function (args) {
var softlist = function () {
$.vifib.softwareList($(this));
};
$.vifib.render($(this), [
{template: $.vifib.panel.softwarelist, callback: softlist},
], {template: $.vifib.header.main, data: {title: 'SlapOs'}});
}
}
};
$.vifib.pages.software = {
dispatch: {
url: '/software<path:url>',
action: function (args) {
var p,
mainpanel = function () {
p = $.routepriority() + 1;
$(this)
.route('add', $.vifib.pages.software.show.url, p)
.done($.vifib.pages.software.show.action);
$(this)
.route('go', $.url.getPath(), p);
},
softwarelist = function () {
var softlist = function () {
$.vifib.softwareList($(this));
};
$.vifib.render($(this), [
{template: $.vifib.panel.softwarelist, callback: softlist},
]);
};
$.vifib.render($(this), [
{template: $.vifib.panel.blank, callback: mainpanel},
{template: $.vifib.panel.softwarelist, callback: softwarelist},
{template: $.vifib.panel.menu.main, data: librarymenudata}
], {template: $.vifib.header.main, data: {title: 'SlapOs'}});
}
},
show: {
url: '/software/show<path:softid>',
action: function (softid) {
$(this).slapos('softwareInfo', softid, {
success: function (response) {
$.vifib.render($(this), [
{template: $.vifib.panel.software, data: response}
], {template: $.vifib.header.main, data: {title: 'SlapOs'}});
}
});
}
}
};
mainmenudata = {
links: [
{url: $.vifib.buildurl($.vifib.pages.library.overview), name: 'Library'}
]
};
librarymenudata = {
links: [
{url: $.vifib.buildurl($.vifib.pages.library.overview), name: 'Overview'},
{url: $.vifib.buildurl($.vifib.pages.library.softwarelist), name: 'Softwares'}
]
};
}(window, jQuery));
(function (window, $) {
'use strict';
$.vifib.pages.login = {
dispatch: {
url: '/login<path:url>',
action: function (args) {
$(this)
.route('add', $.vifib.pages.login.facebook.url)
.done($.vifib.pages.login.facebook.action);
$(this)
.route('add', $.vifib.pages.login.google.url)
.done($.vifib.pages.login.google.action);
$(this)
.route('go', $.url.getPath());
}
},
facebook: {
url: '/login/facebook',
action: function (args) {
var redirect = window.location.protocol + '//' + window.location.host + window.location.pathname + $.vifib.buildurl($.vifib.pages.dashboard.menu) + '?',
fburl = 'https://www.facebook.com/dialog/oauth?' +
'client_id=' + $(document).slapos('store', 'fbappid') +
'&redirect_uri=' + encodeURIComponent(redirect) +
'&scope=email' +
'&response_type=token';
// set token type to Facebook for js library
$(document).slapos('store', 'token_type', 'Facebook');
window.location.href = fburl;
},
},
google: {
url: '/login/google',
action: function (args) {
var redirect = window.location.protocol + '//' + window.location.host + window.location.pathname,
ggurl = 'https://accounts.google.com/o/oauth2/auth?' +
'client_id=' + $(document).slapos('store', 'ggappid') +
'&redirect_uri=' + encodeURIComponent(redirect) +
'&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email++https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile' +
'&response_type=token';
$(document).slapos('store', 'token_type', 'Google');
window.location.href = ggurl;
}
},
googleRedirect: {
url: 'access_token=<path:path>',
action: function (response) {
var options = {},
option;
response = 'access_token=' + response;
$.each(response.split('&'), function (i, e) {
option = e.split('=');
options[option[0]] = option[1];
});
$.url.redirect('/dashboard', options);
}
}
};
}(window, jQuery));
(function (window, $) {
'use strict';
var mainmenudata;
$.vifib.pages.overview = {
url: '/overview',
action: function (args) {
var ccarousel = function () {
if (Modernizr.csstransforms) {
window.mySwipe = new Swipe(document.getElementById('slider'), {
speed: 800,
auto: 4000,
continous: true
});
}
},
clogin = function () {};
$.vifib.render($('body'), [
{template: $.vifib.panel.login, callback: clogin},
{template: $.vifib.panel.menu.main, data: mainmenudata},
{template: $.vifib.panel.carousel, callback: ccarousel}
], {template: $.vifib.header.main, data: {title: 'SlapOs'}});
}
};
mainmenudata = {
links: [
{url: $.vifib.buildurl($.vifib.pages.library.overview), name: 'Library'}
]
};
}(window, jQuery));
......@@ -63,7 +63,7 @@
'<a data-role="button" href="#/login/facebook">Facebook</a><br/>' +
'<a data-role="button" href="#/login/google">Google</a>' +
'</article>',
sidemenu: {
menu: {
main: '<aside><nav><ul data-role="listview">{{# links }}<li><a href="{{ url }}">{{ name }}</a></li>{{/ links }}</ul></nav></aside>',
library:
'<aside><nav>' +
......@@ -103,7 +103,7 @@
'<p><b>{{ description }}</b></p>' +
'<a data-role="button" href="#/login">Buy it for {{ price }}&euro;</a>' +
'</article>',
allsoftware:
softwarelist:
'<article>' +
'<ul data-role="listview">' +
'</ul>' +
......@@ -157,12 +157,17 @@
'</article>',
instancelist:
'<article>' +
'<a href="#/dashboard/instance/request" data-role="button">Create a new instance</a>' +
'<a href="{{ requesturl }}" data-role="button">Create a new instance</a>' +
'<ul data-role="listview">' +
'</ul>' +
'</article>',
rowinstance:
'<a href="{{ insturl }}">{{ title }}</a>',
computerlist:
'<article>' +
'<ul data-role="listview">' +
'</ul>' +
'</article>',
computer:
'<article>' +
'<h2>{{ computer_id }}</h2>' +
......
(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);
var callbacks = [];
$.vifib.render = function (context, panels, header) {
var page, i, c;
if ($('body')[0] === $(context)[0]) {
if ($.vifib.device === 'desktop' && panels.length > 1) {
page = $.vifib.multipanel(panels, 3);
} else if ($.vifib.device === 'tablet' && panels.length > 1) {
page = $.vifib.multipanel(panels, 2);
} else { // Mobile
page = $.vifib.onepanel(context, panels[0]);
}
if (header !== undefined) {
if (header.hasOwnProperty('template')) {
header.data = header.data === undefined ? undefined : header.data;
page.prepend(Mustache.render(header.template, header.data));
} else if (header.hasOwnProperty('title')) {
page.prepend(Mustache.render($.vifib.header.main, header));
}
}
if (panels[0].template !== $.vifib.panel.blank || (panels[0].template === $.vifib.panel.blank && $.vifib.device !== 'mobile')) {
$.vifib.changepage($(page));
}
} else {
$.vifib.replacepanel($(context), panels[0]);
//if ($.vifib.device === 'mobile') {
//page = $.vifib.onepanel(context, panels[0]);
//$.vifib.changepage($(page));
//} else {
//$.vifib.replacepanel($(context), panels[0]);
//}
}
// reverse to call functions from left panel to right panel
callbacks.reverse();
while ((c = callbacks.pop()) !== undefined) {
c.callback.call(c.context);
}
};
$.vifib.twopanel = function (panels, data) {
var page = $('<div data-role="page"></div>')
.append($.vifib.makecontent(panels, data));
$.vifib.onepanel = function (context, panel) {
var page = $('<div data-role="page"></div>'),
content = $('<div data-role="content"></div>'),
pandata = panel.data === undefined ? {} : panel.data;
content
.append(Mustache.render(panel.template, pandata))
.wrapInner('<section id="panel" data-type="panel"></section>');
page.append(content);
if (panel.hasOwnProperty('callback') === true) {
callbacks.push({callback: panel.callback, context: context});
}
return $(page);
};
$.vifib.threepanel = function (panels, data) {
$.vifib.multipanel = function (panels, max) {
var page = $('<div data-role="page"></div>')
.append($.vifib.makecontent(panels, data));
.append($.vifib.makecontent(panels, max));
return $(page);
};
$.vifib.replacepanel = function (context, panel, data) {
context.html(Mustache.render(panel, data));
$.vifib.replacepanel = function (context, panel) {
var data = panel.hasOwnProperty('data') ? panel.data : {};
if (context.data('type') !== 'panel') {
context = context.find(':jqmData(type=panel)');
}
context.html(Mustache.render(panel.template, data));
$(':jqmData(role=page)').trigger('pagecreate');
};
$.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'
},
divcontent = $('<div data-role="content" class="' + gridname[panels.length] + '"></div>');
for (i; i < panels.length; i += 1) {
pandata = data === undefined ? undefined : data[i];
divcontent.append($.vifib.makepanel(panels[i], pandata, i));
if (panel.hasOwnProperty('callback') === true) {
callbacks.push({callback: panel.callback, context: context});
}
return divcontent;
};
$.vifib.makepanel = function (panel, data, index) {
$.vifib.makepanel = function (panel, data, index, name) {
var blockname = [
'ui-block-a',
'ui-block-b',
......@@ -51,10 +79,36 @@
'ui-block-e'
],
divpane = $('<div class="' + blockname[index] + '">')
.append('<section id="panel-' + index + '">' + Mustache.render(panel, data) + '</section>');
.append('<section id="panel-' + name + '" data-type="panel" data-panel-position="' + name + '">' + Mustache.render(panel, data) + '</section>');
return divpane;
};
$.vifib.makecontent = function (panels, max) {
var i, j,
pancontext,
pandata,
nbpanel = panels.length > max ? max : panels.length,
panelname = [['center'], ['left', 'right'], ['left', 'right', 'center']],
gridname = {
2: 'ui-grid-a',
3: 'ui-grid-b',
4: 'ui-grid-c',
5: 'ui-grid-d'
},
divcontent = $('<div data-role="content" data-nbpanel="' + nbpanel + '" class="' + gridname[nbpanel] + '"></div>');
// reverse loop to place the main panel at right side
for (i = nbpanel - 1, j = 0; i >= 0; i -= 1, j += 1) {
pandata = panels[i].data === undefined ? {} : panels[i].data;
pancontext = $($.vifib.makepanel(panels[i].template, pandata, j, panelname[nbpanel - 1][j]));
divcontent.append(pancontext);
if (panels[i].hasOwnProperty('callback')) {
callbacks.push({callback: panels[i].callback, context: pancontext});
//panels[i].callback.call(pancontext);
}
}
return divcontent;
};
$.vifib.changepage = function (page) {
$('[id^=panel]').remove();
$('#slider').remove();
......@@ -65,4 +119,12 @@
transition: $.mobile.defaultPageTransition
});
};
$.vifib.nextpanel = function (context) {
var panelname = [['center'], ['left', 'right'], ['left', 'center', 'right']],
nbpanel = $(':jqmData(role=content)').data('nbpanel') === undefined ? 1 : $(':jqmData(role=content)').data('nbpanel'),
panelindex = panelname[nbpanel - 1].indexOf($(context).data('panel-position')),
nextpanelindex = panelindex === panelname[nbpanel - 1].length - 1 ? panelindex : panelindex + 1;
return nbpanel > 1 ? $(':jqmData(panel-position=' + panelname[nbpanel - 1][nextpanelindex] + ')') : $(context);
};
}(window, jQuery));
......@@ -43,6 +43,28 @@
}
}
});
// COMPUTER
storejs.add('computers', {
COMP0: {
computer_id: "COMP0",
software: [
{software_release: "http://example.com/example.cfg", status: "install"},
],
partition: [
{
title: "slapart1",
instance_id: "foo",
status: "start",
software_release: "http://example.com/example.cfg"
}, {
title: "slapart2",
instance_id: "bar",
status: "stop",
software_release: "http://example.com/example.cfg"
}
]
}
});
// SOFTWARE
storejs.add('softwares', {
Kvm: {
......@@ -74,15 +96,22 @@
/*********************
* RESPONSE
*********************/
// ******* INSTANCE
instance_list = function () {
var response = {list: []};
$.each(storejs.get('instances'), function (i, e) {
response.list.push('/fake/instance_info/' + e.title);
});
return response;
},
computer_list = function () {
var response = {list: []};
$.each(storejs.get('computers'), function (i, e) {
response.list.push('/fake/computer_info/' + e.computer_id);
});
return response;
};
// ******* INSTANCE
// list
fakeserver.respondWith('GET', '/fake/instance', function (xhr) {
var response = {list: []};
......@@ -113,7 +142,24 @@
status: inst.status
}));
});
// ********* COMPUTER
// list
fakeserver.respondWith('GET', '/fake/computer', function (xhr) {
var response = {list: []};
$.each(storejs.get('computers'), function (i, e) {
response.list.push('/fake/computer_info/' + e.computer_id);
});
xhr.respond(200, {'Content-Type': 'application/json'}, JSON.stringify(response));
});
// Get computer info
fakeserver.respondWith("GET", /\/fake\/computer_info\/(.*)/, function (xhr, compid) {
var computers = storejs.get('computers');
if (computers.hasOwnProperty(compid)) {
xhr.respond(200, {'Content-Type': 'application/json'}, JSON.stringify(computers[compid]));
} else {
xhr.respond(404, { 'Content-Type': 'application/json'}, 'Not found');
}
});
//********** SOFTWARE
// Get softwares list
fakeserver.respondWith('GET', '/fake/software', [
......@@ -129,6 +175,7 @@
}
});
// Overwrite ajax method to filter all request from the application
$.ajax = function (url, options) {
// it will not work with cache set to false
if (url.hasOwnProperty('cache')) { url.cache = true; }
......@@ -137,5 +184,6 @@
return result;
};
// Overwrite host
$(document).slapos('store', 'host', '/fake');
}(window, jQuery));
/* jslint */
/*global jQuery, Modernizr, $, window, document, unescape, Spinner, Mustache, Swipe, sinon */
/*global jQuery, Modernizr, $, window, document, unescape, Spinner, Mustache, Swipe, sinon, alert */
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