Commit 057a8d11 authored by Théo GUILLON's avatar Théo GUILLON
Browse files

Ajout : lors de la modification d'un champ si celui-ci fait partie d'une...

Ajout : lors de la modification d'un champ si celui-ci fait partie d'une condition sur un autre champ on propose à l'utilisateur de supprimer les condition associées ou d'annuler
parent 55373b20
<div class="modal fade" id="modalWarningDeleteConditions" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title" id="myModalLabel">
<?php
echo "Suppression des conditions !";
?>
</h4>
</div>
<div class="modal-body">
<?php
echo $this->WebcilForm->create('modalWarningDeleteConditions', [
'url' => '#'
]);
?>
<div class="com-md-12">
<?php
echo 'La modification du champ va entrainer la suppression des conditions suivantes :'
?>
<ul>
<div id="allConditionsDelete" class="row"></div>
</ul>
</div>
</div>
<div class="modal-footer">
<div class="btn-group">
<button type="button" class="btn btn-default-default" data-dismiss="modal">
<i class="fa fa-times-circle fa-lg"><!----></i>
<?php
echo __d('default', 'default.btnAnnuler');
?>
</button>
<button id="deleteCondition" type="button" class="btn btn-default-danger" >
<i class="fa fa-floppy-o fa-lg"><!----></i>
<?php
echo "Supprimer les conditions en relation avec ce champ";
?>
</button>
</div>
</div>
</div>
</div>
</div>
\ No newline at end of file
......@@ -148,6 +148,7 @@ echo $this->WebcilForm->create('Formulaire', [
<?php
echo $this->element('Formulaires/modal/modalAddCondition');
echo $this->element('Formulaires/modal/modalWarningDeleteConditions');
echo $this->WebcilForm->end();
?>
......
......@@ -567,6 +567,14 @@ var createForm = function(typeCreateForm) {
'</label>' +
'</div>';
}
$(idContainer).find('.ui-selected').find(findType).each(function () {
if (list === '') {
list = list + $(this).val();
} else {
list = list + '\n' + $(this).val();
}
});
}
if (object.is('.deroulant, .multi-select')) {
......@@ -590,6 +598,14 @@ var createForm = function(typeCreateForm) {
idListeDesValeurs = 'option-multi-select';
classListeValeur = 'multiSelectForm';
}
$(idContainer).find('.ui-selected').find(findType).each(function () {
if (list === '') {
list = list + $(this).text();
} else {
list = list + '\n' + $(this).text();
}
});
}
if (!$(idContainer).find('.ui-selected').find(findType).attr('name')) {
......@@ -599,14 +615,6 @@ var createForm = function(typeCreateForm) {
classNameNomDeVariableRequired = "readonly='readonly'";
}
$(idContainer).find('.ui-selected').find(findType).each(function () {
if (list === '') {
list = list + $(this).text();
} else {
list = list + '\n' + $(this).text();
}
});
if ($(idContainer).find('.ui-selected').find(findType).attr('class') === "champNomVariableReadonly") {
readonly = "readonly='readonly'";
}
......@@ -712,7 +720,69 @@ var createForm = function(typeCreateForm) {
// On applique les modifications du champ en question au clic sur le boutton "Appliquer"
$('#'+idbtnApplicable).click(function () {
applyOptionsFieldOnField();
var fieldId = $(idContainer).find('.ui-selected').find('[id]').attr('id');
var conditionsTextuelle = '';
$(idContainer).find('[data-virtual-conditions]').not(".ui-selected").each(function (k, dataVitualContions) {
var conditionsJson = $(dataVitualContions).attr('data-virtual-conditions');
if (conditionsJson) {
conditions = JSON.parse(conditionsJson);
if (typeof conditions == 'object') {
$.each(conditions, function (uuid, condition) {
if (fieldId == condition['ifTheField']) {
// $('input[name ="'+condition['ifTheField']+'"],option[name ="'+condition['ifTheField']+'"]').each(function(option, value){
// if ($(this).attr('id') == condition['hasValue']) {
conditionsTextuelle = conditionsTextuelle + writeConditionsInOption(conditionsJson, false);
// }
// });
}
});
}
}
});
if (conditionsTextuelle != '') {
$('#allConditionsDelete').html(conditionsTextuelle);
$('#modalWarningDeleteConditions').modal('show');
// Si on click sur "Supprimer"
$('#deleteCondition').click(function () {
// Suppression des conditions en référence avec le champ qui est modifier
// On supprimer les conditions sur les autres champs si le champ en question fait partie de la condition
$(idContainer).find('[data-virtual-conditions]').not(".ui-selected").each(function (k, dataVitualContions) {
var conditionsJson = $(dataVitualContions).attr('data-virtual-conditions');
if (conditionsJson) {
conditions = JSON.parse(conditionsJson);
if (typeof conditions == 'object') {
$.each(conditions, function (uuid, condition) {
if (fieldId == condition['ifTheField']) {
delete conditions[uuid];
}
});
$(dataVitualContions).attr('data-virtual-conditions', '');
$(dataVitualContions).attr('data-virtual-conditions', JSON.stringify(conditions));
}
}
});
applyOptionsFieldOnField();
$('#modalWarningDeleteConditions').modal('hide');
});
// Si on click sur "Annuler"
$('#modalWarningDeleteConditions').on('hidden.bs.modal', function () {
$('#modalWarningDeleteConditions').modal('hide');
$(idContainer).find('.ui-selected').removeClass('ui-selected');
hideDetails();
});
} else {
applyOptionsFieldOnField();
}
});
// On supprime le champ en question au clic sur le bouton "Poubelle"
......@@ -721,21 +791,23 @@ var createForm = function(typeCreateForm) {
// On supprimer les conditions sur les autres champs si le champ en question fait partie de la condition
$(idContainer).find('[data-virtual-conditions]').not(".ui-selected").each(function (k, dataVitualContions) {
var conditions = $(dataVitualContions).attr('data-virtual-conditions');
if (conditions) {
conditions = JSON.parse(conditions);
$.each(conditions, function (uuid, condition) {
$.each(condition, function (key, value) {
if (jQuery.inArray(key, ['ifTheField', 'thenTheField']) !== -1) {
if (fieldRemoveId == value) {
delete conditions[uuid];
var conditionsJson = $(dataVitualContions).attr('data-virtual-conditions');
if (conditionsJson) {
conditions = JSON.parse(conditionsJson);
if (typeof conditions == 'object') {
$.each(conditions, function (uuid, condition) {
$.each(condition, function (key, value) {
if (jQuery.inArray(key, ['ifTheField', 'thenTheField']) !== -1) {
if (fieldRemoveId == value) {
delete conditions[uuid];
}
}
}
});
});
});
$(dataVitualContions).attr('data-virtual-conditions', '');
$(dataVitualContions).attr('data-virtual-conditions', JSON.stringify(conditions));
$(dataVitualContions).attr('data-virtual-conditions', '');
$(dataVitualContions).attr('data-virtual-conditions', JSON.stringify(conditions));
}
}
});
......@@ -904,7 +976,7 @@ var createForm = function(typeCreateForm) {
* @version V1.2.0
* @author Théo GUILLON <theo.guillon@libriciel.coop>
*/
function writeConditionsInOption(conditions) {
function writeConditionsInOption(conditions, noTrash = true) {
var writeConditions = '';
var success = true;
......@@ -942,7 +1014,14 @@ var createForm = function(typeCreateForm) {
ifNot = 'caché';
}
writeConditions = writeConditions + '<p>' +
var btnTrash = '';
if (noTrash == true) {
btnTrash = '<a id="'+key+'" href="#" class="removeCondition">' +
'<span class="fa fa-trash fa-lg fa-danger"></span>' +
'</a>';
}
writeConditions = writeConditions + '<p><li>' +
'Si le champ' +
'<strong>'+
' "'+ifTheField+'" '+
......@@ -963,10 +1042,8 @@ var createForm = function(typeCreateForm) {
'<strong>'+
' "'+ifNot+'" '+
'</strong>' +
'<a id="'+key+'" href="#" class="removeCondition">' +
'<span class="fa fa-trash fa-lg fa-danger"></span>' +
'</a>'
'</p>';
btnTrash +
'</li></p>';
});
if (success == true) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment