couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject git commit: COUCHDB-1381 - Don't call alert() from jquery.couch.js
Date Sat, 18 Feb 2012 15:15:21 GMT
Updated Branches:
  refs/heads/COUCHDB-1381 [created] 82e9be97b


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/82e9be97
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/82e9be97
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/82e9be97

Branch: refs/heads/COUCHDB-1381
Commit: 82e9be97b0f4b040244c38e8cb71a0ddca758bd7
Parents: 365615d
Author: Sam Bisbee <sam@sbisbee.com>
Authored: Sat Feb 18 15:11:02 2012 +0000
Committer: Robert Newson <rnewson@apache.org>
Committed: Sat Feb 18 15:14:59 2012 +0000

----------------------------------------------------------------------
 share/www/script/futon.browse.js |   10 +++++-
 share/www/script/futon.js        |   63 +++++++++++++++++++-------------
 share/www/script/jquery.couch.js |   20 +++++------
 3 files changed, 55 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/82e9be97/share/www/script/futon.browse.js
----------------------------------------------------------------------
diff --git a/share/www/script/futon.browse.js b/share/www/script/futon.browse.js
index da3344f..5793700 100644
--- a/share/www/script/futon.browse.js
+++ b/share/www/script/futon.browse.js
@@ -60,7 +60,9 @@
               return;
             }
             $.couch.db(data.name).create({
-              error: function(status, id, reason) { callback({name: reason}) },
+              error: function(status, id, reason) {
+                callback({ name: reason })
+              },
               success: function(resp) {
                 location.href = "database.html?" + encodeURIComponent(data.name);
                 callback();
@@ -569,6 +571,9 @@
                     location.href = "database.html?" + encodeURIComponent(dbName) +
                       "/" + $.couch.encodeDocId(doc._id) +
                       "/_view/" + encodeURIComponent(data.name);
+                  },
+                  error: function(status, e, reason) {
+                    alert(reason);
                   }
                 });
               }
@@ -612,6 +617,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/82e9be97/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/82e9be97/share/www/script/jquery.couch.js
----------------------------------------------------------------------
diff --git a/share/www/script/jquery.couch.js b/share/www/script/jquery.couch.js
index 2069992..62831a1 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;
               }
             }
           });
@@ -1012,7 +1010,7 @@
           if (options.error) {
             options.error(req.status, req, e);
           } else {
-            alert(errorMessage + ": " + e);
+            throw errorMessage + ': ' + e;
           }
           return;
         }
@@ -1027,7 +1025,7 @@
                         errorMessage, resp && resp.reason || "no response",
                         reqDuration);
         } else {
-          alert(errorMessage + ": " + resp.reason);
+          throw errorMessage + ": " + resp.reason;
         }
       }
     }, obj), ajaxOptions));


Mime
View raw message