From 0935da6aadd21414607109456bde6effc02edc3a Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Sat, 21 Nov 2009 02:37:08 +0000 Subject: [PATCH] BUGFIX Fixed tree search reloading when all fields are cleared MINOR Documentation and refactoring for tree search javascript git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92619 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- javascript/CMSMain.js | 58 +++++++++++++++++++++------------- javascript/LeftAndMain_left.js | 2 +- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/javascript/CMSMain.js b/javascript/CMSMain.js index ba948143..a55740a3 100644 --- a/javascript/CMSMain.js +++ b/javascript/CMSMain.js @@ -208,17 +208,22 @@ /** * Control the site tree filter. + * Toggles search form fields based on a dropdown selection, + * similar to "Smart Search" criteria in iTunes. */ - $('#Form_SearchTreeForm').concrete('ss.searchTreeForm', function($) {return{ + $('#Form_SearchTreeForm').concrete('ss', function($) {return{ + /** + * @type DOMElement + */ SelectEl: null, onmatch: function() { var self = this; // TODO Cant bind to onsubmit/onreset directly because of IE6 - this.bind('submit', function(e) {return self.submitForm(e);}); - this.bind('reset', function(e) {return self.resetForm(e);}); + this.bind('submit', function(e) {return self._submitForm(e);}); + this.bind('reset', function(e) {return self._resetForm(e);}); // only the first field should be visible by default this.find('.field').not(':first').hide(); @@ -226,7 +231,7 @@ // generate the field dropdown this.setSelectEl($('') .appendTo(this.find('fieldset:first')) - .bind('change', function(e) {self.addField(e);}) + .bind('change', function(e) {self._addField(e);}) ); this._setOptions(); @@ -251,9 +256,10 @@ }); }, - submitForm: function(e) { + _submitForm: function(e) { var self = this; var data = []; + // convert from jQuery object literals to hash map $(this.serializeArray()).each(function(i, el) { data[el.name] = el.value; @@ -265,45 +271,36 @@ // Disable checkbox tree controls that currently don't work with search. // @todo: Make them work together if ($('#sitetree')[0].isDraggable) $('#sitetree')[0].stopBeingDraggable(); - $('.checkboxAboveTree :checkbox').val(false).attr('disabled', true); + this.find('.checkboxAboveTree :checkbox').val(false).attr('disabled', true); // disable buttons to avoid multiple submission //this.find(':submit').attr('disabled', true); this.find(':submit[name=action_getfilteredsubtree]').addClass('loading'); - $('#sitetree')[0].reload({ - onSuccess : function(response) { - console.debug(self); - console.debug(self.find(':submit')); - self.find(':submit').attr('disabled', false).removeClass('loading'); - statusMessage('Filtered tree','good'); - }, - onFailure : function(response) { - self.find(':submit').attr('disabled', false).removeClass('loading'); - errorMessage('Could not filter site tree
' + response.responseText); - } - }); + this._reloadSitetree(); return false; }, - resetForm: function(e) { - this.find('.field').clearFields().not(':first').val('').hide(); + _resetForm: function(e) { + this.find('.field :input').clearFields().not(':first').hide(); // Reset URL to default $('#sitetree')[0].clearCustomURL(); // Enable checkbox tree controls - $('.checkboxAboveTree :checkbox').attr('disabled', 'false'); + this.find('.checkboxAboveTree :checkbox').attr('disabled', 'false'); // reset all options, some of the might be removed this._setOptions(); + this._reloadSitetree(); + return false; }, - addField: function(e) { + _addField: function(e) { var $select = $(e.target); // show formfield matching the option this.find('#' + $select.val()).show(); @@ -315,6 +312,23 @@ $select.val(0); return false; + }, + + _reloadSitetree: function() { + var self = this; + + $('#sitetree')[0].reload({ + onSuccess : function(response) { + self.find(':submit').attr('disabled', false).removeClass('loading'); + self.find('.checkboxAboveTree :checkbox').attr('disabled', 'true'); + statusMessage('Filtered tree','good'); + }, + onFailure : function(response) { + self.find(':submit').attr('disabled', false).removeClass('loading'); + self.find('.checkboxAboveTree :checkbox').attr('disabled', 'true'); + errorMessage('Could not filter site tree
' + response.responseText); + } + }); } }}); diff --git a/javascript/LeftAndMain_left.js b/javascript/LeftAndMain_left.js index 7772ad78..833fbd7a 100755 --- a/javascript/LeftAndMain_left.js +++ b/javascript/LeftAndMain_left.js @@ -63,7 +63,7 @@ TreeAPI.prototype = { }, onFailure: function(response){ errorMessage('error loading tree', response); - if (options.onError) options.onError(response); + if (options.onFailure) options.onFailure(response); } }); },