diff options
author | Sam Bisbee <sam@sbisbee.com> | 2012-02-18 15:20:36 +0000 |
---|---|---|
committer | Robert Newson <rnewson@apache.org> | 2012-02-18 15:33:57 +0000 |
commit | 2ef8ecc08dc232e86d24f3bbbee083ba57182d5a (patch) | |
tree | 0c27f87d7ddf81ba285530e6d5da3b2f0800d1d9 | |
parent | cc9fa66d02d92bc633245f3283a48b635c866e99 (diff) | |
download | couchdb-2ef8ecc08dc232e86d24f3bbbee083ba57182d5a.tar.gz |
COUCHDB-1381 - Don't call alert() from jquery.couch.js
jquery.couch.js is a javascript library and should not assume it's
running inside a browser. Particularly, it should not call
alert(). Instead it should throw an exception.
-rw-r--r-- | share/www/script/futon.browse.js | 6 | ||||
-rw-r--r-- | share/www/script/futon.js | 63 | ||||
-rw-r--r-- | share/www/script/jquery.couch.js | 20 |
3 files changed, 52 insertions, 37 deletions
diff --git a/share/www/script/futon.browse.js b/share/www/script/futon.browse.js index 6df056886..f0208ad59 100644 --- a/share/www/script/futon.browse.js +++ b/share/www/script/futon.browse.js @@ -537,6 +537,9 @@ location.href = "database.html?" + encodeURIComponent(dbName) + "/" + $.couch.encodeDocId(doc._id) + "/_view/" + encodeURIComponent(data.name); + }, + error: function(status, e, reason) { + alert(reason); } }); } @@ -580,6 +583,9 @@ page.storedViewCode = viewDef; $("#viewcode button.revert, #viewcode button.save") .attr("disabled", "disabled"); + }, + error: function(status, e, reason) { + alert(reason); } }); } diff --git a/share/www/script/futon.js b/share/www/script/futon.js index a82269df3..5e0fb78b2 100644 --- a/share/www/script/futon.js +++ b/share/www/script/futon.js @@ -121,6 +121,9 @@ function $$(node) { $.couch.logout({ success : function(resp) { $.futon.session.sidebar(); + }, + error: function(status, e, reason) { + alert('An error occurred logging out: ' + reason); } }) }; @@ -171,33 +174,41 @@ function $$(node) { } else { return false; } - $.couch.session({success: function (resp) { - // admin users may have a config entry, change the password - // there first. Update their user doc later, if it exists - if (resp.userCtx.roles.indexOf("_admin") > -1) { // user is admin - // check whether we have a config entry - $.couch.config({ - success : function (response) { // er do have a config entry - $.couch.config({ - success : function () { - window.setTimeout(function() { - doLogin(resp.userCtx.name, data.password, function(errors) { - if(!$.isEmptyObject(errors)) { - callback(errors); - return; - } else { - location.reload(); - } - }); - }, 1000); - } - }, "admins", resp.userCtx.name, data.password); - } - }, "admins", resp.userCtx.name); - } else { // non-admin users, update their user doc - updateUserDoc(resp, data); + $.couch.session({ + error: function(status, e, reason) { + alert('Could not get your session info: ' + reason); + }, + success: function (resp) { + // admin users may have a config entry, change the password + // there first. Update their user doc later, if it exists + if (resp.userCtx.roles.indexOf("_admin") > -1) { // user is admin + // check whether we have a config entry + $.couch.config({ + success : function (response) { // er do have a config entry + $.couch.config({ + success : function () { + window.setTimeout(function() { + doLogin(resp.userCtx.name, data.password, function(errors) { + if(!$.isEmptyObject(errors)) { + callback(errors); + return; + } else { + location.reload(); + } + }); + }, 1000); + }, + error: function(status, e, reason) { + callback('Could not persist the new password: ' + reason); + } + }, "admins", resp.userCtx.name, data.password); + } + }, "admins", resp.userCtx.name); + } else { // non-admin users, update their user doc + updateUserDoc(resp, data); + } } - }}); + }); } }); return false; diff --git a/share/www/script/jquery.couch.js b/share/www/script/jquery.couch.js index a1f1ad280..4db6efa22 100644 --- a/share/www/script/jquery.couch.js +++ b/share/www/script/jquery.couch.js @@ -151,7 +151,7 @@ } else if (options.error) { options.error(req.status, resp.error, resp.reason); } else { - alert("An error occurred getting session info: " + resp.reason); + throw "An error occurred getting session info: " + resp.reason; } } }); @@ -215,7 +215,7 @@ } else if (options.error) { options.error(req.status, resp.error, resp.reason); } else { - alert("An error occurred logging in: " + resp.reason); + throw 'An error occurred logging in: ' + resp.reason; } } }); @@ -243,7 +243,7 @@ } else if (options.error) { options.error(req.status, resp.error, resp.reason); } else { - alert("An error occurred logging out: " + resp.reason); + throw 'An error occurred logging out: ' + resp.reason; } } }); @@ -268,9 +268,7 @@ rawDocs[doc._id].rev == doc._rev) { // todo: can we use commonjs require here? if (typeof Base64 == "undefined") { - alert("please include /_utils/script/base64.js in the page for " + - "base64 support"); - return false; + throw 'Base64 support not found.'; } else { doc._attachments = doc._attachments || {}; doc._attachments["rev-"+doc._rev.split("-")[0]] = { @@ -556,7 +554,7 @@ } }); } else { - alert("Please provide an eachApp function for allApps()"); + throw 'Please provide an eachApp function for allApps()'; } }, @@ -650,7 +648,7 @@ } else if (options.error) { options.error(req.status, resp.error, resp.reason); } else { - alert("The document could not be saved: " + resp.reason); + throw "The document could not be saved: " + resp.reason; } } }); @@ -748,7 +746,7 @@ } else if (options.error) { options.error(req.status, resp.error, resp.reason); } else { - alert("The document could not be copied: " + resp.reason); + throw "The document could not be copied: " + resp.reason; } } }); @@ -1010,7 +1008,7 @@ if (options.error) { options.error(req.status, req, e); } else { - alert(errorMessage + ": " + e); + throw errorMessage + ': ' + e; } return; } @@ -1024,7 +1022,7 @@ options.error(req.status, resp && resp.error || errorMessage, resp && resp.reason || "no response"); } else { - alert(errorMessage + ": " + resp.reason); + throw errorMessage + ": " + resp.reason; } } }, obj), ajaxOptions)); |