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 014F7E8A8 for ; Mon, 11 Feb 2013 11:12:23 +0000 (UTC) Received: (qmail 50398 invoked by uid 500); 11 Feb 2013 11:12:20 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 50116 invoked by uid 500); 11 Feb 2013 11:12:20 -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 48337 invoked by uid 99); 11 Feb 2013 11:12:15 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Feb 2013 11:12:15 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id C92743C746; Mon, 11 Feb 2013 11:12:14 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jan@apache.org To: commits@couchdb.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [31/50] [abbrv] git commit: More view form validation and error handling Message-Id: <20130211111214.C92743C746@tyr.zones.apache.org> Date: Mon, 11 Feb 2013 11:12:14 +0000 (UTC) More view form validation and error handling Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/48ad0618 Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/48ad0618 Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/48ad0618 Branch: refs/heads/fauxton Commit: 48ad0618c2aeec779055b9844d688c3723fd3d10 Parents: f25958b Author: Russell Branca Authored: Wed Jan 30 17:36:07 2013 -0800 Committer: Russell Branca Committed: Wed Jan 30 17:36:07 2013 -0800 ---------------------------------------------------------------------- src/fauxton/app/modules/documents/views.js | 57 ++++++++++++++- .../app/templates/documents/all_docs_list.html | 1 + 2 files changed, 56 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/48ad0618/src/fauxton/app/modules/documents/views.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/modules/documents/views.js b/src/fauxton/app/modules/documents/views.js index c4107c4..30a799a 100644 --- a/src/fauxton/app/modules/documents/views.js +++ b/src/fauxton/app/modules/documents/views.js @@ -233,7 +233,13 @@ function(app, FauxtonAPI, Codemirror, JSHint) { }, establish: function() { - var deferreds = [this.collection.fetch()]; + var deferreds = [ + this.collection.fetch().error(function() { + // TODO: handle error requests that slip through + // This should just throw a notification, not break the page + console.log("ERROR: ", arguments); + }) + ]; if (this.designDocs) { deferreds.push(this.designDocs.fetch()); } @@ -281,10 +287,50 @@ function(app, FauxtonAPI, Codemirror, JSHint) { updateView: function(event) { event.preventDefault(); var $form = $(event.currentTarget); + // Ignore params without a value var params = _.filter($form.serializeArray(), function(param) { return param.value; }); + + // Validate *key* params to ensure they're valid JSON + var keyParams = ["key","keys","startkey","endkey"]; + var errorParams = _.filter(params, function(param) { + if (_.contains(keyParams, param.name)) { + try { + JSON.parse(param.value); + return false; + } catch(e) { + return true; + } + } else { + return false; + } + }); + + if (_.any(errorParams)) { + _.map(errorParams, function(param) { + + // TODO: Where to add this error? + // bootstrap wants the error on a control-group div, but we're not using that + //$('form.view-query-update input[name='+param+'], form.view-query-update select[name='+param+']').addClass('error'); + + return FauxtonAPI.addNotification({ + msg: "JSON Parse Error on field: "+param.name, + type: "error", + selector: ".view.show .errors-container" + }); + }); + + FauxtonAPI.addNotification({ + msg: "Make sure that strings are properly quoted and any other values are valid JSON structures", + type: "warning", + selector: ".view.show .errors-container" + }); + + return false; + } + var fragment = window.location.hash.replace(/\?.*$/, ''); fragment = fragment + '?' + $.param(params); FauxtonAPI.navigate(fragment); @@ -305,7 +351,14 @@ function(app, FauxtonAPI, Codemirror, JSHint) { // - can't include group_level for reduce=false case "reduce": if ($ele.prop('checked') === true) { - $form.find("input[name=include_docs]").prop("checked", false); + if ($form.find("input[name=include_docs]").prop("checked") === true) { + $form.find("input[name=include_docs]").prop("checked", false); + var notification = FauxtonAPI.addNotification({ + msg: "include_docs has been disabled as you cannot include docs on a reduced view", + type: "warn", + selector: ".view.show .errors-container" + }); + } $form.find("input[name=include_docs]").prop("disabled", true); $form.find("select[name=group_level]").prop("disabled", false); } else { http://git-wip-us.apache.org/repos/asf/couchdb/blob/48ad0618/src/fauxton/app/templates/documents/all_docs_list.html ---------------------------------------------------------------------- diff --git a/src/fauxton/app/templates/documents/all_docs_list.html b/src/fauxton/app/templates/documents/all_docs_list.html index a3536e0..73df4cb 100644 --- a/src/fauxton/app/templates/documents/all_docs_list.html +++ b/src/fauxton/app/templates/documents/all_docs_list.html @@ -11,6 +11,7 @@
+