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
This commit is contained in:
Ingo Schommer 2009-11-21 02:37:08 +00:00
parent 671961cf45
commit 0935da6aad
2 changed files with 37 additions and 23 deletions

View File

@ -208,17 +208,22 @@
/** /**
* Control the site tree filter. * 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, SelectEl: null,
onmatch: function() { onmatch: function() {
var self = this; var self = this;
// TODO Cant bind to onsubmit/onreset directly because of IE6 // TODO Cant bind to onsubmit/onreset directly because of IE6
this.bind('submit', function(e) {return self.submitForm(e);}); this.bind('submit', function(e) {return self._submitForm(e);});
this.bind('reset', function(e) {return self.resetForm(e);}); this.bind('reset', function(e) {return self._resetForm(e);});
// only the first field should be visible by default // only the first field should be visible by default
this.find('.field').not(':first').hide(); this.find('.field').not(':first').hide();
@ -226,7 +231,7 @@
// generate the field dropdown // generate the field dropdown
this.setSelectEl($('<select name="options" class="options"></select>') this.setSelectEl($('<select name="options" class="options"></select>')
.appendTo(this.find('fieldset:first')) .appendTo(this.find('fieldset:first'))
.bind('change', function(e) {self.addField(e);}) .bind('change', function(e) {self._addField(e);})
); );
this._setOptions(); this._setOptions();
@ -251,9 +256,10 @@
}); });
}, },
submitForm: function(e) { _submitForm: function(e) {
var self = this; var self = this;
var data = []; var data = [];
// convert from jQuery object literals to hash map // convert from jQuery object literals to hash map
$(this.serializeArray()).each(function(i, el) { $(this.serializeArray()).each(function(i, el) {
data[el.name] = el.value; data[el.name] = el.value;
@ -265,45 +271,36 @@
// Disable checkbox tree controls that currently don't work with search. // Disable checkbox tree controls that currently don't work with search.
// @todo: Make them work together // @todo: Make them work together
if ($('#sitetree')[0].isDraggable) $('#sitetree')[0].stopBeingDraggable(); 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 // disable buttons to avoid multiple submission
//this.find(':submit').attr('disabled', true); //this.find(':submit').attr('disabled', true);
this.find(':submit[name=action_getfilteredsubtree]').addClass('loading'); this.find(':submit[name=action_getfilteredsubtree]').addClass('loading');
$('#sitetree')[0].reload({ this._reloadSitetree();
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<br />' + response.responseText);
}
});
return false; return false;
}, },
resetForm: function(e) { _resetForm: function(e) {
this.find('.field').clearFields().not(':first').val('').hide(); this.find('.field :input').clearFields().not(':first').hide();
// Reset URL to default // Reset URL to default
$('#sitetree')[0].clearCustomURL(); $('#sitetree')[0].clearCustomURL();
// Enable checkbox tree controls // 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 // reset all options, some of the might be removed
this._setOptions(); this._setOptions();
this._reloadSitetree();
return false; return false;
}, },
addField: function(e) { _addField: function(e) {
var $select = $(e.target); var $select = $(e.target);
// show formfield matching the option // show formfield matching the option
this.find('#' + $select.val()).show(); this.find('#' + $select.val()).show();
@ -315,6 +312,23 @@
$select.val(0); $select.val(0);
return false; 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<br />' + response.responseText);
}
});
} }
}}); }});

View File

@ -63,7 +63,7 @@ TreeAPI.prototype = {
}, },
onFailure: function(response){ onFailure: function(response){
errorMessage('error loading tree', response); errorMessage('error loading tree', response);
if (options.onError) options.onError(response); if (options.onFailure) options.onFailure(response);
} }
}); });
}, },