Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2770A9D1E for ; Sat, 18 Feb 2012 15:34:50 +0000 (UTC) Received: (qmail 25519 invoked by uid 500); 18 Feb 2012 15:34:50 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 25488 invoked by uid 500); 18 Feb 2012 15:34:49 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 25474 invoked by uid 99); 18 Feb 2012 15:34:49 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 18 Feb 2012 15:34:49 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.114] (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 18 Feb 2012 15:34:48 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 7A6C5320A4D; Sat, 18 Feb 2012 15:34:28 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: rnewson@apache.org To: commits@couchdb.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [1/2] git commit: COUCHDB-1381 - Don't call alert() from jquery.couch.js Message-Id: <20120218153428.7A6C5320A4D@tyr.zones.apache.org> Date: Sat, 18 Feb 2012 15:34:28 +0000 (UTC) Updated Branches: refs/heads/1.2.x cc9fa66d0 -> 2ef8ecc08 refs/heads/master 365615daf -> dfc5d37c4 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. Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/2ef8ecc0 Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/2ef8ecc0 Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/2ef8ecc0 Branch: refs/heads/1.2.x Commit: 2ef8ecc08dc232e86d24f3bbbee083ba57182d5a Parents: cc9fa66 Author: Sam Bisbee Authored: Sat Feb 18 15:20:36 2012 +0000 Committer: Robert Newson Committed: Sat Feb 18 15:33:57 2012 +0000 ---------------------------------------------------------------------- share/www/script/futon.browse.js | 6 +++ share/www/script/futon.js | 63 +++++++++++++++++++------------- share/www/script/jquery.couch.js | 20 +++++------ 3 files changed, 52 insertions(+), 37 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/2ef8ecc0/share/www/script/futon.browse.js ---------------------------------------------------------------------- diff --git a/share/www/script/futon.browse.js b/share/www/script/futon.browse.js index 6df0568..f0208ad 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); } }); } http://git-wip-us.apache.org/repos/asf/couchdb/blob/2ef8ecc0/share/www/script/futon.js ---------------------------------------------------------------------- diff --git a/share/www/script/futon.js b/share/www/script/futon.js index a82269d..5e0fb78 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; http://git-wip-us.apache.org/repos/asf/couchdb/blob/2ef8ecc0/share/www/script/jquery.couch.js ---------------------------------------------------------------------- diff --git a/share/www/script/jquery.couch.js b/share/www/script/jquery.couch.js index a1f1ad2..4db6efa 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));