[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] Menu options: Fixed menu option deletion

Benoit Grégoire (@benoitg) via TikiWiki-cvs <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <692a0c52e818c_2a15376eb853039@gitlab-sidekiq-low-urgency-cpu-bound-v2-5df5c99858-7khh2.mail>

Benoit Grégoire pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
3630c8b3 by Espoir Baraka at 2025-11-28T20:47:37+00:00
[FIX] Menu options: Fixed menu option deletion
---
* [FIX] Menu options: Fixed menu option deletion

See merge request tikiwiki/tiki!9128

- - - - -


2 changed files:

- src/js/jquery-tiki/tiki-admin_menu_options.js
- tiki-admin_menu_options.php


Changes:

=====================================
src/js/jquery-tiki/tiki-admin_menu_options.js
=====================================
@@ -2,9 +2,15 @@
 //
 // All Rights Reserved. See copyright.txt for details and a complete list of authors.
 // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
+//
+// This JavaScript file is a handler for tiki-admin_menu_options.php
+// It contains shared knowledge about the menu options management interface
+// and handles the client-side interactions for menu option editing and deletion.
 
 import Sortable from "sortablejs";
 
+var ADMIN_MENU_OPTIONS_SCRIPT = "tiki-admin_menu_options.php";
+
 $(function () {
     var dirty = false,
         $options = $("#options");
@@ -104,11 +110,43 @@ $(function () {
 
         $options.on("click", ".option-remove", function () {
             if (confirm(tr("Are you sure you want to remove this option?"))) {
-                var tab = $(this).siblings("a.option-edit").attr("href");
-                $("#deletemenu").val(tab.split("&")[3]);
-                $("form").submit();
-                $(this).parents("li").first().remove();
-                setDirty();
+                var $li = $(this).parents("li").first();
+                var optionId = $li.data("id");
+                if (optionId) {
+                    var $form = $("form");
+                    var menuId = $form.find("input[name=menuId]").val();
+                    var ticket = $form.find("input[name=ticket]").val();
+
+                    // Submit deletion via POST
+                    $.post(
+                        ADMIN_MENU_OPTIONS_SCRIPT,
+                        {
+                            deletemenu: optionId,
+                            menuId: menuId,
+                            ticket: ticket,
+                        },
+                        function () {
+                            dirty = false;
+                            location.reload();
+                        }
+                    ).fail(function (jqXHR, textStatus, errorThrown) {
+                        var errorMessage = tr("An error occurred while deleting the menu option.");
+                        if (textStatus) {
+                            errorMessage += " " + tr("Status:") + " " + textStatus;
+                        }
+                        if (errorThrown) {
+                            errorMessage += " (" + errorThrown + ")";
+                        }
+                        if (jqXHR && jqXHR.status) {
+                            errorMessage += " [" + jqXHR.status;
+                            if (jqXHR.statusText) {
+                                errorMessage += " " + jqXHR.statusText;
+                            }
+                            errorMessage += "]";
+                        }
+                        feedback(errorMessage, "error");
+                    });
+                }
             }
             return false;
         });


=====================================
tiki-admin_menu_options.php
=====================================
@@ -34,10 +34,15 @@ $auto_query_args = [
     'preview_bootstrap',
 ];
 
-if (! empty($_REQUEST["deletemenu"])) {
-    $content = $_REQUEST["deletemenu"];
-    $content = explode("=", $content)[1];
-    $menulib->remove_menu_option($content);
+if (! empty($_REQUEST["deletemenu"]) && $access->checkCsrf()) {
+    $optionId = (int) $_REQUEST["deletemenu"];
+    if ($optionId > 0) {
+        // Verify the option exists and belongs to the current menu
+        $option = $menulib->get_menu_option($optionId);
+        if ($option && $option['menuId'] == $_REQUEST["menuId"]) {
+            $menulib->remove_menu_option($optionId);
+        }
+    }
 }
 
 $smarty->assign('menuId', $_REQUEST["menuId"]);



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

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/3630c8b3c25c77c9a10de0127d3c86e6081fa117
You're receiving this email because of your account on gitlab.com.

_______________________________________________
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.