Files
tomolino-processmaker/js/cases.js

177 lines
7.5 KiB
JavaScript
Raw Normal View History

/*
-------------------------------------------------------------------------
ProcessMaker plugin for GLPI
* Bugfix Reminders on task cancelled before delete reminders update was not deleted * Bugfix Uncaught ReferenceError: $ is not defined on ITIL Object creation * Delete error message after case cancellation successfully * change minimum version of processmaker server * delete TODO comment * Add possibility to cancel case with multiple tasks * bugfix delete reminder on case's cancel or delete * Add behavior on a claimed task or reasign to the current user for show task in timeline * Fixed issue with default dates settings in reminders for tasks * Added shortcut to select "Me as sender" * Added a test to prevent post-only user to set reminder settings * Updated XML * Fix issue with screen view * Adjusted wordings * Reviewed $new_date computation in cron * Bugfix creating a case in processcase tab doesn't redirect to the case * Adjusted visualization for Reminder * Added an <hr> * Adjusted values in dropdowns when settings are NULL * Added a test to prevent sending of remminders to "ProcessMaker" user * Added view of default and actual reminder settings for a PM task * cronPMReminder reflects changes and send reminders * Re-engineered table fields and search options * Fixed issue with FUP that were no longuer added to timeline. * Added automatic reminders * bugfix on filter * Changed copyrights * added .gitignore * add process category search option + input in process form * Added process categories * bugfixes on helpdesk process * bugfixes html_tags and actiontime * Changed the way the userId of the first task was computed, to be able to have a tobeclaimed task * Added get/set APP_DATA scripts to be able to read/write the APP_DATA in json files * Added a followup when a reminder is sent to task user (or group) Set version 5.2.3
2025-01-14 12:17:17 +01:00
Copyright (C) 2014-2024 by Raynet SAS a company of A.Raymond Network.
https://www.araymond.com/
-------------------------------------------------------------------------
LICENSE
This file is part of ProcessMaker plugin for GLPI.
This file 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.
This plugin 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 this plugin. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
glpi_pm = {
add_tab_panel: function (name, title, html){
//debugger ;
var loctabs = $('#tabspanel');
if( !loctabs[0].children[name] ) { // panel is not yet existing, create one
if (loctabs.find('a[data-bs-target=\"#'+name+'\"]').length == 0 ) {
loctabs.append("<li class='nav-item ms-0'><a class='nav-link justify-content-between pe-1' href='#' data-bs-toggle='tab' title='" + title + "' data-bs-target='#" + name + "'>" + title + "</a></li>" );
}
var select = loctabs.next('select');
select.append("<option value='" + (parseInt(select.children().last().val()) + 1) + "'>" + title + "</option >")
var tabcontentdiv = select.next('div');
tabcontentdiv.append("<div class='tab-pane fade' role='tabpanel' id='" + name + "'>" + html + "</div>");
$("a[data-bs-target='#" +name +"']").tab("show");
//tabcontentdiv.tabs('refresh'); // to show the panel
}
// activate it
//var tabIndex = loctabs.find('a[href=\"#'+name+'\"]').parent().index();
// loctabs.tabs( 'option', 'active', tabIndex) ; // to activate it
},
2023-10-16 14:15:32 +02:00
case_submit_form: function (e) {
//debugger;
2023-10-16 14:15:32 +02:00
if (e.defaultPrevented) {
// means form submit has been cancelled due to wrong values
return;
}
2023-10-16 14:15:32 +02:00
// validation is OK
if (this.pm_glpi_form_validate) {
// then we must wait for the case to be saved and routed before saving our form
// to do this, we must cancel our own submit
e.preventDefault();
// to request the iframe to really submit
$('#' + this.glpi_data.glpi_iframeid)[0].contentWindow.postMessage({
message: 'dosubmitdynaform',
glpi_data: this.glpi_data
}, GLPI_PROCESSMAKER_PLUGIN_DATA.pm_server_URL);
} else {
$(this).prepend("<div id='loadingslide'><div class='loadingindicator'>" + __('Loading...') + "</div></div>");
$('html, body').animate({ scrollTop: 0 }, 'fast');
}
},
2023-10-16 14:15:32 +02:00
case_message: function (e) {
// to block any unwanted messages
if (e.origin !== GLPI_PROCESSMAKER_PLUGIN_DATA.pm_server_URL) {
console.warn('glpi_pm.case_message: sender is ' + e.origin + ', when it should be ' + GLPI_PROCESSMAKER_PLUGIN_DATA.pm_server_URL + '!');
return;
}
2023-10-16 14:15:32 +02:00
let myformjq, myform;
let data = e.data; // here are data sent by the caseiframe window postMessage method
switch (data.message) {
case 'iframeready':
2023-10-16 14:15:32 +02:00
//debugger;
if (data.submitform) { // means the submit has been done in iframe and case has been saved
// the GLPI form must be submitted
myformjq = $('#' + data.glpi_data.glpi_iframeid).parents('form');
myform = myformjq[0];
2023-10-16 14:15:32 +02:00
myform.pm_glpi_form_validate = false;
2023-10-16 14:15:32 +02:00
if (myformjq.attr('data-submitted') != undefined) {
myformjq.attr('data-submitted', 'false');
}
let button = myformjq.find('[name=add][type="submit"]');
myform.requestSubmit(button.length ? button[0] : undefined);
2023-10-16 14:15:32 +02:00
}
else {
e.source.postMessage({
message: 'parentready',
glpi_data: data.glpi_data
}, GLPI_PROCESSMAKER_PLUGIN_DATA.pm_server_URL); // to acknowledge the iframeready
2023-10-16 14:15:32 +02:00
}
break;
2023-10-16 14:15:32 +02:00
case 'iframeresize':
$('#' + data.glpi_data.glpi_iframeid)[0].height = data.height;
break;
2023-10-16 14:15:32 +02:00
case 'dovalidateparentform':
// iframe has been validated then we must validate parent form
//debugger;
2023-10-16 14:15:32 +02:00
// set the content field (description)
if (typeof tinyMCE != 'undefined' && tinyMCE.activeEditor && data.userrequestsumup && data.userrequestsumup != '_') {
let userrequestsumup = data.userrequestsumup.replace(/(\r\n)|(\r)|(\n)/g, '<br>');
tinyMCE.activeEditor.setContent(userrequestsumup);
}
// the GLPI form must be submitted to validate fields
myformjq = $('#' + data.glpi_data.glpi_iframeid).parents('form');
myform = myformjq[0];
myform.pm_glpi_form_validate = true;
if (!myform.glpi_data) {
myform.glpi_data = data.glpi_data;
myform.addEventListener('submit', glpi_pm.case_submit_form);
2023-10-16 14:15:32 +02:00
}
//myformjq.find('[name=add][type="submit"]').trigger("click");
let button = myformjq.find('[name=add][type="submit"]');
myform.requestSubmit(button.length ? button[0] : undefined);
2023-10-16 14:15:32 +02:00
break;
2023-10-16 14:15:32 +02:00
case 'historydynaformgridpreview':
2023-10-16 14:15:32 +02:00
//debugger;
// historyDynaformGridPreview_225414236618935cf976300066744816
const action = 'historyDynaformGridPreview';
let actionToDo = action + '_' + data.DYN_UID;
let iframeid = 'caseiframe-' + actionToDo;
let acturl = data.glpi_data.glpi_pm_server_URL
+ "/cases/casesHistoryDynaformPage_Ajax?actionAjax=" + action
+ '&DYN_UID=' + data.DYN_UID
+ '&sid=' + data.glpi_data.glpi_sid
+ '&glpi_data=' + encodeURI(
JSON.stringify({
glpi_url: data.glpi_data.glpi_url,
glpi_tabtype : 'historydynaformgridpreview',
glpi_tabpanelname: actionToDo,
glpi_iframeid: iframeid,
glpi_elttagname: 'body',
glpi_sid: data.glpi_data.glpi_sid,
glpi_app_uid: data.glpi_data.glpi_app_uid,
glpi_pro_uid: data.glpi_data.glpi_pro_uid
}));
glpi_pm.add_tab_panel(
'historyDynaformGridPreview_' + data.DYN_UID,
data.glpi_data.glpi_preview + '(' + data.DYN_TITLE + ')',
"<iframe id='" + iframeid + "' style='border: none;' width = '100%' src = '" + acturl + "' ></iframe>"
);
break;
case 'click':
// close the select2
$('.select2-hidden-accessible').select2('close');
// close the flatpickr
document.querySelectorAll("div.flatpickr").forEach((e) => { e._flatpickr.close() });
};
2023-10-16 14:15:32 +02:00
}
}
window.addEventListener('message', glpi_pm.case_message);