diff options
author | Garren Smith <garren.smith@gmail.com> | 2013-12-03 16:54:12 +0200 |
---|---|---|
committer | Garren Smith <garren.smith@gmail.com> | 2013-12-03 17:26:12 +0200 |
commit | 862d8ae43ff1f44e910669031945b40c6073a01a (patch) | |
tree | 5a7629a1da483ec51af0ae620328e523e67bde20 | |
parent | 5825fe61a39c8beecc84e57bd7ef097e6e4cf1b4 (diff) | |
download | couchdb-862d8ae43ff1f44e910669031945b40c6073a01a.tar.gz |
Fauxton: hide reduce options for no reduce
-rw-r--r-- | src/fauxton/app/modules/documents/views.js | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/fauxton/app/modules/documents/views.js b/src/fauxton/app/modules/documents/views.js index cf939e26b..1fe4cb7ed 100644 --- a/src/fauxton/app/modules/documents/views.js +++ b/src/fauxton/app/modules/documents/views.js @@ -965,10 +965,11 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, resizeColumns) { this.viewName = options.viewName; this.updateViewFn = options.updateViewFn; this.previewFn = options.previewFn; - this.hadReduce = options.hasReduce || true; + //this.hadReduce = options.hasReduce || true; if (typeof(options.hasReduce) === 'undefined') { this.hasReduce = true; + console.log('set true'); } else { this.hasReduce = options.hasReduce; } @@ -997,6 +998,11 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, resizeColumns) { } }, + renderOnUpdatehasReduce: function (hasReduce) { + this.hasReduce = hasReduce; + this.render(); + }, + queryParams: function () { var $form = this.$(".view-query-update"); // Ignore params without a value @@ -1216,6 +1222,7 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, resizeColumns) { var $reduceContainer = $(".control-group.reduce-function"); if ($ele.val() == "CUSTOM") { this.createReduceEditor(); + this.reduceEditor.setValue(this.langTemplates.javascript.reduce); $reduceContainer.show(); } else { $reduceContainer.hide(); @@ -1286,6 +1293,11 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, resizeColumns) { that.newView = false; } + if (that.reduceFunStr !== reduceVal) { + that.reduceFunStr = reduceVal; + that.advancedOptions.renderOnUpdatehasReduce(that.hasReduce()); + } + FauxtonAPI.triggerRouteEvent('updateAllDocs', {ddoc: ddocName, view: viewName}); }, function(xhr) { @@ -1350,8 +1362,6 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, resizeColumns) { reduceVal = this.reduceVal(), paramsArr = []; - console.log(mapVal); - if (paramsInfo && paramsInfo.params) { paramsArr = paramsInfo.params; } @@ -1398,7 +1408,6 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, resizeColumns) { }, mapVal: function () { - if (this.mapEditor) { return this.mapEditor.getValue(); } @@ -1419,6 +1428,7 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, resizeColumns) { return reduceVal; }, + hasValidCode: function() { return _.every(["mapEditor", "reduceEditor"], function(editorName) { var editor = this[editorName]; @@ -1456,7 +1466,6 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, resizeColumns) { ddocName: this.model.id, viewName: this.viewName, reduceFunStr: this.reduceFunStr, - hasReduce: this.reduceFunStr, isCustomReduce: this.hasCustomReduce(), newView: this.newView, langTemplates: this.langTemplates.javascript @@ -1467,6 +1476,10 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, resizeColumns) { return this.reduceFunStr && ! _.contains(this.builtinReduces, this.reduceFunStr); }, + hasReduce: function () { + return this.reduceFunStr || false; + }, + createReduceEditor: function () { if (this.reduceEditor) { this.reduceEditor.remove(); @@ -1501,13 +1514,14 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, resizeColumns) { ddocName: this.model.id, database: this.database })); - + this.advancedOptions = this.insertView('#query', new Views.AdvancedOptions({ updateViewFn: this.updateView, previewFn: this.previewView, database: this.database, viewName: this.viewName, - ddocName: this.model.id + ddocName: this.model.id, + hasReduce: this.hasReduce })); }, |