From 2dc86ffdfeaee470b2519da126323e7122956e1c Mon Sep 17 00:00:00 2001 From: Yuriy Bakhtin Date: Wed, 17 Jul 2024 10:59:03 +0200 Subject: [PATCH] Fix period selector on default reminder settings --- docs/CHANGELOG.md | 4 ++ models/reminder/forms/ReminderSettings.php | 8 +++- module.json | 2 +- resources/js/humhub.calendar.reminder.Form.js | 41 +++++++++++-------- .../js/humhub.calendar.reminder.Form.min.js | 2 +- 5 files changed, 35 insertions(+), 22 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index b2562aa5..a6311fee 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog ========= +1.6.3 (Unreleased) +--------------------- +- Enh #466: Fix period selector on default reminder settings + 1.6.2 (July 16, 2024) --------------------- - Enh #495: Fix column `exdate` to delete more than 16 recurrence event entries diff --git a/models/reminder/forms/ReminderSettings.php b/models/reminder/forms/ReminderSettings.php index 1da0eee2..d5d0227c 100644 --- a/models/reminder/forms/ReminderSettings.php +++ b/models/reminder/forms/ReminderSettings.php @@ -62,7 +62,9 @@ public function init() protected function initReminders() { $this->reminders = $this->loadReminder(); - $this->reminders[] = new CalendarReminder(); + if (count($this->reminders) < $this->getMaxReminders()) { + $this->reminders[] = new CalendarReminder(); + } } protected function loadReminder($defaults = true) @@ -231,7 +233,9 @@ public function save() $this->initReminder(1)->save(); } - $this->reminders[] = new CalendarReminder(); + if (count($this->reminders) < $this->getMaxReminders()) { + $this->reminders[] = new CalendarReminder(); + } if($this->isGlobalSettings() || $this->isContainerLevelSettings()) { CalendarReminder::flushDefautlts(); diff --git a/module.json b/module.json index 2aebfb22..e804d0a5 100644 --- a/module.json +++ b/module.json @@ -3,7 +3,7 @@ "name": "Calendar", "description": "Create one-time or recurring events, invite and manage attendees, and keep track of all your events with the Calendar module.", "keywords": ["calendar"], - "version": "1.6.2", + "version": "1.6.3", "humhub": { "minVersion": "1.16.1" }, diff --git a/resources/js/humhub.calendar.reminder.Form.js b/resources/js/humhub.calendar.reminder.Form.js index 633d5f5f..7dba6208 100644 --- a/resources/js/humhub.calendar.reminder.Form.js +++ b/resources/js/humhub.calendar.reminder.Form.js @@ -7,12 +7,13 @@ humhub.module('calendar.reminder.Form', function (module, require, $) { var Widget = require('ui.widget').Widget; var client = require('client'); + var additions = require('ui.additions'); var SELECTOR_ITEMS = '.calendar-reminder-items'; + var SELECTOR_ITEM = '[data-reminder-index]'; var SELECTOR_DEFAULT_ITEMS = '.calendar-reminder-item-defaults'; - var SELECTOR_USE_DEFAULT_CHECKBOX = '#remindersettings-usedefaults'; var SELECTOR_REMINDER_TYPE_DROPDOWN = '#remindersettings-remindertype'; - var SELECTOR_ADD_BUTTON = '.btn-primary[data-action-click="add"]'; + var SELECTOR_BUTTON = '[data-action-click]'; var REMINDER_TYPE_NONE = 0; var REMINDER_TYPE_DEFAULTS = 1; @@ -20,17 +21,24 @@ humhub.module('calendar.reminder.Form', function (module, require, $) { var Form = Widget.extend(); - Form.prototype.init = function(evt) { + Form.prototype.init = function() { this.checkMaxReminder(); this.checkRemidnerType(); }; Form.prototype.checkMaxReminder = function() { - var count = this.$.find(SELECTOR_ITEMS).find('[data-reminder-index]').length; - if(count >= this.options.maxReminder) { - this.$.find(SELECTOR_ADD_BUTTON).hide(); - } else { - this.$.find(SELECTOR_ADD_BUTTON).show(); + var rows = this.$.find(SELECTOR_ITEM); + + this.$.find(SELECTOR_BUTTON).data('action-click', 'delete') + .removeClass('btn-primary').addClass('btn-danger') + .find('i') + .removeClass('fa-plus').addClass('fa-times'); + + if (rows.length < this.options.maxReminder) { + rows.last().find(SELECTOR_BUTTON).data('action-click', 'add') + .removeClass('btn-danger').addClass('btn-primary') + .find('i') + .removeClass('fa-times').addClass('fa-plus'); } }; @@ -64,19 +72,16 @@ humhub.module('calendar.reminder.Form', function (module, require, $) { var $newRow = $triggerRow.clone().attr('data-reminder-index', ++$lastIndex); $newRow.find('[name]').each(function() { - var name = $(this).attr('name').replace(/CalendarReminder\[[0-9]]/, 'CalendarReminder['+$lastIndex+']'); - $(this).attr('name', name); + $(this).attr('name', $(this).attr('name').replace(/^CalendarReminder\[\d]/, 'CalendarReminder[' + $lastIndex + ']')); }); + $newRow.find('[id]').each(function() { + $(this).attr('id', $(this).attr('id').replace(/^calendarreminder-\d/, 'calendarreminder-' + $lastIndex)); + }); + $newRow.find('.select2-container').remove(); + additions.applyTo($newRow); $newRow.insertAfter($triggerRow); - evt.$trigger.data('action-click', 'delete') - .removeClass('btn-primary') - .addClass('btn-danger') - .find('i') - .removeClass('fa-plus') - .addClass('fa-times'); - this.checkMaxReminder(); }; @@ -92,4 +97,4 @@ humhub.module('calendar.reminder.Form', function (module, require, $) { module.export = Form; -}); \ No newline at end of file +}); diff --git a/resources/js/humhub.calendar.reminder.Form.min.js b/resources/js/humhub.calendar.reminder.Form.min.js index 14e4ee1e..c5ff8a0e 100644 --- a/resources/js/humhub.calendar.reminder.Form.min.js +++ b/resources/js/humhub.calendar.reminder.Form.min.js @@ -1 +1 @@ -humhub.module("calendar.reminder.Form",function(i,e,n){var t=e("ui.widget").Widget,r=e("client"),a=".calendar-reminder-items",d=".calendar-reminder-item-defaults",c='.btn-primary[data-action-click="add"]',o=t.extend();o.prototype.init=function(e){this.checkMaxReminder(),this.checkRemidnerType()},o.prototype.checkMaxReminder=function(){this.$.find(a).find("[data-reminder-index]").length>=this.options.maxReminder?this.$.find(c).hide():this.$.find(c).show()},o.prototype.checkRemidnerType=function(){var e=n("#remindersettings-remindertype").val();0==e?(n(a).hide(),n(d).hide()):2==e?(n(a).show(),n(d).hide()):1==e&&(n(a).hide(),n(d).show())},o.prototype.delete=function(e){var t=this;e.$trigger.closest(".row").fadeOut("fast",function(){n(this).remove(),t.checkMaxReminder()})},o.prototype.add=function(e){var t=e.$trigger.closest(".row"),i=parseInt(t.attr("data-reminder-index")),r=t.clone().attr("data-reminder-index",++i);r.find("[name]").each(function(){var e=n(this).attr("name").replace(/CalendarReminder\[[0-9]]/,"CalendarReminder["+i+"]");n(this).attr("name",e)}),r.insertAfter(t),e.$trigger.data("action-click","delete").removeClass("btn-primary").addClass("btn-danger").find("i").removeClass("fa-plus").addClass("fa-times"),this.checkMaxReminder()},o.prototype.reset=function(e){var t=this.$.find(".calendar-reminder-items");r.post(e).then(function(e){t.replaceWith(n(e.html).find(".calendar-reminder-items")),i.log.success("saved")}).catch(function(e){i.log.error(e,!0)})},i.export=o}); \ No newline at end of file +humhub.module("calendar.reminder.Form",function(i,e,a){var t=e("ui.widget").Widget,n=e("client"),r=e("ui.additions"),d=".calendar-reminder-items",s=".calendar-reminder-item-defaults",c="[data-action-click]",o=t.extend();o.prototype.init=function(){this.checkMaxReminder(),this.checkRemidnerType()},o.prototype.checkMaxReminder=function(){var e=this.$.find("[data-reminder-index]");this.$.find(c).data("action-click","delete").removeClass("btn-primary").addClass("btn-danger").find("i").removeClass("fa-plus").addClass("fa-times"),e.length