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 0a65856cd7..22743ce564 100644 --- a/ui/src/core/xibo-cms.js +++ b/ui/src/core/xibo-cms.js @@ -175,6 +175,23 @@ window.XiboInitialise = function(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').on('click', function(ev) { $.ajax({ diff --git a/views/forms.twig b/views/forms.twig index 6a17060baf..769cefd30c 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 6d3708ce9c..79b89ad389 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 @@
- +