From cddaa4bd8d0ad66147c7ecf71f0013562068d106 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Sat, 31 Dec 2016 17:49:10 -0600
Subject: [PATCH] queue: Implement queue delete from view page

---
 include/ajax.search.php                       | 41 ++++++++++---------
 .../staff/templates/queue-tickets.tmpl.php    | 12 ++++--
 scp/ajax.php                                  |  3 +-
 scp/css/dropdown.css                          |  2 +-
 4 files changed, 33 insertions(+), 25 deletions(-)

diff --git a/include/ajax.search.php b/include/ajax.search.php
index ccd861d1b..0186f8d22 100644
--- a/include/ajax.search.php
+++ b/include/ajax.search.php
@@ -198,25 +198,6 @@ class SearchAjaxAPI extends AjaxController {
         )));
     }
 
-    function deleteSearch($id) {
-        global $thisstaff;
-
-        if (!$thisstaff) {
-            Http::response(403, 'Agent login is required');
-        }
-        elseif (!($search = SavedSearch::lookup($id))) {
-            Http::response(404, 'No such saved search');
-        }
-        elseif (!$search->delete()) {
-            Http::response(500, 'Unable to delete search');
-        }
-
-        Http::response(200, $this->encode(array(
-            'id' => $search->id,
-            'success' => true,
-        )));
-    }
-
     function editColumn($column_id) {
         global $thisstaff;
 
@@ -262,6 +243,28 @@ class SearchAjaxAPI extends AjaxController {
         include STAFFINC_DIR . 'templates/queue-sorting-edit.tmpl.php';
     }
 
+    function deleteQueue($id) {
+        global $thisstaff;
+
+        if (!$thisstaff) {
+            Http::response(403, 'Agent login is required');
+        }
+        if ($id && (!($queue = CustomQueue::lookup($id)))) {
+            Http::response(404, 'No such queue');
+        }
+        if (!$queue || !$queue->checkAccess($thisstaff)) {
+            Http::response(404, 'No such queue');
+        }
+        if ($_POST) {
+            if (!$queue->delete()) {
+                Http::response(500, 'Unable to delete queue');
+            }
+            Http::response(201, 'Have a nice day');
+        }
+
+        include STAFFINC_DIR . 'templates/queue-delete-confirm.tmpl.php';
+    }
+
     function previewQueue($id=false) {
         global $thisstaff;
 
diff --git a/include/staff/templates/queue-tickets.tmpl.php b/include/staff/templates/queue-tickets.tmpl.php
index f87afe61e..045d668e1 100644
--- a/include/staff/templates/queue-tickets.tmpl.php
+++ b/include/staff/templates/queue-tickets.tmpl.php
@@ -190,11 +190,15 @@ if ($thisstaff->isAdmin()) { ?>
                         </li>
 <?php }
 if (
-    ($thisstaff->isAdmin() && $queue->parent_id)
-    || $queue->isPrivate()
-) { ?>
+    $queue->id > 0
+    && (
+        ($thisstaff->isAdmin() && $queue->parent_id)
+        || $queue->isPrivate()
+)) { ?>
                         <li class="danger">
-                            <a class="no-pjax" href="#"><i
+                            <a class="no-pjax confirm-action" href="#"
+                                data-dialog="ajax.php/queue/<?php
+                                echo $queue->id; ?>/delete"><i
                             class="icon-fixed-width icon-trash"></i>
                             <?php echo __('Delete'); ?></a>
                         </li>
diff --git a/scp/ajax.php b/scp/ajax.php
index 570020809..215079e18 100644
--- a/scp/ajax.php
+++ b/scp/ajax.php
@@ -266,7 +266,8 @@ $dispatcher = patterns('',
         url_get('^addColumn$', 'addColumn'),
         url_get('^condition/add$', 'addCondition'),
         url_get('^condition/addProperty$', 'addConditionProperty'),
-        url_get('^counts$', 'collectQueueCounts')
+        url_get('^counts$', 'collectQueueCounts'),
+        url('^(?P<id>\d+)/delete$', 'deleteQueue')
     ))
 );
 
diff --git a/scp/css/dropdown.css b/scp/css/dropdown.css
index dfb354dc0..20db72e40 100644
--- a/scp/css/dropdown.css
+++ b/scp/css/dropdown.css
@@ -5,7 +5,7 @@
 
 .action-dropdown, .noclick-dropdown {
   position: absolute;
-  z-index: 9999998;
+  z-index: 8;
   display: none;
   margin-top: 8px;
 }
-- 
GitLab