Site-Proximo/assets/js/categories.js
2020-02-10 23:36:17 +01:00

143 lines
5.1 KiB
JavaScript

// let listContainer = $("#dataList");
// let currentTypes = [];
// let displayedTypes = [];
let listManager;
$(document).ready(function () {
listManager = new ListManager($("#dataList"), json_dump,
[
{
name: 'icon',
description: 'Icone',
type: 'icon'
},
{
name: 'name',
description: 'Nom',
type: 'text'
},
]);
});
//
// function initValuesFromPHPDump() {
// currentTypes = json_dump;
// console.log(currentTypes);
//
// }
//
// $(document).ready(function () {
// initValuesFromPHPDump();
// generateList();
// console.log(displayedTypes);
// });
//
// function generateList() {
// for (let i = 0; i < currentTypes.length; i++) {
// createNewListEntry(currentTypes[i]);
// }
// }
//
// function createNewListEntry(type) {
// displayedTypes.push(
// $("<li id='listItem_" + type["id"] + "' onclick='showEditPopup(" + displayedTypes.length + ")'>" +
// "<div>" +
// "<span class='category-icon'><i class='mdi mdi-" + type["icon"] + "'></i></span>" +
// "<span class='category-title'>" + type["name"] + "</span>" +
// "</div>" +
// "</li>"));
// listContainer.append(displayedTypes[displayedTypes.length - 1]);
// }
//
// function deleteListEntry(id) {
// $('#listItem_' + id).remove();
// }
//
//
// function showEditPopup(index) {
// let defaultValues = {
// name: "",
// icon: ""
// };
// let title = "Créer une catégorie";
// if (index !== -1) {
// defaultValues = currentTypes[index];
// title = "Modifier la catégorie";
// }
// $.confirm({
// title: title,
// content:
// '<form action="" class="categoryForm">' +
// '<div class="form-group">' +
// '<label for="nameInput">Nom :</label>' +
// '<input id="nameInput" type="text" placeholder="Nom" class="name-input form-control" value="' + defaultValues['name'] + '" required />' +
// '<label for="iconInput">Icone :</label>' +
// '<input id="iconInput" type="text" placeholder="icone" class="icon-input form-control" value="' + defaultValues['icon'] + '" required />' +
// '</div>' +
// '</form>',
// buttons: {
// formSubmit: {
// text: 'Sauvegarder',
// btnClass: 'btn-blue',
// action: async function () {
// let name = this.$content.find('#nameInput').val();
// let icon = this.$content.find('#iconInput').val();
// if (!name) {
// $.alert('Merci de donner un nom');
// return false;
// } else if (!icon) {
// $.alert('Merci de donner une icone');
// return false;
// }
// let itemToSave;
// if (index !== -1) {
// currentTypes[index]['name'] = name;
// currentTypes[index]['icon'] = icon;
// itemToSave = currentTypes[index];
// displayedTypes[index].find(".category-title").text(name);
// displayedTypes[index].find(".mdi")[0].className = "mdi mdi-" + icon;
// } else {
// itemToSave = {
// name: name,
// icon: icon,
// display_order: 0,
// };
// }
// let id = await SaveManager.saveCategory(itemToSave, index === -1);
// if (id >= 0 && index === -1) {
// itemToSave = {
// name: name,
// icon: icon,
// display_order: 0,
// id: id
// };
// currentTypes[displayedTypes.length] = itemToSave;
// createNewListEntry(itemToSave);
// }
// }
// },
// deleteButton: {
// text: 'Supprimer',
// btnClass: 'btn-red',
// isHidden: index === -1,
// action: function () {
// let id = currentTypes[index]['id'];
// SaveManager.deleteCategory(id);
// deleteListEntry(id);
// }
// },
// cancelButton: {
// text: 'Annuler',
// },
// },
// onContentReady: function () {
// // bind to events
// let jc = this;
// this.$content.find('form').on('submit', function (e) {
// // if the user submits the form by pressing enter in the field.
// e.preventDefault();
// jc.$$formSubmit.trigger('click'); // reference the button and click it
// });
// }
// });
// }