From fa7c9699dbad6d0526ebcb9ad809e9edfdc6365b Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 24 Jul 2019 22:00:15 +0200 Subject: [PATCH] filtering of dynamic scrolling fields --- lam/lib/html.inc | 2 +- lam/templates/lib/500_lam.js | 63 +++++++++++++++++++++++++++++++----- 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/lam/lib/html.inc b/lam/lib/html.inc index b29a1090..cd335f4f 100644 --- a/lam/lib/html.inc +++ b/lam/lib/html.inc @@ -851,7 +851,7 @@ class htmlInputField extends htmlElement { * @param String $name select box name */ public function filterSelectBox($name) { - $this->setOnKeyUp('filterSelect(\'' . $this->fieldName . '\', \'' . $name . '\', event);'); + $this->setOnKeyUp('window.lam.filterSelect.activate(\'' . $this->fieldName . '\', \'' . $name . '\', event);'); } /** diff --git a/lam/templates/lib/500_lam.js b/lam/templates/lib/500_lam.js index 4f6e348d..febcaabc 100644 --- a/lam/templates/lib/500_lam.js +++ b/lam/templates/lib/500_lam.js @@ -19,6 +19,8 @@ */ +window.lam = window.lam || {}; + /** * Called when user clicks on a table row. This toggles the checkbox in the row. * @@ -608,6 +610,8 @@ function updateModulePositions(id, oldPos, newPos) { jQuery('#' + id).val(positions.join(',')); } +window.lam.filterSelect = window.lam.filterSelect || {}; + /** * Filters a select box by the value of the filter input field. * @@ -615,30 +619,73 @@ function updateModulePositions(id, oldPos, newPos) { * @param select ID of select box to filter * @param event key event */ -function filterSelect(filterInput, select, event) { +window.lam.filterSelect.activate = function (filterInput, select, event) { + var inputField = jQuery('#' + filterInput); + var selectField = jQuery('#' + select); + if (selectField.hasClass('lam-dynamicOptions')) { + window.lam.filterSelect.filterDynamic(inputField, selectField); + } + else { + window.lam.filterSelect.filterStandard(inputField, selectField); + } +} + +/** + * Filters a normal select field. + * + * @param inputField input field with filter value + * @param selectField select field + */ +window.lam.filterSelect.filterStandard = function(inputField, selectField) { // if values were not yet saved, save them - if (!jQuery('#' + select).data('options')) { + if (!selectField.data('options')) { var options = []; - jQuery('#' + select).find('option').each(function() { + selectField.find('option').each(function() { options.push({value: $(this).val(), text: $(this).text()}); }); - jQuery('#' + select).data('options', options); + selectField.data('options', options); } // get matching values - var list = jQuery('#' + select).empty().scrollTop(0).data('options'); - var search = jQuery.trim(jQuery('#' + filterInput).val()); + var list = selectField.empty().scrollTop(0).data('options'); + var search = jQuery.trim(inputField.val()); var regex = new RegExp(search,'gi'); jQuery.each(list, function(i) { var option = list[i]; if(option.text.match(regex) !== null) { - jQuery('#' + select).append( + selectField.append( jQuery('