dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #12682
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3954: implemented option for not sorting the selected list (ajax-load plugin)
------------------------------------------------------------
revno: 3954
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2011-06-19 20:25:08 +0300
message:
implemented option for not sorting the selected list (ajax-load plugin)
modified:
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.array.js
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.array.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.array.js 2011-06-01 08:19:02 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.array.js 2011-06-19 17:25:08 +0000
@@ -39,7 +39,7 @@
dhis2.array.remove = function( array, from, to )
{
// Array Remove - By John Resig (MIT Licensed)
- var rest = array.slice( (to || from) + 1 || array.length );
+ var rest = array.slice( ( to || from ) + 1 || array.length );
array.length = from < 0 ? array.length + from : from;
return array.push.apply( array, rest );
=== 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-06-19 11:30:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.select.js 2011-06-19 17:25:08 +0000
@@ -158,3 +158,33 @@
{
$select.children().attr('selected', false);
}
+
+/**
+ * Sort options in a select. Based on their html() content. This version is case
+ * sensitive.
+ *
+ * @param $options Array of the options to sort
+ *
+ * @return Sorted array of options
+ */
+dhis2.select.sort = function($options)
+{
+ return $.makeArray($options).sort(function(a, b) {
+ return dhis2.comparator.htmlComparator( $(a), $(b) );
+ });
+}
+
+/**
+ * Sort options in a select. Based on their html() content. This version is case
+ * insensitive
+ *
+ * @param $options Array of the options to sort
+ *
+ * @return Sorted array of options
+ */
+dhis2.select.sortNC = function($options)
+{
+ return $($.makeArray($options).sort(function(a, b) {
+ return dhis2.comparator.htmlNoCaseComparator( $(a), $(b) );
+ }) );
+}
=== 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-06-19 11:30:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.dhisAjaxSelect.js 2011-06-19 17:25:08 +0000
@@ -123,8 +123,13 @@
{
var jqAvailableList = $("#" + sourceId);
var jqSelectedList = $("#" + targetId);
+ var settings = jqAvailableList.data("settings");
- dhis2.select.moveSorted(jqSelectedList, jqAvailableList.find(":selected"));
+ if(settings.sortSelected) {
+ dhis2.select.moveSorted(jqSelectedList, jqAvailableList.find(":selected"));
+ } else {
+ dhis2.select.move(jqSelectedList, jqAvailableList.find(":selected"));
+ }
}
}
@@ -134,8 +139,15 @@
{
var jqAvailableList = $("#" + targetId);
var jqSelectedList = $("#" + sourceId);
-
- dhis2.select.moveSorted(jqAvailableList, jqSelectedList.find(":selected"));
+ var settings = jqAvailableList.data("settings");
+
+ var $children = jqSelectedList.find(":selected");
+
+ if(!settings.sortSelected) {
+ $children = dhis2.select.sortNC( $children );
+ }
+
+ dhis2.select.moveSorted(jqAvailableList, $children);
}
}
@@ -194,7 +206,11 @@
},
init : function(options)
{
- var settings = {}
+ var settings = {
+ sortAvailable: true,
+ sortSelected: true
+ };
+
var params = {}
$.extend(settings, options);