summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarren Smith <garren.smith@gmail.com>2013-09-19 16:02:02 +0200
committerGarren Smith <garren.smith@gmail.com>2013-09-19 16:02:02 +0200
commit10f2be4ceb0945332a04ddcb007df6a9d5a5538c (patch)
treed93bb669d06383a6b7b514215ac795c57b274207
parentd719b781fba6f2f9cb90d55b2dd741c859124455 (diff)
downloadcouchdb-10f2be4ceb0945332a04ddcb007df6a9d5a5538c.tar.gz
Fauxton: warn user if they edit _id
-rw-r--r--src/fauxton/Gruntfile.js6
-rw-r--r--src/fauxton/app/modules/documents/resources.js6
-rw-r--r--src/fauxton/app/modules/documents/views.js18
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;
},