ENHANCEMENT Fixed tree search

This commit is contained in:
Ingo Schommer 2011-03-18 10:50:13 +13:00
parent 15d320ec91
commit cfea011680
2 changed files with 32 additions and 23 deletions

View File

@ -106,20 +106,15 @@
data[el.name] = el.value; data[el.name] = el.value;
}); });
// Set new URL
$('#sitetree')[0].setCustomURL(this.attr('action') + '&action_doSearchTree=1', data);
// 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 this.find('.checkboxAboveTree :checkbox').attr('disabled', 'disabled');
if ($('#sitetree')[0].isDraggable) $('#sitetree')[0].stopBeingDraggable();
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_doSearchTree]').addClass('loading'); this.find(':submit[name=action_doSearchTree]').addClass('loading');
this._reloadSitetree(); this._reloadSitetree(this.serializeArray());
return false; return false;
}, },
@ -134,9 +129,6 @@
this.find('.field :input').clearFields(); this.find('.field :input').clearFields();
this.find('.field').not('.show-default').hide(); this.find('.field').not('.show-default').hide();
// Reset URL to default
$('#sitetree')[0].clearCustomURL();
// Enable checkbox tree controls // Enable checkbox tree controls
this.find('.checkboxAboveTree :checkbox').attr('disabled', 'false'); this.find('.checkboxAboveTree :checkbox').attr('disabled', 'false');
@ -171,21 +163,22 @@
/** /**
* Function: _reloadSitetree * Function: _reloadSitetree
*/ */
_reloadSitetree: function() { _reloadSitetree: function(params) {
var self = this; var self = this;
$('#sitetree')[0].reload({ $('#sitetree_ul').search(
onSuccess : function(response) { params,
function() {
self.find(':submit').attr('disabled', false).removeClass('loading'); self.find(':submit').attr('disabled', false).removeClass('loading');
self.find('.checkboxAboveTree :checkbox').attr('disabled', 'true'); self.find('.checkboxAboveTree :checkbox').attr('disabled', 'true');
statusMessage('Filtered tree','good'); statusMessage('Filtered tree','good');
}, },
onFailure : function(response) { function() {
self.find(':submit').attr('disabled', false).removeClass('loading'); self.find(':submit').attr('disabled', false).removeClass('loading');
self.find('.checkboxAboveTree :checkbox').attr('disabled', 'true'); self.find('.checkboxAboveTree :checkbox').attr('disabled', 'true');
errorMessage('Could not filter site tree<br />' + response.responseText); errorMessage('Could not filter site tree<br />' + response.responseText);
} }
}); );
} }
}); });

View File

@ -36,6 +36,7 @@
* @todo When new edit form is loaded, automatically: Select matching node, set correct parent, * @todo When new edit form is loaded, automatically: Select matching node, set correct parent,
* update icon and title * update icon and title
*/ */
var self = this;
this this
.jstree({ .jstree({
'core': { 'core': {
@ -83,17 +84,19 @@
data.inst._set_settings({'html_data': {'ajax': { data.inst._set_settings({'html_data': {'ajax': {
'url': self.data('url-tree'), 'url': self.data('url-tree'),
'data': function(node) { 'data': function(node) {
return $.extend( var params = self.data('searchparams') || [];
self.data('searchparams') || {}, // Avoid duplication of parameters
{ ID : $(node).data("id") ? $(node).data("id") : 0 , ajax: 1} params = $.grep(params, function(n, i) {return (n.name != 'ID' && n.name != 'value');});
); params.push({name: 'ID', value: $(node).data("id") ? $(node).data("id") : 0});
params.push({name: 'ajax', value: 1});
return params;
} }
}}}); }}});
}) })
.bind('before.jstree', function(e, data) { .bind('before.jstree', function(e, data) {
if(data.func == 'start_drag') { if(data.func == 'start_drag') {
// Only allow drag'n'drop if it has been specifically enabled // Only allow drag'n'drop if it has been specifically enabled, or the tree is in search mode
if(!$('input[id=sortitems]').is(':checked')) { if(!$('input[id=sortitems]').is(':checked') || self.data('searchparams')) {
e.stopImmediatePropagation(); e.stopImmediatePropagation();
return false; return false;
} }
@ -133,12 +136,25 @@
}); });
}); });
var self = this;
$('#Form_EditForm').bind('loadnewpage', function(e, data) { $('#Form_EditForm').bind('loadnewpage', function(e, data) {
self._onLoadNewPage(e, data); self._onLoadNewPage(e, data);
}); });
}, },
/**
* Function:
* search
*
* Parameters:
* (Object) data Pass empty data to cancel search
* (Function) callback Success callback
*/
search: function(params, callback) {
if(params) this.data('searchparams', params);
else this.removeData('searchparams');
this.jstree('refresh', -1, callback);
},
/** /**
* Assumes to be triggered by a form element with the following input fields: * Assumes to be triggered by a form element with the following input fields:
* ID, ParentID, TreeTitle (or Title), ClassName * ID, ParentID, TreeTitle (or Title), ClassName