[TikiWiki-commits] [Git][tikiwiki/tiki][master] [ENH][UX] Calendar: use service confirmation modal with event-count warning before delete

"Adrien Mbuya Maloba \(@adrienmaloba\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <69e76fb552ba0_37197198664c7@gitlab-sidekiq-low-urgency-cpu-bound-v2-bbdd87bd5-nrfj9.mail>

Adrien Mbuya Maloba pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
ac6cc6e9 by MAGENE Sem Joel at 2026-04-21T14:30:18+02:00
[ENH][UX] Calendar: use service confirmation modal with event-count warning before delete
---
* [ENH][UX] Calendar: use service confirmation modal with event-count warning before delete

See merge request tikiwiki/tiki!9982

- - - - -


3 changed files:

- lib/core/Services/Calendar/Controller.php
- templates/tiki-admin_calendars.tpl
- tiki-admin_calendars.php


Changes:

=====================================
lib/core/Services/Calendar/Controller.php
=====================================
@@ -778,6 +778,60 @@ class Services_Calendar_Controller extends Services_Calendar_BaseController
         return [];
     }
 
+    public function action_remove_calendar(JitFilter $input): array
+    {
+        $calendarId = $input->calendarId->int();
+        if (! $calendarId) {
+            throw new Services_Exception_NotFound(tr('Calendar not found'));
+        }
+
+        $calendar = $this->calendarLib->get_calendar($calendarId);
+        if (empty($calendar)) {
+            throw new Services_Exception_NotFound(tr('Calendar not found'));
+        }
+
+        if (! $this->calendarLib->canAdminCalendar($calendar)) {
+            throw new Services_Exception_Denied(tr('Permission denied'));
+        }
+
+        $util = new Services_Utilities();
+        if ($util->notConfirmPost()) {
+            $util->setVars($input, ['calendarId' => 'int']);
+
+            $calendarDisplayName = ! empty($calendar['name']) ? $calendar['name'] : tr('Id #%0', $calendarId);
+
+            $eventCount = (int) $this->calendarLib->getOne(
+                "SELECT COUNT(*) FROM `tiki_calendar_items` WHERE `calendarId` = ?",
+                [$calendarId]
+            );
+
+            $extras = [];
+            if ($eventCount === 1) {
+                $extras['warning'] = tr(
+                    'This calendar has 1 event. Deleting this calendar will permanently delete all events and cannot be undone.'
+                );
+            } elseif ($eventCount > 1) {
+                $extras['warning'] = tr(
+                    'This calendar has %0 events. Deleting this calendar will permanently delete all events and cannot be undone.',
+                    $eventCount
+                );
+            }
+
+            return $util->confirm(tr('Delete calendar "%0"?', $calendarDisplayName), tra('Delete'), $extras);
+        } elseif ($util->checkCsrf()) {
+            $result = $this->calendarLib->drop_calendar($calendarId);
+            if ($result->numRows()) {
+                Feedback::success(tr('Calendar %0 deleted', $calendarId));
+            } else {
+                Feedback::error(tr('Calendar %0 not deleted', $calendarId));
+            }
+
+            return Services_Utilities::refresh();
+        }
+
+        return [];
+    }
+
     public function action_delete_recurrent_items(JitFilter $input): array
     {
         $calitemId = $this->getItemId($input); // also checks edit perms


=====================================
templates/tiki-admin_calendars.tpl
=====================================
@@ -140,9 +140,7 @@
                                     {permission_link mode=text type=calendar id=$id title=$cal.name}
                                 </action>
                                 <action>
-                                    <a href="tiki-admin_calendars.php?offset={$offset}&amp;sort_mode={$sort_mode}&amp;drop={$id}&amp;calendarId={$id}"
-                                        onclick="confirmPopup('{tr}Delete calendar?{/tr}', '{ticket mode=get}')"
-                                    >
+                                    <a href="{bootstrap_modal controller='calendar' action='remove_calendar' calendarId=$id}">
                                         {icon name='remove' _menu_text='y' _menu_icon='y' alt="{tr}Delete{/tr}"}
                                     </a>
                                 </action>


=====================================
tiki-admin_calendars.php
=====================================
@@ -15,7 +15,6 @@ $inputConfiguration = [
             'offset'                      => 'digits',            //get
             'sort_mode'                   => 'alnumdash',         //get
             'description'                 => 'xss',               //post
-            'drop'                        => 'int',               //get
             'remove_subscription'         => 'int',               //get
             'save'                        => 'alpha',             //post
             'customlanguages'             => 'alpha',             //post
@@ -106,15 +105,6 @@ if (! empty($_REQUEST['subscriptionId'])) {
     $smarty->assign('subscription', $subscription);
 }
 
-if (isset($_REQUEST["drop"]) && $access->checkCsrf(true)) {
-    $result = $calendarlib->drop_calendar($_REQUEST['calendarId']);
-    if ($result->numRows()) {
-        Feedback::success(tr('Calendar %0 deleted', (int) $_REQUEST['calendarId']));
-    } else {
-        Feedback::error(tr('Calendar %0 not deleted', (int) $_REQUEST['calendarId']));
-    }
-    $_REQUEST["calendarId"] = 0;
-}
 if (isset($_REQUEST["remove_subscription"]) && $access->checkCsrf(true)) {
     $subscription = $calendarlib->get_subscription($_REQUEST['remove_subscription']);
     if ($subscription['user'] == $user) {



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/ac6cc6e9b56b9d74eb8bdb48d1b927e3eeef8b42

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/ac6cc6e9b56b9d74eb8bdb48d1b927e3eeef8b42
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.