// changement d'un element texte
$('body').on('dblclick', '[data-action="allow-change"] [data-action="change-text"]', function (event) {
event.preventDefault();
var self = $(this);
if (!self.next('tr').hasClass('change-data-text')) {
var data = {
'manager': self.closest('table').data('manager'),
'object': self.closest('table').data('object'),
'attribute': self.data('attribute')
};
$.ajax({
type: 'GET',
url: Routing.generate('admin_ajax_change_data_text'),
data: data,
dataType: 'json',
success: function (json) {
$(json['form']).insertAfter(self);
}
}
);
}
});
// sauvegarde d'un element texte
$('body').on('click', '[data-action="allow-change"] [data-action="change-text-save"]', function (event) {
event.preventDefault();
var self = $(this);
var data = {
'manager': self.data('manager'),
'object': self.data('object'),
'attribute': self.data('attribute'),
'persist': self.data('persist'),
'value': self.closest('.input-group').find('textarea').val(),
'option': self.closest('table').data('option'),
};
$.ajax({
type: 'PATCH',
url: Routing.generate('admin_ajax_change_data_text_save'),
data: data,
dataType: 'json',
success: function (json) {
self.closest('tr').prev('tr').find('td').html(json['value']);
self.closest('tr').remove();
// création d'un evenement pour appeller un callback
$('body').trigger("change_text_" + data.manager+'_'+data.attribute, data);
}
}
);
});
// changement d'une relation
$('body').on('click', '[data-action="allow-change"] [data-action="change-relation"]', function (event) {
event.preventDefault();
var self = $(this);
if (!self.next('tr').hasClass('change-data-relation')) {
var data = {
'manager': self.closest('table').data('manager'),
'object': self.closest('table').data('object'),
'option': self.closest('table').data('option'),
'attribute': self.data('attribute'),
'managerRelation': self.data('manager-relation'),
};
$.ajax({
type: 'GET',
url: Routing.generate('admin_ajax_change_data_relation'),
data: data,
dataType: 'json',
success: function (json) {
$(json['form']).insertAfter(self);
}
}
);
}
});
// sauvegarde d'une relation
$('body').on('click', '[data-action="allow-change"] [data-action="change-relation-save"]', function (event) {
event.preventDefault();
var self = $(this);
var data = {
'manager': self.closest('table').data('manager'),
'managerRelation': self.closest('table').data('manager-relation'),
'object': self.closest('table').data('object'),
'attribute': self.closest('table').data('attribute'),
'option': self.closest('table').data('option'),
'value': self.data('value'),
};
$.ajax({
type: 'PATCH',
url: Routing.generate('admin_ajax_change_data_relation_save'),
data: data,
dataType: 'json',
success: function (json) {
self.closest('table').closest('tr').prev('tr').find('td').html(json['html']);
self.closest('table').closest('tr').remove();
// création d'un evenement pour appeller un callback
$('body').trigger("change_relation_" + data.manager+'_'+data.attribute, data);
}
}
);
});