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 | |
| 4 | function assert(outcome, description) { |
| 5 | if (!outcome) { |
| 6 | console.log(description); |
| 7 | } |
| 8 | } |
| 9 | |
| 10 | XOSAdminApp = new XOSApplication(); |
| 11 | |
| 12 | XOSAdminApp.addRegions({ |
| 13 | navigation: "#navigationPanel", |
| 14 | |
| 15 | detail: "#detail", |
| 16 | linkedObjs1: "#linkedObjs1", |
| 17 | linkedObjs2: "#linkedObjs2", |
| 18 | linkedObjs3: "#linkedObjs3", |
| 19 | linkedObjs4: "#linkedObjs4" |
| 20 | }); |
| 21 | |
| 22 | XOSAdminApp.navigateToModel = function(app, detailClass, detailNavLink, model) { |
| 23 | XOSAdminApp.Router.navigate(detailNavLink + "/" + model.id, {trigger: true}); |
| 24 | };
|
| 25 |
|
| 26 | XOSAdminApp.updateNavigationPanel = function() {
|
| 27 | buttonTemplate=$("#xos-navbutton").html();
|
| 28 | assert(buttonTemplate != undefined, "buttonTemplate is undefined");
|
| 29 | html=""
|
| 30 | for (var index in NAV_OBJS) {
|
| 31 | name = NAV_OBJS[index];
|
| 32 | collection_name = name+"s";
|
| 33 | nav_url = "/" + collection_name;
|
| 34 | id = "nav-"+name;
|
| 35 |
|
| 36 | html = html + _.template(buttonTemplate, {name: collection_name, router: "XOSAdminApp.Router", routeUrl: nav_url});
|
| 37 | }
|
| 38 |
|
| 39 | $("#navigationPanel").html(html);
|
| 40 | };
|
| 41 |
|
| 42 | XOSAdminApp.buildViews = function() {
|
| 43 | for (var index in OBJS) {
|
| 44 | name = OBJS[index]; |
| 45 | tr_template = '#xosAdmin-' + name + '-listitem-template'; |
| 46 | table_template = '#xosAdmin-' + name + '-list-template'; |
| 47 | detail_template = '#xosAdmin-' + name + '-detail-template'; |
| 48 | collection_name = name + "s"; |
| 49 | region_name = name + "List"; |
| 50 | detailNavLink = collection_name; |
| 51 | |
| 52 | detailClass = XOSDetailView.extend({ |
| 53 | template: detail_template,
|
| 54 | app: XOSAdminApp,
|
| 55 | });
|
| 56 | XOSAdminApp[collection_name + "DetailView"] = detailClass;
|
| 57 | |
| 58 | itemViewClass = XOSItemView.extend({ |
| 59 | detailClass: detailClass, |
| 60 | template: tr_template, |
| 61 | app: XOSAdminApp, |
| 62 | detailNavLink: detailNavLink, |
| 63 | }); |
| 64 | |
| 65 | listViewClass = XOSListView.extend({ |
| 66 | childView: itemViewClass, |
| 67 | template: table_template, |
| 68 | collection: xos[collection_name], |
| 69 | title: name + "s", |
| 70 | app: XOSAdminApp, |
| 71 | }); |
| 72 | |
| 73 | XOSAdminApp[collection_name + "ListView"] = listViewClass; |
| 74 | |
| 75 | xos[collection_name].fetch(); //startPolling(); |
| 76 | }
|
| 77 | };
|
| 78 |
|
| 79 | XOSAdminApp.initRouter = function() {
|
| 80 | router = Marionette.AppRouter.extend({
|
| 81 | });
|
| 82 |
|
| 83 | var api = {};
|
| 84 | var routes = {};
|
| 85 |
|
| 86 | function listViewShower(listViewName) {
|
| 87 | return function() {
|
| 88 | XOSAdminApp.detail.show(new XOSAdminApp[listViewName]);
|
| 89 | }
|
| 90 | };
|
| 91 |
|
| 92 | function detailShower(detailName, collection_name) {
|
| 93 | shower = function(model_id) {
|
| 94 | model = xos[collection_name].get(model_id);
|
| 95 | if (model == undefined) {
|
| 96 | $("#detail").html("not ready yet");
|
| 97 | return;
|
| 98 | }
|
| 99 | detailViewClass = XOSAdminApp[detailName];
|
| 100 | detailView = new detailViewClass({model: model});
|
| 101 | XOSAdminApp.detail.show(detailView);
|
| 102 | detailView.showLinkedItems();
|
| 103 | }
|
| 104 | return shower;
|
| 105 | };
|
| 106 |
|
| 107 | for (var index in OBJS) {
|
| 108 | name = OBJS[index];
|
| 109 | collection_name = name + "s";
|
| 110 | nav_url = collection_name;
|
| 111 | api_command = "list" + collection_name.charAt(0).toUpperCase() + collection_name.slice(1);
|
| 112 | listViewName = collection_name + "ListView";
|
| 113 | detailViewName = collection_name + "DetailView";
|
| 114 |
|
| 115 | api[api_command] = listViewShower(listViewName);
|
| 116 | routes[nav_url] = api_command;
|
| 117 |
|
| 118 | nav_url = collection_name + "/:id";
|
| 119 | api_command = "detail" + collection_name.charAt(0).toUpperCase() + collection_name.slice(1);
|
| 120 |
|
| 121 | api[api_command] = detailShower(detailViewName, collection_name);
|
| 122 | routes[nav_url] = api_command;
|
| 123 | };
|
| 124 |
|
| 125 | XOSAdminApp.Router = new router({ appRoutes: routes, controller: api });
|
| 126 | }
|
| 127 |
|
| 128 | XOSAdminApp.on("start", function() {
|
| 129 | XOSAdminApp.buildViews(); |
| 130 | |
| 131 | XOSAdminApp.initRouter(); |
| 132 | |
| 133 | XOSAdminApp.updateNavigationPanel(); |
| 134 | |
| 135 | if (Backbone.history) { |
| 136 | console.log("history start"); |
| 137 | Backbone.history.start(); |
| 138 | } |
| 139 | }); |
| 140 | |
| 141 | $(document).ready(function(){ |
| 142 | XOSAdminApp.start(); |
| 143 | }); |
| 144 | |