1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120 |
- // Avoid `console` errors in browsers that lack a console.
- (function() {
- var method;
- var noop = function () {};
- var methods = [
- 'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
- 'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
- 'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
- 'timeline', 'timelineEnd', 'timeStamp', 'trace', 'warn'
- ];
- var length = methods.length;
- var console = (window.console = window.console || {});
- while (length--) {
- method = methods[length];
- // Only stub undefined methods.
- if (!console[method]) {
- console[method] = noop;
- }
- }
- }());
- //Affiche un message 'message' de type 'type' pendant 'timeout' secondes
- $.message = function (type,message,timeout){
- message = message.replace(/<\/?script|iframe|object[^>]*>/gim,'');
- $.toast({ type: type, content: message, timeout: timeout });
- }
- //Permet les notifications types toast sans dépendance de librairie/css/html
- $.toast = function (options) {
- var defaults = {
- title: null,
- content: '',
- type: 'info',
- timeout: 3000
- };
- var o = $.extend(defaults, options);
- var css = "word-wrap:break-word;color:#ffffff;border-radius:1px;margin-bottom:10px;text-align:center;width:100%;box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.3);position:relative;";
- var types = {
- error: { css: "background:#dc2626;", icon: 'fas fa-exclamation-triangle' },
- warning: { css: "background:#ffc107;color:#212529;", icon: 'fas fa-exclamation-circle' },
- info: { css: "background:#2AA7EA;", icon: 'fas fa-info-circle' },
- success: { css: "background:#28a745;", icon: 'fas fa-check' },
- }
- css += types[o.type].css;
- o.icon = types[o.type].icon;
- if ($('.toastContainer').length == 0)
- $('body').append('<div class="toastContainer" style="z-index:1100;position:fixed;right:15px;top:65px;width:350px;"></div>');
- var popupContainer = $('.toastContainer');
- var popup = $('<div style="' + css + '" class="noPrint toast-'+o.type+'"><i class="toastRemove fas fa-times hidden" style="position:absolute;top:5px;right:5px;cursor:pointer;" onclick="$(this).parent().remove();"; style="position:absolute;top:5px;right:5px;cursor:pointer;"></i><h1 class="toastTitle" style="margin:0;padding:10px;"></h1><i class="toastIcon" style="display:inline-block;vertical-align:top;width:30px;font-size:20px;margin:15px 0;"></i><p style="display: inline-block;margin-top: 10px;padding:0 10px 0 10px;width:300px;" class="toastContent"></p><div style="clear:both;"></div></div>');
- $(popupContainer).append(popup);
- if (o.title) $('.toastTitle', popup).html(o.title);
- $('.toastIcon', popup).attr('class', o.icon);
- if (!o.title) $('.toastTitle', popup).remove();
- $('.toastContent', popup).html(o.content);
- popup.removeClass('hidden');
-
- if (o.timeout != 0) {
- setTimeout(function () { popup.addClass('hidden'); }, o.timeout);
- } else {
- popup.find('.toastRemove').removeClass('hidden');
- }
- }
-
- $.page = function(element){
- var path = window.location.pathname.split('/') ;
- path = path[path.length-1];
- path = path.replace('.php','');
- return path;
- }
- $.getForm= function(element){
- return $(element).getForm();
- }
-
- $.setForm= function(element,data){
- var o = {};
- var obj = $(element);
- $('input,select,textarea',obj).each(function(i,element){
-
- if(element.id!=null && element.id!=""){
-
- if(data[element.id]!=null){
- if($(element).attr("type")=='checkbox' || $(element).attr("type")=='radio'){
- $(element).prop("checked",data[element.id]==1 || data[element.id]=='true' ?true:false);
- } else {
- $(element).val(data[element.id]);
- }
- }
- }
- });
- return o;
- }
- //Gestion des tableaux pour le formData
- $.form_data = function(formData, key,values){
- var hasFile = false;
- if(values instanceof File ) hasFile = true;
-
- if( typeof values == 'object' && !(values instanceof File) ){
- for(subkey in values)
- if($.form_data(formData,key + '[' + subkey + ']',values[subkey])) hasFile = true;
- }else{
- formData.append(key, values);
- }
- return hasFile;
- }
- $.action = function(data,success,error,progress) {
- var formData = new FormData();
- var defaultSuccess = data.defaultSuccess != undefined ? data.defaultSuccess : true;
- // if(data.defaultSuccess !== undefined) delete data.defaultSuccess;
- //hasFile determine si un fichier uploadé se trouve dans le tableau des data
- // Si c'est le cas, il envois les données en multipart, sinon il les envoie en json classique.
- var hasFile = false;
- $.each(data, function(key, value){
- if($.form_data(formData,key, value) == true) hasFile = true;
- });
- var request = {
- url : 'action.php',
- method : 'POST',
- success: function(response){
- if(response && !response.error){
- if(success!=null)success(response);
- } else {
- if(response.errorCode && response.errorCode=='401') window.location = 'action.php?action=logout';
- var errorMessage = 'ERREUR : '+"\n"+response.error;
- if(response.trace) errorMessage += "\n<div style='font-size:10px;max-height:200px;overflow:auto;text-align:left;'>"+response.trace+"</div>";
- if(defaultSuccess) $.message('error',errorMessage,0);
- if(error!=null) error(response);
- }
- },
- error : function(response){
- if(response.status == 200 && $.localhost() ){
- $('body').append('<div class="debugFrame" style="box-shadow: 0px 0px 10px rgba(0,0,0,0.5);z-index: 10001;padding: 5px;position: fixed;left: 0;top: 0;width: 40%;min-height: 100%;border-right: 2px solid #ff3b00;background: rgba(210, 222, 255, 0.9);overflow-y: auto;height: 100%; word-break: break-word;"><h3>Action debug</h3> <i style="position:absolute; right:10px; top:10px;font-size:1.5em;" onclick="$(this).parent().remove()" class="fas fa-times pointer"></i>'+response.responseText+'</div>');
- } else {
- if(response.readyState == 0 && error==null) return;
- if(error!=null){
- if(response.errorCode && response.errorCode=='401') window.location = 'action.php?action=logout';
- error(response);
- }else{
- $.message('error','Erreur indefinie, merci de contacter un administrateur',0);
- }
- }
- },
- xhr: function() {
- var xhr = new window.XMLHttpRequest();
- if(data.downloadResponse) xhr.responseType = 'blob';
- xhr.upload.addEventListener("progress", function(evt){
- if (evt.lengthComputable) {
- var percentComplete = (evt.loaded / evt.total) * 100;
- percentComplete = Math.round(percentComplete * 100) / 100;
- if(progress) progress(percentComplete,'upload');
- }
- }, false);
- xhr.addEventListener("progress", function(evt){
- if (evt.lengthComputable) {
- var percentComplete = evt.loaded / evt.total;
- if(progress) progress(percentComplete,'download');
- }
- }, false);
- xhr.addEventListener('readystatechange', function(e) {
- if(xhr.readyState == 4 && xhr.status == 200) {
- if(data.downloadResponse){
- var disposition = xhr.getResponseHeader('content-disposition');
- var matches = /"([^"]*)"/.exec(disposition);
- var filename = (matches != null && matches[1] ? matches[1] : 'file');
- var blob = new Blob([xhr.response], { type: xhr.response.type });
- var link = document.createElement('a');
- link.href = window.URL.createObjectURL(blob);
- link.download = filename;
- $('body').append(link);
- link.click();
- link.remove();
- window.URL.revokeObjectURL(link);
- }
- }
- });
- return xhr;
- }
- };
- if(!hasFile){
- request.data = data;
- }else{
- request.data = formData;
- request.processData = false;
- request.contentType = false;
- }
- $.ajax(request);
- }
-
- $.localhost = function(){
- return (document.location.hostname=='127.0.0.1' || document.location.hostname=='localhost');
- }
-
-
- $.hashData = function(name){
- var page = window.location.hash.substring(1);
- page += "&"+window.location.search.substring(1);
- data = {};
- if(page!='' && page!= null){
- options = page.split('&');
- var data = {};
- for(var key in options){
- infos = options[key].split('=');
- data[infos[0]] = infos[1];
- }
- }
- if(name == null) return data;
- if(typeof name === "object"){
- data = name;
- hashstring = '';
- for(var key in data)
- hashstring+= "&"+key+"="+data[key];
- hashstring = hashstring.substring(1);
- window.location.hash = hashstring;
- return;
- }
- return typeof data[name] == "undefined" ? '':data[name];
- }
- $.urlParam = function (name,value) {
- var parameters = window.location.href.match(/[\\?&]([^&#]*)=([^&#]*)/g);
- var data = {};
- for (var key in parameters) {
- var couple = parameters[key].substring(1, parameters[key].length).split('=');
- data[couple[0]] = couple[1];
- }
- if(name == null) return data;
- if (value == null)
- return data[name] ? data[name] : null;
- if (value != false) data[name] = value;
- var url = '?';
- for (var key in data) {
- if (value == false && key == name) continue;
- url += key + '=' + data[key]+'&';
- }
- window.history.pushState('', document.title, url.substring(0, url.length-1));
- }
-
- $.fn.extend({
- toJson : function(){
- return $.getForm(this);
- },
- getForm : function(){
- var o = {};
- var obj = $(this);
- for(var key in obj.data()){
- if(key!="action" && key != "id") continue;
- o[key] = obj.attr('data-'+key);
- }
-
- $('input,select,textarea',obj).each(function(i,element){
- if(element.id!=null && element.id!=""){
- if($(element).attr("type")=='checkbox' || $(element).attr("type")=='radio'){
- o[element.id] = ($(element).is(':checked')?1:0);
- }else{
- o[element.id] = $(element).val();
- }
- }
- });
- return o;
- },
- upload: function (options) {
-
- //var options = $.extend(defaults, options);
- return this.each(function () {
- var o = options;
- var droppedFiles = false;
- var div = $(this);
- var data = div.data();
- data.html =!div.attr('data-label') ? '': div.attr('data-label');
- data.label = data.html;
- div.html('');
- var o = $.extend(o, data);
-
- if(o.readonly == false){
- var form = $('<form class="box" method="post" action="' + o.action + '" enctype="multipart/form-data"><input type="file" name="'+(o.fileName?o.fileName:div.attr('id'))+'[]" multiple /></form>');
- div.append(form);
-
- var input = form.find('input[type="file"]');
- var zone = $('<div>' + o.label + '</div>');
- div.append(zone);
- //test if dnd is enabled n browser
- var div = document.createElement('div');
- var dragAndDropEnabled = (('draggable' in div) || ('ondragstart' in div && 'ondrop' in div)) && 'FormData' in window && 'FileReader' in window;
- //set elements styles
- input.attr('style', "width: 0.1px;height: 0.1px;opacity: 0;overflow: hidden; position: absolute;z-index: -1");
- zone.css('cursor', "pointer");
- //set events
- zone
- .on('click', function (e) {
- form.find('input[type="file"]').trigger('click');
- e.preventDefault();
- e.stopPropagation();
- })
- .on('drag dragstart dragend dragover dragenter dragleave drop', function (e) {
- e.preventDefault();
- e.stopPropagation();
- })
- .on('dragover dragenter', function () {
- if (o.hover) form.addClass(o.hover);
- })
- .on('dragleave dragend drop', function () {
- if (o.hover) form.removeClass(o.hover);
- })
- .on('drop', function (e) {
- droppedFiles = e.originalEvent.dataTransfer.files;
- form.trigger('submit');
- });
- input.on('change', function (e) {
- form.trigger('submit');
- });
- form.on('submit', function (e) {
- if (o.start) o.start();
-
- if (dragAndDropEnabled) {
- e.preventDefault();
- var ajaxData = new FormData();
- if (droppedFiles) {
-
- $.each(droppedFiles, function (i, file) {
- var ext = file.name.split('.');
- ext = ext.pop();
-
- if(o.allowed && $.inArray(ext.toLowerCase(),o.allowed.split(','))===-1){
- $.message('error','Extension fichier '+ext+' non permise (autorisé:'+o.allowed+')',0);
- return;
- }
- if(o.size && file.size > o.size){
- $.message('error','Taille fichier '+file.size+' octets trop grande (autorisé:'+o.size+' octets)',0);
- return;
- }
- ajaxData.append(input.attr('name'), file);
- });
- }else{
- ajaxData = new FormData(form.get(0));
-
- for(var key in $('input',form).get(0).files){
- var file = $('input',form).get(0).files[key];
- if(file.name==null || typeof file !='object') continue;
- var ext = file.name.split('.');
-
- ext = ext.pop();
-
- if(o.allowed && $.inArray(ext.toLowerCase(),o.allowed.split(','))===-1){
- $.message('error','Extension fichier '+ext+' non permise (autorisé:'+o.allowed+')',0);
- $('input',form).val();
- return;
- }
- if(o.size && file.size > o.size){
- $.message('error','Taille fichier '+file.size+' octets trop grande (autorisé:'+o.size+' octets)',0);
- $('input',form).val();
- return;
- }
- }
- }
- if (o.addData){
- var addionalData = o.addData();
- for(var k in addionalData){
- ajaxData.append(k, addionalData[k]);
- }
- }
- droppedFiles = null;
- $.ajax({
- url: form.attr('action'),
- type: form.attr('method'),
- data: ajaxData,
- dataType: 'json',
- cache: false,
- contentType: false,
- processData: false,
- complete: function (data) {
-
- if (o.complete) o.complete(data.responseJSON);
- },
- success: function (data) {
-
- if (o.success) o.success(data);
- },
- error: function (data) {
- if (o.error) o.error(data);
- }
- });
- } else {
- var iframeName = 'uploadiframe' + new Date().getTime();
- iframe = $('<iframe name="' + iframeName + '" style="display: none;"></iframe>');
- $('body').append(iframe);
- form.attr('target', iframeName);
- iframe.one('load', function () {
- var data = JSON.parse(iframe.contents().find('body').text());
- if (!data.success) alert(data.error);
- form.removeAttr('target');
- iframe.remove();
- if (o.complete) o.complete();
- });
- }
- });
- }
- });
- },
- clear: function (){
- return this.each(function() {
- var obj = $(this);
- obj.find('input,select,textarea').val('').prop('checked',false).prop('selected',false);
-
- });
- },
- addLine: function (rows){
-
- return this.each(function() {
-
- var obj = $(this);
- var model = null;
- var container = null;
-
- if(obj.prop("tagName") == 'UL'){
- container = obj;
- model = container.find('li:first-child');
- container.find('li:visible').remove();
- }else if(obj.prop("tagName") == 'TABLE'){
- container = obj.find('tbody');
- model = container.find('tr:first-child');
- container.find('tr:visible').remove();
- }else{
- container = obj;
- childName = container.children().get(0).nodeName;
- model = container.find(childName+':first-child');
- container.find(childName+':visible:not(.nofill)').remove();
- }
- var tpl = model.get(0).outerHTML;
-
- //fix jquery backslahes break
- tpl = tpl.replace(/{{##/g,'{{/').replace(/{{\/(.*)}}=""/g,'{{/$1}}');
-
- //fix images url not found on template
- tpl = tpl.replace(/(<img\s[^>]*\s)(data-src)/g,'$1src');
-
- for(var key in rows){
- var line = $(Mustache.render(tpl,rows[key]));
- container.append(line);
- line.removeClass('hidden');
- }
-
-
- });
- },
- //Permet le resize d'un panel vertical
- panelResize : function(options){
- var obj = $(this);
- var o = $.extend({
- handlerClass : 'panel-resize-handler',
- hoverClass : 'panel-resize-handler-hover',
- handlerWidth : 10,
- direction : 'right',
- minWidth : 30,
- maxWidth : 700,
- update : function(data){}
- }, options);
- var handlerId = 'handler-'+generate_uuid(10);
- var handler = $('<div id="'+handlerId+'" class="'+o.handlerClass+'" style="cursor:col-resize;opacity:0.1;position:absolute;z-index:1000;height:'+obj.outerHeight()+'px;width:'+o.handlerWidth+'px;"></div>');
- var timeout = null;
- var left;
- if( o.direction== 'right'){
- left = obj.position().left+obj.outerWidth()-(o.handlerWidth/2);
- }else if (o.direction== 'left'){
- left = obj.position().left-(o.handlerWidth/2);
- }
- handler.css({
- left :left,
- top : obj.position().top
- });
- handler.hover(function(){
- clearTimeout(timeout);
- handler.addClass(o.hoverClass);
- },
- function(){
- timeout = setTimeout(function(){
- handler.removeClass(o.hoverClass);
- },300);
- });
- if(!window.handlerActive) window.handlerActive = {};
- if(!window.handlerPosition) window.handlerPosition = {};
- handler.mousedown(function(){
- window.handlerPosition[handlerId] = handler.position().left;
- window.handlerPanelWidth = obj.outerWidth();
- window.handlerActive[handlerId] = true;
- });
- $(document).mouseup(function(){
- window.handlerActive[handlerId] = false;
- var left;
- if( o.direction== 'right'){
- left = obj.position().left+obj.outerWidth()-(o.handlerWidth/2);
- }else if (o.direction== 'left'){
- left = obj.position().left-(o.handlerWidth/2);
- }
- handler.css({left : left});
- o.update({
- element : obj,
- handler : handler,
- width : obj.outerWidth()
- });
- });
- $(document).mousemove(function( event ) {
- if(!window.handlerActive[handlerId]) return;
- var newPosition = (event.pageX-2);
- var negativeWidth = window.handlerPosition[handlerId] - newPosition;
- var newWidth = window.handlerPanelWidth- (negativeWidth * (o.direction== 'right'?1:-1) );
- if(newWidth < o.minWidth || newWidth <1 || newWidth > o.maxWidth ){
- return;
- }
- handler.css({
- left : newPosition+'px'
- });
- obj.css({
- width : newWidth+'px',
- maxWidth : newWidth+'px'
- });
- });
- obj.after(handler);
- },
- fill: function (option,callback,progress){
-
- return this.each(function() {
-
- var obj = $(this);
- var model = null;
- var container = null;
- option = $.extend({
- differential : false,
- showing : function(item){
- //permet la personnalisation de l'apparition des lignes ( removeClass('hidden') par defaut)
- item.removeClass('hidden');
- }
- },option);
- var preloader = null;
- if(option.preloader){
- var preloader = $(option.preloader);
- preloader.css('position','absolute');
- preloader.css('left',(obj.offset().left+obj.width()/2)+'px');
- preloader.css('top',(obj.offset().top+30)+'px');
- $('body').append(preloader);
- }
-
-
- if(obj.prop("tagName") == 'UL'){
- container = obj;
- model = container.find('li:first-child');
- if(!option.export && !option.differential) container.children('li:visible').remove();
- } else if(obj.prop("tagName") == 'TABLE'){
- container = obj.find('tbody');
- model = container.find('tr:first-child');
- if(!option.export && !option.differential) container.children('tr:visible').remove();
- } else if(obj.prop("tagName") == "SELECT"){
- container = obj;
- model = container.find('option[value*="{{"]');
- if(model.length==0) model = $('<option class="hidden" value="{{value}}">{{label}}</option>');
- if(!option.export && !option.differential) container.find('option:not([value*="{{"])').remove();
- } else{
- container = obj;
- childName = container.children().get(0).nodeName;
- model = container.find(childName+':first-child');
- if(!option.export && !option.differential) container.find(childName+':visible:not(.nofill)').remove();
- }
- var tpl = model.get(0).outerHTML;
- //fix jquery backslashes break
- tpl = tpl.replace(/{{##/g,'{{/').replace(/{{\/(.*)}}=""/g,'{{/$1}}');
-
- //fix images url not found on template
- tpl = tpl.replace(/(<img\s[^>]*\s?)(data-src)/g,'$1src');
- var pagination = obj.nextAll('.pagination').length ? obj.nextAll('.pagination') : obj.parent().nextAll('.pagination');
- if(pagination.length!=0) option.page = $('li.active',pagination).attr('data-value');
-
- tpl = tpl.replace(/(data-style)/g, 'style');
- if(option.export)
- option.downloadResponse = true;
-
- //on clone l'objet option pour ne transmettre que des datas utiles
- data = $.extend({},option);
- delete data.showing;
- delete data.templating;
- $.action(data,function(r){
- //On ne gere la pagination et l'affichage tableau que si on est pas en mode export
- if(!option.export){
- var activeIds = [];
- for(var key in r.rows){
- var line;
- var data = r.rows[key];
- var lineTpl = tpl;
- if(option.templating) lineTpl = option.templating(data,line,tpl);
- if(!option.differential){
- line = $(Mustache.render(lineTpl,data));
- container.append(line);
- option.showing(line,key);
- }else{
- activeIds.push(data.id);
- var existing = $('> [data-id="'+data.id+'"]',container);
- //existe en data et pas dans le dom : ajout
- if(existing.length == 0){
- line = $(Mustache.render(lineTpl,data));
- line.attr('data-update-tag',data.updated);
-
- if(key==0){
- container.append(line);
- }else{
- var previousIndex = key-1;
- var previous = $('>[data-id]:visible',container).eq(previousIndex);
- previous.after(line);
- }
- option.showing(line,key);
- }else{
- //existe en data et dans le dom et pas de modification : on passe au suivant
- if(existing.attr('data-update-tag') == data.updated){
- continue;
- //existe en data et dans le dom mais a été modifié : on remplace
- }else{
- line = $(Mustache.render(lineTpl,data));
- line.attr('data-update-tag',data.updated);
- existing.after(line);
- existing.remove();
- option.showing(line,key);
- }
- }
- }
- }
- //suppression des élements dom qui ne sont plus en db
- if(option.differential){
- $('>[data-id]:visible',container).each(function(i,line){
-
- var line = $(line);
-
-
- if(activeIds.indexOf(line.attr('data-id')) == -1){
- console.log(line.attr('data-id'));
- console.log('suppression ',line);
- line.remove();
- }
- });
- }
- if(r.pagination){
- $('.page-item-previous,.page-item-next').remove();
- r.pagination.pages = Math.ceil(r.pagination.pages);
- var previewNumber = pagination.attr('data-range') != '' && pagination.attr('data-range') != null ? parseInt(pagination.attr('data-range')) : 5;
- previewNumber = previewNumber < 2 ? 2 : previewNumber;
- var template = pagination.find('li:not(:visible)');
- if(template.length>0 ){
- template = template.get(0).outerHTML;
- $('li:not(:eq(0))',pagination).remove();
- var current = parseInt(r.pagination.current);
- var previousPages = current-previewNumber;
- var nextPages = current+previewNumber;
- var dropDownTpl = '<div data-toggle="dropdown"><i class="fas fa-ellipsis-h pointer"></i></div><div class="dropdown-menu pagination-select">{{#choices}}<span class="dropdown-item">{{.}}</span>{{/choices}}</div>';
- for(i=0;i<r.pagination.pages;i++){
- var li = $(Mustache.render(template,{value:i,label:i+1}));
- if(
- (previousPages < i && i < nextPages)
- || i==0 || i==r.pagination.pages-1
- ){
- li.removeClass('hidden');
- if(i==current) li.addClass('active');
- }else{
- if(i==1 || i==r.pagination.pages-2){
- var dotli = li.clone()
- var start = i==1 ? 2: current+previewNumber+1;
- var end = i==1 ? (current+1)-previewNumber : r.pagination.pages-1;
- var choices = [];
- for(u=start; u<end+1;u++)
- choices.push(u);
- rightDropDown = $(Mustache.render(dropDownTpl,{choices:choices}));
- dotli.removeClass('hidden')
- .attr('title','Voir les pages '+(start)+' à '+(end))
- .removeAttr('onclick')
- .css('position','relative')
- .addClass('page-link').html(rightDropDown);
- pagination.append(dotli);
- }
- }
- pagination.append(li);
- }
- if(current!=0){
- var prev = $('<li class="page-item page-item-previous"><span class="page-link" ><span><i class="fas fa-angle-left"></i></span></span></li>');
- pagination.prepend(prev);
- prev.click(function(){
- pagination.find('li[data-value="'+(current-1)+'"]').trigger('click');
- });
- }
- if(current<r.pagination.pages-1){
- var next = $('<li class="page-item page-item-next"><span class="page-link" ><span><i class="fas fa-angle-right"></i></span></span></li>');
- pagination.append(next);
- next.click(function(){
- pagination.find('li[data-value="'+(current+1)+'"]').trigger('click');
- });
- }
-
- if(r.pagination.pages>1){
- pagination.find('.page-item:not(.hidden):first .page-link').css('border-radius','0.25rem 0 0 0.25rem');
- }else{
- pagination.find('.page-item:not(.hidden):first .page-link').css('border-radius','0.25rem 0.25rem 0.25rem 0.25rem');
- }
- $('.pagination-select span',pagination).click(function(){
- var selectedPage = (parseInt($(this).text())-1);
- pagination.find('li[data-value="'+selectedPage+'"]').trigger('click');
- });
- }
- }
- }
- if(preloader) preloader.remove();
- if(callback!=null)callback(r);
- },null,function(percent,type){
- if(progress) progress(percent,type);
- });
- });
- },
-
- filters: function (values){
- var obj = $(this);
- var box = obj.next('.filter-box');
- if(values){
-
- if(values.keyword && values.keyword!='')
- $('.filter-keyword',box).val(values.keyword);
- for(var key in values.advanced){
- var filter = values.advanced[key];
- filter_add($('.filter-add-button',box),filter);
- }
- return;
- }
- var formData = {
- keyword : $('.filter-keyword',box).val()
- };
- formData.advanced = [], formData.multiple = [], formData.custom = {};
- $('.filterRow:visible',box).each(function(i,row){
-
- var row = $(row);
- if(row.find('.filter-column').val()=='') return;
- var filter = {
- join : row.find('.filter-join').val(),
- column : row.find('.filter-column').val(),
- type : row.find('.filter-column option:selected').attr('data-filter-type'),
- operator : {},
- value : {}
- }
- if ($('.filter-value-block',row).length > 1) {
- $('.filter-value-block',row).each(function(j,block){
- var block = $(block);
- filter.operator[j] = block.find('.filter-operator').val();
- filter.value[j] = block.find('.filter-value').last().val();
- });
- formData.multiple.push(filter);
- } else {
- filter.operator = row.find('.filter-operator').val();
- values = row.find('.filter-value');
- if(values.length > 1){
- filter.value = [];
- for(var j=0; j<values.length; ++j){
- filter.value.push(values.eq(j).val());
- }
- values.eq(j).attr('data-custom') == 'true' ? formData.custom[filter.column] = filter : formData.advanced.push(filter);
- } else {
- filter.value = values.val();
- values.last().attr('data-custom') == 'true' ? formData.custom[filter.column] = filter : formData.advanced.push(filter);
- }
- }
- });
- return formData;
- },
- enter: function (option){
- return this.each(function() {
- var obj = $(this);
- obj.keydown(function(event){
- if(event.keyCode == 13){
- option();
- return false;
- }
- });
-
- });
- },
- sortable_table: function (option){
- if(option=='get'){
- var obj = $(this);
- var response = {};
- obj.find('thead th[data-sortable]').each(function(i,th){
- var th = $(th);
-
- if(th.attr('data-sort') && th.attr('data-sort')!=""){
- response = {
- sort : th.attr('data-sort'),
- sortable : th.attr('data-sortable')
- };
- }
- });
- return response;
- }
- return this.each(function() {
- var obj = $(this);
- obj.find('thead th[data-sortable]').click(function(){
- var th = $(this);
- var data = th.data();
- if(!data.sort || data.sort==''){
- data.sort = 'asc'
- }else if(data.sort == 'asc'){
- data.sort ='desc'
- }else{
- data.sort = '';
- }
- obj.find('thead th').removeClass('sort-asc').removeClass('sort-desc').removeAttr('data-sort');
- if(data.sort!='') th.addClass('sort-'+data.sort);
- th.attr('data-sort',data.sort);
- if(option.onSort) option.onSort();
- });
-
- });
- },
- autocomplete: function(o){
- return this.each(function() {
- var obj = $(this);
- if(o == 'off') return obj.typeahead('destroy');
- obj.attr('autocomplete','off');
- var option = obj.data();
- option = $.extend(option,o);
-
- obj.typeahead({
- items: (o.items) ? o.items : 5,
- minLength: o.suggest ? 0 : (o.minLength ? o.minLength : 2) ,
- fitToElement: false,
- autoSelect : false,
- selectOnBlur : false,
- displayText : function(item){
- return (o.skin) ? o.skin(item) : item.name || item;
- },
- source: function(keyword, response){
- if(o.onKeypress) o.onKeypress(obj);
- if(o.dynamicData) o.data = $.extend(o.data,o.dynamicData());
- $.action({
- action: option.action,
- keyword: obj.val(),
- data: o.data
- },function(r){
- if(r.rows != null)
- response(r.rows);
- });
- },
- highlighter: function(item){
- if(o.highlight) {
- return o.highlight(item)
- }
- else {
- var query = this.query.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&')
- return item.replace(new RegExp('('+query+')', 'ig'), function($1, match){
- return '<strong>'+match+'</strong>';
- });
- }
- },
- matcher: function(r){
- if(obj.val() == r.name)
- if(o.onClick)
- o.onClick(r,obj);
- return '<div>'+r.name+'</div>';
- },
- afterSelect: function(item) {
- obj.data('selected',true);
- if(o.onClick) o.onClick(item,obj);
- obj.trigger("change");
- }
- }).blur(function(){
- if(o.onBlur) o.onBlur(obj);
- });
- if(o.suggest){
- obj.on("click", function () {
- ev = $.Event("keydown");
- ev.keyCode = ev.which = 40;
- $(this).trigger(ev);
- return true
- });
- }
- obj.data('typeahead').next = function (event) {
- var active = this.$menu.find('.active').removeClass('active');
- var next = active.next();
- if (!next.length) {
- next = $(this.$menu.find($(this.options.item || this.theme.item).prop('tagName'))[0]);
- }
- while (next.hasClass('divider') || next.hasClass('dropdown-header')) {
- next = next.next();
- }
- next.addClass('active');
- var newVal = this.updater(next.data('value'));
- this.$element.val(newVal.name || newVal);
- };
- obj.data('typeahead').prev = function (event) {
- var active = this.$menu.find('.active').removeClass('active');
- var prev = active.prev();
- if (!prev.length){
- prev = this.$menu.find($(this.options.item || this.theme.item).prop('tagName')).last();
- }
- while (prev.hasClass('divider') || prev.hasClass('dropdown-header')) {
- prev = prev.prev();
- }
- prev.addClass('active');
- var newVal = this.updater(prev.data('value'));
- if (this.changeInputOnMove) this.$element.val(newVal.name || newVal);
- };
- });
- },
- location: function (options){
- return this.each(function() {
- try{
- //var options = $.extend({},options);
- var obj = $(this);
- obj.attr('autocomplete','off');
- var data = $('#algolia').data();
- var placesAutocomplete = places({
- appId: data.api,
- apiKey: data.key,
- container: obj.get(0)
- });
- placesAutocomplete.on('change', function(e) {
- var m = /[0-9]*/m.exec(e.suggestion.name)
- var infos = {
- latitude: e.suggestion.latlng.lat,
- longitude : e.suggestion.lng,
- types : e.suggestion.type,
- number : '',
- street : e.suggestion.name,
- city : e.suggestion.city,
- country : e.suggestion.country,
- code : e.suggestion.postcode,
- picture : '',
- map : ''
- };
- if(m && m.length > 0 ) infos.number = m[0] ;
- infos.address = (infos.street && infos.street.length && infos.number && infos.number.length) ? infos.number+' '+infos.street : (infos.street ? infos.street : '');
- if(options.select) options.select(infos);
- });
- }catch(e){
- console.warn('Composant Location en erreur, désactivé :'+e);
- }
- });
- },
- date: function (options){
- return this.each(function() {
- var obj = $(this);
- obj.on('paste', function(e){
- is_valid_date(e.originalEvent.clipboardData.getData('Text')) ? obj.val("") : e.preventDefault();
- });
- obj.datepicker({
- dateFormat: options.dateFormat,
- dayNames: ["Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"],
- dayNamesMin: ["Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa"],
- dayNamesShort: ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"],
- monthNames: ["Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Aout","Septembre","Octobre","Novembre","Décembre"],
- monthNamesShort: ["Jan","Fév","Mars","Avr","Mai","Juin","Juil","Aout","Sept","Oct","Nov","Déc"],
- firstDay: 1,
- minDate: options.beginDate,
- maxDate: options.endDate,
- changeMonth: true,
- yearRange: "-30:+30",
- changeYear: true,
- onSelect: function(dateText, inst) {
- obj.trigger("blur");
- }
- }).keypress(function(event){
- var length = obj.val().length;
- if(length == 2 || length == 5) obj.val(obj.val()+'/');
- }).blur(function(event){
- obj.removeClass('border border-danger');
- if(obj.val()=='') return;
- var segments = obj.val().split('/');
- if(segments.length!=3) return;
- if(segments[0] > 31 || segments[1] > 12) obj.addClass('border border-danger');
- }).attr('maxlength','10');
-
- obj.attr('placeholder',options.placeholder);
- obj.attr('pattern',"^(\\d{2}(?:\\d{2})?)\/(\d{2})\/(\\d{2}(?:\\d{2})?)$");
- obj.attr('title','Format '+options.dateFormat);
- });
- },
- hour: function (options){
- return this.each(function() {
- var obj = $(this);
- obj.on('paste', function(e){
- is_valid_hour(e.originalEvent.clipboardData.getData('Text')) ? obj.val("") : e.preventDefault();
- });
- obj.timepicker({
- scrollDefault: 'now',
- timeFormat: options.timeFormat,
- step: options.step,
- onSelect: function(timeText, inst) {
- obj.trigger("blur");
- }
- }).keypress(function(e) {
- if(!e.key.match(/[0-9:]/)) e.preventDefault();
- if(obj.val().length == 2) obj.val(obj.val()+':');
- }).blur(function(event){
- obj.removeClass('border border-danger')
- if(obj.val()=='') return;
- var segments = obj.val().split(':');
- if(segments.length!=2) return;
- if(segments[0] > 23 || segments[1] > 59) obj.addClass('border border-danger');
- }).attr('maxlength','5');
- obj.attr("placeholder",options.placeholder);
- obj.attr('pattern',"(\\d{2})\\:(\\d{2})");
- obj.attr('title',"Format hh:mm");
- });
- },
- raiseNumber: function(from,to) {
- return this.each(function(){
- var obj = $(this);
- obj.text(from);
- var interval = 800 / (to - from);
- var interval = setInterval(function(){
- var number = parseFloat(obj.text());
- if(number>=to) {
- clearInterval(interval);
- return;
- }
- obj.text(number+1);
- },interval);
- });
- }
- });
|