couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From deathb...@apache.org
Subject [2/3] git commit: updated refs/heads/master to 8a1118e
Date Fri, 20 Sep 2013 14:52:24 GMT
Fauxton: warn user if they edit _id


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/faa65cd5
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/faa65cd5
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/faa65cd5

Branch: refs/heads/master
Commit: faa65cd5021bc0a1e855571e9626fec647502cd7
Parents: 446e139
Author: Garren Smith <garren.smith@gmail.com>
Authored: Thu Sep 19 16:02:02 2013 +0200
Committer: suelockwood <deathbearbrown@gmail.com>
Committed: Fri Sep 20 10:52:15 2013 -0400

----------------------------------------------------------------------
 src/fauxton/Gruntfile.js                       |  6 +++---
 src/fauxton/app/modules/documents/resources.js |  6 ++++++
 src/fauxton/app/modules/documents/views.js     | 18 +++++++++++++++---
 3 files changed, 24 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/faa65cd5/src/fauxton/Gruntfile.js
----------------------------------------------------------------------
diff --git a/src/fauxton/Gruntfile.js b/src/fauxton/Gruntfile.js
index 29a70ba..f9af371 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'

http://git-wip-us.apache.org/repos/asf/couchdb/blob/faa65cd5/src/fauxton/app/modules/documents/resources.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/documents/resources.js b/src/fauxton/app/modules/documents/resources.js
index 395d171..de27ab0 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";
     },

http://git-wip-us.apache.org/repos/asf/couchdb/blob/faa65cd5/src/fauxton/app/modules/documents/views.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/documents/views.js b/src/fauxton/app/modules/documents/views.js
index 09ef2b5..de19386 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;
     },


Mime
View raw message