Commit 7f42bc1b authored by Thomas Lechauve's avatar Thomas Lechauve

new routing system implemented

parent b3ee8da5
...@@ -36,15 +36,16 @@ $.extend({ ...@@ -36,15 +36,16 @@ $.extend({
search: function (hash) { search: function (hash) {
var stop = false, var stop = false,
i = 0, j = 0, i, j,
regex, regex,
result, result,
extracted; extracted;
while ((stop === false) && (i < this.list.length)) { i = this.list.length - 1;
while ((stop === false) && (i >= 0)) {
j = 0; j = 0;
while ((stop === false) && (j < this.list[i].length)) { while ((stop === false) && (j < this.list[i].length)) {
extracted = $.router.extractKeys(this.list[i][j].route); extracted = $.router.extractKeys(this.list[i][j].route);
regex = new RegExp('^' + extracted.regex + '$'); regex = new RegExp(extracted.regex);
if (regex.test(hash.route)) { if (regex.test(hash.route)) {
result = regex.exec(hash.route); result = regex.exec(hash.route);
stop = true; stop = true;
...@@ -57,7 +58,7 @@ $.extend({ ...@@ -57,7 +58,7 @@ $.extend({
} }
j += 1; j += 1;
} }
i += 1; i -= 1;
} }
} }
}, },
......
...@@ -281,9 +281,8 @@ ...@@ -281,9 +281,8 @@
{{ message }} {{ message }}
</div> </div>
</script> </script>
</head>
<body>
<script id="root" type="text/html">
<div id="loading" style="position: absolute; right: 20px; top: 20px;"></div> <div id="loading" style="position: absolute; right: 20px; top: 20px;"></div>
<div class="navbar"> <div class="navbar">
<div class="navbar-inner"> <div class="navbar-inner">
...@@ -304,7 +303,6 @@ ...@@ -304,7 +303,6 @@
</div> </div>
</div> </div>
</div> </div>
<div class="container-fluid"> <div class="container-fluid">
<div class="row-fluid"> <div class="row-fluid">
<div class="span3"> <div class="span3">
...@@ -330,7 +328,9 @@ ...@@ -330,7 +328,9 @@
</section> </section>
</div> </div>
</div> </div>
</script>
</head>
<body>
<script type="text/javascript" src="static/js/jquery-1.7.2.js"></script> <script type="text/javascript" src="static/js/jquery-1.7.2.js"></script>
<script type="text/javascript" src="static/js/bootstrap-transition.js"></script> <script type="text/javascript" src="static/js/bootstrap-transition.js"></script>
<script type="text/javascript" src="static/js/bootstrap-alert.js"></script> <script type="text/javascript" src="static/js/bootstrap-alert.js"></script>
......
...@@ -59,18 +59,18 @@ ...@@ -59,18 +59,18 @@
methods = { methods = {
init: function () { init: function () {
var routes = []; var routes = [[['/', methods['showRoot']]]];
routes[0] = [ //routes[0] = [
['/catalog', methods['showCatalog']], //['/catalog', methods['showCatalog']],
['/catalog/all', methods['showCatalogAll']], //['/catalog/all', methods['showCatalogAll']],
['/instance', methods['requestInstance']], //['/instance', methods['requestInstance']],
['/instance/:url', methods['showInstance']], //['/instance/:url', methods['showInstance']],
['/instance/:url/bang', methods['showBangInstance']], //['/instance/:url/bang', methods['showBangInstance']],
['/computers', methods['listComputers']], //['/computers', methods['listComputers']],
['/instances', methods['listInstances']], //['/instances', methods['listInstances']],
['/invoices', methods['listInvoices']], //['/invoices', methods['listInvoices']],
['/dashboard', methods['showDashboard']] //['/dashboard', methods['showDashboard']]
]; //];
return this.each(function () { return this.each(function () {
// 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'});
...@@ -89,6 +89,13 @@ ...@@ -89,6 +89,13 @@
}); });
}, },
showRoot: function (params) {
var route = $.router.routes.current,
nextLevel = route.level + 1;
$(this).vifib('render', 'root');
$.router.routes.add('/catalog', nextLevel, methods.showCatalog, $("#main"));
},
genInstanceUrl: function (uri) { genInstanceUrl: function (uri) {
return $.genHash(['instance', encodeURIComponent(uri)]); return $.genHash(['instance', encodeURIComponent(uri)]);
}, },
...@@ -457,4 +464,4 @@ ...@@ -457,4 +464,4 @@
}; };
}(jQuery)); }(jQuery));
$('#main').vifib(); $('body').vifib();
...@@ -36,15 +36,16 @@ $.extend({ ...@@ -36,15 +36,16 @@ $.extend({
search: function (hash) { search: function (hash) {
var stop = false, var stop = false,
i = 0, j = 0, i, j,
regex, regex,
result, result,
extracted; extracted;
while ((stop === false) && (i < this.list.length)) { i = this.list.length - 1;
while ((stop === false) && (i >= 0)) {
j = 0; j = 0;
while ((stop === false) && (j < this.list[i].length)) { while ((stop === false) && (j < this.list[i].length)) {
extracted = $.router.extractKeys(this.list[i][j].route); extracted = $.router.extractKeys(this.list[i][j].route);
regex = new RegExp('^' + extracted.regex + '$'); regex = new RegExp(extracted.regex);
if (regex.test(hash.route)) { if (regex.test(hash.route)) {
result = regex.exec(hash.route); result = regex.exec(hash.route);
stop = true; stop = true;
...@@ -57,7 +58,7 @@ $.extend({ ...@@ -57,7 +58,7 @@ $.extend({
} }
j += 1; j += 1;
} }
i += 1; i -= 1;
} }
} }
}, },
......
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