Commit 3fedf9fa authored by Thomas Lechauve's avatar Thomas Lechauve

Separate project in multiple files

parent 90d527a5
......@@ -349,17 +349,24 @@
</div>
</script>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="static/js/ICanHaz.min.js"></script>
<script type="text/javascript" src="static/js/swipe.min.js"></script>
<script type="text/javascript" src="static/js/modernizr-2.5.3.js"></script>
<script type="text/javascript" src="static/js/sinon-1.3.2.js"></script>
<script type="text/javascript" src="static/js/jquery.slapos.js"></script>
<script type="text/javascript" src="static/js/jquery.urljs.js"></script>
<script type="text/javascript" src="static/js/libs/jquery-1.7.2.js"></script>
<script type="text/javascript" src="static/js/libs/ICanHaz.min.js"></script>
<script type="text/javascript" src="static/js/libs/swipe.min.js"></script>
<script type="text/javascript" src="static/js/libs/modernizr-2.5.3.js"></script>
<script type="text/javascript" src="static/js/libs/sinon-1.3.2.js"></script>
<script type="text/javascript" src="static/js/libs/jquery.slapos.js"></script>
<script type="text/javascript" src="static/js/libs/jquery.urljs.js"></script>
<script type="text/javascript" src="static/js/fake.js"></script>
<script type="text/javascript" src="static/js/jqm-config.js"></script>
<script type="text/javascript" src="static/js/core.js"></script>
<script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
<script type="text/javascript" src="static/js/vifib.utils.js"></script>
<script type="text/javascript" src="static/js/vifib.core.js"></script>
<script type="text/javascript" src="static/js/pages/vifib.homepage.js"></script>
<script type="text/javascript" src="static/js/pages/vifib.dashboard.js"></script>
<script type="text/javascript" src="static/js/pages/vifib.instance.js"></script>
<script type="text/javascript" src="static/js/pages/vifib.library.js"></script>
<script type="text/javascript" src="static/js/pages/vifib.login.js"></script>
<script type="text/javascript" src="static/js/vifib.init.js"></script>
<script type="text/javascript" src="static/js/libs/jquery.mobile-1.1.0.js"></script>
</head>
<body>
</body>
......
This diff is collapsed.
This diff is collapsed.
$.extend(methods, {
showDashboard: function (params) {
return this.each(function () {
var mainPanel = $(this).vifib('getRender', 'dashboardPanel'),
options = {
'title': 'Dashboard',
'mainPanel': mainPanel
},
page = $(this).vifib('getPageRender', 'dashboard', options);
methods.changePage(page);
});
}
});
$.extend(methods, {
noRoute: function (params) {
$.router.routes.add('/notfound', 1, methods.showNotFound, $(":jqmData(role=page)"));
$.router.redirect('/notfound');
},
showNotFound: function (params) {
return this.each(function () {
var options = {
'title': 'Error',
'mainPanel': $(this).vifib('getRender', 'notfoundPanel')
};
$(this).vifib('render', 'error', options);
});
}
})
/*
*HOMEPAGE
*/
$.extend(methods, {
showHomepage: function (params) {
return this.each(function () {
var options = {
'title': 'Vifib',
'mainPanel': $(this).vifib('getRender', 'homepagePanel'),
'headmenu': true,
'headlinks': [
{'name': 'Software library', 'link': '#/library'},
{'name': 'Documentation', 'link': '#/documentation'}
]
};
$(this).vifib('render', 'homepage', options);
if ( Modernizr.csstransforms ) {
window.mySwipe = new Swipe(document.getElementById('slider'), {
speed: 800,
auto: 5000
});
}
});
}
});
// SERVICES // INSTANCES
$.extend(methods, {
showInstanceList: function (params) {
return this.each(function () {
var nextLevel = $.router.routes.current.level + 1,
statusCode = {
401: redirect,
402: payment,
404: notFound,
500: serverError,
503: serverError
},
options = {
'title': 'My Services',
'mainPanel': $(this).vifib('getRender', 'instance.list'),
'leftbutton': {
'link': $(this).vifib('isAuthenticated') ? '#/dashboard' : '#/homepage',
'icon': 'home',
'title': 'Homepage'
},
'rightbutton': {
'link': '/instance/new',
'icon': 'plus',
'title': 'add service'
}
},
listview = $(this).vifib('render', 'instance', options).find('#instance-list');
// Routing
$.router.routes.add('/instance/id/:id', nextLevel, methods.showInstance, $(this));
if (params.route !== '/instance') {
$.router.start(params.route, nextLevel, methods.noRoute);
} else {
//table.vifib('refresh', methods.refreshListInstance, 30);
$(this).slapos('instanceList', {
success: function (data) {
if (typeof (data) !== "object") {
data = $.parseJSON(data);
}
$.each(data.list, function () {
var url = this.toString(),
row = $('<li></li>').vifib('fillRowInstance', url);
//row.vifib('refresh', methods.refreshRowInstance, 30);
listview.append(row).listview('refresh');
});
},
statusCode: statusCode
});
}
});
},
fillRowInstance: function (url) {
return this.each(function () {
$(this).slapos('instanceInfo', url, {
success: function (instance) {
if (typeof (instance) !== "object") {
instance = $.parseJSON(instance);
}
$.extend(instance, {'instance_url': methods.genInstanceUrl(url)});
$(this).vifib('render', 'instance.listitem', instance);
}
});
});
},
showInstanceRoot: function (params) {
return this.each(function () {
var nextLevel = $.router.routes.current.level + 1,
options = {
'title': 'Service',
'menu': 'true',
'leftbutton': {
'link': $(this).vifib('isAuthenticated') ? '#/dashboard' : '#/homepage',
'icon': 'home',
'title': 'Homepage'
},
'menulinks': [
{'link': '#/instance', 'name': 'All services'}
],
};
$(this).vifib('render', 'instance', options);
$.router.routes.add('/instance/list', nextLevel, methods.showInstanceList, $(this).find('.content-primary'));
$.router.routes.add('/instance/id/:id', nextLevel, methods.showInstance, $(this).find('.content-primary'));
$.router.routes.add('/instance/id/:id/bang', nextLevel, methods.showBangInstance, $(this).find('.content-primary'));
if ($.router.routes.isCurrent(params) === false) {
$.router.start(params.route, nextLevel, methods.noRoute);
}
});
},
showInstance: function (params) {
return this.each(function () {
var statusCode = {
401: redirect,
402: payment,
404: notFound,
500: serverError
},
nextLevel = $.router.routes.current.level + 1;
$(this).slapos('instanceInfo', params.id, {
success: function (response) {
if (typeof (response) !== "object") {
response = $.parseJSON(response);
}
var content = {
'information': [
{'name': 'Reference', 'value': response.instance_id},
{'name': 'Status', 'value': response.status},
{'name': 'Software release', 'value': response.software_release},
{'name': 'Software type', 'value': response.software_type}
],
'actions': [
{'name': 'Bang', 'link': methods.genBangUrl(params.id)},
{'name': 'Rename', 'link': '#/instance/rename'}
]
};
//response.status = $(this).vifib('getRender', 'instance.' + response.status);
response.actions = [
{'name': "Bang", 'url': methods.genBangUrl(decodeURIComponent(params.id))}
];
$.extend(response, content);
$(this).vifib('render', 'instancePanel', response);
//var form = $(this).find("#instance-form");
//form.vifib('prepareForm');
},
statusCode: statusCode
});
})
},
showBangInstance: function (params) {
var statusCode = {
400: bad_request,
401: redirect,
402: payment,
404: notFound,
500: serverError
};
return this.each(function () {
console.log("plop")
$(this).vifib('render', 'instance.bangPanel');
$(this).find('#form-bang').submit(function () {
var data = $(this).serializeObject(),
uri = methods.extractInstanceURIFromHashtag();
$(this).slapos('instanceBang', uri, {
data: data,
statusCode: statusCode,
success: function () {
$.redirect(['instance', encodeURIComponent(uri)]);
}
});
return false;
});
});
}
})
/*
*LIBRARY
*/
$.extend(methods, {
showLibrary: function (params) {
return this.each(function () {
var i, item, nextLevel,
/* FAKE ************/
data = {
'most': [
{'link': '#/library/software/kvm', 'name': 'Kvm'},
{'link': '#/library/software/kvm', 'name': 'Kvm'},
],
'new': [
{'link': '#/library', 'name': 'Another Kvm'}
],
'newCount': '1'
},
/*******************/
options = {
'title': 'Library',
'mainPanel': $(this).vifib('getRender', 'libraryPanel', data),
'leftbutton': {
'link': $(this).vifib('isAuthenticated') ? '#/dashboard' : '#/homepage',
'icon': 'home',
'title': 'Homepage'
},
'menu': true,
'menulinks': [
{'link': '#/library/all', 'name': 'All softwares'}
],
'footlinks': [
{'link': '#/library', 'name': 'Library'},
{'link': '#/documentation', 'name': 'Documentation'}
],
};
$(this).vifib('render', 'library', options);
nextLevel = $.router.routes.current.level + 1;
$.router.routes.add('/library/all', nextLevel, methods.showLibraryAll, $(this));
/* FAKE *********/
$.router.routes.add('/library/software/:software_url', nextLevel, methods.showSoftware, $(this));
/****************/
$.router.start(params.route, nextLevel, methods.noRoute);
});
},
showLibraryAll: function (params) {
return this.each(function () {
var options = {
'title': 'All softwares',
'mainPanel': $(this).vifib('getRender', 'library.allPanel'),
'leftbutton': {
'link': $(this).vifib('isAuthenticated') ? '#/dashboard' : '#/homepage',
'icon': 'home',
'title': 'Homepage'
}
},
listview = $(this).vifib('render', 'library.all', options).find('#software-list');
$(this).slapos('softwareList', {
success: function (response) {
if (typeof (response) !== "object") {
response = $.parseJSON(response);
}
$.each(response.list, function () {
var url = this.toString(),
row = $('<li></li>').vifib('fillRowSoftware', url);
listview.append(row).listview('refresh');
})
}
})
});
},
fillRowSoftware: function (uri) {
return this.each(function () {
$(this).slapos('softwareInfo', uri, {
success: function (response) {
if (typeof (response) !== "object") {
response = $.parseJSON(response);
}
$.extend(response, {'software_url': methods.genSoftwareUrl(uri)});
$(this).vifib('render', 'software.listitem', response);
}
})
});
},
showSoftware: function (params) {
return this.each(function () {
$(this).slapos('softwareInfo', params.software_url, {
success: function (response) {
var options = {
'title': response.name,
'mainPanel': $(this).vifib('getRender', 'softwarePanel', response),
'leftbutton': {
'link': $(this).vifib('isAuthenticated') ? '#/dashboard' : '#/homepage',
'icon': 'home',
'title': 'Homepage'
},
'menu': true,
'menulinks': [
{'link': '#/library/all', 'name': 'All softwares'}
],
'menu-extension': 'From the same category',
'menuextlinks': [
{'link': '#/library/software/html5', 'name': 'Html5 AS'}
]
}
$.extend(options, response)
$(this).vifib('render', 'software', options);
}
})
});
}
});
//LOGIN
$.extend(methods, {
showLogin: function (params) {
return this.each(function () {
var mainPanel = $(this).vifib('getRender', 'loginPanel'),
options = {
'title': 'Vifib',
'mainPanel': mainPanel,
'leftbutton': {
'link': '#/homepage',
'icon': 'home',
'title': 'Homepage'
}
},
nextLevel = $.router.routes.current.level + 1;
$(this).vifib('render', 'login', options);
});
},
});
/** * NEXEDI
* Author: Thomas Lechauve
* Date: 4/17/12
*/
var methods = {
// URL GENERATORS / EXTRACTORS
genInstanceUrl: function (uri) {
return $.router.genHash(['instance', 'id', encodeURIComponent(uri)]);
},
genSoftwareUrl: function (uri) {
return $.router.genHash(['library', 'software', encodeURIComponent(uri)]);
},
genBangUrl: function (uri) {
return methods.genInstanceUrl(uri) + "/bang";
},
extractInstanceURIFromHref: function () {
return decodeURIComponent($(this).attr('href').split('/').pop());
},
extractInstanceURIFromHashtag: function () {
var loc = window.location.href.split('#')[1].split('/'),
i = $.inArray("instance", loc);
return (i !== -1 && loc.length > i) ? decodeURIComponent(loc[i + 1]) : "";
},
// AUTHENTICATION
isAuthenticated: function () {
// TODO
return true;
},
// RENDER
changePage: function (page) {
$('body').append($(page));
$.mobile.changePage($(page), {changeHash: false, transition: $.mobile.defaultPageTransition});
},
render: function (template, data, raw) {
raw = raw || true;
return this.each(function () {
$(this).html(ich[template](data, raw));
$(this).trigger('pagecreate');
});
},
getRender: function (template, data, raw) {
raw = raw || true;
return ich[template](data, raw);
},
getPageRender: function (template, data, raw) {
return $('<div></div>').html(methods.getRender(template, data, raw)).attr('data-role', 'page');
},
renderAppend: function (template, data, raw) {
raw = raw || true;
return this.each(function () {
$(this).append(ich[template](data, raw));
$(this).trigger('pagecreate');
});
},
renderPrepend: function (template, data, raw) {
raw = raw || true;
return this.each(function () {
$(this).prepend(ich[template](data, raw));
$(this).trigger('pagecreate');
});
}
};
$.fn.vifib = function (method) {
if (methods[method]) {
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.vifib' );
}
};
/**
* NEXEDI
* Author: Thomas Lechauve
* Date: 6/28/12
*/
$(document).ready(function () {
var appContext = $('body');
//$.router.routes.add('/homepage', 0, appContext.vifib('showHomepage'));
//$.router.routes.add('/library', 0, appContext.vifib('showLibrary'));
//$.router.routes.add('/documentation', 0, appContext.vifib('showDocumentation'));
$.router.routes.add('/dashboard', 0, appContext.vifib('showDashboard'));
//$.router.routes.add('/instance', 0, appContext.vifib('showInstanceRoot'));
//$.router.routes.add('/login', 0, appContext.vifib('showLogin'));
appContext.slapos({'host': 'http://10.8.2.34:12006/erp5/portal_vifib_rest_api_v1'});
});
// UTILS
$.fn.substractLists = function (l1, l2) {
var newList = [];
$.each(l2, function () {
if ($.inArray(this.toString(), l1) === -1) {
newList.push(this.toString());
}
});
return newList;
};
/* Thanks to Ben Alman
* https://raw.github.com/cowboy/jquery-misc/master/jquery.ba-serializeobject.js
*/
$.fn.serializeObject = function () {
var obj = {};
$.each(this.serializeArray(), function (i, o) {
var n = o.name,
v = o.value;
obj[n] = obj[n] === undefined ? v
: $.isArray(obj[n]) ? obj[n].concat(v)
: [ obj[n], v ];
});
return obj;
};
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