couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jch...@apache.org
Subject svn commit: r910054 - in /couchdb/trunk/share/www/script: futon.browse.js jquery.dialog.js
Date Sun, 14 Feb 2010 18:17:20 GMT
Author: jchris
Date: Sun Feb 14 18:17:19 2010
New Revision: 910054

URL: http://svn.apache.org/viewvc?rev=910054&view=rev
Log:
fix futon to use _security object. thanks Filipe Manana, closes COUCHDB-654

Modified:
    couchdb/trunk/share/www/script/futon.browse.js
    couchdb/trunk/share/www/script/jquery.dialog.js

Modified: couchdb/trunk/share/www/script/futon.browse.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/futon.browse.js?rev=910054&r1=910053&r2=910054&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/futon.browse.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/futon.browse.js [utf-8] Sun Feb 14 18:17:19 2010
@@ -182,25 +182,69 @@
       this.databaseSecurity = function() {
         $.showDialog("dialog/_database_security.html", {
           load : function(d) {
-            ["admin", "reader"].forEach(function(key) {
-              db.getDbProperty("_"+key+"s", {
-                success : function(r) {
-                  $("input[name="+key+"_names]",d).val(JSON.stringify(r.names||[]));
-                  $("input[name="+key+"_roles]",d).val(JSON.stringify(r.roles||[]));
-                }
-              });
+            db.getDbProperty("_security", {
+              success: function(r) {
+                ["admin", "reader"].forEach(function(key) {
+                  var names = [];
+                  var roles = [];
+
+                  if (r && typeof r[key + "s"] === "object") {
+                    if ($.isArray(r[key + "s"]["names"])) {
+                      names = r[key + "s"]["names"];
+                    }
+                    if ($.isArray(r[key + "s"]["roles"])) {
+                      roles = r[key + "s"]["roles"];
+                    }
+                  }
+
+                  $("input[name=" + key + "_names]", d).val(JSON.stringify(names));
+                  $("input[name=" + key + "_roles]", d).val(JSON.stringify(roles));
+                });
+              }
             });
           },
           // maybe this should be 2 forms
           submit: function(data, callback) {
+            var errors = {};
+            var secObj = {
+              admins: {
+                names: [],
+                roles: []
+              },
+              readers: {
+                names: [],
+                roles: []
+              }
+            };
+
             ["admin", "reader"].forEach(function(key) {
-              var new_value = {
-                names : JSON.parse(data[key+"_names"]),
-                roles : JSON.parse(data[key+"_roles"])
-              };
-              db.setDbProperty("_"+key+"s", new_value);
+              var names, roles;
+
+              try {
+                names = JSON.parse(data[key + "_names"]);
+              } catch(e) { }
+              try {
+                roles = JSON.parse(data[key + "_roles"]);
+              } catch(e) { }
+
+              if ($.isArray(names)) {
+                secObj[key + "s"]["names"] = names;
+              } else {
+                errors[key + "_names"] = "The " + key +
+                  " names must be an array of strings";
+              }
+              if ($.isArray(roles)) {
+                secObj[key + "s"]["roles"] = roles;
+              } else {
+                errors[key + "_roles"] = "The " + key +
+                  " roles must be an array of strings";
+              }
             });
-            callback();
+
+            if ($.isEmptyObject(errors)) {
+              db.setDbProperty("_security", secObj);
+            }
+            callback(errors);
           }
         });
       }

Modified: couchdb/trunk/share/www/script/jquery.dialog.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/jquery.dialog.js?rev=910054&r1=910053&r2=910054&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/jquery.dialog.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/jquery.dialog.js [utf-8] Sun Feb 14 18:17:19 2010
@@ -79,7 +79,7 @@
             data[this.name] = this.value; // file inputs need special handling
           });
           options.submit(data, function callback(errors) {
-            if (errors == null || errors == {}) {
+            if ($.isEmptyObject(errors)) {
               dismiss();
             } else {
               for (var name in errors) {



Mime
View raw message