From 62450a60bd03ef6f0e6002683307b08223687115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mauro=20Ferr=C3=A3o?= Date: Tue, 24 Dec 2024 13:41:13 +0000 Subject: [PATCH] Schedule form: Limit numeric inputs to min/max (#2831) * Schedule form: Limit numeric inputs to min/max relates to xibosignage/xibo#3558 * Schedule form: Limit maxPlaysPerHour relates to xibosignage/xibo#3559 --- lib/Entity/Schedule.php | 4 ++++ ui/src/core/xibo-cms.js | 17 +++++++++++++++++ views/forms.twig | 4 ++-- views/inline.twig | 4 ++-- views/schedule-form-add.twig | 8 ++++---- views/schedule-form-edit.twig | 8 ++++---- 6 files changed, 33 insertions(+), 12 deletions(-) diff --git a/lib/Entity/Schedule.php b/lib/Entity/Schedule.php index c76263d78a..7649615986 100644 --- a/lib/Entity/Schedule.php +++ b/lib/Entity/Schedule.php @@ -765,6 +765,10 @@ public function validate() if ($this->isPriority < 0) { throw new InvalidArgumentException(__('Priority must be 0 or a positive number'), 'isPriority'); } + // Check max plays per hour is positive + if ($this->maxPlaysPerHour < 0) { + throw new InvalidArgumentException(__('Maximum plays per hour must be 0 or a positive number'), 'maxPlaysPerHour'); + } // Run some additional validation if we have a recurrence type set. if (!empty($this->recurrenceType)) { diff --git a/ui/src/core/xibo-cms.js b/ui/src/core/xibo-cms.js index abcf598957..35a43af066 100644 --- a/ui/src/core/xibo-cms.js +++ b/ui/src/core/xibo-cms.js @@ -303,6 +303,23 @@ function XiboInitialise(scope, options) { } }); + // Prevent manual numbers input outside of min/max + $( + scope + ' input[type="number"][min], ' + + scope + ' input[type="number"][max]', + ).each((_idx, input) => { + const $input = $(input); + const max = $input.attr('max'); + const min = $input.attr('min'); + + $input.on('blur', () => { + (max && $input.val() > max) && + ($input.val(max).trigger('change')); + (min && $input.val() < min) && + ($input.val(min).trigger('change')); + }); + }); + // Links that just need to be submitted as forms $(scope + ' .XiboAjaxSubmit').click(function(){ diff --git a/views/forms.twig b/views/forms.twig index fcab80e17e..4bb2a335f9 100644 --- a/views/forms.twig +++ b/views/forms.twig @@ -118,11 +118,11 @@ {% endmacro %} -{% macro number(name, title, value, helpText, groupClass, validation, accessKey, maxNumber) %} +{% macro number(name, title, value, helpText, groupClass, validation, accessKey, maxNumber, minNumber) %}
- + {{ helpText }}
diff --git a/views/inline.twig b/views/inline.twig index b25f074883..f5cf8a3dd4 100644 --- a/views/inline.twig +++ b/views/inline.twig @@ -67,10 +67,10 @@ {% endmacro %} -{% macro number(name, title, value, helpText, groupClass, validation, accessKey, maxNumber) %} +{% macro number(name, title, value, helpText, groupClass, validation, accessKey, maxNumber, minNumber) %}
- +
{% endmacro %} diff --git a/views/schedule-form-add.twig b/views/schedule-form-add.twig index a4f227c59b..1c9aeda8d8 100644 --- a/views/schedule-form-add.twig +++ b/views/schedule-form-add.twig @@ -229,15 +229,15 @@ {% set title %}{% trans "Display Order" %}{% endset %} {% set helpText %}{% trans "Please select the order this event should appear in relation to others when there is more than one event scheduled" %}{% endset %} - {{ forms.number("displayOrder", title, "", helpText, 'displayOrder-control') }} + {{ forms.number("displayOrder", title, "", helpText, 'displayOrder-control', "", "", "", "0") }} {% set title %}{% trans "Priority" %}{% endset %} {% set helpText %}{% trans "Sets the event priority - events with the highest priority play in preference to lower priority events." %}{% endset %} - {{ forms.number("isPriority", title, "", helpText, 'priority-control') }} + {{ forms.number("isPriority", title, "", helpText, 'priority-control', "", "", "", "0") }} {% set title %}{% trans "Maximum plays per hour" %}{% endset %} {% set helpText %}{% trans "Limit the number of times this event will play per hour on each display. For unlimited plays set to 0." %}{{ forms.playerCompat("R308", "", "", "", "R306", "") }}{% endset %} - {{ forms.number("maxPlaysPerHour", title, 0, helpText, 'max-plays-control') }} + {{ forms.number("maxPlaysPerHour", title, 0, helpText, 'max-plays-control', "", "", "", "0") }} {% set title %}{% trans "Run at CMS Time?" %}{% endset %} {% set helpText %}{% trans "When selected, your event will run according to the timezone set on the CMS, otherwise the event will run at Display local time" %}{% endset %} @@ -297,7 +297,7 @@
- +
diff --git a/views/schedule-form-edit.twig b/views/schedule-form-edit.twig index 278386368a..f2907a7790 100644 --- a/views/schedule-form-edit.twig +++ b/views/schedule-form-edit.twig @@ -226,15 +226,15 @@ {% set title %}{% trans "Display Order" %}{% endset %} {% set helpText %}{% trans "Please select the order this event should appear in relation to others when there is more than one event scheduled" %}{% endset %} - {{ forms.number("displayOrder", title, event.displayOrder, helpText, 'displayOrder-control') }} + {{ forms.number("displayOrder", title, event.displayOrder, helpText, 'displayOrder-control', "", "", "", "0") }} {% set title %}{% trans "Priority" %}{% endset %} {% set helpText %}{% trans "Sets the event priority - events with the highest priority play in preference to lower priority events." %}{% endset %} - {{ forms.number("isPriority", title, event.isPriority, helpText, 'priority-control') }} + {{ forms.number("isPriority", title, event.isPriority, helpText, 'priority-control', "", "", "", "0") }} {% set title %}{% trans "Maximum plays per hour" %}{% endset %} {% set helpText %}{% trans "Limit the number of times this event will play per hour on each display. For unlimited plays set to 0." %}{{ forms.playerCompat("R308", "", "", "", "R306", "") }}{% endset %} - {{ forms.number("maxPlaysPerHour", title, event.maxPlaysPerHour, helpText, 'max-plays-control') }} + {{ forms.number("maxPlaysPerHour", title, event.maxPlaysPerHour, helpText, 'max-plays-control', "", "", "", "0") }} {% set title %}{% trans "Run at CMS Time?" %}{% endset %} {% set helpText %}{% trans "When selected, your event will run according to the timezone set on the CMS, otherwise the event will run at Display local time" %}{% endset %} @@ -311,7 +311,7 @@
- +