Commit 90d527a5 authored by Thomas Lechauve's avatar Thomas Lechauve

Transition between page work in progress

parent 41f20ba6
...@@ -47,7 +47,7 @@ $.extend({ ...@@ -47,7 +47,7 @@ $.extend({
this.list = this.list.slice(0, 0); this.list = this.list.slice(0, 0);
}, },
search: function (hash, level, failcallback, context) { search: function (hash, level, failcallback) {
var stop = false, var stop = false,
i, j, i, j,
regex, regex,
...@@ -56,6 +56,7 @@ $.extend({ ...@@ -56,6 +56,7 @@ $.extend({
level = level || 0; level = level || 0;
i = this.list.length - 1; i = this.list.length - 1;
hash.route = hash.route === "undefined" ? "/" : hash.route; hash.route = hash.route === "undefined" ? "/" : hash.route;
console.log(hash)
while ((stop === false) && (i >= level)) { while ((stop === false) && (i >= level)) {
j = 0; j = 0;
while ((stop === false) && (j < this.list[i].length)) { while ((stop === false) && (j < this.list[i].length)) {
...@@ -77,11 +78,7 @@ $.extend({ ...@@ -77,11 +78,7 @@ $.extend({
i -= 1; i -= 1;
} }
if (stop === false && failcallback !== undefined) { if (stop === false && failcallback !== undefined) {
if (context === undefined) { failcallback();
failcallback();
} else {
failcallback.call(context);
}
} }
}, },
...@@ -96,10 +93,10 @@ $.extend({ ...@@ -96,10 +93,10 @@ $.extend({
} }
}, },
start: function (hash, level) { start: function (hash, level, failcallback) {
var hashInfo = this.parseHash(hash); var hashInfo = this.parseHash(hash);
if ($.router.routes.current.route !== hashInfo.route) { if ($.router.routes.current.route !== hashInfo.route) {
this.routes.search(hashInfo, level); this.routes.search(hashInfo, level, failcallback);
} }
}, },
......
...@@ -29,6 +29,22 @@ ...@@ -29,6 +29,22 @@
margin-right: -119px; margin-right: -119px;
} }
</style> </style>
<script id="page1" type="text/html">
<header data-role="header">
<h2>Page1</h2>
</header>
<section data-role="content">
<a href="#/page2">Vers page2</a>
</section>
</script>
<script id="page2" type="text/html">
<header data-role="header">
<h2>Page2</h2>
</header>
<section data-role="content">
<a href="#/page1">Vers page1</a>
</section>
</script>
<!-- <!--
-COMPONENTS -COMPONENTS
--> -->
...@@ -109,6 +125,17 @@ ...@@ -109,6 +125,17 @@
<script id="service-inlist" type="text/html"> <script id="service-inlist" type="text/html">
<li><a href="{{ link }}"><h4>{{ name }}</h4></a></li> <li><a href="{{ link }}"><h4>{{ name }}</h4></a></li>
</script> </script>
<!--
-ERRORPAGE
-->
<script id="error" type="text/html">
{{> headbar}}
{{> content}}
</script>
<script id="notfoundPanel" type="text/html">
<h3>NOT FOUND</h3>
</script>
<!-- <!--
-HOMEPAGE -HOMEPAGE
--> -->
......
...@@ -59,19 +59,34 @@ ...@@ -59,19 +59,34 @@
methods = { methods = {
init: function () { init: function () {
var routes = [[['/', methods.showRoot]]];
return this.each(function () { return this.each(function () {
// JQM configuration // JQM configuration
// Initialize slapos in this context // Initialize slapos in this context
$(this).slapos({'host': 'http://10.8.2.34:12006/erp5/portal_vifib_rest_api_v1'}); $(this).slapos({'host': 'http://10.8.2.34:12006/erp5/portal_vifib_rest_api_v1'});
for (var level = 0; level < routes.length; level += 1) { $.router.routes.add('/page1', 0, methods.showPage1, $(this));
for (var i = 0; i < routes[level].length; i += 1) { $.router.routes.add('/page2', 0, methods.showPage2, $(this));
var r = routes[level][i]; $.router.routes.add('/', 0, methods.showRoot, $(this));
$.router.routes.add(r[0], level, r[1], $(this)); });
} },
}
showPage1: function (params) {
return this.each(function () {
var page = methods.getRender('page1');
methods.changePage(page);
}); });
}, },
showPage2: function (params) {
return this.each(function () {
var page = methods.getRender('page2');
methods.changePage(page);
});
},
changePage: function (page) {
$('body').append(page);
$.mobile.changePage(page, {changeHash: false, transition: 'slide'});
},
genInstanceUrl: function (uri) { genInstanceUrl: function (uri) {
return $.router.genHash(['instance', 'id', encodeURIComponent(uri)]); return $.router.genHash(['instance', 'id', encodeURIComponent(uri)]);
...@@ -121,6 +136,22 @@ ...@@ -121,6 +136,22 @@
}); });
}); });
}, },
// DEFAULT ERROR PAGE
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);
});
},
// ROOT // ROOT
showRoot: function (params) { showRoot: function (params) {
var route = $.router.routes.current, var route = $.router.routes.current,
...@@ -136,7 +167,7 @@ ...@@ -136,7 +167,7 @@
if ($.router.routes.isCurrent(params.route)) { if ($.router.routes.isCurrent(params.route)) {
$.router.redirect('/homepage'); $.router.redirect('/homepage');
} else { } else {
$.router.start(params.route, nextLevel); $.router.start(params.route, nextLevel, methods.noRoute);
} }
}, },
...@@ -229,7 +260,7 @@ ...@@ -229,7 +260,7 @@
/* FAKE *********/ /* FAKE *********/
$.router.routes.add('/library/software/:software_url', nextLevel, methods.showSoftware, $(this)); $.router.routes.add('/library/software/:software_url', nextLevel, methods.showSoftware, $(this));
/****************/ /****************/
$.router.start(params.route, nextLevel); $.router.start(params.route, nextLevel, methods.noRoute);
}); });
}, },
...@@ -247,7 +278,7 @@ ...@@ -247,7 +278,7 @@
}); });
}, },
showLibraryAll: function () { showLibraryAll: function (params) {
return this.each(function () { return this.each(function () {
var options = { var options = {
'title': 'All softwares', 'title': 'All softwares',
...@@ -330,7 +361,7 @@ ...@@ -330,7 +361,7 @@
// Routing // Routing
$.router.routes.add('/instance/id/:id', nextLevel, methods.showInstance, $(this)); $.router.routes.add('/instance/id/:id', nextLevel, methods.showInstance, $(this));
if (params.route !== '/instance') { if (params.route !== '/instance') {
$.router.start(params.route, nextLevel); $.router.start(params.route, nextLevel, methods.noRoute);
} else { } else {
//table.vifib('refresh', methods.refreshListInstance, 30); //table.vifib('refresh', methods.refreshListInstance, 30);
$(this).slapos('instanceList', { $(this).slapos('instanceList', {
...@@ -385,7 +416,7 @@ ...@@ -385,7 +416,7 @@
$.router.routes.add('/instance/id/:id', nextLevel, methods.showInstance, $(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')); $.router.routes.add('/instance/id/:id/bang', nextLevel, methods.showBangInstance, $(this).find('.content-primary'));
if ($.router.routes.isCurrent(params) === false) { if ($.router.routes.isCurrent(params) === false) {
$.router.start(params.route); $.router.start(params.route, nextLevel, methods.noRoute);
} }
}); });
}, },
...@@ -622,7 +653,7 @@ ...@@ -622,7 +653,7 @@
getRender: function (template, data, raw) { getRender: function (template, data, raw) {
raw = raw || true; raw = raw || true;
return ich[template](data, raw); return $('<div></div>').html(ich[template](data, raw)).attr('data-role', 'page');
}, },
renderAppend: function (template, data, raw) { renderAppend: function (template, data, raw) {
...@@ -672,3 +703,5 @@ ...@@ -672,3 +703,5 @@
$(document).ready(function () { $(document).ready(function () {
$('body').vifib(); $('body').vifib();
}); });
...@@ -47,7 +47,7 @@ $.extend({ ...@@ -47,7 +47,7 @@ $.extend({
this.list = this.list.slice(0, 0); this.list = this.list.slice(0, 0);
}, },
search: function (hash, level, failcallback, context) { search: function (hash, level, failcallback) {
var stop = false, var stop = false,
i, j, i, j,
regex, regex,
...@@ -56,6 +56,7 @@ $.extend({ ...@@ -56,6 +56,7 @@ $.extend({
level = level || 0; level = level || 0;
i = this.list.length - 1; i = this.list.length - 1;
hash.route = hash.route === "undefined" ? "/" : hash.route; hash.route = hash.route === "undefined" ? "/" : hash.route;
console.log(hash)
while ((stop === false) && (i >= level)) { while ((stop === false) && (i >= level)) {
j = 0; j = 0;
while ((stop === false) && (j < this.list[i].length)) { while ((stop === false) && (j < this.list[i].length)) {
...@@ -77,11 +78,7 @@ $.extend({ ...@@ -77,11 +78,7 @@ $.extend({
i -= 1; i -= 1;
} }
if (stop === false && failcallback !== undefined) { if (stop === false && failcallback !== undefined) {
if (context === undefined) { failcallback();
failcallback();
} else {
failcallback.call(context);
}
} }
}, },
...@@ -96,10 +93,10 @@ $.extend({ ...@@ -96,10 +93,10 @@ $.extend({
} }
}, },
start: function (hash, level) { start: function (hash, level, failcallback) {
var hashInfo = this.parseHash(hash); var hashInfo = this.parseHash(hash);
if ($.router.routes.current.route !== hashInfo.route) { if ($.router.routes.current.route !== hashInfo.route) {
this.routes.search(hashInfo, level); this.routes.search(hashInfo, level, failcallback);
} }
}, },
......
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