dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #12396
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3806: made both filters of ajaxSelect work, group filtering (on anything else than all) disables key fi...
------------------------------------------------------------
revno: 3806
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-05-31 13:26:04 +0200
message:
made both filters of ajaxSelect work, group filtering (on anything else than all) disables key filtering
modified:
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.select.js
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.dhisAjaxSelect.js
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.select.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.select.js 2011-05-31 09:30:22 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.select.js 2011-05-31 11:26:04 +0000
@@ -47,3 +47,90 @@
return $select_ghost;
}
+
+/**
+ * Filter a select on a given key. Options that are not matched, are moved to ghost.
+ *
+ * NOTE: Both selects should already be in sorted order.
+ *
+ * @param $select A jQuery wrapped select
+ * @param key {String} Key to search for
+ * @param caseSensitive {Boolean} Case sensitive search (defaults to false, so this parameter only needed if you want
+ * case sensitive search)
+ */
+dhis2.select.filterWithKey = function( $select, key, caseSensitive )
+{
+ $select_ghost = dhis2.select.getGhost( $select );
+ caseSensitive = caseSensitive ||Â false;
+
+ if (key.length === 0) {
+ dhisAjaxSelect_moveSorted( $select, $select_ghost.children() );
+ } else {
+ var $select_options = $select.children();
+ var $select_ghost_options = $select_ghost.children();
+ var $select_ghost_matched;
+ var $select_not_matched;
+
+ if(caseSensitive) {
+ $select_ghost_matched = $select_ghost_options.filter( ':contains(' + key + ')' );
+ $select_not_matched = $select_options.filter( ':not( :contains(' + key + ') )' );
+ } else {
+ $select_ghost_matched = $select_ghost_options.filter( ':containsNC(' + key + ')' );
+ $select_not_matched = $select_options.filter( ':not( :containsNC(' + key + ') )' );
+ }
+
+ dhisAjaxSelect_moveSorted( $select_ghost, $select_not_matched );
+ dhisAjaxSelect_moveSorted( $select, $select_ghost_matched );
+ }
+}
+
+/**
+ * Moves an array of child elements into a select, these will be moved in a sorted fashion. Both the select and array is
+ * assumed to be sorted to start with.
+ *
+ * @param $select A jQuery wrapped select which acts as the target
+ * @param $array An array of child elements to move
+ */
+dhis2.select.moveSorted = function ($select, $array)
+{
+ if ($select.children().size() === 0) {
+ $select.append($array);
+ } else {
+ var array = $array.get();
+ var array_idx = 0;
+ var current = array.shift();
+ var $children = $select.children();
+
+ while (current !== undefined) {
+ var $current = $(current);
+
+ if ( dhis2.comparator.htmlNoCaseComparator( $children.eq(array_idx), $current) > 0) {
+ $(current).insertBefore($children.eq(array_idx));
+ current = array.shift();
+ } else {
+ array_idx++;
+ }
+
+ if ($children.size() < array_idx) {
+ break;
+ }
+ }
+
+ if (current !== undefined) {
+ $select.append(current);
+ }
+
+ $select.append(array);
+ }
+}
+
+/**
+ * Moves an array of child elements into a select.
+ *
+ * @param $select A jQuery wrapped select which acts as the target
+ * @param $array An array of child elements to move
+ */
+dhis2.select.move = function ($select, $array)
+{
+ $select.append($array);
+}
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.dhisAjaxSelect.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.dhisAjaxSelect.js 2011-05-31 09:30:22 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.dhisAjaxSelect.js 2011-05-31 11:26:04 +0000
@@ -47,59 +47,6 @@
jqSource.dblclick();
}
-function dhisAjaxSelect_moveSorted($target, $array)
-{
- if ($target.children().size() === 0) {
- $target.append($array);
- } else {
- var array = $array.get();
- var array_idx = 0;
- var current = array.shift();
- var $children = $target.children();
-
- while (current !== undefined) {
- var $current = $(current);
-
- if ( dhis2.comparator.htmlNoCaseComparator( $children.eq(array_idx), $current) > 0) {
- $(current).insertBefore($children.eq(array_idx));
- current = array.shift();
- } else {
- array_idx++;
- }
-
- if ($children.size() < array_idx) {
- break;
- }
- }
-
- if (current !== undefined) {
- $target.append(current);
- }
-
- $target.append(array);
- }
-}
-
-/* filter a select-target with a given key */
-function dhisAjaxSelect_filter($target, key)
-{
- $ghost_target = dhis2.select.getGhost($target);
- key = key.toLowerCase();
-
- if (key.length === 0) {
- dhisAjaxSelect_moveSorted($target, $ghost_target.children());
- } else {
- var $target_options = $target.children();
- var $ghost_target_options = $ghost_target.children();
-
- var $ghost_target_matched = $ghost_target_options.filter(':containsNC(' + key + ')');
- var $target_not_matched = $target_options.filter(':not( :containsNC(' + key + ') )');
-
- dhisAjaxSelect_moveSorted($ghost_target, $target_not_matched);
- dhisAjaxSelect_moveSorted($target, $ghost_target_matched);
- }
-}
-
/**
* filter a selector on data-key = value
*/
@@ -108,7 +55,7 @@
$ghost_target = dhis2.select.getGhost($target);
if (key.length === 0) {
- dhisAjaxSelect_moveSorted($target, $ghost_target.children());
+ dhis2.select.moveSorted($target, $ghost_target.children());
return;
}
@@ -124,7 +71,7 @@
}
});
- dhisAjaxSelect_moveSorted($ghost_target, $(array));
+ dhis2.select.moveSorted($ghost_target, $(array));
// filter options that match on ghost
var $ghost_options = $ghost_target.children();
@@ -138,7 +85,7 @@
}
});
- dhisAjaxSelect_moveSorted($target, $(ghost_array));
+ dhis2.select.moveSorted($target, $(ghost_array));
}
/**
@@ -177,7 +124,7 @@
var jqAvailableList = $("#" + sourceId);
var jqSelectedList = $("#" + targetId);
- dhisAjaxSelect_moveSorted(jqSelectedList, jqAvailableList.find(":selected"));
+ dhis2.select.moveSorted(jqSelectedList, jqAvailableList.find(":selected"));
}
}
@@ -188,7 +135,7 @@
var jqAvailableList = $("#" + targetId);
var jqSelectedList = $("#" + sourceId);
- dhisAjaxSelect_moveSorted(jqAvailableList, jqSelectedList.find(":selected"));
+ dhis2.select.moveSorted(jqAvailableList, jqSelectedList.find(":selected"));
}
}
@@ -287,18 +234,27 @@
});
$filter_select.bind("change", {
- "id" : id
+ 'id' : id,
+ 'filter_input_id' : filter_input_id
}, function(event)
{
var $option = $(this).find(":selected");
var key = $option.data("key");
var value = $option.data("value");
+ var $filter_input = $('#' + event.data.filter_input_id);
key = !!key ? key : "";
value = !!value ? value : "";
var settings = $("#" + event.data.id).data("settings");
+ if(key.length === 0) {
+ $filter_input.removeAttr('disabled');
+ } else {
+ $filter_input.attr('disabled', 'disabled');
+ $filter_input.attr('value', '');
+ }
+
dhisAjaxSelect_filter_on_kv($("#" + event.data.id), key, value);
});
}
@@ -339,10 +295,10 @@
$select.data("settings", settings);
methods.load("" + id);
- $filter_button.click(function()
+ $filter_button.bind('click', function(e)
{
key = $filter_input.val();
- dhisAjaxSelect_filter($select, key);
+ dhis2.select.filterWithKey($select, key);
});
$filter_input.keypress(function(e)