summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Metson <simon+github@cloudant.com>2014-01-27 11:38:35 +0000
committersuelockwood <deathbear@apache.org>2014-01-29 10:34:29 -0500
commit77fbb4dbed79e277063bea9fe52f132e5495f4ad (patch)
tree5dfb62a98b8fb826aff831decc5a47b0331bdd96
parent24eb32c809697605cc16136395c88fcfa5b3c840 (diff)
downloadcouchdb-77fbb4dbed79e277063bea9fe52f132e5495f4ad.tar.gz
Make a ModalView to dry the code a bit
-rw-r--r--src/fauxton/app/addons/documents/views.js94
-rw-r--r--src/fauxton/app/addons/fauxton/components.js43
2 files changed, 46 insertions, 91 deletions
diff --git a/src/fauxton/app/addons/documents/views.js b/src/fauxton/app/addons/documents/views.js
index 455bfda7f..8ddf46f04 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({
diff --git a/src/fauxton/app/addons/fauxton/components.js b/src/fauxton/app/addons/fauxton/components.js
index c26fc963f..1f5e4ada7 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) {