Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 1 | OBJS = ['deployment', 'image', 'networkTemplate', 'network', 'networkSliver', 'networkDeployment', 'node', 'service', 'site', 'slice', 'sliceDeployment', 'slicePrivilege', 'sliver', 'user', 'sliceRole', 'userDeployment']; |
| 2 | NAV_OBJS = ['deployment', 'site', 'slice', 'user']; |
| 3 | |
Scott Baker | ac69422 | 2014-11-05 22:12:33 -0800 | [diff] [blame] | 4 | REWRITES = {"/admin/core/deployment/": "#deployments", |
| 5 | "/admin/core/site/" : "#sites", |
| 6 | "/admin/core/slice/" : "#slices", |
| 7 | "/admin/core/user/" : "#users"}; |
| 8 | |
| 9 | XOSAdminApp = new XOSApplication({ |
| 10 | logTableId: "#logTable", |
| 11 | statusMsgId: "#statusMsg", |
| 12 | hideTabsByDefault: true |
| 13 | }); |
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 14 | |
| 15 | XOSAdminApp.addRegions({ |
| 16 | navigation: "#navigationPanel", |
| 17 | |
| 18 | detail: "#detail", |
| 19 | linkedObjs1: "#linkedObjs1", |
| 20 | linkedObjs2: "#linkedObjs2", |
| 21 | linkedObjs3: "#linkedObjs3", |
Scott Baker | 3e8d473 | 2014-12-04 17:22:01 -0800 | [diff] [blame] | 22 | linkedObjs4: "#linkedObjs4", |
| 23 | |
Scott Baker | ca4bf92 | 2014-12-09 18:38:13 -0800 | [diff] [blame] | 24 | addChildDetail: "#xos-addchild-detail", |
| 25 | |
| 26 | rightButtonPanel: "#rightButtonPanel" |
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 27 | }); |
| 28 | |
Scott Baker | 13e6f0d | 2014-11-18 17:02:07 -0800 | [diff] [blame] | 29 | XOSAdminApp.navigate = function(what, modelName, modelId) {
|
Scott Baker | ab5f136 | 2014-12-09 19:39:45 -0800 | [diff] [blame] | 30 | console.log("XOSAsminApp.navigate");
|
Scott Baker | 13e6f0d | 2014-11-18 17:02:07 -0800 | [diff] [blame] | 31 | collection_name = modelName + "s";
|
| 32 | if (what=="list") {
|
| 33 | XOSAdminApp.Router.navigate(collection_name, {trigger: true})
|
| 34 | } else if (what=="detail") {
|
| 35 | XOSAdminApp.Router.navigate(collection_name + "/" + modelId, {trigger: true})
|
| 36 | } else if (what=="add") {
|
Scott Baker | ab5f136 | 2014-12-09 19:39:45 -0800 | [diff] [blame] | 37 | XOSAdminApp.Router.navigate("add" + firstCharUpper(modelName), {trigger: true, force: true})
|
Scott Baker | 13e6f0d | 2014-11-18 17:02:07 -0800 | [diff] [blame] | 38 | }
|
| 39 | }
|
| 40 |
|
Scott Baker | f76d33a | 2014-11-04 09:34:01 -0800 | [diff] [blame] | 41 | ICON_CLASSES = {home: "icon-home", deployments: "icon-deployment", sites: "icon-site", slices: "icon-slice", users: "icon-user"};
|
| 42 |
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 43 | XOSAdminApp.updateNavigationPanel = function() {
|
| 44 | buttonTemplate=$("#xos-navbutton").html();
|
| 45 | assert(buttonTemplate != undefined, "buttonTemplate is undefined");
|
Scott Baker | f76d33a | 2014-11-04 09:34:01 -0800 | [diff] [blame] | 46 | html="<div class='left-nav'><ul>";
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 47 | for (var index in NAV_OBJS) {
|
| 48 | name = NAV_OBJS[index];
|
| 49 | collection_name = name+"s";
|
Scott Baker | f76d33a | 2014-11-04 09:34:01 -0800 | [diff] [blame] | 50 | nav_url = "#" + collection_name;
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 51 | id = "nav-"+name;
|
Scott Baker | f76d33a | 2014-11-04 09:34:01 -0800 | [diff] [blame] | 52 | icon_class = ICON_CLASSES[collection_name] || "icon-cog";
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 53 |
|
Scott Baker | f76d33a | 2014-11-04 09:34:01 -0800 | [diff] [blame] | 54 | html = html + _.template(buttonTemplate, {name: collection_name, router: "XOSAdminApp.Router", routeUrl: nav_url, iconClass: icon_class});
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 55 | }
|
| 56 |
|
Scott Baker | f76d33a | 2014-11-04 09:34:01 -0800 | [diff] [blame] | 57 | html = html + "</ul>";
|
| 58 |
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 59 | $("#navigationPanel").html(html);
|
| 60 | };
|
| 61 |
|
| 62 | XOSAdminApp.buildViews = function() {
|
Scott Baker | 0a636cb | 2014-12-07 22:27:09 -0800 | [diff] [blame] | 63 | genericAddChildClass = XOSDetailView.extend({template: "#xos-add-template",
|
| 64 | app: XOSAdminApp});
|
| 65 | XOSAdminApp["genericAddChildView"] = genericAddChildClass;
|
| 66 |
|
| 67 | genericDetailClass = XOSDetailView.extend({template: "#xos-detail-template",
|
| 68 | app: XOSAdminApp});
|
| 69 | XOSAdminApp["genericDetailView"] = genericDetailClass;
|
| 70 |
|
Scott Baker | e68d37b | 2014-12-09 16:59:08 -0800 | [diff] [blame] | 71 | genericItemViewClass = XOSItemView.extend({template: "#xos-listitem-template",
|
| 72 | app: XOSAdminApp});
|
| 73 | XOSAdminApp["genericItemView"] = genericItemViewClass;
|
| 74 |
|
| 75 | genericListViewClass = XOSListView.extend({template: "#xos-list-template",
|
| 76 | app: XOSAdminApp});
|
| 77 | XOSAdminApp["genericListView"] = genericListViewClass;
|
| 78 |
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 79 | for (var index in OBJS) {
|
| 80 | name = OBJS[index]; |
| 81 | tr_template = '#xosAdmin-' + name + '-listitem-template'; |
| 82 | table_template = '#xosAdmin-' + name + '-list-template'; |
| 83 | detail_template = '#xosAdmin-' + name + '-detail-template'; |
Scott Baker | 0a636cb | 2014-12-07 22:27:09 -0800 | [diff] [blame] | 84 | add_child_template = '#xosAdmin-' + name + '-add-child-template'; |
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 85 | collection_name = name + "s"; |
| 86 | region_name = name + "List"; |
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 87 | |
Scott Baker | 0a636cb | 2014-12-07 22:27:09 -0800 | [diff] [blame] | 88 | if ($(detail_template).length) { |
| 89 | detailClass = XOSDetailView.extend({ |
| 90 | template: detail_template,
|
| 91 | app: XOSAdminApp,
|
| 92 | });
|
| 93 | } else {
|
| 94 | detailClass = genericDetailClass;
|
| 95 | }
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 96 | XOSAdminApp[collection_name + "DetailView"] = detailClass;
|
Scott Baker | 0a636cb | 2014-12-07 22:27:09 -0800 | [diff] [blame] | 97 |
|
| 98 | if ($(add_child_template).length) {
|
| 99 | addClass = XOSDetailView.extend({ |
| 100 | template: add_child_template,
|
| 101 | app: XOSAdminApp,
|
| 102 | });
|
| 103 | } else {
|
| 104 | addClass = genericAddChildClass;
|
| 105 | }
|
| 106 | XOSAdminApp[collection_name + "AddChildView"] = addClass;
|
| 107 |
|
Scott Baker | e68d37b | 2014-12-09 16:59:08 -0800 | [diff] [blame] | 108 | if ($(tr_template).length) {
|
| 109 | itemViewClass = XOSItemView.extend({
|
| 110 | template: tr_template,
|
| 111 | app: XOSAdminApp, |
| 112 | }); |
| 113 | } else { |
| 114 | itemViewClass = genericItemViewClass; |
| 115 | } |
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 116 | |
Scott Baker | e68d37b | 2014-12-09 16:59:08 -0800 | [diff] [blame] | 117 | if ($(table_template).length) { |
| 118 | listViewClass = XOSListView.extend({ |
| 119 | childView: itemViewClass, |
| 120 | template: table_template, |
| 121 | collection: xos[collection_name], |
| 122 | title: name + "s", |
| 123 | app: XOSAdminApp, |
| 124 | }); |
| 125 | } else { |
| 126 | listViewClass = genericListViewClass.extend( { childView: itemViewClass, |
| 127 | collection: xos[collection_name], |
| 128 | title: name + "s", |
| 129 | } ); |
| 130 | } |
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 131 | |
| 132 | XOSAdminApp[collection_name + "ListView"] = listViewClass; |
| 133 | |
| 134 | xos[collection_name].fetch(); //startPolling(); |
| 135 | }
|
| 136 | };
|
| 137 |
|
| 138 | XOSAdminApp.initRouter = function() {
|
Scott Baker | 29e8a2c | 2014-12-02 17:59:02 -0800 | [diff] [blame] | 139 | router = XOSRouter;
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 140 | var api = {};
|
| 141 | var routes = {};
|
| 142 |
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 143 | for (var index in OBJS) {
|
| 144 | name = OBJS[index];
|
| 145 | collection_name = name + "s";
|
| 146 | nav_url = collection_name;
|
Scott Baker | 7ce2365 | 2014-11-07 16:40:30 -0800 | [diff] [blame] | 147 | api_command = "list" + firstCharUpper(collection_name);
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 148 | listViewName = collection_name + "ListView";
|
| 149 | detailViewName = collection_name + "DetailView";
|
Scott Baker | 0a636cb | 2014-12-07 22:27:09 -0800 | [diff] [blame] | 150 | addChildViewName = collection_name + "AddChildView";
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 151 |
|
Scott Baker | 3e8d473 | 2014-12-04 17:22:01 -0800 | [diff] [blame] | 152 | api[api_command] = XOSAdminApp.createListHandler(listViewName, collection_name, "detail", collection_name);
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 153 | routes[nav_url] = api_command;
|
| 154 |
|
| 155 | nav_url = collection_name + "/:id";
|
Scott Baker | 7ce2365 | 2014-11-07 16:40:30 -0800 | [diff] [blame] | 156 | api_command = "detail" + firstCharUpper(collection_name);
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 157 |
|
Scott Baker | 3e8d473 | 2014-12-04 17:22:01 -0800 | [diff] [blame] | 158 | api[api_command] = XOSAdminApp.createDetailHandler(detailViewName, collection_name, "detail", name);
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 159 | routes[nav_url] = api_command;
|
Scott Baker | 7ce2365 | 2014-11-07 16:40:30 -0800 | [diff] [blame] | 160 |
|
| 161 | nav_url = "add" + firstCharUpper(name);
|
| 162 | api_command = "add" + firstCharUpper(name);
|
Scott Baker | 3e8d473 | 2014-12-04 17:22:01 -0800 | [diff] [blame] | 163 | api[api_command] = XOSAdminApp.createAddHandler(detailViewName, collection_name, "detail", name);
|
| 164 | routes[nav_url] = api_command;
|
| 165 |
|
| 166 | nav_url = "addChild" + firstCharUpper(name) + "/:parentModel/:parentField/:parentId";
|
| 167 | api_command = "addChild" + firstCharUpper(name);
|
Scott Baker | 0a636cb | 2014-12-07 22:27:09 -0800 | [diff] [blame] | 168 | api[api_command] = XOSAdminApp.createAddChildHandler(addChildViewName, collection_name);
|
Scott Baker | 7ce2365 | 2014-11-07 16:40:30 -0800 | [diff] [blame] | 169 | routes[nav_url] = api_command;
|
Scott Baker | 29e8a2c | 2014-12-02 17:59:02 -0800 | [diff] [blame] | 170 |
|
| 171 | nav_url = "delete" + firstCharUpper(name) + "/:id";
|
| 172 | api_command = "delete" + firstCharUpper(name);
|
Scott Baker | 3e8d473 | 2014-12-04 17:22:01 -0800 | [diff] [blame] | 173 | api[api_command] = XOSAdminApp.createDeleteHandler(collection_name, name);
|
Scott Baker | 29e8a2c | 2014-12-02 17:59:02 -0800 | [diff] [blame] | 174 | routes[nav_url] = api_command;
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 175 | };
|
| 176 |
|
| 177 | XOSAdminApp.Router = new router({ appRoutes: routes, controller: api });
|
Scott Baker | ac69422 | 2014-11-05 22:12:33 -0800 | [diff] [blame] | 178 | };
|
| 179 |
|
| 180 | /* rewriteLinks
|
| 181 |
|
| 182 | Rewrite the links in the suit navbar from django-links to marionette
|
| 183 | links. This let's us intercept the navbar and make it function within
|
| 184 | this view rather than jumping back out to a django view.
|
| 185 | */
|
| 186 |
|
| 187 | XOSAdminApp.rewriteLinks = function () {
|
| 188 | $("a").each(function() {
|
| 189 | href=$(this).attr("href");
|
| 190 | rewrite_href=REWRITES[href];
|
| 191 | if (rewrite_href) {
|
| 192 | $(this).attr("href", rewrite_href);
|
| 193 | }
|
| 194 | });
|
| 195 | };
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 196 |
|
Scott Baker | 66aaad4 | 2014-11-13 15:52:02 -0800 | [diff] [blame] | 197 | XOSAdminApp.startNavigation = function() {
|
| 198 | Backbone.history.start();
|
| 199 | XOSAdminApp.navigationStarted = true;
|
| 200 | }
|
| 201 |
|
| 202 | XOSAdminApp.collectionLoadChange = function() {
|
| 203 | stats = xos.getCollectionStatus();
|
| 204 |
|
| 205 | if (!XOSAdminApp.navigationStarted) {
|
| 206 | if (stats["isLoaded"] + stats["failedLoad"] >= stats["startedLoad"]) {
|
| 207 | XOSAdminApp.startNavigation();
|
| 208 | } else {
|
| 209 | $("#detail").html("<h3>Loading...</h3><div id='xos-startup-progress'></div>");
|
| 210 | $("#xos-startup-progress").progressbar({value: stats["completedLoad"], max: stats["startedLoad"]});
|
| 211 | }
|
| 212 | }
|
| 213 | };
|
| 214 |
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 215 | XOSAdminApp.on("start", function() {
|
| 216 | XOSAdminApp.buildViews(); |
| 217 | |
| 218 | XOSAdminApp.initRouter(); |
| 219 | |
| 220 | XOSAdminApp.updateNavigationPanel(); |
| 221 | |
Scott Baker | ac69422 | 2014-11-05 22:12:33 -0800 | [diff] [blame] | 222 | XOSAdminApp.rewriteLinks(); |
| 223 | |
Scott Baker | 66aaad4 | 2014-11-13 15:52:02 -0800 | [diff] [blame] | 224 | // fire it once to initially show the progress bar |
| 225 | XOSAdminApp.collectionLoadChange(); |
| 226 | |
| 227 | // fire it each time the collection load status is updated |
| 228 | Backbone.on("xoslib:collectionLoadChange", XOSAdminApp.collectionLoadChange); |
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 229 | }); |
| 230 | |
| 231 | $(document).ready(function(){ |
| 232 | XOSAdminApp.start(); |
| 233 | }); |
| 234 | |