mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-21 01:28:47 +02:00
* Rebase onto develop * Use exit condition instead of englobing condition * Add informative modals that can be called from modal toolbox * Refactor "apply_modify" and "apply_new" into own controller, handle ajax requests with a json response and handle these responses in linkset creation/edition * Fix merge issues * Remove inverted condition * Move linkset create button to a better place, still needs to fix duplicate "New" button caused by a refactor * Handle "Cancel" button in modals * Do not display relations when editing an object in a modal * More elegant way to add "New" button to relations lists * Factorize vertical highlights in alerts and modal in a single mixin * Replace button name with dict entry code * Change route name to snake case * More elegant way to add "Create in modal" button to relations lists * Replace triple if with in_array * Move listener to body * Rename variable to match boolean rules * Rename event * Rename extra param * Add phpdoc * Revert changes * Check indirect linkset rights before allowing creation in modal
127 lines
3.8 KiB
JavaScript
127 lines
3.8 KiB
JavaScript
let LinkSetWorker = new function(){
|
|
|
|
// defines
|
|
const ROUTER_BASE_URL = '../pages/ajax.render.php';
|
|
const ROUTE_LINK_SET_DELETE_OBJECT = 'linkset.delete_linked_object';
|
|
const ROUTE_LINK_SET_DETACH_OBJECT = 'linkset.detach_linked_object';
|
|
const ROUTE_LINK_SET_MODIFY_OBJECT = 'object.modify';
|
|
const ROUTE_LINK_SET_CREATE_OBJECT = 'linkset.create_linked_object';
|
|
|
|
/**
|
|
* CallAjaxDeleteLinkedObject.
|
|
*
|
|
* @param sLinkedObjectClass
|
|
* @param sLinkedObjectKey
|
|
* @constructor
|
|
*/
|
|
const CallAjaxDeleteLinkedObject = function(sLinkedObjectClass, sLinkedObjectKey){
|
|
$.post(`${ROUTER_BASE_URL}?route=${ROUTE_LINK_SET_DELETE_OBJECT}`, {
|
|
linked_object_class: sLinkedObjectClass,
|
|
linked_object_key: sLinkedObjectKey,
|
|
transaction_id: $('#linkset_transactions_id').val()
|
|
}, function (data) {
|
|
if(data.data.success){
|
|
alert('Operation succeeded, todo refresh table !!');
|
|
}
|
|
else{
|
|
alert('Operation failed, todo feedback !!');
|
|
}
|
|
});
|
|
};
|
|
|
|
/**
|
|
* CallAjaxDetachLinkedObject.
|
|
*
|
|
* @param sLinkedObjectClass
|
|
* @param sLinkedObjectKey
|
|
* @param sExternalKeyAttCode
|
|
* @constructor
|
|
*/
|
|
const CallAjaxDetachLinkedObject = function(sLinkedObjectClass, sLinkedObjectKey, sExternalKeyAttCode){
|
|
$.post(`${ROUTER_BASE_URL}?route=${ROUTE_LINK_SET_DETACH_OBJECT}`, {
|
|
linked_object_class: sLinkedObjectClass,
|
|
linked_object_key: sLinkedObjectKey,
|
|
external_key_att_code: sExternalKeyAttCode,
|
|
transaction_id: $('#linkset_transactions_id').val()
|
|
}, function (data) {
|
|
if(data.data.success){
|
|
alert('Operation succeeded, todo refresh table !!');
|
|
}
|
|
else{
|
|
alert('Operation failed, todo feedback !!');
|
|
}
|
|
});
|
|
};
|
|
|
|
/**
|
|
* CallAjaxModifyLinkedObject.
|
|
*
|
|
* @param {string} sLinkedObjectClass
|
|
* @param {string} sLinkedObjectKey
|
|
* @param {string} sTableId
|
|
* @constructor
|
|
*/
|
|
const CallAjaxModifyLinkedObject = function(sLinkedObjectClass, sLinkedObjectKey, sTableId){
|
|
let oTable = $('#datatable_' + sTableId);
|
|
let oTableSettingsDialog = $('#datatable_dlg_datatable_'+sTableId);
|
|
|
|
let oOptions = {
|
|
title: Dict.S('UI:Links:ActionRow:Modify:Modal:Title'),
|
|
content: {
|
|
endpoint: `${ROUTER_BASE_URL}?route=${ROUTE_LINK_SET_MODIFY_OBJECT}`,
|
|
data: {
|
|
class: sLinkedObjectClass,
|
|
id: sLinkedObjectKey,
|
|
},
|
|
},
|
|
extra_options: {
|
|
callback_on_modal_close: function () {
|
|
oTableSettingsDialog.DataTableSettings('DoRefresh');
|
|
$(this).find("form").remove();
|
|
$(this).dialog('destroy');
|
|
}
|
|
},
|
|
}
|
|
CombodoModal.OpenModal(oOptions);
|
|
};
|
|
|
|
/**
|
|
* @param {string} sTableId
|
|
*/
|
|
const CallAjaxCreateLinkedObject = function(sTableId){
|
|
let oTable = $('#datatable_' + sTableId);
|
|
let oTableSettingsDialog = $('#datatable_dlg_datatable_'+sTableId);
|
|
let sClass = oTable.closest('[data-role="ibo-block-links-table"]').attr('data-link-class');
|
|
let sAttCode = oTable.closest('[data-role="ibo-block-links-table"]').attr('data-link-attcode');
|
|
let sHostObjectClass = oTable.closest('[data-role="ibo-object-details"]').attr('data-object-class');
|
|
let sHostObjectId = oTable.closest('[data-role="ibo-object-details"]').attr('data-object-id');
|
|
|
|
let oOptions = {
|
|
title: Dict.S('UI:Links:New:Modal:Title'),
|
|
content: {
|
|
endpoint: `${ROUTER_BASE_URL}?route=${ROUTE_LINK_SET_CREATE_OBJECT}`,
|
|
data: {
|
|
class: sClass,
|
|
att_code: sAttCode,
|
|
host_class: sHostObjectClass,
|
|
host_id: sHostObjectId
|
|
}
|
|
},
|
|
extra_options: {
|
|
callback_on_modal_close: function () {
|
|
oTableSettingsDialog.DataTableSettings('DoRefresh');
|
|
$(this).find("form").remove();
|
|
$(this).dialog('destroy');
|
|
}
|
|
},
|
|
}
|
|
CombodoModal.OpenModal(oOptions);
|
|
};
|
|
|
|
return {
|
|
DeleteLinkedObject: CallAjaxDeleteLinkedObject,
|
|
DetachLinkedObject: CallAjaxDetachLinkedObject,
|
|
ModifyLinkedObject: CallAjaxModifyLinkedObject,
|
|
CreateLinkedObject: CallAjaxCreateLinkedObject
|
|
}
|
|
}; |