X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetstack%2Fcore%2Fxoslib%2Fstatic%2Fjs%2FxosAdminSite.js;h=f5c756692c7cbea0e253ca3ffb74b58f0503dbfc;hb=23728671481acb47aee46826a35e8dca289ed8d1;hp=e3457eb8f4870e4e8a74db01b40bf088f36134f4;hpb=4f448db2b8df00b6bb4df53fd1e6c8e0e7ae4ad5;p=plstackapi.git
diff --git a/planetstack/core/xoslib/static/js/xosAdminSite.js b/planetstack/core/xoslib/static/js/xosAdminSite.js
index e3457eb..f5c7566 100644
--- a/planetstack/core/xoslib/static/js/xosAdminSite.js
+++ b/planetstack/core/xoslib/static/js/xosAdminSite.js
@@ -1,13 +1,17 @@
-OBJS = ['deployment', 'image', 'networkTemplate', 'network', 'networkSliver', 'networkDeployment', 'node', 'service', 'site', 'slice', 'sliceDeployment', 'slicePrivilege', 'sliver', 'user', 'sliceRole', 'userDeployment'];
+OBJS = ['deployment', 'image', 'networkTemplate', 'network', 'networkSliver', 'node', 'service', 'site', 'slice', 'slicePrivilege', 'sliver', 'user', 'sliceRole', 'flavor', 'controller', 'siteDeployment'];
+// 'networkDeployment', 'userDeployment', 'sliceDeployment', 'imageDeployment'
NAV_OBJS = ['deployment', 'site', 'slice', 'user'];
-function assert(outcome, description) {
- if (!outcome) {
- console.log(description);
- }
-}
+REWRITES = {"/admin/core/deployment/": "#deployments",
+ "/admin/core/site/" : "#sites",
+ "/admin/core/slice/" : "#slices",
+ "/admin/core/user/" : "#users"};
-XOSAdminApp = new XOSApplication();
+XOSAdminApp = new XOSApplication({
+ logTableId: "#logTable",
+ statusMsgId: "#statusMsg",
+ hideTabsByDefault: true
+});
XOSAdminApp.addRegions({
navigation: "#navigationPanel",
@@ -16,59 +20,123 @@ XOSAdminApp.addRegions({
linkedObjs1: "#linkedObjs1",
linkedObjs2: "#linkedObjs2",
linkedObjs3: "#linkedObjs3",
- linkedObjs4: "#linkedObjs4"
+ linkedObjs4: "#linkedObjs4",
+
+ addChildDetail: "#xos-addchild-detail",
+
+ rightButtonPanel: "#rightButtonPanel"
});
-XOSAdminApp.navigateToModel = function(app, detailClass, detailNavLink, model) {
- XOSAdminApp.Router.navigate(detailNavLink + "/" + model.id, {trigger: true});
-};
+XOSAdminApp.navigate = function(what, modelName, modelId) {
+ console.log("XOSAsminApp.navigate");
+ collection_name = modelName + "s";
+ if (what=="list") {
+ XOSAdminApp.Router.navigate(collection_name, {trigger: true})
+ } else if (what=="detail") {
+ XOSAdminApp.Router.navigate(collection_name + "/" + modelId, {trigger: true})
+ } else if (what=="add") {
+ XOSAdminApp.Router.navigate("add" + firstCharUpper(modelName), {trigger: true, force: true})
+ }
+}
+
+ICON_CLASSES = {home: "icon-home", deployments: "icon-deployment", sites: "icon-site", slices: "icon-slice", users: "icon-user"};
XOSAdminApp.updateNavigationPanel = function() {
buttonTemplate=$("#xos-navbutton").html();
assert(buttonTemplate != undefined, "buttonTemplate is undefined");
- html=""
+ html="
";
for (var index in NAV_OBJS) {
name = NAV_OBJS[index];
collection_name = name+"s";
- nav_url = "/" + collection_name;
+ nav_url = "#" + collection_name;
id = "nav-"+name;
+ icon_class = ICON_CLASSES[collection_name] || "icon-cog";
- html = html + _.template(buttonTemplate, {name: collection_name, router: "XOSAdminApp.Router", routeUrl: nav_url});
+ html = html + _.template(buttonTemplate, {name: collection_name, router: "XOSAdminApp.Router", routeUrl: nav_url, iconClass: icon_class});
}
+ html = html + "
";
+
$("#navigationPanel").html(html);
};
XOSAdminApp.buildViews = function() {
+ genericAddChildClass = XOSDetailView.extend({template: "#xos-add-template",
+ app: XOSAdminApp});
+ XOSAdminApp["genericAddChildView"] = genericAddChildClass;
+
+ genericDetailClass = XOSDetailView.extend({template: "#xos-detail-template",
+ app: XOSAdminApp});
+ XOSAdminApp["genericDetailView"] = genericDetailClass;
+
+ genericItemViewClass = XOSItemView.extend({template: "#xos-listitem-template",
+ app: XOSAdminApp});
+ XOSAdminApp["genericItemView"] = genericItemViewClass;
+
+ //genericListViewClass = XOSListView.extend({template: "#xos-list-template",
+ // app: XOSAdminApp});
+
+ genericListViewClass = XOSDataTableView.extend({template: "#xos-list-template", app: XOSAdminApp});
+ XOSAdminApp["genericListView"] = genericListViewClass;
+
for (var index in OBJS) {
name = OBJS[index];
tr_template = '#xosAdmin-' + name + '-listitem-template';
table_template = '#xosAdmin-' + name + '-list-template';
detail_template = '#xosAdmin-' + name + '-detail-template';
+ add_child_template = '#xosAdmin-' + name + '-add-child-template';
collection_name = name + "s";
region_name = name + "List";
- detailNavLink = collection_name;
- detailClass = XOSDetailView.extend({
- template: detail_template,
- app: XOSAdminApp,
- });
+ if (window["XOSDetailView_" + name]) {
+ detailClass = window["XOSDetailView_" + name].extend({template: "#xos-detail-template",
+ app: XOSAdminApp});
+ } else {
+ detailClass = genericDetailClass;
+ }
+ if ($(detail_template).length) {
+ detailClass = detailClass.extend({
+ template: detail_template,
+ });
+ }
XOSAdminApp[collection_name + "DetailView"] = detailClass;
+
+ if (window["XOSDetailView_" + name]) {
+ addClass = window["XOSDetailView_" + name].extend({template: "#xos-add-template",
+ app: XOSAdminApp});
+ } else {
+ addClass = genericAddChildClass;
+ }
+ if ($(add_child_template).length) {
+ addClass = detailClass.extend({
+ template: add_child_template,
+ });
+ }
+ XOSAdminApp[collection_name + "AddChildView"] = addClass;
+
+ if ($(tr_template).length) {
+ itemViewClass = XOSItemView.extend({
+ template: tr_template,
+ app: XOSAdminApp,
+ });
+ } else {
+ itemViewClass = genericItemViewClass;
+ }
- itemViewClass = XOSItemView.extend({
- detailClass: detailClass,
- template: tr_template,
- app: XOSAdminApp,
- detailNavLink: detailNavLink,
- });
-
- listViewClass = XOSListView.extend({
- childView: itemViewClass,
- template: table_template,
- collection: xos[collection_name],
- title: name + "s",
- app: XOSAdminApp,
- });
+ if ($(table_template).length) {
+ listViewClass = XOSListView.extend({
+ childView: itemViewClass,
+ template: table_template,
+ collection: xos[collection_name],
+ title: name + "s",
+ app: XOSAdminApp,
+ });
+ } else {
+ listViewClass = genericListViewClass.extend( { childView: itemViewClass,
+ collection: xos[collection_name],
+ title: name + "s",
+ } );
+ }
XOSAdminApp[collection_name + "ListView"] = listViewClass;
@@ -77,54 +145,84 @@ XOSAdminApp.buildViews = function() {
};
XOSAdminApp.initRouter = function() {
- router = Marionette.AppRouter.extend({
- });
-
+ router = XOSRouter;
var api = {};
var routes = {};
- function listViewShower(listViewName) {
- return function() {
- XOSAdminApp.detail.show(new XOSAdminApp[listViewName]);
- }
- };
-
- function detailShower(detailName, collection_name) {
- shower = function(model_id) {
- model = xos[collection_name].get(model_id);
- if (model == undefined) {
- $("#detail").html("not ready yet");
- return;
- }
- detailViewClass = XOSAdminApp[detailName];
- detailView = new detailViewClass({model: model});
- XOSAdminApp.detail.show(detailView);
- detailView.showLinkedItems();
- }
- return shower;
- };
-
for (var index in OBJS) {
name = OBJS[index];
collection_name = name + "s";
nav_url = collection_name;
- api_command = "list" + collection_name.charAt(0).toUpperCase() + collection_name.slice(1);
+ api_command = "list" + firstCharUpper(collection_name);
listViewName = collection_name + "ListView";
detailViewName = collection_name + "DetailView";
+ addChildViewName = collection_name + "AddChildView";
- api[api_command] = listViewShower(listViewName);
+ api[api_command] = XOSAdminApp.createListHandler(listViewName, collection_name, "detail", collection_name);
routes[nav_url] = api_command;
nav_url = collection_name + "/:id";
- api_command = "detail" + collection_name.charAt(0).toUpperCase() + collection_name.slice(1);
+ api_command = "detail" + firstCharUpper(collection_name);
- api[api_command] = detailShower(detailViewName, collection_name);
+ api[api_command] = XOSAdminApp.createDetailHandler(detailViewName, collection_name, "detail", name);
+ routes[nav_url] = api_command;
+
+ nav_url = "add" + firstCharUpper(name);
+ api_command = "add" + firstCharUpper(name);
+ api[api_command] = XOSAdminApp.createAddHandler(detailViewName, collection_name, "detail", name);
+ routes[nav_url] = api_command;
+
+ nav_url = "addChild" + firstCharUpper(name) + "/:parentModel/:parentField/:parentId";
+ api_command = "addChild" + firstCharUpper(name);
+ api[api_command] = XOSAdminApp.createAddChildHandler(addChildViewName, collection_name);
+ routes[nav_url] = api_command;
+
+ nav_url = "delete" + firstCharUpper(name) + "/:id";
+ api_command = "delete" + firstCharUpper(name);
+ api[api_command] = XOSAdminApp.createDeleteHandler(collection_name, name);
routes[nav_url] = api_command;
};
+ routes["*part"] = "listSlices";
+
XOSAdminApp.Router = new router({ appRoutes: routes, controller: api });
+};
+
+/* rewriteLinks
+
+ Rewrite the links in the suit navbar from django-links to marionette
+ links. This let's us intercept the navbar and make it function within
+ this view rather than jumping back out to a django view.
+*/
+
+XOSAdminApp.rewriteLinks = function () {
+ $("a").each(function() {
+ href=$(this).attr("href");
+ rewrite_href=REWRITES[href];
+ if (rewrite_href) {
+ $(this).attr("href", rewrite_href);
+ }
+ });
+};
+
+XOSAdminApp.startNavigation = function() {
+ Backbone.history.start();
+ XOSAdminApp.navigationStarted = true;
}
+XOSAdminApp.collectionLoadChange = function() {
+ stats = xos.getCollectionStatus();
+
+ if (!XOSAdminApp.navigationStarted) {
+ if (stats["isLoaded"] + stats["failedLoad"] >= stats["startedLoad"]) {
+ XOSAdminApp.startNavigation();
+ } else {
+ $("#detail").html("
Loading...
");
+ $("#xos-startup-progress").progressbar({value: stats["completedLoad"], max: stats["startedLoad"]});
+ }
+ }
+};
+
XOSAdminApp.on("start", function() {
XOSAdminApp.buildViews();
@@ -132,10 +230,13 @@ XOSAdminApp.on("start", function() {
XOSAdminApp.updateNavigationPanel();
- if (Backbone.history) {
- console.log("history start");
- Backbone.history.start();
- }
+ XOSAdminApp.rewriteLinks();
+
+ // fire it once to initially show the progress bar
+ XOSAdminApp.collectionLoadChange();
+
+ // fire it each time the collection load status is updated
+ Backbone.on("xoslib:collectionLoadChange", XOSAdminApp.collectionLoadChange);
});
$(document).ready(function(){