admin.js 5.33 KB
Newer Older
Julien Jorry committed
1 2 3 4 5 6 7 8 9 10 11 12
/*
 * Welcome to your app's main JavaScript file!
 *
 * We recommend including the built version of this JavaScript file
 * (and its CSS file) in your base layout (base.html.twig).
 */

// any CSS you require will output into a single css file (app.css in this case)
require('../css/admin.css');
require('bootstrap');
require('../css/common.css');
require('../js/geoloc.js');
13
const $ = require("jquery");
Julien Jorry committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33

$('#flash-messages').flashNotification('init');

$(document).ready(function() {

	/*
	 * On user edit page, on the rolesgroup checkbox:
	 *		- display 'group' select if "Gestionnaire de groupe" is checked
	 *		- display 'comptoir' select if "Comptoir" is checked
	*/
	function possiblegroups_display_selects(e) {
		var label = $(this).closest('li').find('.control-label__text')[0].textContent.trim().toLowerCase()
		var isChecked = $(this).closest('li').find('.checked').length > 0

		if (label.includes('comptoir')) {
			if (isChecked) {
				$('.comptoirsgeres_select').removeClass('hide')
			} else {
				$('.comptoirsgeres_select').addClass('hide')
			}
34
		} else if (label.includes('groupe') || label.includes('contact')) {
Julien Jorry committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
			if (isChecked) {
				$('.groupesgeres_select').removeClass('hide')
			} else {
				$('.groupesgeres_select').addClass('hide')
			}
		}
	}

	$('.possible_group_cblist li .checkbox label').on('click', possiblegroups_display_selects);
	$('.possible_group_cblist li .checkbox label ins').on('click', possiblegroups_display_selects);


	$('.editableboolean').on('click', function (e) {
	    e.preventDefault();
	    var self = $(this);
	    $.ajax({
	        url : self.data('url'),
	        type: 'post',
	        data : {'value' : (self.data('value') == 'true')},
	        success: function(data) {
	            if(data.status == 'success' && !data.messages) {
	                if (data.newvalue == 'false') {
	                    self.text('non');
	                    self.data('value', 'false');
	                    self.addClass('label-danger');
	                    self.removeClass('label-success');
	                } else {
	                    self.data('value', 'true');
	                    self.text('oui');
	                    self.removeClass('label-danger');
	                    self.addClass('label-success');
	                }
	            } else {
	                // $(this).addClass('error');
	            }
	        }
	    });
	});
73

74
	// Hide or display Cotisation, Profils de Cotisation and Products Families submenu depending on TAV env
75 76 77 78 79
	const tav_env = document.getElementsByName('is-tav-env')[0].getAttribute('content');

	let linksToCotisationAdherent = $('a[href="/admin/cotisation_adherent/list"]');
	for(let i = 0 ; i < linksToCotisationAdherent.length ; i++) {
		if(linksToCotisationAdherent[i].innerText === "Cotisation") {
Yvon committed
80
			linksToCotisationAdherent[i].parentNode.style.display = (tav_env === "1") ? "none" : "";
81 82
		}
	}
83 84 85 86 87 88
	let linksToCotisationPresta = $('a[href="/admin/cotisation_prestataire/list"]');
	for(let i = 0 ; i < linksToCotisationPresta.length ; i++) {
		if(linksToCotisationPresta[i].innerText === "Cotisation") {
			linksToCotisationPresta[i].parentNode.style.display = (tav_env === "1") ? "none" : "";
		}
	}
89 90
	let linksToProfilDeCotisation = $('a[href="/admin/profilcotisation/list"]');
	for(let i = 0 ; i < linksToProfilDeCotisation.length ; i++) {
91
		if(linksToProfilDeCotisation[i].innerText === "Profils De Cotisation") {
Yvon committed
92
			linksToProfilDeCotisation[i].parentNode.style.display = (tav_env === "1") ? "" : "none";
93 94
		}
	}
95 96 97 98 99 100
	let linksToProductsFamily = $('a[href="/admin/app/productfamily/list"]');
	for(let i = 0 ; i < linksToProductsFamily.length ; i++) {
		if(linksToProductsFamily[i].innerText === "Familles de produits") {
			linksToProductsFamily[i].parentNode.style.display = (tav_env === "1") ? "" : "none";
		}
	}
101

102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133

	var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;

	var moyenDePaiement = document.querySelector('[id$="_moyenDePaiement"].select2-container a span');
	if(moyenDePaiement) {
		var moyenDePaiementObserver = new MutationObserver(actionOnMoyenDePaiementChange);
		moyenDePaiementObserver.observe(moyenDePaiement, {
			childList: true
		});
		function actionOnMoyenDePaiementChange() {
			var selector = document.querySelector('[id$="_jourPrelevement"].form-group');
			if (selector !== null) {
				selector.style.display = moyenDePaiement.innerHTML === "prélèvement" ? "" : "none";
			}
		}
		actionOnMoyenDePaiementChange();
	}

	var recevoirUnRappel = document.querySelector('[id$="_mailRappelCotisation"].form-group div div label div');
	if(recevoirUnRappel) {
		var recevoirUnRappelObserver = new MutationObserver(actionOnRecevoirUnRappelChange);
		recevoirUnRappelObserver.observe(recevoirUnRappel, {
			attributes: true
		});
		function actionOnRecevoirUnRappelChange() {
			var selector = document.querySelector('[id$="_jourMailRappelCotisation"].form-group');
			if (selector !== null) {
				selector.style.display = recevoirUnRappel.classList.contains('checked') ? "" : "none";
			}
		}
		actionOnRecevoirUnRappelChange();
	}
134 135 136 137 138 139 140

	if($(".fixBalanceAdherentFormPart").length > 0) {
		$(".fixBalanceAdherentFormPart").parent().parent().hide();
		$("div[id$='_idmlc']").append(
			"<br/><input type='button' id='showFieldsToFixBalance' onclick='$(\".fixBalanceAdherentFormPart\").parent().parent().show();' value='Afficher les champs pour corriger le solde'> </input>"
		);
	}
Julien Jorry committed
141
});