diff options
author | Garren Smith <garren.smith@gmail.com> | 2013-09-19 16:02:02 +0200 |
---|---|---|
committer | suelockwood <deathbearbrown@gmail.com> | 2013-09-20 10:52:15 -0400 |
commit | faa65cd5021bc0a1e855571e9626fec647502cd7 (patch) | |
tree | 3570ec920209184bb4c6adce7d7339674d4c4d78 | |
parent | 446e139338945f60d0d937ab3a442d603b86da1d (diff) | |
download | couchdb-faa65cd5021bc0a1e855571e9626fec647502cd7.tar.gz |
Fauxton: warn user if they edit _id
-rw-r--r-- | src/fauxton/Gruntfile.js | 6 | ||||
-rw-r--r-- | src/fauxton/app/modules/documents/resources.js | 6 | ||||
-rw-r--r-- | src/fauxton/app/modules/documents/views.js | 18 |
3 files changed, 24 insertions, 6 deletions
diff --git a/src/fauxton/Gruntfile.js b/src/fauxton/Gruntfile.js index 29a70ba7a..f9af37146 100644 --- a/src/fauxton/Gruntfile.js +++ b/src/fauxton/Gruntfile.js @@ -218,9 +218,9 @@ module.exports = function(grunt) { port: 8000, proxy: { target: { - host: 'localhost', - port: 5984, - https: false + host: 'garrensmith.cloudant.com', + port: 443, + https: true }, // This sets the Host header in the proxy so that you can use external // CouchDB instances and not have the Host set to 'localhost' diff --git a/src/fauxton/app/modules/documents/resources.js b/src/fauxton/app/modules/documents/resources.js index 395d17178..de27ab046 100644 --- a/src/fauxton/app/modules/documents/resources.js +++ b/src/fauxton/app/modules/documents/resources.js @@ -44,6 +44,12 @@ function(app, FauxtonAPI) { return this.database ? this.database : this.collection.database; }, + validate: function(attrs, options) { + if (this.id && this.id !== attrs._id && this.get('_rev') ) { + return "Cannot change a documents id."; + } + }, + docType: function() { return this.id.match(/^_design/) ? "design doc" : "doc"; }, diff --git a/src/fauxton/app/modules/documents/views.js b/src/fauxton/app/modules/documents/views.js index 09ef2b5a1..de1938633 100644 --- a/src/fauxton/app/modules/documents/views.js +++ b/src/fauxton/app/modules/documents/views.js @@ -633,6 +633,7 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, Codemirror, JSHint, re event.preventDefault(); this.duplicateModal.showModal(); }, + updateValues: function() { var notification; if (this.model.changedAttributes()) { @@ -676,6 +677,7 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, Codemirror, JSHint, re this.getDocFromEditor(); notification = FauxtonAPI.addNotification({msg: "Saving document."}); + console.log('save',this.model); this.model.save().then(function () { FauxtonAPI.navigate('/database/' + that.database.id + '/' + that.model.id); @@ -684,9 +686,17 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, Codemirror, JSHint, re notification = FauxtonAPI.addNotification({ msg: "Save failed: " + responseText, type: "error", - clear: true + clear: true, + selector: "#doc .errors-container" }); }); + } else if(this.model.validationError && this.model.validationError === 'Cannot change a documents id.') { + notification = FauxtonAPI.addNotification({ + msg: "Cannot save: " + 'Cannot change a documents _id, try Duplicate doc instead!', + type: "error", + selector: "#doc .errors-container" + }); + delete this.model.validationError; } else { notification = FauxtonAPI.addNotification({ msg: "Please fix the JSON errors and try again.", @@ -702,8 +712,10 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, Codemirror, JSHint, re } json = JSON.parse(this.editor.getValue()); - this.model.clear({silent:true}); - this.model.set(json); + this.model.set(json, {validate: true}); + if (this.model.validationError) { + return false; + } return this.model; }, |