Make a ModalView to dry the code a bit
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/77fbb4db Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/77fbb4db Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/77fbb4db Branch: refs/heads/master Commit: 77fbb4dbed79e277063bea9fe52f132e5495f4ad Parents: 24eb32c Author: Simon Metson <[email protected]> Authored: Mon Jan 27 11:38:35 2014 +0000 Committer: suelockwood <[email protected]> Committed: Wed Jan 29 10:34:29 2014 -0500 ---------------------------------------------------------------------- src/fauxton/app/addons/documents/views.js | 94 +---------------------- src/fauxton/app/addons/fauxton/components.js | 43 ++++++++++- 2 files changed, 46 insertions(+), 91 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/77fbb4db/src/fauxton/app/addons/documents/views.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/documents/views.js b/src/fauxton/app/addons/documents/views.js index 455bfda..8ddf46f 100644 --- a/src/fauxton/app/addons/documents/views.js +++ b/src/fauxton/app/addons/documents/views.js @@ -113,15 +113,9 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum } }); - Views.DeleteDBModal = FauxtonAPI.View.extend({ + Views.DeleteDBModal = Components.ModalView.extend({ template: "addons/documents/templates/delete_database_modal", - disableLoader: true, - - initialize: function (options) { - _.bindAll(this); - }, - events: { "click a#delete-db-btn": "deleteDatabase", "submit #delete-db-check": "deleteDatabase" @@ -155,43 +149,12 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum clear: true }); }); - }, - - showModal: function () { - this.clear_error_msg(); - this.$('.modal').modal(); - // hack to get modal visible - $('.modal-backdrop').css('z-index',1025); - }, - - hideModal: function () { - this.$('.modal').modal('hide'); - }, - - set_error_msg: function (msg) { - var text; - if (typeof(msg) == 'string') { - text = msg; - } else { - text = JSON.parse(msg.responseText).reason; - } - this.$('#modal-error').text(text).removeClass('hide'); - }, - - clear_error_msg: function () { - this.$('#modal-error').text(' ').addClass('hide'); } }); - Views.UploadModal = FauxtonAPI.View.extend({ + Views.UploadModal = Components.ModalView.extend({ template: "addons/documents/templates/upload_modal", - disableLoader: true, - - initialize: function (options) { - _.bindAll(this); - }, - events: { "click a#upload-btn": "uploadFile" }, @@ -247,39 +210,13 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum this.$('.progress').removeClass('hide'); }, - showModal: function () { + _showModal: function () { this.$('.bar').css({width: '0%'}); this.$('.progress').addClass('hide'); - this.clear_error_msg(); - this.$('.modal').modal(); - // hack to get modal visible - $('.modal-backdrop').css('z-index',1025); - }, - - hideModal: function () { - this.$('.modal').modal('hide'); - }, - - set_error_msg: function (msg) { - var text; - if (typeof(msg) == 'string') { - text = msg; - } else { - text = JSON.parse(msg.responseText).reason; - } - this.$('#modal-error').text(text).removeClass('hide'); - }, - - clear_error_msg: function () { - this.$('#modal-error').text(' ').addClass('hide'); - }, - - serialize: function () { - return this.model.toJSON(); } }); - Views.DuplicateDocModal = FauxtonAPI.View.extend({ + Views.DuplicateDocModal = Components.ModalView.extend({ template: "addons/documents/templates/duplicate_doc_modal", initialize: function () { @@ -325,30 +262,7 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum setDefaultIdValue: function (id) { this.$('#dup-id').val(id); - }, - - hideModal: function () { - this.$('.modal').modal('hide'); - }, - - set_error_msg: function (msg) { - var text; - if (typeof(msg) == 'string') { - text = msg; - } else { - text = JSON.parse(msg.responseText).reason; - } - this.$('#modal-error').text(text).removeClass('hide'); - }, - - clear_error_msg: function () { - this.$('#modal-error').text(' ').addClass('hide'); - }, - - serialize: function () { - return this.model.toJSON(); } - }); Views.FieldEditorTabs = FauxtonAPI.View.extend({ http://git-wip-us.apache.org/repos/asf/couchdb/blob/77fbb4db/src/fauxton/app/addons/fauxton/components.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/fauxton/components.js b/src/fauxton/app/addons/fauxton/components.js index c26fc96..1f5e4ad 100644 --- a/src/fauxton/app/addons/fauxton/components.js +++ b/src/fauxton/app/addons/fauxton/components.js @@ -119,7 +119,7 @@ function(app, FauxtonAPI, ace, spin) { }, pageStart: function () { - return (this.previousParams.length * this.pageLimit()) + 1; + return (this.previousParams.length * this.pageLimit()) + 1; }, @@ -160,6 +160,47 @@ function(app, FauxtonAPI, ace, spin) { }); + Components.ModalView = FauxtonAPI.View.extend({ + + disableLoader: true, + + initialize: function (options) { + _.bindAll(this); + }, + + showModal: function () { + if (this._showModal){ this._showModal();} + this.clear_error_msg(); + this.$('.modal').modal(); + // hack to get modal visible + $('.modal-backdrop').css('z-index',1025); + }, + + hideModal: function () { + this.$('.modal').modal('hide'); + }, + + set_error_msg: function (msg) { + var text; + if (typeof(msg) == 'string') { + text = msg; + } else { + text = JSON.parse(msg.responseText).reason; + } + this.$('#modal-error').text(text).removeClass('hide'); + }, + + clear_error_msg: function () { + this.$('#modal-error').text(' ').addClass('hide'); + }, + + serialize: function () { + if (this.model){ + return this.model.toJSON(); + } + return {}; + } + }); Components.DbSearchTypeahead = Components.Typeahead.extend({ initialize: function (options) {
