2018-04-02 08:29:19 +02:00
|
|
|
/**
|
2021-02-17 13:51:12 +01:00
|
|
|
* This file is part of Zwii.
|
2018-04-02 08:29:19 +02:00
|
|
|
* For full copyright and license information, please see the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*
|
|
|
|
* @author Rémi Jean <remi.jean@outlook.com>
|
|
|
|
* @copyright Copyright (C) 2008-2018, Rémi Jean
|
2021-02-17 13:49:58 +01:00
|
|
|
* @author Frédéric Tempez <frederic.tempez@outlook.com>
|
2023-01-09 10:23:32 +01:00
|
|
|
* @copyright Copyright (C) 2018-2023, Frédéric Tempez
|
2022-12-29 17:02:20 +01:00
|
|
|
* @license CC Attribution-NonCommercial-NoDerivatives 4.0 International
|
2020-09-01 20:48:40 +02:00
|
|
|
* @link http://zwiicms.fr/
|
2018-04-02 08:29:19 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ajout d'un champ
|
|
|
|
*/
|
|
|
|
function add(inputUid, input) {
|
|
|
|
// Nouveau champ
|
|
|
|
var newInput = $($("#formConfigCopy").html());
|
|
|
|
// Ajout de l'ID unique aux champs
|
|
|
|
newInput.find("a, input, select").each(function() {
|
|
|
|
var _this = $(this);
|
|
|
|
_this.attr({
|
|
|
|
id: _this.attr("id").replace("[]", "[" + inputUid + "]"),
|
|
|
|
name: _this.attr("name").replace("[]", "[" + inputUid + "]")
|
|
|
|
});
|
|
|
|
});
|
|
|
|
newInput.find("label").each(function() {
|
|
|
|
var _this = $(this);
|
|
|
|
_this.attr("for", _this.attr("for").replace("[]", "[" + inputUid + "]"));
|
|
|
|
});
|
|
|
|
// Attribue les bonnes valeurs
|
|
|
|
if(input) {
|
|
|
|
// Nom du champ
|
|
|
|
newInput.find("[name='formConfigName[" + inputUid + "]']").val(input.name);
|
|
|
|
// Type de champ
|
|
|
|
newInput.find("[name='formConfigType[" + inputUid + "]']").val(input.type);
|
|
|
|
// Largeur du champ
|
|
|
|
newInput.find("[name='formConfigWidth[" + inputUid + "]']").val(input.width);
|
|
|
|
// Valeurs du champ
|
|
|
|
newInput.find("[name='formConfigValues[" + inputUid + "]']").val(input.values);
|
|
|
|
// Champ obligatoire
|
|
|
|
newInput.find("[name='formConfigRequired[" + inputUid + "]']").prop("checked", input.required);
|
|
|
|
}
|
|
|
|
// Ajout du nouveau champ au DOM
|
|
|
|
$("#formConfigInputs")
|
|
|
|
.append(newInput.hide())
|
|
|
|
.find(".formConfigInput").last().show();
|
|
|
|
// Cache le texte d'absence de champ
|
|
|
|
$("#formConfigNoInput:visible").hide();
|
|
|
|
// Check le type
|
|
|
|
$(".formConfigType").trigger("change");
|
|
|
|
// Actualise les positions
|
|
|
|
position();
|
|
|
|
}
|
|
|
|
|
2022-02-18 12:43:48 +01:00
|
|
|
/**
|
|
|
|
* Afficher/cacher les options supplémentaires
|
|
|
|
*/
|
|
|
|
$(document).on("click", ".formConfigMoreToggle", function() {
|
|
|
|
|
|
|
|
$(this).parents(".formConfigInput").find(".formConfigMore").slideToggle();
|
|
|
|
$(this).parents(".formConfigInput").find(".formConfigMoreLabel").slideToggle();
|
|
|
|
});
|
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
/**
|
|
|
|
* Calcul des positions
|
|
|
|
*/
|
|
|
|
function position() {
|
|
|
|
$("#formConfigInputs").find(".formConfigPosition").each(function(i) {
|
|
|
|
$(this).val(i + 1);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ajout des champs déjà existant
|
|
|
|
*/
|
|
|
|
var inputUid = 0;
|
|
|
|
var inputs = <?php echo json_encode($this->getData(['module', $this->getUrl(0), 'input'])); ?>;
|
|
|
|
if(inputs) {
|
2022-04-06 09:46:28 +02:00
|
|
|
var inputsPerPosition = <?php echo json_encode(helper::arrayColumn($this->getData(['module', $this->getUrl(0), 'input']), 'position', 'SORT_ASC')); ?>;
|
2018-04-02 08:29:19 +02:00
|
|
|
$.each(inputsPerPosition, function(id) {
|
|
|
|
add(inputUid, inputs[id]);
|
|
|
|
inputUid++;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Crée un nouveau champ à partir des champs cachés
|
|
|
|
*/
|
|
|
|
$("#formConfigAdd").on("click", function() {
|
|
|
|
add(inputUid);
|
|
|
|
inputUid++;
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Actions sur les champs
|
|
|
|
*/
|
2022-02-18 12:43:48 +01:00
|
|
|
|
|
|
|
// Validation auto après ajout d'un champ
|
|
|
|
$("a#formConfigAdd.button").click(function () {
|
|
|
|
$("#formConfigForm").submit();
|
|
|
|
});
|
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
// Tri entre les champs
|
|
|
|
sortable("#formConfigInputs", {
|
|
|
|
forcePlaceholderSize: true,
|
|
|
|
containment: "#formConfigInputs",
|
|
|
|
handle: ".formConfigMove"
|
|
|
|
});
|
|
|
|
$("#formConfigInputs")
|
|
|
|
// Actualise les positions
|
|
|
|
.on("sortupdate", function() {
|
|
|
|
position();
|
|
|
|
})
|
|
|
|
// Suppression du champ
|
|
|
|
.on("click", ".formConfigDelete", function() {
|
|
|
|
var inputDOM = $(this).parents(".formConfigInput");
|
|
|
|
// Cache le champ
|
|
|
|
inputDOM.hide();
|
|
|
|
// Supprime le champ
|
|
|
|
inputDOM.remove();
|
|
|
|
// Affiche le texte d'absence de champ
|
|
|
|
if($("#formConfigInputs").find(".formConfigInput").length === 0) {
|
|
|
|
$("#formConfigNoInput").show();
|
|
|
|
}
|
|
|
|
// Actualise les positions
|
|
|
|
position();
|
|
|
|
})
|
|
|
|
// Affiche/cache le champ "Valeurs" en fonction des champs cachés
|
|
|
|
.on("change", ".formConfigType", function() {
|
|
|
|
var _this = $(this);
|
2019-12-04 11:46:23 +01:00
|
|
|
switch (_this.val()) {
|
|
|
|
case "select":
|
|
|
|
_this.parents(".formConfigInput").find("label[for*=formConfigRequired]").show();
|
|
|
|
_this.parents(".formConfigInput").find(".formConfigValuesWrapper").slideDown();
|
|
|
|
_this.parents(".formConfigInput").find(".formConfigLabelWrapper").slideUp();
|
|
|
|
break;
|
|
|
|
case "label":
|
|
|
|
_this.parents(".formConfigInput").find("label[for*=formConfigRequired]").hide();
|
|
|
|
_this.parents(".formConfigInput").find(".formConfigLabelWrapper").slideDown();
|
2021-05-03 09:02:58 +02:00
|
|
|
_this.parents(".formConfigInput").find(".formConfigValuesWrapper").slideUp();
|
2019-12-04 11:46:23 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_this.parents(".formConfigInput").find("label[for*=formConfigRequired]").show();
|
2021-05-03 09:02:58 +02:00
|
|
|
_this.parents(".formConfigInput").find(".formConfigValuesWrapper").slideUp();
|
|
|
|
_this.parents(".formConfigInput").find(".formConfigLabelWrapper").slideUp();
|
|
|
|
}
|
2018-04-02 08:29:19 +02:00
|
|
|
});
|
|
|
|
// Simule un changement de type au chargement de la page
|
|
|
|
$(".formConfigType").trigger("change");
|