Merge branch 'master' of git://git.planet-lab.org/plstackapi
authorSapan <sapanb@cs.princeton.edu>
Wed, 3 Dec 2014 19:50:39 +0000 (14:50 -0500)
committerSapan <sapanb@cs.princeton.edu>
Wed, 3 Dec 2014 19:50:39 +0000 (14:50 -0500)
planetstack/core/xoslib/static/js/xosAdminSite.js
planetstack/core/xoslib/static/js/xoslib/xos-util.js
planetstack/core/xoslib/static/js/xoslib/xosHelper.js
planetstack/core/xoslib/templates/xosAdmin.html

index ceb2589..36ffd0b 100644 (file)
@@ -96,9 +96,7 @@ XOSAdminApp.buildViews = function() {
 };\r
 \r
 XOSAdminApp.initRouter = function() {\r
-    router = Marionette.AppRouter.extend({\r
-    });\r
-\r
+    router = XOSRouter;\r
     var api = {};\r
     var routes = {};\r
 \r
@@ -123,6 +121,11 @@ XOSAdminApp.initRouter = function() {
         api_command = "add" + firstCharUpper(name);\r
         api[api_command] = XOSAdminApp.addShower(detailViewName, collection_name, "detail", name);\r
         routes[nav_url] = api_command;\r
+\r
+        nav_url = "delete" + firstCharUpper(name) + "/:id";\r
+        api_command = "delete" + firstCharUpper(name);\r
+        api[api_command] = XOSAdminApp.deleteShower(collection_name, name);\r
+        routes[nav_url] = api_command;\r
     };\r
 \r
     XOSAdminApp.Router = new router({ appRoutes: routes, controller: api });\r
index 5e91a3d..c1f736e 100644 (file)
@@ -1,5 +1,19 @@
 // misc utility functions
 
+function assert(outcome, description) {
+    if (!outcome) {
+        console.log(description);
+    }
+}
+
+function templateFromId(id) {
+    return _.template($(id).html());
+}
+
+function firstCharUpper(s) {
+    return s.charAt(0).toUpperCase() + s.slice(1);
+}
+
 // http://stackoverflow.com/questions/2117320/set-maximum-displayed-rows-count-for-html-table
 function limitTableRows(tableSelector, maxRows) {
     var table = $(tableSelector)[0] //document.getElementById(tableId);
index ca7a5bf..eb8008c 100644 (file)
@@ -1,23 +1,25 @@
-function assert(outcome, description) {
-    if (!outcome) {
-        console.log(description);
-    }
-}
-
-function templateFromId(id) {
-    return _.template($(id).html());
-}
-
-function firstCharUpper(s) {
-    return s.charAt(0).toUpperCase() + s.slice(1);
-}
-
 HTMLView = Marionette.ItemView.extend({
   render: function() {
       this.$el.append(this.options.html);
   },
 });
 
+XOSRouter = Marionette.AppRouter.extend({
+        initialize: function() {\r
+            this.routeStack=[];\r
+        },\r
+\r
+        onRoute: function(x,y,z) {\r
+             this.routeStack.push(Backbone.history.fragment);\r
+        },\r
+\r
+        prevPage: function() {\r
+             return this.routeStack.slice(-2)[0];
+        },
+    });\r
+
+
+
 XOSApplication = Marionette.Application.extend({
     detailBoxId: "#detailBox",
     errorBoxId: "#errorBox",
@@ -107,6 +109,17 @@ XOSApplication = Marionette.Application.extend({
         }
     },
 
+    deleteShower: function(collection_name) {
+        var app=this;
+        return function(model_id) {
+            console.log("deleteCalled");
+            collection = xos[collection_name];
+            model = collection.get(model_id);
+            assert(model!=undefined, "failed to get model " + model_id + " from collection " + collection_name);
+            app.deleteDialog(model,"back");
+        }
+    },
+
     detailShower: function(detailName, collection_name, regionName, title) {
         var app=this;
         showModelId = function(model_id) {
@@ -217,9 +230,11 @@ XOSApplication = Marionette.Application.extend({
 
     saveSuccess: function(model, result, xhr, infoMsgId, addToCollection) {
         console.log("saveSuccess");
-        if (addToCollection) {
-            addToCollection.add(model);
-            addToCollection.sort();
+        if (model.addToCollection) {
+            console.log("addToCollection");
+            model.addToCollection.add(model);
+            model.addToCollection.sort();
+            model.addToCollection = undefined;
         }
         result = {status: xhr.xhr.status, statusText: xhr.xhr.statusText};
         result["what"] = "save " + model.modelName + " " + model.attributes.humanReadableName;
@@ -251,15 +266,23 @@ XOSApplication = Marionette.Application.extend({
                         success: function(model, result, xhr) { that.destroySuccess(model,result,xhr,infoMsgId);}});
     },
 
-    deleteDialog: function(model, navToListAfterDelete) {
+    deleteDialog: function(model, afterDelete) {
         var that=this;
+        console.log("XXX");
+        console.log(Backbone.history.fragment);
+        assert(model!=undefined, "deleteDialog's model is undefined");
         //console.log("deleteDialog"); console.log(model);
         this.confirmDialog(null, null, function() {
             //console.log("deleteConfirm"); console.log(model);
             modelName = model.modelName;
             that.destroyModel(model);
-            if (navToListAfterDelete) {
+            if (afterDelete=="list") {
                 that.navigate("list", modelName);
+            } else if (afterDelete=="back") {
+                prevPage = that.Router.prevPage();
+                if (prevPage) {
+                    that.Router.navigate("#"+prevPage, {trigger: false, replace: true} );
+                }
             }
 
         });
@@ -367,7 +390,7 @@ XOSDetailView = Marionette.ItemView.extend({
 
              deleteClicked: function(e) {
                  e.preventDefault();
-                 this.app.deleteDialog(this.model, true);
+                 this.app.deleteDialog(this.model, "list");
              },
 
             tabClick: function(tabId, regionName) {
index b032e00..854a852 100644 (file)
 </script>
 
 <script type="text/template" id="xos-delete-button-template">
-    <a href="#delete?model=<%= modelName %>&id=<%= id %>">delete</a>
-</script>
-
-<script type="text/template" id="xos-delete-button-template">
-    <a href="#delete?model=<%= modelName %>&id=<%= id %>">delete</a>
+    <a href="#delete<%= firstCharUpper(modelName) %>/<%= id %>">delete</a>
 </script>
 
 <script type="text/template" id="xos-detail-link-template">
      <th>disk_format</th>
      <th>container_format</th>
      <th>path</th>
+     <th>delete</th>
   </tr></thead>
   <tbody></tbody>
   </table>
   <td><%= disk_format %></td>
   <td><%= container_format %></td>
   <td><%= path %></td>
+  <td><%= xosDeleteButtonTemplate({modelName: modelName, id: id}) %></td>
 </script>
 
 <script type="text/template" id="xosAdmin-image-detail-template">
      <th>translation</th>
      <th>sharedNetworkName</th>
      <th>sharedNetworkId</th>
+     <th>delete</th>
   </tr></thead>
   <tbody></tbody>
   </table>
   <td><%= translation %></td>
   <td><%= sharedNetworkName %></td>
   <td><%= sharedNetworkId %></td>
+  <td><%= xosDeleteButtonTemplate({modelName: modelName, id: id}) %></td>
 </script>
 
 <script type="text/template" id="xosAdmin-networkTemplate-detail-template">
      <th>ports</th>
      <th>labels</th>
      <th>owner</th>
+     <th>delete</th>
   </tr></thead>
   <tbody></tbody>
   </table>
   <td><%= ports %></td>
   <td><%= labels %></td>
   <td><%= idToName(owner,"slices","name") %></td>
+  <td><%= xosDeleteButtonTemplate({modelName: modelName, id: id}) %></td>
 </script>
 
 <script type="text/template" id="xosAdmin-network-detail-template">
      <th>sliver</th>
      <th>ip</th>
      <th>port_id</th>
+     <th>delete</th>
   </tr></thead>
   <tbody></tbody>
   </table>
   <td><%= idToName(sliver,"slivers","name") %></td>
   <td><%= ip %></td>
   <td><%= port_id %></td>
+  <td><%= xosDeleteButtonTemplate({modelName: modelName, id: id}) %></td>
 </script>
 
 <script type="text/template" id="xosAdmin-networkSliver-detail-template">
      <th>network</th>
      <th>deployment</th>
      <th>net_id</th>
+     <th>delete</th>
   </tr></thead>
   <tbody></tbody>
   </table>
   <td><%= idToName(network,"networks","name") %></td>
   <td><%= idToName(deployment,"deployments","name") %></td>
   <td><%= net_id %></td>
+  <td><%= xosDeleteButtonTemplate({modelName: modelName, id: id}) %></td>
 </script>
 
 <script type="text/template" id="xosAdmin-networkDeployment-detail-template">
      <th>name</th>
      <th>site</th>
      <th>deployment</th>
+     <th>delete</th>
   </tr></thead>
   <tbody></tbody>
   </table>
   <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: name}) %></td>
   <td><%= idToName(site,"sites","name") %></td>
   <td><%= idToName(deployment,"deployments","name") %></td>
+  <td><%= xosDeleteButtonTemplate({modelName: modelName, id: id}) %></td>
 </script>
 
 <script type="text/template" id="xosAdmin-node-detail-template">
   <thead><tr>
      <th>id</th>
      <th>role</th>
+     <th>delete</th>
   </tr></thead>
   <tbody></tbody>
   </table>
 <script type="text/template" id="xosAdmin-sliceRole-listitem-template">
   <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: id}) %></td>
   <td><%= role %></td>
+  <td><%= xosDeleteButtonTemplate({modelName: modelName, id: id}) %></td>
 </script>
 
 <script type="text/template" id="xosAdmin-sliceRole-detail-template">
      <th>enabled</th>
      <th>versionNumber</th>
      <th>published</th>
+     <th>delete</th>
   </tr></thead>
   <tbody></tbody>
   </table>
   <td><%= enabled %></td>
   <td><%= versionNumber %></td>
   <td><%= published %></td>
+  <td><%= xosDeleteButtonTemplate({modelName: modelName, id: id}) %></td>
 </script>
 
 <script type="text/template" id="xosAdmin-service-detail-template">
      <th>login_base</th>
      <th>is_public</th>
      <th>abbreviated_name</th>
+     <th>delete</th>
   </tr></thead>
   <tbody></tbody>
   </table>
   <td><%= login_base %></td>
   <td><%= is_public %></td>
   <td><%= abbreviated_name %></td>
+  <td><%= xosDeleteButtonTemplate({modelName: modelName, id: id}) %></td>
 </script>
 
 <script type="text/template" id="xosAdmin-site-detail-template">
      <th>site</th>
      <th>max_slivers</th>
      <th>service</th>
+     <th>delete</th>
   </tr></thead>
   <tbody></tbody>
   </table>
   <td><%= idToName(site,"sites","name") %></td>
   <td><%= max_slivers %></td>
   <td><%= idToName(service,"services","name") %></td>
+  <td><%= xosDeleteButtonTemplate({modelName: modelName, id: id}) %></td>
 </script>
 
 <script type="text/template" id="xosAdmin-slice-detail-template">
      <th>slice</th>
      <th>deployment</th>
      <th>tenant_id</th>
+     <th>delete</th>
   </tr></thead>
   <tbody></tbody>
   </table>
   <td><%= idToName(slice,"slices","name") %></td>
   <td><%= idToName(deployment,"deployments","name") %></td>
   <td><%= tenant_id %></td>
+  <td><%= xosDeleteButtonTemplate({modelName: modelName, id: id}) %></td>
 </script>
 
 <script type="text/template" id="xosAdmin-sliceDeployment-detail-template">
      <th>user</th>
      <th>slice</th>
      <th>role</th>
+     <th>delete</th>
   </tr></thead>
   <tbody></tbody>
   </table>
   <td><%= idToName(user,"users","username") %></td>
   <td><%= idToName(slice,"slices","name") %></td>
   <td><%= idToName(role,"sliceRoles","role") %></td>
+  <td><%= xosDeleteButtonTemplate({modelName: modelName, id: id}) %></td>
 </script>
 
 <script type="text/template" id="xosAdmin-slicePrivilege-detail-template">
      <th>deploymentNetwork</th>
      <th>flavor</th>
      <th>userData</th>
+     <th>delete</th>
   </tr></thead>
   <tbody></tbody>
   </table>
   <td><%= idToName(deploymentNetwork,"deployments","name") %></td>
   <td><%= flavor %></td>
   <td><%= userData %></td>
+  <td><%= xosDeleteButtonTemplate({modelName: modelName, id: id}) %></td>
 </script>
 
 <script type="text/template" id="xosAdmin-sliver-detail-template">
      <th>phone</th>
      <th>user_url</th>
      <th>site</th>
+     <th>delete</th>
   </tr></thead>
   <tbody></tbody>
   </table>
   <td><%= phone %></td>
   <td><%= user_url %></td>
   <td><%= idToName(site,"sites","name") %></td>
+  <td><%= xosDeleteButtonTemplate({modelName: modelName, id: id}) %></td>
 </script>
 
 <script type="text/template" id="xosAdmin-user-detail-template">
      <th>user</th>
      <th>deployment</th>
      <th>kuser_id</th>
+     <th>delete</th>
   </tr></thead>
   <tbody></tbody>
   </table>
   <td><%= idToName(user,"users","username") %></td>
   <td><%= idToName(deployment,"deployments","name") %></td>
   <td><%= kuser_id %></td>
+  <td><%= xosDeleteButtonTemplate({modelName: modelName, id: id}) %></td>
 </script>
 
 <script type="text/template" id="xosAdmin-userDeployment-detail-template">