Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ENHANCEMENT Fixed tree search

  • Loading branch information...
commit cfea01168096c78f84b155f9f6e0c336d5c6ed9a 1 parent 15d320e
@chillu chillu authored
Showing with 32 additions and 23 deletions.
  1. +9 −16 javascript/CMSMain.js
  2. +23 −7 javascript/LeftAndMain.Tree.js
View
25 javascript/CMSMain.js
@@ -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
30 javascript/LeftAndMain.Tree.js
@@ -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,13 +136,26 @@
});
});
- 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
*/
Please sign in to comment.
Something went wrong with that request. Please try again.