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;
});
// Set new URL
$('#sitetree')[0].setCustomURL(this.attr('action') + '&action_doSearchTree=1', data);
// Disable checkbox tree controls that currently don't work with search.
// @todo: Make them work together
if ($('#sitetree')[0].isDraggable) $('#sitetree')[0].stopBeingDraggable();
this.find('.checkboxAboveTree :checkbox').val(false).attr('disabled', true);
this.find('.checkboxAboveTree :checkbox').attr('disabled', 'disabled');
// disable buttons to avoid multiple submission
//this.find(':submit').attr('disabled', true);
this.find(':submit[name=action_doSearchTree]').addClass('loading');
this._reloadSitetree();
this._reloadSitetree(this.serializeArray());
return false;
},
@ -134,9 +129,6 @@
this.find('.field :input').clearFields();
this.find('.field').not('.show-default').hide();
// Reset URL to default
$('#sitetree')[0].clearCustomURL();
// Enable checkbox tree controls
this.find('.checkboxAboveTree :checkbox').attr('disabled', 'false');
@ -171,21 +163,22 @@
/**
* Function: _reloadSitetree
*/
_reloadSitetree: function() {
_reloadSitetree: function(params) {
var self = this;
$('#sitetree')[0].reload({
onSuccess : function(response) {
$('#sitetree_ul').search(
params,
function() {
self.find(':submit').attr('disabled', false).removeClass('loading');
self.find('.checkboxAboveTree :checkbox').attr('disabled', 'true');
statusMessage('Filtered tree','good');
},
onFailure : function(response) {
function() {
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

@ -36,6 +36,7 @@
* @todo When new edit form is loaded, automatically: Select matching node, set correct parent,
* update icon and title
*/
var self = this;
this
.jstree({
'core': {
@ -83,17 +84,19 @@
data.inst._set_settings({'html_data': {'ajax': {
'url': self.data('url-tree'),
'data': function(node) {
return $.extend(
self.data('searchparams') || {},
{ ID : $(node).data("id") ? $(node).data("id") : 0 , ajax: 1}
);
var params = self.data('searchparams') || [];
// Avoid duplication of parameters
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) {
if(data.func == 'start_drag') {
// Only allow drag'n'drop if it has been specifically enabled
if(!$('input[id=sortitems]').is(':checked')) {
// Only allow drag'n'drop if it has been specifically enabled, or the tree is in search mode
if(!$('input[id=sortitems]').is(':checked') || self.data('searchparams')) {
e.stopImmediatePropagation();
return false;
}
@ -133,12 +136,25 @@
});
});
var self = this;
$('#Form_EditForm').bind('loadnewpage', function(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:
* ID, ParentID, TreeTitle (or Title), ClassName