fix issue with delete dialog
authorScott Baker <smbaker@gmail.com>
Tue, 2 Dec 2014 22:50:26 +0000 (14:50 -0800)
committerScott Baker <smbaker@gmail.com>
Tue, 2 Dec 2014 22:50:26 +0000 (14:50 -0800)
planetstack/core/xoslib/static/js/xoslib/xosHelper.js

index d9e23a6..ca7a5bf 100644 (file)
@@ -30,22 +30,22 @@ XOSApplication = Marionette.Application.extend({
 
     confirmDialog: function(view, event, callback) {
         $("#xos-confirm-dialog").dialog({
-           autoOpen: false,\r
-           modal: true,\r
-           buttons : {\r
-                "Confirm" : function() {\r
-                  $(this).dialog("close");\r
-                  if (event) {\r
-                      view.trigger(event);\r
-                  }\r
-                  if (callback) {\r
-                      callback();\r
-                  }\r
-                },\r
-                "Cancel" : function() {\r
-                  $(this).dialog("close");\r
-                }\r
-              }\r
+           autoOpen: false,
+           modal: true,
+           buttons : {
+                "Confirm" : function() {
+                  $(this).dialog("close");
+                  if (event) {
+                      view.trigger(event);
+                  }
+                  if (callback) {
+                      callback();
+                  }
+                },
+                "Cancel" : function() {
+                  $(this).dialog("close");
+                }
+              }
             });
         $("#xos-confirm-dialog").dialog("open");
     },
@@ -76,61 +76,61 @@ XOSApplication = Marionette.Application.extend({
 
     hideLinkedItems: function(result) {
         var index=0;
-        while (index<4) {\r
-            this["linkedObjs" + (index+1)].empty();\r
-            index = index + 1;\r
-        }\r
-    },\r
-\r
-    listViewShower: function(listViewName, collection_name, regionName, title) {\r
-        var app=this;\r
-        return function() {\r
-            app[regionName].show(new app[listViewName]);\r
-            app.hideLinkedItems();\r
-            $("#contentTitle").html(templateFromId("#xos-title-list")({"title": title}));\r
-            $("#detail").show();\r
-            $("#xos-listview-button-box").show();\r
-            $("#tabs").hide();\r
-            $("#xos-detail-button-box").hide();\r
-        }\r
-    },\r
-\r
-    addShower: function(detailName, collection_name, regionName, title) {\r
-        var app=this;\r
-        return function() {\r
-            model = new xos[collection_name].model();\r
-            detailViewClass = app[detailName];\r
-            detailView = new detailViewClass({model: model, collection:xos[collection_name]});\r
-            app[regionName].show(detailView);\r
-            $("#xos-detail-button-box").show();\r
-            $("#xos-listview-button-box").hide();\r
-        }\r
-    },\r
-\r
-    detailShower: function(detailName, collection_name, regionName, title) {\r
-        var app=this;\r
-        showModelId = function(model_id) {\r
-            $("#contentTitle").html(templateFromId("#xos-title-detail")({"title": title}));\r
-\r
-            collection = xos[collection_name];\r
-            model = collection.get(model_id);\r
-            if (model == undefined) {\r
-                app[regionName].show(new HTMLView({html: "failed to load object " + model_id + " from collection " + collection_name}));\r
-            } else {\r
-                detailViewClass = app[detailName];\r
-                detailView = new detailViewClass({model: model});\r
-                app[regionName].show(detailView);\r
-                detailView.showLinkedItems();\r
-                $("#xos-detail-button-box").show();\r
-                $("#xos-listview-button-box").hide();\r
-            }\r
-        }\r
-        return showModelId;\r
-    },\r
-\r
-    /* error handling callbacks */\r
-\r
-    hideError: function() {\r
+        while (index<4) {
+            this["linkedObjs" + (index+1)].empty();
+            index = index + 1;
+        }
+    },
+
+    listViewShower: function(listViewName, collection_name, regionName, title) {
+        var app=this;
+        return function() {
+            app[regionName].show(new app[listViewName]);
+            app.hideLinkedItems();
+            $("#contentTitle").html(templateFromId("#xos-title-list")({"title": title}));
+            $("#detail").show();
+            $("#xos-listview-button-box").show();
+            $("#tabs").hide();
+            $("#xos-detail-button-box").hide();
+        }
+    },
+
+    addShower: function(detailName, collection_name, regionName, title) {
+        var app=this;
+        return function() {
+            model = new xos[collection_name].model();
+            detailViewClass = app[detailName];
+            detailView = new detailViewClass({model: model, collection:xos[collection_name]});
+            app[regionName].show(detailView);
+            $("#xos-detail-button-box").show();
+            $("#xos-listview-button-box").hide();
+        }
+    },
+
+    detailShower: function(detailName, collection_name, regionName, title) {
+        var app=this;
+        showModelId = function(model_id) {
+            $("#contentTitle").html(templateFromId("#xos-title-detail")({"title": title}));
+
+            collection = xos[collection_name];
+            model = collection.get(model_id);
+            if (model == undefined) {
+                app[regionName].show(new HTMLView({html: "failed to load object " + model_id + " from collection " + collection_name}));
+            } else {
+                detailViewClass = app[detailName];
+                detailView = new detailViewClass({model: model});
+                app[regionName].show(detailView);
+                detailView.showLinkedItems();
+                $("#xos-detail-button-box").show();
+                $("#xos-listview-button-box").hide();
+            }
+        }
+        return showModelId;
+    },
+
+    /* error handling callbacks */
+
+    hideError: function() {
         if (this.logWindowId) {
         } else {
             $(this.errorBoxId).hide();
@@ -150,9 +150,9 @@ XOSApplication = Marionette.Application.extend({
                  $(that.successBoxId).hide();
              });
          }
-    },\r
-\r
-    showError: function(result) {\r
+    },
+
+    showError: function(result) {
          result["statusclass"] = "failure";
          if (this.logTableId) {
              this.appendLogWindow(result);
@@ -166,9 +166,9 @@ XOSApplication = Marionette.Application.extend({
                  $(that.errorBoxId).hide();
              });
          }
-    },\r
-\r
-    showInformational: function(result) {\r
+    },
+
+    showInformational: function(result) {
          result["statusclass"] = "inprog";
          if (this.logTableId) {
              return this.appendLogWindow(result);
@@ -206,43 +206,44 @@ XOSApplication = Marionette.Application.extend({
         limitTableRows(this.logTableId, 5);
 
         return logMessageId;
-    },\r
-\r
-    saveError: function(model, result, xhr, infoMsgId) {\r
-        console.log("saveError");\r
-        result["what"] = "save " + model.modelName + " " + model.attributes.humanReadableName;\r
-        result["infoMsgId"] = infoMsgId;\r
-        this.showError(result);\r
-    },\r
-\r
-    saveSuccess: function(model, result, xhr, infoMsgId, addToCollection) {\r
-        console.log("saveSuccess");\r
-        if (addToCollection) {\r
-            addToCollection.add(model);\r
-            addToCollection.sort();\r
-        }\r
-        result = {status: xhr.xhr.status, statusText: xhr.xhr.statusText};\r
-        result["what"] = "save " + model.modelName + " " + model.attributes.humanReadableName;\r
-        result["infoMsgId"] = infoMsgId;\r
-        this.showSuccess(result);\r
+    },
+
+    saveError: function(model, result, xhr, infoMsgId) {
+        console.log("saveError");
+        result["what"] = "save " + model.modelName + " " + model.attributes.humanReadableName;
+        result["infoMsgId"] = infoMsgId;
+        this.showError(result);
+    },
+
+    saveSuccess: function(model, result, xhr, infoMsgId, addToCollection) {
+        console.log("saveSuccess");
+        if (addToCollection) {
+            addToCollection.add(model);
+            addToCollection.sort();
+        }
+        result = {status: xhr.xhr.status, statusText: xhr.xhr.statusText};
+        result["what"] = "save " + model.modelName + " " + model.attributes.humanReadableName;
+        result["infoMsgId"] = infoMsgId;
+        this.showSuccess(result);
     },
 
     destroyError: function(model, result, xhr, infoMsgId) {
-        result["what"] = "destroy " + model.modelName + " " + model.attributes.humanReadableName;\r
-        result["infoMsgId"] = infoMsgId;\r
-        this.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.modelName + " " + model.attributes.humanReadableName;\r
-        result["infoMsgId"] = infoMsgId;\r
-        this.showSuccess(result);\r
-    },\r
-\r
-    /* end error handling callbacks */\r
-\r
-    destroyModel: function(model) {\r
+        result["what"] = "destroy " + model.modelName + " " + model.attributes.humanReadableName;
+        result["infoMsgId"] = infoMsgId;
+        this.showError(result);
+    },
+
+    destroySuccess: function(model, result, xhr, infoMsgId) {
+        result = {status: xhr.xhr.status, statusText: xhr.xhr.statusText};
+        result["what"] = "destroy " + model.modelName + " " + model.attributes.humanReadableName;
+        result["infoMsgId"] = infoMsgId;
+        this.showSuccess(result);
+    },
+
+    /* end error handling callbacks */
+
+    destroyModel: function(model) {
+         //console.log("destroyModel"); console.log(model);
          this.hideError();
          var infoMsgId = this.showInformational( {what: "destroy " + model.modelName + " " + model.attributes.humanReadableName, status: "", statusText: "in progress..."} );
          var that = this;
@@ -252,7 +253,9 @@ XOSApplication = Marionette.Application.extend({
 
     deleteDialog: function(model, navToListAfterDelete) {
         var that=this;
-        this.confirmDialog(this, callback=function() {
+        //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) {
@@ -262,7 +265,7 @@ XOSApplication = Marionette.Application.extend({
         });
     },
 });
-\r
+
 /* XOSDetailView
       extend with:
          app - MarionetteApplication
@@ -278,20 +281,20 @@ XOSDetailView = Marionette.ItemView.extend({
                      "click button.btn-xos-delete": "deleteClicked",
                      "change input": "inputChanged"},
 
-            initialize: function() {
+            /*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
-            */\r
-\r
-            inputChanged: function(e) {\r
-                this.dirty = true;\r
-            },\r
-\r
-            submitContinueClicked: function(e) {\r
+               do this to track when this view is 'dirty', so we can throw up a warning
+               if the user tries to change his slices without saving first.
+            */
+
+            inputChanged: function(e) {
+                this.dirty = true;
+            },
+
+            submitContinueClicked: function(e) {
                 console.log("saveContinue");
                 e.preventDefault();
                 this.save();
@@ -313,37 +316,37 @@ XOSDetailView = Marionette.ItemView.extend({
 
             save: function() {
                 this.app.hideError();
-                var data = Backbone.Syphon.serialize(this);\r
-                var that = this;\r
-                var isNew = !this.model.id;\r
-\r
-                this.$el.find(".help-inline").remove();\r
-\r
-                /* although model.validate() is called automatically by\r
-                   model.save, we call it ourselves, so we can throw up our\r
-                   validation error before creating the infoMsg in the log\r
-                */\r
-                errors =  this.model.xosValidate(data);\r
-                if (errors) {\r
-                    this.onFormDataInvalid(errors);\r
-                    return;\r
-                }\r
-\r
-                if (isNew) {\r
-                    this.model.attributes.humanReadableName = "new " + model.modelName;\r
-                    this.model.addToCollection = this.collection;\r
-                } else {\r
-                    this.model.addToCollection = undefined;\r
-                }\r
-\r
-                var infoMsgId = this.app.showInformational( {what: "save " + model.modelName + " " + model.attributes.humanReadableName, status: "", statusText: "in progress..."} );\r
-\r
-                this.model.save(data, {error: function(model, result, xhr) { that.app.saveError(model,result,xhr,infoMsgId);},\r
-                                       success: function(model, result, xhr) { that.app.saveSuccess(model,result,xhr,infoMsgId);}});\r
-                this.dirty = false;\r
+                var data = Backbone.Syphon.serialize(this);
+                var that = this;
+                var isNew = !this.model.id;
+
+                this.$el.find(".help-inline").remove();
+
+                /* although model.validate() is called automatically by
+                   model.save, we call it ourselves, so we can throw up our
+                   validation error before creating the infoMsg in the log
+                */
+                errors =  this.model.xosValidate(data);
+                if (errors) {
+                    this.onFormDataInvalid(errors);
+                    return;
+                }
+
+                if (isNew) {
+                    this.model.attributes.humanReadableName = "new " + model.modelName;
+                    this.model.addToCollection = this.collection;
+                } else {
+                    this.model.addToCollection = undefined;
+                }
+
+                var infoMsgId = this.app.showInformational( {what: "save " + model.modelName + " " + model.attributes.humanReadableName, status: "", statusText: "in progress..."} );
+
+                this.model.save(data, {error: function(model, result, xhr) { that.app.saveError(model,result,xhr,infoMsgId);},
+                                       success: function(model, result, xhr) { that.app.saveSuccess(model,result,xhr,infoMsgId);}});
+                this.dirty = false;
             },
 
-            destroyModel: function() {
+            /*destroyModel: function() {
                  this.app.hideError();
                  var infoMsgId = this.app.showInformational( {what: "destroy " + model.modelName + " " + model.attributes.humanReadableName, status: "", statusText: "in progress..."} );
                  var that = this;
@@ -353,28 +356,33 @@ XOSDetailView = Marionette.ItemView.extend({
 
              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
+                 this.app.confirmDialog(this, "deleteConfirmed");
+             },
+
+             deleteConfirmed: function() {
+                 modelName = this.model.modelName;
+                 this.destroyModel();
+                 this.app.navigate("list", modelName);
+             }, */
+
+             deleteClicked: function(e) {
+                 e.preventDefault();
+                 this.app.deleteDialog(this.model, true);
+             },
+
             tabClick: function(tabId, regionName) {
-                    region = this.app[regionName];\r
-                    if (this.currentTabRegion != undefined) {\r
-                        this.currentTabRegion.$el.hide();\r
-                    }\r
-                    if (this.currentTabId != undefined) {\r
-                        $(this.currentTabId).removeClass('active');\r
-                    }\r
-                    this.currentTabRegion = region;\r
-                    this.currentTabRegion.$el.show();\r
-\r
-                    this.currentTabId = tabId;\r
-                    $(tabId).addClass('active');\r
+                    region = this.app[regionName];
+                    if (this.currentTabRegion != undefined) {
+                        this.currentTabRegion.$el.hide();
+                    }
+                    if (this.currentTabId != undefined) {
+                        $(this.currentTabId).removeClass('active');
+                    }
+                    this.currentTabRegion = region;
+                    this.currentTabRegion.$el.show();
+
+                    this.currentTabId = tabId;
+                    $(tabId).addClass('active');
             },
 
             showTabs: function(tabs) {
@@ -397,44 +405,44 @@ XOSDetailView = Marionette.ItemView.extend({
                     tabs.push({name: "details", region: "detail"});
 
                     var index=0;
-                    for (relatedName in this.model.collection.relatedCollections) {\r
-                        relatedField = this.model.collection.relatedCollections[relatedName];\r
-                        regionName = "linkedObjs" + (index+1);\r
-\r
-                        relatedListViewClassName = relatedName + "ListView";\r
-                        assert(this.app[relatedListViewClassName] != undefined, relatedListViewClassName + " not found");\r
-                        relatedListViewClass = this.app[relatedListViewClassName].extend({collection: xos[relatedName].filterBy(relatedField,this.model.id)});\r
-                        this.app[regionName].show(new relatedListViewClass());\r
-                        if (this.app.hideTabsByDefault) {\r
-                            this.app[regionName].$el.hide();\r
-                        }\r
-                        tabs.push({name: relatedName, region: regionName});\r
-                        index = index + 1;\r
-                    }\r
-\r
-                    while (index<4) {\r
-                        this.app["linkedObjs" + (index+1)].empty();\r
-                        index = index + 1;\r
-                    }\r
-\r
-                    this.showTabs(tabs);\r
-                    this.tabClick('#xos-nav-detail', 'detail');\r
-              },\r
-\r
-            onFormDataInvalid: function(errors) {\r
-                var self=this;\r
-                var markErrors = function(value, key) {\r
-                    console.log("name='" + key + "'");\r
-                    var $inputElement = self.$el.find("[name='" + key + "']");\r
-                    var $inputContainer = $inputElement.parent();\r
-                    //$inputContainer.find(".help-inline").remove();\r
-                    var $errorEl = $("<span>", {class: "help-inline error", text: value});\r
-                    $inputContainer.append($errorEl).addClass("error");\r
-                }\r
-                _.each(errors, markErrors);\r
-            },\r
-\r
-});\r
+                    for (relatedName in this.model.collection.relatedCollections) {
+                        relatedField = this.model.collection.relatedCollections[relatedName];
+                        regionName = "linkedObjs" + (index+1);
+
+                        relatedListViewClassName = relatedName + "ListView";
+                        assert(this.app[relatedListViewClassName] != undefined, relatedListViewClassName + " not found");
+                        relatedListViewClass = this.app[relatedListViewClassName].extend({collection: xos[relatedName].filterBy(relatedField,this.model.id)});
+                        this.app[regionName].show(new relatedListViewClass());
+                        if (this.app.hideTabsByDefault) {
+                            this.app[regionName].$el.hide();
+                        }
+                        tabs.push({name: relatedName, region: regionName});
+                        index = index + 1;
+                    }
+
+                    while (index<4) {
+                        this.app["linkedObjs" + (index+1)].empty();
+                        index = index + 1;
+                    }
+
+                    this.showTabs(tabs);
+                    this.tabClick('#xos-nav-detail', 'detail');
+              },
+
+            onFormDataInvalid: function(errors) {
+                var self=this;
+                var markErrors = function(value, key) {
+                    console.log("name='" + key + "'");
+                    var $inputElement = self.$el.find("[name='" + key + "']");
+                    var $inputContainer = $inputElement.parent();
+                    //$inputContainer.find(".help-inline").remove();
+                    var $errorEl = $("<span>", {class: "help-inline error", text: value});
+                    $inputContainer.append($errorEl).addClass("error");
+                }
+                _.each(errors, markErrors);
+            },
+
+});
 
 /* XOSItemView
       This is for items that will be displayed as table rows.
@@ -463,32 +471,32 @@ XOSItemView = Marionette.ItemView.extend({
 */
 
 XOSListView = Marionette.CompositeView.extend({
-             childViewContainer: 'tbody',\r
-\r
-             events: {"click button.btn-xos-add": "addClicked",\r
-                      "click button.btn-xos-refresh": "refreshClicked",\r
-                     },\r
-\r
-             _fetchStateChange: function() {\r
-                 if (this.collection.fetching) {\r
-                    $("#xos-list-title-spinner").show();\r
-                 } else {\r
-                    $("#xos-list-title-spinner").hide();\r
-                 }\r
-             },\r
-\r
+             childViewContainer: 'tbody',
+
+             events: {"click button.btn-xos-add": "addClicked",
+                      "click button.btn-xos-refresh": "refreshClicked",
+                     },
+
+             _fetchStateChange: function() {
+                 if (this.collection.fetching) {
+                    $("#xos-list-title-spinner").show();
+                 } else {
+                    $("#xos-list-title-spinner").hide();
+                 }
+             },
+
              addClicked: function(e) {
                 e.preventDefault();
                 this.app.Router.navigate("add" + firstCharUpper(this.collection.modelName), {trigger: true});
              },
-\r
-\r             refreshClicked: function(e) {
-\r                 e.preventDefault();
-\r                 this.collection.refresh(refreshRelated=true);
-\r             },
-\r
-\r             initialize: function() {
-\r                 this.listenTo(this.collection, 'change', this._renderChildren)
+
+             refreshClicked: function(e) {
+                 e.preventDefault();
+                 this.collection.refresh(refreshRelated=true);
+             },
+
+             initialize: function() {
+                 this.listenTo(this.collection, 'change', this._renderChildren)
                  this.listenTo(this.collection, 'fetchStateChange', this._fetchStateChange);
 
                  // Because many of the templates use idToName(), we need to
@@ -506,7 +514,7 @@ XOSListView = Marionette.CompositeView.extend({
 
              templateHelpers: function() {
                 return { title: this.title };
-             },\r
+             },
 });
 
 /* Give an id, the name of a collection, and the name of a field for models