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 ...@@ -39,14 +39,14 @@ $(DEVDIR)/js/fake.js: js/utils/fake.js
cp $< $@ cp $< $@
# Sort files for concatenation # 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 CATCSSFILES = $(DEVDIR)/lib/qunit.css $(DEVDIR)/lib/jquery.mobile.css
# List all javascript files except tests files and lib files # 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) manifest: $(APPDIR)/index.html $(APPDIR)/$(DEVJS) $(APPDIR)/$(DEVCSS)
@if test -f $(MANIFESTNAME); then \ @if test -f $(MANIFESTNAME); then \
...@@ -54,14 +54,13 @@ manifest: $(APPDIR)/index.html $(APPDIR)/$(DEVJS) $(APPDIR)/$(DEVCSS) ...@@ -54,14 +54,13 @@ manifest: $(APPDIR)/index.html $(APPDIR)/$(DEVJS) $(APPDIR)/$(DEVCSS)
else \ else \
echo "CACHE MANIFEST" > $(MANIFESTNAME); \ echo "CACHE MANIFEST" > $(MANIFESTNAME); \
echo "#rel 1" >> $(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 fi
$(APPDIR)/index.html: index.html $(APPDIR)/index.html: index.html
@mkdir -p $(@D) @mkdir -p $(@D)
cp $< $@ cp $< $@
# Lint javascript files #
$(DEVDIR)/js/%.js: js/%.js $(DEVDIR)/js/%.js: js/%.js
@mkdir -p $(@D) @mkdir -p $(@D)
@# Prepend jslintrc to defined global variables # @# Prepend jslintrc to defined global variables #
...@@ -101,7 +100,7 @@ $(DEVDIR)/lib/jquery.mobile.zip: ...@@ -101,7 +100,7 @@ $(DEVDIR)/lib/jquery.mobile.zip:
@mkdir -p $(APPDIR) @mkdir -p $(APPDIR)
curl -s -o $@ http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.zip curl -s -o $@ http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.zip
unzip $@ -d $(DEVDIR) 'jquery.mobile-?.?.?/images/*' 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 rm -rf $(DEVDIR)/jquery.mobile-1.1.0
$(DEVDIR)/lib/mustache.js: $(DEVDIR)/lib/mustache.js:
...@@ -171,7 +170,7 @@ $(DEVDIR)/tests/%_test.html.ok: $(DEVDIR)/tests/%_test.html $(DEVDIR)/tests/%_te ...@@ -171,7 +170,7 @@ $(DEVDIR)/tests/%_test.html.ok: $(DEVDIR)/tests/%_test.html $(DEVDIR)/tests/%_te
######################################### #########################################
clean: clean:
@echo soft cleaning @echo soft cleaning
rm -rf $(APPDIR) rm -rf $(APPDIR)/*.*
cleanall: cleanall:
@echo cleaning @echo cleaning
rm -rf $(DEVDIR) ${RELDIR} $(TARBALL) rm -rf $(DEVDIR) ${RELDIR} $(TARBALL)
<!DOCTYPE HTML> <!DOCTYPE HTML>
<html manifest="slapos.manifest"> <!--<html manifest="slapos.manifest">-->
<html>
<head> <head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"> <meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
......
...@@ -4,8 +4,53 @@ $(document).bind('mobileinit', function () { ...@@ -4,8 +4,53 @@ $(document).bind('mobileinit', function () {
if (!$.vifib) { if (!$.vifib) {
$.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 //SlapOs configuration
$(document).slapos({ $(document).slapos({
// REST API url // REST API url
......
...@@ -131,7 +131,7 @@ ...@@ -131,7 +131,7 @@
}, },
computerList: function (args) { computerList: function (args) {
return $(this).slapos('request', '', args); return $(this).slapos('request', 'GET', '/computer', args);
}, },
computerInfo: function (url, args) { computerInfo: function (url, args) {
......
...@@ -15,66 +15,66 @@ ...@@ -15,66 +15,66 @@
$.vifib.devices = { $.vifib.devices = {
"mobile": function (url) { "mobile": function (url) {
$('body') $('body')
.route('add', '') .route('add', $.vifib.pages.overview.url)
.done($.vifib.mobile.overview); .done($.vifib.pages.overview.action);
$('body') //$('body')
.route('add', '/login/facebook') //.route('add', '')
.done($.vifib.login.facebook); //.done($.vifib.mobile.overview);
$('body') //$('body')
.route('add', '/login/google') //.route('add', '/login/facebook')
.done($.vifib.login.google); //.done($.vifib.login.facebook);
//$('body')
//.route('add', '/login/google')
//.done($.vifib.login.google);
// when Google send back the token, it reset hashtag from url // when Google send back the token, it reset hashtag from url
$('body') //$('body')
.route('add', 'access_token=<path:path>') //.route('add', '/overview')
.done($.vifib.login.googleRedirect); //.done($.vifib.mobile.overview);
$('body') //$('body')
.route('add', '/overview') //.route('add', '/library<path:url>')
.done($.vifib.mobile.overview); //.done($.vifib.mobile.library.dispatch);
$('body') //$('body')
.route('add', '/library<path:url>') //.route('add', '/dashboard<path:url>')
.done($.vifib.mobile.library.dispatch); //.done($.vifib.mobile.dashboard.dispatch);
$('body')
.route('add', '/dashboard<path:url>')
.done($.vifib.mobile.dashboard.dispatch);
}, },
"tablet": function () { "tablet": function () {
$('body') $('body')
.route('add', '') .route('add', $.vifib.pages.overview.url)
.done($.vifib.tablet.overview); .done($.vifib.pages.overview.action);
$('body') //$('body')
.route('add', '/login/facebook') //.route('add', '/login/facebook')
.done($.vifib.login.facebook); //.done($.vifib.login.facebook);
$('body') //$('body')
.route('add', '/login/google') //.route('add', '/login/google')
.done($.vifib.login.google); //.done($.vifib.login.google);
// when Google send back the token, it reset hashtag from url //when Google send back the token, it reset hashtag from url
$('body') //$('body')
.route('add', 'access_token=<path:path>') //.route('add', 'access_token=<path:path>')
.done($.vifib.login.googleRedirect); //.done($.vifib.login.googleRedirect);
$('body') //$('body')
.route('add', '/overview') //.route('add', '/overview')
.done($.vifib.tablet.overview); //.done($.vifib.tablet.overview);
$('body') //$('body')
.route('add', '/library<path:url>') //.route('add', '/library<path:url>')
.done($.vifib.tablet.library.dispatch); //.done($.vifib.tablet.library.dispatch);
$('body') //$('body')
.route('add', '/dashboard<path:url>') //.route('add', '/dashboard<path:url>')
.done($.vifib.tablet.dashboard.dispatch); //.done($.vifib.tablet.dashboard.dispatch);
}, },
"desktop": function () { "desktop": function () {
$('body') $('body')
.route('add', '') .route('add', $.vifib.pages.overview.url)
.done($.vifib.desktop.redirect); .done($.vifib.pages.overview.action);
$('body') //$('body')
.route('add', '<path:url>') //.route('add', '<path:url>')
.done($.vifib.desktop.dispatch); //.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
...@@ -110,15 +110,18 @@ ...@@ -110,15 +110,18 @@
$(document).ready(function () { $(document).ready(function () {
// bind on resize screen event // bind on resize screen event
$(window).resize(function () { $(window).resize(function () {
setTimeout(function () { if ($(window).data('resizing')) {
clearTimeout($(window).data('resizing'));
}
$(window).data('resizing', setTimeout(function () {
var curdevice = getDevice($(window).width()); var curdevice = getDevice($(window).width());
if ($.vifib.device !== curdevice) { if ($.vifib.device !== curdevice) {
$.vifib.device = curdevice; $.vifib.device = curdevice;
$.routereset(); $.routereset();
$.vifib.devices[$.vifib.device](); $.vifib.initroutes();
$.vifib.startrouter(); $.vifib.startrouter();
} }
}, 800); }, 800));
}); });
// Url change event // Url change event
...@@ -127,7 +130,7 @@ ...@@ -127,7 +130,7 @@
if (options.hasOwnProperty('access_token')) { if (options.hasOwnProperty('access_token')) {
$(document).slapos('access_token', options.access_token); $(document).slapos('access_token', options.access_token);
} }
$.vifib.devices[$.vifib.device](); $.vifib.initroutes();
$.vifib.startrouter(); $.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, $) { (function (window, $) {
'use strict'; '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 = { $.vifib.statuscode = {
400: function (jqxhr, textstatus) { 400: function (jqxhr, textstatus) {
var page; var page;
...@@ -115,7 +82,7 @@ ...@@ -115,7 +82,7 @@
$.vifib.fillRowInstance = function (list, row, instid) { $.vifib.fillRowInstance = function (list, row, instid) {
return row.slapos('instanceInfo', instid, { return row.slapos('instanceInfo', instid, {
success: function (response) { success: function (response) {
$.extend(response, {insturl: '#/dashboard/instance/id' + instid}); $.extend(response, {insturl: '#/instance/show' + instid});
$(this).html(Mustache.render($.vifib.panel.rowinstance, response)); $(this).html(Mustache.render($.vifib.panel.rowinstance, response));
}, },
complete: function (jqxhr, textstatus) { complete: function (jqxhr, textstatus) {
...@@ -144,7 +111,7 @@ ...@@ -144,7 +111,7 @@
return context.each(function () { return context.each(function () {
$(this).slapos('softwareInfo', softid, { $(this).slapos('softwareInfo', softid, {
success: function (response) { success: function (response) {
$.extend(response, {softurl: '#/library/software/id' + softid}); $.extend(response, {softurl: '#/software/show' + softid});
$(this).html(Mustache.render($.vifib.panel.rowsoftware, response)); $(this).html(Mustache.render($.vifib.panel.rowsoftware, response));
}, },
statusCode: $.extend(false, $.vifib.statuscode, {}) statusCode: $.extend(false, $.vifib.statuscode, {})
...@@ -155,11 +122,14 @@ ...@@ -155,11 +122,14 @@
return context.each(function () { return context.each(function () {
$(this).slapos('computerInfo', compid, { $(this).slapos('computerInfo', compid, {
success: function (response) { success: function (response) {
$.extend(response, {compurl: '#/dashboard/computer/id/' + compid}); $.extend(response, {compurl: '#/computer/show' + compid});
$(this).html(Mustache.render($.vifib.panel.rowcomputer, response)); $(this).html(Mustache.render($.vifib.panel.rowcomputer, response));
}, },
statusCode: $.extend(false, $.vifib.statuscode, {}) statusCode: $.extend(false, $.vifib.statuscode, {})
}); });
}); });
}; };
$.vifib.buildurl = function (panel) {
return '#' + panel.url;
};
}(window, jQuery)); }(window, jQuery));
This diff is collapsed.
(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 @@ ...@@ -63,7 +63,7 @@
'<a data-role="button" href="#/login/facebook">Facebook</a><br/>' + '<a data-role="button" href="#/login/facebook">Facebook</a><br/>' +
'<a data-role="button" href="#/login/google">Google</a>' + '<a data-role="button" href="#/login/google">Google</a>' +
'</article>', '</article>',
sidemenu: { menu: {
main: '<aside><nav><ul data-role="listview">{{# links }}<li><a href="{{ url }}">{{ name }}</a></li>{{/ links }}</ul></nav></aside>', main: '<aside><nav><ul data-role="listview">{{# links }}<li><a href="{{ url }}">{{ name }}</a></li>{{/ links }}</ul></nav></aside>',
library: library:
'<aside><nav>' + '<aside><nav>' +
...@@ -103,7 +103,7 @@ ...@@ -103,7 +103,7 @@
'<p><b>{{ description }}</b></p>' + '<p><b>{{ description }}</b></p>' +
'<a data-role="button" href="#/login">Buy it for {{ price }}&euro;</a>' + '<a data-role="button" href="#/login">Buy it for {{ price }}&euro;</a>' +
'</article>', '</article>',
allsoftware: softwarelist:
'<article>' + '<article>' +
'<ul data-role="listview">' + '<ul data-role="listview">' +
'</ul>' + '</ul>' +
...@@ -157,12 +157,17 @@ ...@@ -157,12 +157,17 @@
'</article>', '</article>',
instancelist: instancelist:
'<article>' + '<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 data-role="listview">' +
'</ul>' + '</ul>' +
'</article>', '</article>',
rowinstance: rowinstance:
'<a href="{{ insturl }}">{{ title }}</a>', '<a href="{{ insturl }}">{{ title }}</a>',
computerlist:
'<article>' +
'<ul data-role="listview">' +
'</ul>' +
'</article>',
computer: computer:
'<article>' + '<article>' +
'<h2>{{ computer_id }}</h2>' + '<h2>{{ computer_id }}</h2>' +
......
(function (window, $) { (function (window, $) {
'use strict'; 'use strict';
$.vifib.onepanel = function (panel, data) { var callbacks = [];
var page = $('<div data-role="page"></div>'), $.vifib.render = function (context, panels, header) {
content = $('<div data-role="content"></div>') var page, i, c;
.append(Mustache.render(panel, data)); if ($('body')[0] === $(context)[0]) {
page.append(content); if ($.vifib.device === 'desktop' && panels.length > 1) {
return $(page); 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) { $.vifib.onepanel = function (context, panel) {
var page = $('<div data-role="page"></div>') var page = $('<div data-role="page"></div>'),
.append($.vifib.makecontent(panels, data)); 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); return $(page);
}; };
$.vifib.threepanel = function (panels, data) { $.vifib.multipanel = function (panels, max) {
var page = $('<div data-role="page"></div>') var page = $('<div data-role="page"></div>')
.append($.vifib.makecontent(panels, data)); .append($.vifib.makecontent(panels, max));
return $(page); return $(page);
}; };
$.vifib.replacepanel = function (context, panel, data) { $.vifib.replacepanel = function (context, panel) {
context.html(Mustache.render(panel, data)); 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'); $(':jqmData(role=page)').trigger('pagecreate');
}; if (panel.hasOwnProperty('callback') === true) {
callbacks.push({callback: panel.callback, context: context});
$.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));
} }
return divcontent;
}; };
$.vifib.makepanel = function (panel, data, index) { $.vifib.makepanel = function (panel, data, index, name) {
var blockname = [ var blockname = [
'ui-block-a', 'ui-block-a',
'ui-block-b', 'ui-block-b',
...@@ -51,10 +79,36 @@ ...@@ -51,10 +79,36 @@
'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-' + name + '" data-type="panel" data-panel-position="' + name + '">' + Mustache.render(panel, data) + '</section>');
return divpane; 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) { $.vifib.changepage = function (page) {
$('[id^=panel]').remove(); $('[id^=panel]').remove();
$('#slider').remove(); $('#slider').remove();
...@@ -65,4 +119,12 @@ ...@@ -65,4 +119,12 @@
transition: $.mobile.defaultPageTransition 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)); }(window, jQuery));
...@@ -43,6 +43,28 @@ ...@@ -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 // SOFTWARE
storejs.add('softwares', { storejs.add('softwares', {
Kvm: { Kvm: {
...@@ -74,15 +96,22 @@ ...@@ -74,15 +96,22 @@
/********************* /*********************
* RESPONSE * RESPONSE
*********************/ *********************/
// ******* INSTANCE
instance_list = function () { instance_list = function () {
var response = {list: []}; var response = {list: []};
$.each(storejs.get('instances'), function (i, e) { $.each(storejs.get('instances'), function (i, e) {
response.list.push('/fake/instance_info/' + e.title); response.list.push('/fake/instance_info/' + e.title);
}); });
return response; return response;
},
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 // list
fakeserver.respondWith('GET', '/fake/instance', function (xhr) { fakeserver.respondWith('GET', '/fake/instance', function (xhr) {
var response = {list: []}; var response = {list: []};
...@@ -113,7 +142,24 @@ ...@@ -113,7 +142,24 @@
status: inst.status 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 //********** SOFTWARE
// Get softwares list // Get softwares list
fakeserver.respondWith('GET', '/fake/software', [ fakeserver.respondWith('GET', '/fake/software', [
...@@ -129,6 +175,7 @@ ...@@ -129,6 +175,7 @@
} }
}); });
// Overwrite ajax method to filter all request from the application
$.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; }
...@@ -137,5 +184,6 @@ ...@@ -137,5 +184,6 @@
return result; return result;
}; };
// Overwrite host
$(document).slapos('store', 'host', '/fake'); $(document).slapos('store', 'host', '/fake');
}(window, jQuery)); }(window, jQuery));
/* jslint */ /* 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