/*
 * 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('../js/geoloc.js');

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

$(document).ready(function() {
	$('.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');
	            }
	        }
	    });
	});
});