Skip to content

Commit b110ed3

Browse files
committed
fix(ticket): put new ticket to trash bin
Signed-off-by: Thierry Bugier <[email protected]>
1 parent 1922051 commit b110ed3

File tree

6 files changed

+85
-0
lines changed

6 files changed

+85
-0
lines changed

ajax/cancelticket.php

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* ---------------------------------------------------------------------
4+
* Formcreator is a plugin which allows creation of custom forms of
5+
* easy access.
6+
* ---------------------------------------------------------------------
7+
* LICENSE
8+
*
9+
* This file is part of Formcreator.
10+
*
11+
* Formcreator is free software; you can redistribute it and/or modify
12+
* it under the terms of the GNU General Public License as published by
13+
* the Free Software Foundation; either version 2 of the License, or
14+
* (at your option) any later version.
15+
*
16+
* Formcreator is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU General Public License
22+
* along with Formcreator. If not, see <http://www.gnu.org/licenses/>.
23+
* ---------------------------------------------------------------------
24+
* @copyright Copyright © 2011 - 2019 Teclib'
25+
* @license http://www.gnu.org/licenses/gpl.txt GPLv3+
26+
* @link https://github.com/pluginsGLPI/formcreator/
27+
* @link https://pluginsglpi.github.io/formcreator/
28+
* @link http://plugins.glpi-project.org/#/plugin/formcreator
29+
* ---------------------------------------------------------------------
30+
*/
31+
32+
include ('../../../inc/includes.php');
33+
if (!isset($_POST['id'])) {
34+
http_response_code(400);
35+
exit;
36+
}
37+
$ticketId = (int) $_POST['id'];
38+
PluginFormcreatorCommon::cancelMyTicket($ticketId);

css/styles.css

+3
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,9 @@ span.fc_list_icon {
13751375
color: #a0a0a0;
13761376
}
13771377

1378+
.plugin_formcreator_cancel_my_ticket {
1379+
background: #fec95c;
1380+
}
13781381

13791382
/* ################--------------- Responsive ---------------#################### */
13801383
@media screen and (max-width: 700px) {

hook.php

+21
Original file line numberDiff line numberDiff line change
@@ -483,3 +483,24 @@ function plugin_formcreator_dynamicReport($params) {
483483

484484
return false;
485485
}
486+
487+
/**
488+
* Hook for timeline_actions; display a new action for a CommonITILObject
489+
* @see CommonITILObject
490+
*
491+
* @return void
492+
*/
493+
function plugin_formcreator_timelineActions($options) {
494+
$item = $options['item'];
495+
if (!$item->canDeleteItem()) {
496+
return;
497+
}
498+
499+
if (!(isset($_SESSION['glpiactiveprofile']) &&
500+
$_SESSION['glpiactiveprofile']['interface'] == 'helpdesk')) {
501+
return;
502+
}
503+
echo "<li class='plugin_formcreator_cancel_my_ticket' onclick='".
504+
"javascript:plugin_formcreator_cancelMyTicket(".$item->fields['id'].");'>"
505+
."<i class='fa'></i>".__('Cancel my ticket', 'formcreator')."</li>";
506+
}

inc/common.class.php

+10
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,14 @@ public static function showFontAwesomeDropdown($name, $options = []) {
200200
$output .= '<i id="' . $previewId . '" class="'. $options['value'] . '"></i>';
201201
echo $output;
202202
}
203+
204+
public static function cancelMyTicket($id) {
205+
$ticket = new Ticket();
206+
$ticket->getFromDB($id);
207+
if (!$ticket->canRequesterUpdateItem()) {
208+
return false;
209+
}
210+
211+
return $ticket->delete($ticket->fields);
212+
}
203213
}

js/scripts.js.php

+11
Original file line numberDiff line numberDiff line change
@@ -1328,4 +1328,15 @@ function plugin_formcreator_updateCompositePeerType(rand) {
13281328
$('#plugin_formcreator_link_ticket').hide();
13291329
$('#plugin_formcreator_link_target').show();
13301330
}
1331+
}
1332+
1333+
function plugin_formcreator_cancelMyTicket(id) {
1334+
$.ajax({
1335+
url: rootDoc + '/plugins/formcreator/ajax/cancelticket.php',
1336+
data: {id: id},
1337+
type: "POST",
1338+
dataType: "json"
1339+
}).done(function(response) {
1340+
reloadTab;
1341+
});
13311342
}

setup.php

+2
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ function plugin_init_formcreator() {
154154
PluginFormcreatorTargetTicket::class => 'plugin_formcreator_hook_pre_purge_targetTicket',
155155
PluginFormcreatorTargetChange::class => 'plugin_formcreator_hook_pre_purge_targetChange'
156156
];
157+
// hook to add custom actions on a ticket in service catalog
158+
$PLUGIN_HOOKS['timeline_actions']['formcreator'] = 'plugin_formcreator_timelineActions';
157159

158160
$plugin = new Plugin();
159161
if ($plugin->isInstalled('formcreator') && $plugin->isActivated('formcreator')) {

0 commit comments

Comments
 (0)