chg: [UI] Generic picker code cleanup

pull/8327/head
Jakub Onderka 2022-05-15 12:22:10 +02:00
parent 34e17d276c
commit 0b0aa0fa1e
2 changed files with 19 additions and 19 deletions

View File

@ -152,7 +152,7 @@ function redrawChosenWithTemplate($select, $chosenContainer, eventType) {
$option = $select.find('option:eq(' + index + ')');
} else { // if it is a `chosen-single span`, don't have index
var text = $item.text();
$option = $select.find('option').filter(function(index) {
$option = $select.find('option').filter(function() {
var temp = $.trim($(this).text());
return temp === text;
});
@ -191,7 +191,7 @@ function fetchRequestedData(clicked) {
var $wrapper = $clicked.closest('div').find('div.generic-picker-wrapper');
syncPopoverArrow($arrow, $wrapper, loadingHtml)
},
success:function (data, textStatus) {
success:function (data) {
$wrapper = $clicked.closest('div').find('div.generic-picker-wrapper');
var $arrow = $clicked.closest('div.popover').find('div.arrow');
syncPopoverArrow($arrow, $wrapper, data)
@ -229,7 +229,7 @@ function submitFunction(clicked, callback) {
var dismissId = $clicked.closest('.popover[data-dismissid]').data('dismissid');
var callingButton = $('button[data-dismissid="' + dismissId + '"]');
if (callingButton.data('popover-no-submit') && callingButton.data('popover-callback-function') !== undefined) {
callbackFunction = callingButton.data('popover-callback-function');
var callbackFunction = callingButton.data('popover-callback-function');
execAndClose(clicked);
callbackFunction(selected, additionalData);
} else {
@ -238,14 +238,13 @@ function submitFunction(clicked, callback) {
}
}
</script>
<div class="generic_picker">
<div class='generic-picker-wrapper-warning-text alert alert-error <?php echo ($countThresholdReached ? '' : 'hidden'); ?>' style="margin-bottom: 5px;">
<div class="generic-picker-wrapper-warning-text alert alert-error<?= $countThresholdReached ? '' : ' hidden' ?>" style="margin-bottom: 5px;">
<i class="fa fa-exclamation-triangle"></i>
<?php echo __('Due to the large number of options, no contextual information is provided.'); ?>
</div>
<?php
$select_id = h(uniqid()); // used to only register the listener on this select (allowing nesting)
$select_id = 'gp_' . dechex(mt_rand()); // used to only register the listener on this select (allowing nesting)
$flag_addPills = false;
?>
<?php if ($use_select): ?>
@ -295,7 +294,7 @@ function submitFunction(clicked, callback) {
});
</script>
<?php elseif (count($items) > 0): ?>
<?php elseif (!empty($items)): ?>
<ul class="nav nav-pills">
<select id="<?php echo $select_id; ?>"<?= $defaults['autofocus'] ? ' autofocus' : '' ?> style="display: none;" <?php echo $this->GenericPicker->add_select_params($defaults); ?>></select>
<?php
@ -312,7 +311,7 @@ function submitFunction(clicked, callback) {
<span style="margin-left: 15px;"><?php echo __('Nothing to pick'); ?></span>
<?php endif; ?>
<div class='generic-picker-wrapper hidden'></div>
<div class="generic-picker-wrapper hidden"></div>
<script>
if (options_templates === undefined) {

View File

@ -1,11 +1,11 @@
<?php
App::uses('AppHelper', 'View/Helper');
/* Class containing functions to ease the creation of the GenericPicker */
class GenericPickerHelper extends AppHelper {
function add_select_params($options) {
class GenericPickerHelper extends AppHelper
{
public function add_select_params($options)
{
if (isset($options['select_options']['additionalData'])) {
$additionalData = json_encode($options['select_options']['additionalData']);
unset($options['select_options']['additionalData']);
@ -41,7 +41,8 @@ class GenericPickerHelper extends AppHelper {
return $option_html;
}
function add_link_params($param, $defaults=array(), $ignoreFunction=false) {
private function add_link_params($param, $defaults=array(), $ignoreFunction=false)
{
$param_html = ' ';
if (!$ignoreFunction && isset($param['functionName'])) {
$param_html .= sprintf('onclick="execAndClose(this);%s" ', h($param['functionName']));
@ -66,9 +67,9 @@ class GenericPickerHelper extends AppHelper {
return $param_html;
}
function add_pill($param, $defaults=array()) {
$pill_html = '<li>';
$pill_html .= '<a href="#" data-toggle="pill" class="pill-pre-picker"';
public function add_pill($param, $defaults=array())
{
$pill_html = '<li><a href="#" data-toggle="pill" class="pill-pre-picker"';
$pill_html .= ' ' . $this->add_link_params($param, $defaults) . '>';
if (isset($param['img'])) {
$pill_html .= '<img src="' . h($param['img']) . '" style="margin-right: 5px; height: 14px;">';
@ -90,12 +91,12 @@ class GenericPickerHelper extends AppHelper {
);
$pill_html .= $span;
}
$pill_html .= '</a>';
$pill_html .= '</li>';
$pill_html .= '</a></li>';
return $pill_html;
}
public function build_template($param) {
public function build_template($param)
{
$template = "";
if (isset($param['template'])) {
$templateParam = $param['template'];