From 2de803188f6a9fea703bc1f02679e8fc29050297 Mon Sep 17 00:00:00 2001 From: John Christopher Anderson Date: Sun, 14 Feb 2010 18:17:19 +0000 Subject: 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 --- share/www/script/futon.browse.js | 70 +++++++++++++++++++++++++++++++-------- share/www/script/jquery.dialog.js | 2 +- 2 files changed, 58 insertions(+), 14 deletions(-) (limited to 'share') 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) { -- cgit v1.2.3