137 lines
4.3 KiB
JavaScript
137 lines
4.3 KiB
JavaScript
$(document).ready(function(){
|
|
|
|
$('div.ciblage-one input[type=radio]').change(function(e){
|
|
e.preventDefault();
|
|
var btn = $(this);
|
|
set(btn.attr('name'), btn.val());
|
|
});
|
|
|
|
$('div.ciblage-many button').click(function(e){
|
|
e.preventDefault();
|
|
var key = $(this).data('ciblagename');
|
|
var values = $('select[name='+key+']:selected').val();
|
|
set(key, values);
|
|
});
|
|
|
|
$('div.ciblage-range button').click(function(e){
|
|
e.preventDefault();
|
|
var key = $(this).data('ciblagename');
|
|
var values = $('#slider-'+key).val();
|
|
set(key, values);
|
|
});
|
|
|
|
$('div.ciblage-rangeinput button').click(function(e){
|
|
e.preventDefault();
|
|
var key = $(this).data('ciblagename');
|
|
var values = [];
|
|
values[0] = $('#rangeinput-'+key+'-selectmin').val();
|
|
values[1] = $('#rangeinput-'+key+'-selectmax').val();
|
|
set(key, values);
|
|
});
|
|
|
|
$('div.ciblage-rangedate button').click(function(e){
|
|
e.preventDefault();
|
|
var key = $(this).data('ciblagename');
|
|
var date = $('div#rangedate-'+key+' span').text();
|
|
var reg = new RegExp(" - ", "g");
|
|
var get = date.replace(reg,',').split( /,\s*/ );
|
|
var values = [];
|
|
values[0] = moment(get[0], "DD/MM/YYYY").format("YYYYMMDD");
|
|
values[1] = moment(get[1], "DD/MM/YYYY").format("YYYYMMDD");
|
|
set(key, values);
|
|
});
|
|
|
|
$('div.ciblage-tag button').click(function(e){
|
|
e.preventDefault();
|
|
var key = $(this).data('ciblagename');
|
|
var list = $('#tagitems-'+key).find('span.label');
|
|
var values = [];
|
|
if (list.length>0) {
|
|
list.each(function(){
|
|
//console.log($(this).data('value'));
|
|
values.push($(this).data('value'));
|
|
});
|
|
}
|
|
console.log(values);
|
|
set(key, values);
|
|
});
|
|
|
|
$('div.ciblage-tag input[type=text].tag').autocomplete({
|
|
minLength:2,
|
|
delay: 500,
|
|
source: function(request, response) {
|
|
$.getJSON('/fields/tag', { q: request.term, name: this.element.data('tagname'), key: this.element.data('tagkey') }, function(data) {
|
|
response(data);
|
|
});
|
|
},
|
|
focus: function() { return false; },
|
|
select: function( event, ui ) {
|
|
if (ui.item.value != '') {
|
|
var $items = $(this).parents('div.ciblage-tag').find('div.ciblage-tagitems');
|
|
$('<span class="label label-success" style="display:inline-block;" data-value="' +
|
|
ui.item.value + '">' + ui.item.label + '</span>').appendTo($items);
|
|
}
|
|
this.value = '';
|
|
return false;
|
|
},
|
|
close: function ( event, ui) { this.value = ''; },
|
|
});
|
|
|
|
$('div.ciblage-tree a').click(function(e) {
|
|
e.preventDefault();
|
|
var title = $(this).attr('title');
|
|
var href = $(this).attr('href');
|
|
var name = $(this).data('treename');
|
|
var key = $(this).data('treekey');
|
|
var dialogOpts = {
|
|
bgiframe: true,
|
|
title: title,
|
|
width: 900,
|
|
height: 500,
|
|
modal: true,
|
|
open: function(event, ui) {
|
|
$(this).html('Chargement...');
|
|
$(this).load(href, { name: name, key: key });
|
|
},
|
|
buttons: {
|
|
Valider: function() {
|
|
var key = $('div.jstree').attr('id');
|
|
var elements = [];
|
|
//console.log($('div.jstree').jstree().get_top_selected());
|
|
elements = $('div.jstree').jstree().get_top_selected();
|
|
set(key, elements.join(","));
|
|
$(this).dialog('close');
|
|
},
|
|
Fermer: function() { $(this).dialog('close'); }
|
|
},
|
|
close: function() { $('#dialogtree').remove(); }
|
|
};
|
|
$('<div id="dialogtree"></div>').dialog(dialogOpts);
|
|
return false;
|
|
});
|
|
|
|
});
|
|
|
|
function set(key, value, ex) {
|
|
ex = typeof ex !== 'undefined' ? ex : 0;
|
|
$('div#panel div.sidebar').html('<span class="glyphicon glyphicon-refresh img-rounded"></span>');
|
|
var isCount = false;
|
|
$.post('/comptage/index', { cle:key, valeur:value, exclude:ex }, function(data, status) {
|
|
if (data.error==1) {
|
|
$('div#actionMessage').html('<div class="alert alert-danger"><strong>Erreur !</strong> Un problème technique est survenu.</div>');
|
|
isCount = false;
|
|
}
|
|
if (data.error==2) {
|
|
$('div#actionMessage').html('<div class="alert alert-warning"><strong>Information !</strong> Valeur saisi incorrecte.</div>');
|
|
isCount = false;
|
|
}
|
|
isCount = true;
|
|
//Resume criteres content
|
|
if (isCount) {
|
|
$.post('/index/criteres', { total:data.count, insee:data.insee }, function(data) { $('#panel').html(data); });
|
|
}
|
|
}, 'json').error(function(){
|
|
$('div#actionMessage').html('<div class="alert alert-danger"><strong>Erreur !</strong> Un problème inconnu est survenu.</div>');
|
|
isCount = false;
|
|
});
|
|
} |