summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorJohn Christopher Anderson <jchris@apache.org>2010-02-14 18:17:19 +0000
committerJohn Christopher Anderson <jchris@apache.org>2010-02-14 18:17:19 +0000
commit2de803188f6a9fea703bc1f02679e8fc29050297 (patch)
tree9a85e452e4cf273359d4d964d0c9b990657ee32c /share
parent64a52c788a5b7efb633b8a09d495665ed9a976b7 (diff)
fix futon to use _security object. thanks Filipe Manana, closes COUCHDB-654
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@910054 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share')
-rw-r--r--share/www/script/futon.browse.js70
-rw-r--r--share/www/script/jquery.dialog.js2
2 files changed, 58 insertions, 14 deletions
diff --git a/share/www/script/futon.browse.js b/share/www/script/futon.browse.js
index ade16b20..cc9c846e 100644
--- a/share/www/script/futon.browse.js
+++ b/share/www/script/futon.browse.js
@@ -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);
}
});
}
diff --git a/share/www/script/jquery.dialog.js b/share/www/script/jquery.dialog.js
index 41dd08e6..02c0c497 100644
--- a/share/www/script/jquery.dialog.js
+++ b/share/www/script/jquery.dialog.js
@@ -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) {