Merge branch 'master' of git://git.planet-lab.org/plstackapi
diff --git a/planetstack/core/xoslib/static/js/xosAdminSite.js b/planetstack/core/xoslib/static/js/xosAdminSite.js
index ceb2589..36ffd0b 100644
--- a/planetstack/core/xoslib/static/js/xosAdminSite.js
+++ b/planetstack/core/xoslib/static/js/xosAdminSite.js
@@ -96,9 +96,7 @@
};
XOSAdminApp.initRouter = function() {
- router = Marionette.AppRouter.extend({
- });
-
+ router = XOSRouter;
var api = {};
var routes = {};
@@ -123,6 +121,11 @@
api_command = "add" + firstCharUpper(name);
api[api_command] = XOSAdminApp.addShower(detailViewName, collection_name, "detail", name);
routes[nav_url] = api_command;
+
+ nav_url = "delete" + firstCharUpper(name) + "/:id";
+ api_command = "delete" + firstCharUpper(name);
+ api[api_command] = XOSAdminApp.deleteShower(collection_name, name);
+ routes[nav_url] = api_command;
};
XOSAdminApp.Router = new router({ appRoutes: routes, controller: api });
diff --git a/planetstack/core/xoslib/static/js/xoslib/xos-util.js b/planetstack/core/xoslib/static/js/xoslib/xos-util.js
index 5e91a3d..c1f736e 100644
--- a/planetstack/core/xoslib/static/js/xoslib/xos-util.js
+++ b/planetstack/core/xoslib/static/js/xoslib/xos-util.js
@@ -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);
diff --git a/planetstack/core/xoslib/static/js/xoslib/xosHelper.js b/planetstack/core/xoslib/static/js/xoslib/xosHelper.js
index ca7a5bf..eb8008c 100644
--- a/planetstack/core/xoslib/static/js/xoslib/xosHelper.js
+++ b/planetstack/core/xoslib/static/js/xoslib/xosHelper.js
@@ -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() {
+ this.routeStack=[];
+ },
+
+ onRoute: function(x,y,z) {
+ this.routeStack.push(Backbone.history.fragment);
+ },
+
+ prevPage: function() {
+ return this.routeStack.slice(-2)[0];
+ },
+ });
+
+
+
XOSApplication = Marionette.Application.extend({
detailBoxId: "#detailBox",
errorBoxId: "#errorBox",
@@ -107,6 +109,17 @@
}
},
+ 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 @@
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 @@
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 @@
deleteClicked: function(e) {
e.preventDefault();
- this.app.deleteDialog(this.model, true);
+ this.app.deleteDialog(this.model, "list");
},
tabClick: function(tabId, regionName) {
diff --git a/planetstack/core/xoslib/templates/xosAdmin.html b/planetstack/core/xoslib/templates/xosAdmin.html
index b032e00..854a852 100644
--- a/planetstack/core/xoslib/templates/xosAdmin.html
+++ b/planetstack/core/xoslib/templates/xosAdmin.html
@@ -91,11 +91,7 @@
</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">
@@ -154,6 +150,7 @@
<th>disk_format</th>
<th>container_format</th>
<th>path</th>
+ <th>delete</th>
</tr></thead>
<tbody></tbody>
</table>
@@ -165,6 +162,7 @@
<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">
@@ -193,6 +191,7 @@
<th>translation</th>
<th>sharedNetworkName</th>
<th>sharedNetworkId</th>
+ <th>delete</th>
</tr></thead>
<tbody></tbody>
</table>
@@ -207,6 +206,7 @@
<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">
@@ -237,6 +237,7 @@
<th>ports</th>
<th>labels</th>
<th>owner</th>
+ <th>delete</th>
</tr></thead>
<tbody></tbody>
</table>
@@ -249,6 +250,7 @@
<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">
@@ -277,6 +279,7 @@
<th>sliver</th>
<th>ip</th>
<th>port_id</th>
+ <th>delete</th>
</tr></thead>
<tbody></tbody>
</table>
@@ -288,6 +291,7 @@
<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">
@@ -314,6 +318,7 @@
<th>network</th>
<th>deployment</th>
<th>net_id</th>
+ <th>delete</th>
</tr></thead>
<tbody></tbody>
</table>
@@ -324,6 +329,7 @@
<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">
@@ -349,6 +355,7 @@
<th>name</th>
<th>site</th>
<th>deployment</th>
+ <th>delete</th>
</tr></thead>
<tbody></tbody>
</table>
@@ -360,6 +367,7 @@
<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">
@@ -383,6 +391,7 @@
<thead><tr>
<th>id</th>
<th>role</th>
+ <th>delete</th>
</tr></thead>
<tbody></tbody>
</table>
@@ -392,6 +401,7 @@
<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">
@@ -417,6 +427,7 @@
<th>enabled</th>
<th>versionNumber</th>
<th>published</th>
+ <th>delete</th>
</tr></thead>
<tbody></tbody>
</table>
@@ -430,6 +441,7 @@
<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">
@@ -458,6 +470,7 @@
<th>login_base</th>
<th>is_public</th>
<th>abbreviated_name</th>
+ <th>delete</th>
</tr></thead>
<tbody></tbody>
</table>
@@ -471,6 +484,7 @@
<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">
@@ -504,6 +518,7 @@
<th>site</th>
<th>max_slivers</th>
<th>service</th>
+ <th>delete</th>
</tr></thead>
<tbody></tbody>
</table>
@@ -519,6 +534,7 @@
<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">
@@ -547,6 +563,7 @@
<th>slice</th>
<th>deployment</th>
<th>tenant_id</th>
+ <th>delete</th>
</tr></thead>
<tbody></tbody>
</table>
@@ -557,6 +574,7 @@
<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">
@@ -582,6 +600,7 @@
<th>user</th>
<th>slice</th>
<th>role</th>
+ <th>delete</th>
</tr></thead>
<tbody></tbody>
</table>
@@ -592,6 +611,7 @@
<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">
@@ -624,6 +644,7 @@
<th>deploymentNetwork</th>
<th>flavor</th>
<th>userData</th>
+ <th>delete</th>
</tr></thead>
<tbody></tbody>
</table>
@@ -642,6 +663,7 @@
<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">
@@ -674,6 +696,7 @@
<th>phone</th>
<th>user_url</th>
<th>site</th>
+ <th>delete</th>
</tr></thead>
<tbody></tbody>
</table>
@@ -688,6 +711,7 @@
<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">
@@ -716,6 +740,7 @@
<th>user</th>
<th>deployment</th>
<th>kuser_id</th>
+ <th>delete</th>
</tr></thead>
<tbody></tbody>
</table>
@@ -726,6 +751,7 @@
<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">