Browse Source

Ticket due dates can be updated via the calendar

merge-requests/1/head
Mike Koch 6 years ago
parent
commit
d4840a297a
  1. 7
      internal-api/admin/calendar/index.php
  2. 8
      internal-api/dao/calendar_dao.php
  3. 92
      js/calendar/mods-for-hesk-calendar.js

7
internal-api/admin/calendar/index.php

@ -59,6 +59,13 @@ if ($request_method === 'GET') {
$id = hesk_POST('id');
delete_event($id, $hesk_settings);
return http_response_code(200);
} elseif ($action === 'update-ticket') {
$ticket['due_date'] = hesk_POST('dueDate');
$ticket['trackid'] = hesk_POST('trackingId');
update_ticket_due_date($ticket, $hesk_settings);
return http_response_code(200);
}
}

8
internal-api/dao/calendar_dao.php

@ -83,3 +83,11 @@ function delete_event($id, $hesk_settings) {
hesk_dbQuery($sql);
}
function update_ticket_due_date($ticket, $hesk_settings) {
$due_date = date('Y-m-d H:i:s', strtotime($ticket['due_date']));
$sql = "UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `due_date` = '" . $due_date . "'
WHERE `trackid` = '" . hesk_dbEscape($ticket['trackid']) . "'";
hesk_dbQuery($sql);
}

92
js/calendar/mods-for-hesk-calendar.js

@ -40,44 +40,62 @@ $(document).ready(function() {
}
},
eventDrop: function(event, delta, revertFunc) {
var start = event.start.format('YYYY-MM-DD');
if (event.end === null) {
event.end = event.start.clone();
}
var end = event.end.format('YYYY-MM-DD');
if (!event.allDay) {
start += ' ' + event.start.format('HH:mm:ss');
end += ' ' + event.end.format('HH:mm:ss');
}
var createTicketDate = event.createTicketDate;
if (createTicketDate != null) {
createTicketDate = createTicketDate.format('YYYY-MM-DD');
}
var data = {
id: event.id,
title: event.title,
location: event.location,
startTime: start,
endTime: end,
allDay: event.allDay,
comments: event.comments,
createTicketDate: createTicketDate,
assignTo: event.assignTo,
action: 'update'
};
console.log(data);
$.ajax({
method: 'POST',
url: getHelpdeskUrl() + '/internal-api/admin/calendar',
data: data,
success: function() {
$.jGrowl('Event successfully updated', { theme: 'alert-success', closeTemplate: '' });
},
error: function() {
$.jGrowl('An error occurred when trying to update the event', { theme: 'alert-danger', closeTemplate: '' });
revertFunc();
if (event.type === 'TICKET') {
$.ajax({
method: 'POST',
url: getHelpdeskUrl() + '/internal-api/admin/calendar',
data: {
trackingId: event.trackingId,
action: 'update-ticket',
dueDate: event.start.format('YYYY-MM-DD')
},
success: function() {
$.jGrowl('Ticket due date successfully updated', { theme: 'alert-success', closeTemplate: '' });
},
error: function() {
$.jGrowl('An error occurred when trying to update the ticket due date', { theme: 'alert-danger', closeTemplate: '' });
revertFunc();
}
});
} else {
var start = event.start.format('YYYY-MM-DD');
if (event.end === null) {
event.end = event.start.clone();
}
});
var end = event.end.format('YYYY-MM-DD');
if (!event.allDay) {
start += ' ' + event.start.format('HH:mm:ss');
end += ' ' + event.end.format('HH:mm:ss');
}
var createTicketDate = event.createTicketDate;
if (createTicketDate != null) {
createTicketDate = createTicketDate.format('YYYY-MM-DD');
}
var data = {
id: event.id,
title: event.title,
location: event.location,
startTime: start,
endTime: end,
allDay: event.allDay,
comments: event.comments,
createTicketDate: createTicketDate,
assignTo: event.assignTo,
action: 'update'
};
$.ajax({
method: 'POST',
url: getHelpdeskUrl() + '/internal-api/admin/calendar',
data: data,
success: function() {
$.jGrowl('Event successfully updated', { theme: 'alert-success', closeTemplate: '' });
},
error: function() {
$.jGrowl('An error occurred when trying to update the event', { theme: 'alert-danger', closeTemplate: '' });
revertFunc();
}
});
}
}
});

Loading…
Cancel
Save