delete working for deployments, confirmation dialog
authorScott Baker <smbaker@gmail.com>
Wed, 19 Nov 2014 07:31:48 +0000 (23:31 -0800)
committerScott Baker <smbaker@gmail.com>
Wed, 19 Nov 2014 07:31:48 +0000 (23:31 -0800)
planetstack/core/xoslib/dashboards/xosAdminDashboard.html
planetstack/core/xoslib/static/css/xosAdminSite.css
planetstack/core/xoslib/static/js/xoslib/xosHelper.js

index 99050e1..b5dacc9 100644 (file)
   </tr>
 </script>
 
+<div id="xos-confirm-dialog" title="Confirmation Required">
+  Are you sure about this?\r
+</div>
+
 <div id="contentPanel">
 <div id="contentTitle">
 </div>
index 6de351b..98dfb88 100644 (file)
@@ -28,6 +28,23 @@ XOSApplication = Marionette.Application.extend({
     successTemplate: "#xos-success-template",
     logMessageCount: 0,
 
+    confirmDialog: function(view, event) {
+        $("#xos-confirm-dialog").dialog({
+           autoOpen: false,\r
+           modal: true,\r
+           buttons : {\r
+                "Confirm" : function() {\r
+                  $(this).dialog("close");\r
+                  view.trigger(event);\r
+                },\r
+                "Cancel" : function() {\r
+                  $(this).dialog("close");\r
+                }\r
+              }\r
+            });
+        $("#xos-confirm-dialog").dialog("open");
+    },
+
     hideError: function() {
         if (this.logWindowId) {
         } else {
@@ -169,8 +186,13 @@ XOSDetailView = Marionette.ItemView.extend({
             events: {"click button.btn-xos-save-continue": "submitContinueClicked",
                      "click button.btn-xos-save-leave": "submitLeaveClicked",
                      "click button.btn-xos-save-another": "submitAddAnotherClicked",
+                     "click button.btn-xos-delete": "deleteClicked",
                      "change input": "inputChanged"},
 
+            initialize: function() {
+                this.on('deleteConfirmed', this.deleteConfirmed);
+            },
+
             /* inputChanged is watching the onChange events of the input controls. We
                do this to track when this view is 'dirty', so we can throw up a warning\r
                if the user tries to change his slices without saving first.\r
@@ -193,6 +215,19 @@ XOSDetailView = Marionette.ItemView.extend({
                 this.app.showSuccess(result);\r
             },
 
+            destroyError: function(model, result, xhr, infoMsgId) {
+                result["what"] = "destroy " + model.__proto__.modelName;\r
+                result["infoMsgId"] = infoMsgId;\r
+                this.app.showError(result);\r
+            },\r
+\r
+            destroySuccess: function(model, result, xhr, infoMsgId) {\r
+                result = {status: xhr.xhr.status, statusText: xhr.xhr.statusText};\r
+                result["what"] = "destroy " + model.__proto__.modelName;\r
+                result["infoMsgId"] = infoMsgId;\r
+                this.app.showSuccess(result);\r
+            },
+
             submitContinueClicked: function(e) {
                 console.log("saveContinue");
                 e.preventDefault();
@@ -229,6 +264,25 @@ XOSDetailView = Marionette.ItemView.extend({
                 this.dirty = false;\r
             },
 
+            destroyModel: function() {
+                 this.app.hideError();
+                 var infoMsgId = this.app.showInformational( {what: "destroy " + this.model.__proto__.modelName, status: "", statusText: "in progress..."} );
+                 var that = this;
+                 this.model.destroy({error: function(model, result, xhr) { that.destroyError(model,result,xhr,infoMsgId);},
+                                     success: function(model, result, xhr) { that.destroySuccess(model,result,xhr,infoMsgId);}});
+            },
+
+             deleteClicked: function(e) {
+                 e.preventDefault();
+\r                 this.app.confirmDialog(this, "deleteConfirmed");
+\r             },
+\r
+\r             deleteConfirmed: function() {
+\r                 modelName = this.model.modelName;
+\r                 this.destroyModel();
+\r                 this.app.navigate("list", modelName);
+\r             },
+\r
             tabClick: function(tabId, regionName) {
                     region = this.app[regionName];\r
                     if (this.currentTabRegion != undefined) {\r