Skip to content

Commit

Permalink
fix(ticket): put new ticket to trash bin
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed May 18, 2020
1 parent 1922051 commit b110ed3
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 0 deletions.
38 changes: 38 additions & 0 deletions ajax/cancelticket.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* ---------------------------------------------------------------------
* Formcreator is a plugin which allows creation of custom forms of
* easy access.
* ---------------------------------------------------------------------
* LICENSE
*
* This file is part of Formcreator.
*
* Formcreator is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Formcreator is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Formcreator. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------
* @copyright Copyright © 2011 - 2019 Teclib'
* @license http://www.gnu.org/licenses/gpl.txt GPLv3+
* @link https://github.com/pluginsGLPI/formcreator/
* @link https://pluginsglpi.github.io/formcreator/
* @link http://plugins.glpi-project.org/#/plugin/formcreator
* ---------------------------------------------------------------------
*/

include ('../../../inc/includes.php');
if (!isset($_POST['id'])) {
http_response_code(400);
exit;
}
$ticketId = (int) $_POST['id'];
PluginFormcreatorCommon::cancelMyTicket($ticketId);
3 changes: 3 additions & 0 deletions css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,9 @@ span.fc_list_icon {
color: #a0a0a0;
}

.plugin_formcreator_cancel_my_ticket {
background: #fec95c;
}

/* ################--------------- Responsive ---------------#################### */
@media screen and (max-width: 700px) {
Expand Down
21 changes: 21 additions & 0 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,3 +483,24 @@ function plugin_formcreator_dynamicReport($params) {

return false;
}

/**
* Hook for timeline_actions; display a new action for a CommonITILObject
* @see CommonITILObject
*
* @return void
*/
function plugin_formcreator_timelineActions($options) {
$item = $options['item'];
if (!$item->canDeleteItem()) {
return;
}

if (!(isset($_SESSION['glpiactiveprofile']) &&
$_SESSION['glpiactiveprofile']['interface'] == 'helpdesk')) {
return;
}
echo "<li class='plugin_formcreator_cancel_my_ticket' onclick='".
"javascript:plugin_formcreator_cancelMyTicket(".$item->fields['id'].");'>"
."<i class='fa'></i>".__('Cancel my ticket', 'formcreator')."</li>";
}
10 changes: 10 additions & 0 deletions inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,14 @@ public static function showFontAwesomeDropdown($name, $options = []) {
$output .= '<i id="' . $previewId . '" class="'. $options['value'] . '"></i>';
echo $output;
}

public static function cancelMyTicket($id) {
$ticket = new Ticket();
$ticket->getFromDB($id);
if (!$ticket->canRequesterUpdateItem()) {
return false;
}

return $ticket->delete($ticket->fields);
}
}
11 changes: 11 additions & 0 deletions js/scripts.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -1328,4 +1328,15 @@ function plugin_formcreator_updateCompositePeerType(rand) {
$('#plugin_formcreator_link_ticket').hide();
$('#plugin_formcreator_link_target').show();
}
}

function plugin_formcreator_cancelMyTicket(id) {
$.ajax({
url: rootDoc + '/plugins/formcreator/ajax/cancelticket.php',
data: {id: id},
type: "POST",
dataType: "json"
}).done(function(response) {
reloadTab;
});
}
2 changes: 2 additions & 0 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ function plugin_init_formcreator() {
PluginFormcreatorTargetTicket::class => 'plugin_formcreator_hook_pre_purge_targetTicket',
PluginFormcreatorTargetChange::class => 'plugin_formcreator_hook_pre_purge_targetChange'
];
// hook to add custom actions on a ticket in service catalog
$PLUGIN_HOOKS['timeline_actions']['formcreator'] = 'plugin_formcreator_timelineActions';

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

0 comments on commit b110ed3

Please sign in to comment.