From 05cb9817444254ed08a2f56018159176d1f147c1 Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Tue, 2 Dec 2014 14:50:26 -0800 Subject: [PATCH] fix issue with delete dialog --- .../core/xoslib/static/js/xoslib/xosHelper.js | 478 +++++++++--------- 1 file changed, 243 insertions(+), 235 deletions(-) diff --git a/planetstack/core/xoslib/static/js/xoslib/xosHelper.js b/planetstack/core/xoslib/static/js/xoslib/xosHelper.js index d9e23a6..ca7a5bf 100644 --- a/planetstack/core/xoslib/static/js/xoslib/xosHelper.js +++ b/planetstack/core/xoslib/static/js/xoslib/xosHelper.js @@ -30,22 +30,22 @@ XOSApplication = Marionette.Application.extend({ confirmDialog: function(view, event, callback) { $("#xos-confirm-dialog").dialog({ - autoOpen: false, - modal: true, - buttons : { - "Confirm" : function() { - $(this).dialog("close"); - if (event) { - view.trigger(event); - } - if (callback) { - callback(); - } - }, - "Cancel" : function() { - $(this).dialog("close"); - } - } + 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) { - 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() { + 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(); }); } - }, - - showError: function(result) { + }, + + showError: function(result) { result["statusclass"] = "failure"; if (this.logTableId) { this.appendLogWindow(result); @@ -166,9 +166,9 @@ XOSApplication = Marionette.Application.extend({ $(that.errorBoxId).hide(); }); } - }, - - showInformational: function(result) { + }, + + 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; - }, - - 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); + }, + + 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; - 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) { + 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({ }); }, }); - + /* 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 - if the user tries to change his slices without saving first. - */ - - inputChanged: function(e) { - this.dirty = true; - }, - - submitContinueClicked: function(e) { + 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); - 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; + 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(); - this.app.confirmDialog(this, "deleteConfirmed"); - }, - - deleteConfirmed: function() { - modelName = this.model.modelName; - this.destroyModel(); - this.app.navigate("list", modelName); - }, - + 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]; - 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'); + 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) { - 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 = $("", {class: "help-inline error", text: value}); - $inputContainer.append($errorEl).addClass("error"); - } - _.each(errors, markErrors); - }, - -}); + 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 = $("", {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', - - 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(); - } - }, - + 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}); }, - - refreshClicked: function(e) { - e.preventDefault(); - this.collection.refresh(refreshRelated=true); - }, - - initialize: function() { - 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 }; - }, + }, }); /* Give an id, the name of a collection, and the name of a field for models -- 2.43.0