Bug 8508 - Holds to Pull : Library dropdown options are erroneously concatenated...
authorDavid Cook <dcook@prosentient.com.au>
Mon, 10 Sep 2012 21:18:54 +0000 (07:18 +1000)
committerJared Camins-Esakov <jcamins@cpbibliography.com>
Sat, 30 Mar 2013 12:14:10 +0000 (08:14 -0400)
This patch introduces a new javascript function that breaks apart option
strings that are erroneously concatenated by br tags. The split strings
are then checked against non-concatenated option strings, and pushed into
the option array if there is no duplication.

This function is nestled into the JQuery datatable function for populating
the drop-down menu.

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt

index 0b832dc..9bf2aa4 100644 (file)
@@ -15,7 +15,34 @@ $(document).ready(function() {
   var holdst = $("#holdst").dataTable($.extend(true, {}, dataTablesDefaults, {
   }));
   holdst.fnAddFilters("filter");
+  [%# add separateData function to cleanse jQuery select lists by breaking apart strings glued with BR tags and then de-duplicating any repeated library codes %]
+  function separateData ( ColumnData ){
+    var cD = ColumnData;
+    var new_array = new Array();
+    for ( j=0 ; j<cD.length ; j++ ) {
+        var strMatch = cD[j].match(/<br>/gi);
+        if (strMatch) {
+            var split_array = cD[j].split(/<br>/gi);
+            for ( k=0 ; k<split_array.length ; k++ ){
+                var check_array = $.inArray(split_array[k], new_array);
+                if (check_array == -1) {
+                new_array.push(split_array[k]);
+                }
+            }
+        }
+        else {
+            var check_array = $.inArray(cD[j], new_array);
+            if (check_array == -1) {
+                new_array.push(cD[j]);
+            }
+        }
+    }
+    new_array.sort();
+    return new_array;
+  }
+  [%# add SeparateData function into createSelect function, so that it does the createSelect on clean data %]
   function createSelect( data ) {
+      data = separateData(data);
       var r='<select style="width:99%"><option value="">None</option>', i, len=data.length;
       for ( i=0 ; i<len ; i++ ) {
           r += '<option value="'+data[i]+'">'+data[i]+'</option>';