12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771 |
- var isProcessing;
- //Permet aux composant de mutualiser leurs appels
- var componentQueue = {};
- $(document).ready(function(){
- if($.urlParam('title')!=null){
- window.parent.document.title = decodeURI($.urlParam('title'));
- }
- var page = $.page();
- page = page == '' ? 'index' : page;
- var init = 'init_'+page;
- init = init.replace(/[^a-z_0-9]/g,'_');
- init_components();
- if($.urlParam('module')==null){
- if(window[init]!=null) window[init]($.urlParam());
- } else {
- var mod = $.urlParam('module').replace(/[^a-z_0-9]/g,'_');
- var init = 'init_plugin_'+mod;
- if(window[init]!=null) window[init]($.urlParam());
- }
- //SHOW HTTP ERROR/NOTICE
- if ($.urlParam('error') != null) {
- $.message('error', decodeURIComponent($.urlParam('error')), 0);
- $.urlParam('error', false);
- }
- if ($.urlParam('info') != null) {
- $.message('info', decodeURIComponent($.urlParam('info')));
- $.urlParam('info', false);
- }
- if ($.urlParam('success') != null) {
- $.message('success', decodeURIComponent($.urlParam('success')));
- $.urlParam('success', false);
- }
- //Icône menu mobile
- $('#mainMenu > button').on('click', function(e){
- $('.menu').toggleClass('open');
- });
- $('.navbar-toggler').on('click', function(e){
- if($(e.target).closest('#mainMenu').length) return;
- $('#navbarCollapse').collapse('hide');
- $('.menu').removeClass('open');
- });
- //Positionnement du loginHeader
- if($(document).width() <= 767) $('#mainMenu .navbar-brand').after($('#loginHeader').detach());
- });
- //Changement positionnement loginHeader
- //au redimensionnement de la fenêtre
- $(window).resize(function(event) {
- if(is_phone()) return;
- var width = $(document).width();
- var loginForm = $('#loginHeader').detach();
- if(width>767) $('#navbarCollapse').append(loginForm);
- if(width<=767) $('#mainMenu .navbar-brand').after(loginForm);
- });
- /* COMPOSANT */
- function init_components(selector){
- var selected = selector ? $('[data-type]',selector) : '[data-type]';
- $(selected).each(function(i,input){
- var input = $(input);
- switch($(input).attr('data-type')){
- /**
- * data-format : Supporte les formats dd/mm/yyyy ou yyyy/mm/dd avec séparateur "/" ou "-"
- * data-begin : date de début de sélection par rapport à aujourd'hui(peut être en nb de jour, en objet Date ou en string de type dateFormat ou en date relative [+1m +7d]==>Début à 1 mois et 7 jours)
- * data-end : date de début de sélection par rapport à aujourd'hui(peut être en nb de jour, en objet Date ou en string de type dateFormat ou en date relative [+1m +7d]==>Début à 1 mois et 7 jours)
- * data-workdays : si attribut est présent, seuls les jours ouvrés sont sélectionnables
- */
- case 'date':
- //Les séparateurs doivent être similaires entre les éléments de la chaîne
- var dateFormatRegex = /^(dd|yy)([\/|-])(mm)\2(dd|yy)$/;
- var dateFormat = input.attr('data-format') != undefined && input.attr('data-format').match(dateFormatRegex) ? input.attr('data-format').match(dateFormatRegex)[0] : "dd/mm/yy";
- var begin = input.attr('data-begin');
- begin = (begin != undefined && (begin.match(/-?\d+/) || begin.match(/^(\d{2}(?:\d{2})?)\/(\d{2})\/(\d{2}(?:\d{2})?)$/))) ? begin : null ;
- var end = input.attr('data-end');
- end = (end != undefined && (end.match(/-?\d+/) || end.match(/^(\d{2}(?:\d{2})?)[-|\/](\d{2})[-|\/](\d{2}(?:\d{2})?)$/))) ? end : null ;
- input.date({
- placeholder: input.attr('placeholder') != undefined ? input.attr('placeholder') : "jj/mm/aaaa",
- dateFormat: dateFormat,
- beginDate: begin,
- endDate: end,
- workdays: input.attr('data-workdays') != null
- });
- break;
- /**
- * data-format : Supporte les formats dd/mm/yyyy ou yyyy/mm/dd avec séparateur "/" ou "-"
- * data-step : L'intervalle entre 2 valeurs en minutes
- */
- case 'hour':
- var timeFormatRegex = /^(H):(i)$/;
- var timeFormat = input.attr('data-format') != undefined && input.attr('data-format').match(timeFormatRegex) ? input.attr('data-format').match(timeFormatRegex)[0] : "H:i";
- var step = input.attr('data-step');
- input.hour({
- placeholder: input.attr('placeholder') != undefined ? input.attr('placeholder') : "hh:mm",
- timeFormat: timeFormat,
- step: is_numeric(step) && step>0 ? step : 1
- });
- break;
- case 'color':
- $(input).colorInput();
- break;
- case 'image':
- if(input.closest('.type-image-bloc').length!=0) break;
- input.attr('type', 'file');
- input.wrap( "<div class='type-image-bloc'></div>");
- var src = ($(input).attr('value')!='') ? $(input).attr('value') : 'img/default-image.png';
- src += src.indexOf('?')!=-1 ? '&' : '?';
- src += 't='+(Math.random()*1000);
- var thumbnail = $('<img src="'+src+'" >');
- var deleteBtn = !input.attr('data-delete') ? '' : '<div class="btn btn-delete-img noPrint" onclick="'+input.attr('data-delete')+'"><i class="fas fa-times"></i></div>';
- input.before(thumbnail);
- if(thumbnail.attr('src').indexOf('default-') === -1) thumbnail.before(deleteBtn);
- input.addClass('noPrint');
- input.change(function(){
- var reader = new FileReader();
- reader.onload = function (e) {
- thumbnail.attr('src', e.target.result);
- thumbnail.before(deleteBtn);
- }
- reader.readAsDataURL(input.get(0).files[0]);
- });
- break;
- //Selection de tag liés a un dictionnary
- case 'tag-list':
- var container;
- var picker;
- var pickerLi;
- if(!input.data("data-component")){
- var placeholder = input.attr("placeholder") != undefined ? input.attr("placeholder") : "";
- container = $('<div class="'+input.attr('class')+' data-type-tag-list"><ul><li class="tag-picker-li"><input placeholder="'+placeholder+'" type="text"></li></ul></div>');
- input.before(container);
- input.data("data-component", container);
- if(input.attr("required")) container.attr("required","");
- if(input.attr("disabled")) container.attr("disabled","");
- if(input.attr("readonly")) container.attr("readonly","");
- } else {
- container = input.data("data-component");
- }
- picker = container.find('input:eq(0)');
- pickerLi = container.find('ul li.tag-picker-li');
- if(container.attr('disabled') || container.attr('readonly'))
- pickerLi.find('input').attr('readonly','');
- container.find('.tag-picker-tag').remove();
- pickerLi.removeClass('hidden');
- var pickerFunctions = {
- //Récuperation des valeurs sélectionnées (objet et id) en fonction des tags visuels présents
- getValues : function( container){
- var tags = container.find('ul .tag-picker-tag');
- var values = {object:[],id:[]};
- tags.each(function(i,element){
- if($(element).attr('data-id') == '') return;
- var object = $(element).data();
- values['object'].push(object);
- values['id'].push(object.id);
- });
- return values;
- },
- //Ajout d'un tag visuel et mise à jour de l'input brut en fonction de l'objet fournis
- addTag : function( container,tag){
- pickerLi = container.find('ul li.tag-picker-li');
- if( container.find('li[data-id="'+tag.id+'"]').length>0) return;
- var closeBtn = container.attr('disabled') || container.attr('readonly') ? '' : '<i class="fa fa-times"></i>';
- var tag = $('<li class="tag-picker-tag" data-slug="'+tag.slug+'" data-id="'+tag.id+'"><div>'+tag.name+closeBtn+'</div></li>');
- pickerLi.before(tag);
- var values = pickerFunctions.getValues( container);
- input.val(values['id'].join(','));
- input.data('values',values['object']);
- if((values['id'].length) == 1 && input.attr('data-multiple') == null){
- pickerLi.addClass('hidden');
- }else{
- pickerLi.removeClass('hidden');
- }
- tag.find('i').click(function(){
- if(container.attr('disabled') || container.attr('readonly')) return;
- $(this).closest('.tag-picker-tag').remove();
- var values = pickerFunctions.getValues( container);
- input.val(values['id'].join(','));
- input.data('values',values['object']);
- if((values['id'].length-1) ==1 && input.attr('data-multiple') == null){
- pickerLi.addClass('hidden');
- }else{
- pickerLi.removeClass('hidden');
- }
- });
- }
- }
- //Gestion des champs déja remplis au chargement de la page
- if(input.val() !=''){
- var id = input.val();
- container.find('ul').append('<li class="tag-picker-loader"><i class="fas fa-spinner fa-pulse"></i> Chargement</li>');
- picker.addClass('hidden');
- $.action({
- action : 'tag_list_by_id',
- id : id
- },function(r){
- container.find('.tag-picker-loader').remove();
- picker.removeClass('hidden');
- for(var key in r.tags)
- pickerFunctions.addTag( container,r.tags[key]);
- });
- }
- //Sélectionne l'input d'auto-completion ou que l'on clique dans le composant
- container.find('ul').click(function(e){
- picker.focus();
- e.stopPropagation();
- });
- //Selectionne l'item dropdown actif lors de l'appuis sur entré
- picker.off('keyup').keyup(function(e){
- //si appui sur Entrée, virgule ou espace on valide le tag
- if((e.key!='Enter' && e.key!=' ' && e.key!=',') || input.is('[readonly]') || input.is('[disabled]')) return;
- var active = $('.tag-picker-li .dropdown-menu .active');
- if(active.length==0){
- //Si aucun clic sur un tag existant et que la saisie libre est desactivée on quitte
- if(input.data('force')){
- picker.val('');
- return;
- }
- //si la saisie libre est activée on ajoute le tag au dictionnaire
- $.action({
- action : 'tag_list_autocreate',
- slug : input.attr('data-slug'),
- label : picker.val()
- },function(newTag){
- picker.val('');
- selected.label = picker.val();
- pickerFunctions.addTag(container,newTag);
- input.trigger('click').trigger('change');
- });
-
- }else{
- active.trigger('click');
- }
-
- });
- //aucompletion sur le nom des tags
- picker.autocomplete({
- action : 'tag_list_autocomplete',
- suggest : !input.is('[readonly]') && !input.is('[disabled]'),
- items : input.attr('data-items'),
- data : {
- parent : input.attr('data-slug')
- },
- skin : function(item){
- var html = '';
- var re = new RegExp(picker.val(),"gi");
- name = item.name.replace(re, function (x) {
- return '<strong>'+x+'</strong>';
- });
- html += '<div class="tag-infos"><span>'+name+'</span>';
- html += '<div class="clear"></div>';
- return html;
- },
- highlight : function(item){
- return item;
- },
- onClick : function(selected,element){
- picker.val('');
- selected.label = selected.name;
- pickerFunctions.addTag(container,selected);
- input.trigger('click').trigger('change');
- },
- onBlur : function(selected){
- if(input.attr('data-force')!='false' && input.val() == '') picker.val('');
- }
- });
- break;
- //composant permettant les listes sous
- //form de dropdown avec icones et couleurs
- case 'dropdown-select':
- if(!input.is(':visible')) return;
- var container;
- if(!input.data("data-component")){
- container = $('<div class="'+input.attr('class')+' btn-group data-type-dropdown-select"> \
- <button '+(input.attr('title')!=null?'title="'+input.attr('title')+'"':'')+' type="button" class="btn btn-small btn-secondary border-0 dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></button> \
- <div class="dropdown-menu w-100 p-0 text-center"></div> \
- </div>');
- input.before(container);
- input.data("data-component", container);
- if(input.attr("required")) container.attr("required","");
- var html = '';
- input.find('option').each(function(i,element){
- var option = $(element);
- var classes = option.attr('class') ? option.attr('class') : '';
- var icon = option.attr("data-icon") ? '<i class="'+option.attr("data-icon")+'"></i> ': '';
- var title = option.attr("data-title") ? 'title="'+option.attr("data-title")+'"': '';
- html += '<a class="dropdown-item pointer '+classes+'" '+title+' data-value="'+option.val()+'" '+(option.attr("style")!=null?'style="'+option.attr("style")+'"':'')+'>'+icon+option.html()+'</a>';
- });
- container.find('.dropdown-menu').append(html);
- $('.dropdown-menu a',container).click(function(){
- if(input.attr("readonly") == 'readonly') return;
- var item = $(this);
- $('.dropdown-menu a',container).removeClass('active');
- //Utilisation background-color pour fonctionner sous FF
- container.find('.dropdown-toggle').html(item.html()).css('background-color',item.css('background-color'));
- item.addClass('active');
- input.val(item.attr('data-value')).trigger('change');
- });
- } else {
- container = input.data("data-component");
- }
- input.addClass('hidden');
- var state = input.attr('data-value') != null ? input.attr('data-value') : input.val();
- if(state == '') return;
- var item = $('.dropdown-menu a[data-value="'+state+'"]', container);
- //Utilisation background-color pour fonctionner sous FF
- container.find('.dropdown-toggle').html(item.html()).css('background-color',item.css('background-color'));
- item.addClass('active');
- input.val(item.attr('data-value')).trigger('change');
- break;
- case 'user':
- var userContainer;
- var userPicker;
- var pickerLi;
- if(!input.data("data-component")){
- userContainer = $('<div class="'+input.attr('class')+' data-type-user"><ul><li class="user-picker-li"><input type="text" '+(input.attr('placeholder')!=null?'placeholder="'+input.attr('placeholder')+'"':'')+'></li></ul></div>');
- input.before(userContainer);
- input.data("data-component", userContainer);
- if(input.attr("required")) userContainer.attr("required","");
- if(input.attr("disabled")) userContainer.attr("disabled","");
- if(input.attr("readonly")) userContainer.attr("readonly","");
- } else {
- userContainer = input.data("data-component");
- }
- userPicker = userContainer.find('input:eq(0)');
- pickerLi = userContainer.find('ul li.user-picker-li');
- if(userContainer.attr('disabled') || userContainer.attr('readonly'))
- pickerLi.find('input').attr('readonly','');
- userContainer.find('.user-picker-tag').remove();
- pickerLi.removeClass('hidden');
- var pickerFunctions = {
- //Récuperation des valeurs sélectionnées (objet et uid) en fonction des tags visuels présents
- getValues : function(userContainer){
- var tags = userContainer.find('ul .user-picker-tag');
- var values = {object:[],uid:[]};
- tags.each(function(i,element){
- if($(element).attr('data-uid') == '') return;
- var object = $(element).data();
- values['object'].push(object);
- values['uid'].push(object.uid);
- });
- return values;
- },
- //Ajout d'un tag visuel et mise à jour de l'input brut en fonction de l'objet user fournis
- addTag : function(userContainer,user,input){
- pickerLi = userContainer.find('ul li.user-picker-li');
- if(userContainer.find('li[data-uid="'+user.uid+'"]').length>0) return;
- var closeBtn = userContainer.attr('disabled') || userContainer.attr('readonly') ? '' : '<i class="fa fa-times"></i>';
- var tag = $('<li class="user-picker-tag" data-entity="'+user.type+'" data-fullname="'+user.fullname+'" data-uid="'+user.uid+'"><div title="'+(user.type=='rank'?'Rang':'Utilisateur')+'">'+user.name+closeBtn+'</div></li>');
- pickerLi.before(tag);
- var values = pickerFunctions.getValues(userContainer);
- input.val(values['uid'].join(','));
- input.data('values',values['object']);
- if((values['uid'].length) == 1 && input.attr('data-multiple') == null){
- pickerLi.addClass('hidden');
- }else{
- pickerLi.removeClass('hidden');
- }
- tag.find('i').click(function(){
- if(userContainer.attr('disabled') || userContainer.attr('readonly')) return;
- $(this).closest('.user-picker-tag').remove();
- var values = pickerFunctions.getValues(userContainer);
- input.val(values['uid'].join(','));
- input.data('values',values['object']);
- pickerLi = userContainer.find('ul li.user-picker-li');
- if((values['uid'].length-1) ==1 && input.attr('data-multiple') == null){
- pickerLi.addClass('hidden');
- }else{
- pickerLi.removeClass('hidden');
- }
- });
- if(userContainer.find('ul li.user-picker-tag'))
- userContainer.find('ul li.user-picker-li input').removeAttr('placeholder');
- }
- }
- //Gestion des champs déja remplis au chargement de la page
- if(input.val() !=''){
- var uid = input.val();
- if(!window.componentQueue.user) window.componentQueue.user = {timeout : null,components : [],uids :{} };
- clearTimeout(window.componentQueue.user.timeout);
- var uids = uid.split(',');
- for(var k in uids)
- window.componentQueue.user.uids[uids[k]] = 1;
- window.componentQueue.user.components.push({
- input : input,
- picker : userPicker,
- container : userContainer,
- values : uids
- });
- userContainer.find('ul').append('<li class="user-picker-loader"><i class="fas fa-spinner fa-pulse"></i> Chargement</li>');
- userPicker.addClass('hidden');
- window.componentQueue.user.timeout = setTimeout(function(){
- $.action({
- action : 'user_by_uid',
- uids : Object.keys(window.componentQueue.user.uids)
- },function(r){
- for(var key in window.componentQueue.user.components){
- var component = window.componentQueue.user.components[key];
- component.container.find('.user-picker-loader').remove();
- component.picker.removeClass('hidden');
- input = window.componentQueue.user.components[key].input;
- for(var i in component.values){
- var value = component.values[i];
- if(!r.users[value]) continue;
- pickerFunctions.addTag(component.container,r.users[value],input);
- }
- }
- delete window.componentQueue.user;
- });
- },50);
- /*var login = input.val();
- userContainer.find('ul').append('<li class="user-picker-loader"><i class="fas fa-spinner fa-pulse"></i> Chargement</li>');
- userPicker.addClass('hidden');
- $.action({
- action : 'user_by_uid',
- login : login
- },function(r){
- userContainer.find('.user-picker-loader').remove();
- userPicker.removeClass('hidden');
- for(var key in r.users)
- pickerFunctions.addTag(userContainer,r.users[key]);
- });*/
- }
- //Sélectionne l'input d'auto-completion ou que l'on clique dans le composant
- userContainer.find('ul').click(function(e){
- if(input.attr("readonly") == "readonly") return;
- userPicker.focus();
- e.stopPropagation();
- });
- //Selectionne l'item dropdown actif lors de l'appui sur entrée
- userPicker.keyup(function(e){
- if(e.keyCode!=13 || input.is('[readonly]') || input.is('[disabled]')) return;
- if(input.attr("readonly") == "readonly") return;
- var active = $('.user-picker-li .dropdown-menu .active');
- if(active.length==0) return;
- active.trigger('click').trigger('change');
- });
- var types = ['user'];
- if(input.data('types') && input.data('types')!='')
- types = input.data('types').split(',');
- //aucompletion sur le nom des users / rangs
- userPicker.autocomplete({
- action : 'user_autocomplete',
- data : {
- types : types
- },
- skin : function(item){
- var html = '';
- var re = new RegExp(escape_regex_chars(userPicker.val()),"gi");
- name = item.name.replace(re, function (x) {
- return '<strong>'+x+'</strong>';
- });
- if(item.type=='user'){
- if(item.avatar) html += '<div class="user-logo"><img src="'+item.avatar+'" class="avatar-mini avatar-rounded"></div>';
- html += '<div class="user-infos"><span>'+name+'</span> <small class="text-muted">- Utilisateur (@'+item.id+')</small>';
- html += item.function ? '<br/><small>'+item.function+'</small></div>' : '</div>';
- html += '<div class="clear"></div>';
- }else{
- html += '<div class="rank-logo"><i class="far fa-address-card"></i></div>';
- html += '<div class="rank-infos"><span>'+name+'</span> <small class="text-muted">- Rang</small>';
- html += item.description ? '<br/><small>'+item.description+'</small></div>' : '</div>';
- html += '<div class="clear"></div>';
- }
- return html;
- },
- highlight : function(item){
- return item;
- },
- onClick : function(selected,element){
- userPicker.val('');
- pickerFunctions.addTag(userContainer,selected,input);
- input.trigger('click').trigger('change');
- },
- onBlur : function(selected){
- if(input.attr('data-force')!='false' && input.val() == '') userPicker.val('');
- }
- });
- break;
- /**
- * data-labels : tableau des libellés entre double quotes eg : ["Libellé 1","Libellé 2"]
- * data-values : taleau des valeurs eg : [12,13]
- * data-colors : taleau des couleurs entre double quotes eg : ["#cecece","#222222"]
- */
- case 'doughnut':
- var data = input.data();
- var myChart = new Chart(input.get(0).getContext('2d'), {
- type: 'doughnut',
- data: {
- labels: data.labels,
- datasets: [{
- data: data.values,
- backgroundColor: data.colors
- }]
- },
- options: {
- cutoutPercentage:80
- }
- });
- break;
- /**
- * data-labels : tableau des libellés entre double quotes eg : ["Libellé1","Libellé 2"]
- * data-values : taleau des valeurs eg : [12,13]
- * data-colors : taleau des couleurs entre double quotes eg : ["#cecece","#222222"]
- */
- case 'bar':
- var data = input.data();
- var myChart = new Chart(input.get(0).getContext('2d'), {
- type: 'bar',
- data: {
- labels: data.labels,
- datasets: [{
- label : input.html(),
- data: data.values,
- backgroundColor: data.colors
- }]
- },
- options: {
- scales: {
- yAxes: [{
- ticks: {
- beginAtZero:true
- }
- }]
- },
- legend: {
- display: false
- }
- }
- });
- break;
- /**
- * data-labels : tableau des libellés entre double quotes eg : ["Libellé1","Libellé 2"]
- * data-values : taleau des valeurs eg : [12,13]
- * data-color : couleurs eg : #cecece
- */
- case 'line':
- var data = input.data();
- var myChart = new Chart(input.get(0).getContext('2d'), {
- type: 'line',
- data: {
- labels: data.labels,
- datasets: [{
- label : input.html(),
- data: data.values,
- borderColor: [data.color]
- }]
- },
- options: {
- scales: {
- yAxes: [{
- ticks: {
- beginAtZero:true
- }
- }]
- }
- }
- });
- break;
- /**
- * data-filter-country : filtre par pays à rechercher séparés par virgule (format ISO 3 numériques, ex : FRA)
- * data-filter-items : nb de résultats à retourner
- * data-filter-language : langue dans laquelle retourner les résultats
- *
- * data-select-callback : fonction de callback appelée lors de la sélection d'un élément
- *
- * data-filter-geocode : retourne les infos complémentaires de l'élément sélectionné (latitude, longitude,etc...)
- * data-geocode-callback : fonction de callback appelée pour traiter les infos retournées via geocode
- */
- case 'location':
- input.location({
- items: input.attr('data-filter-items'),
- language: input.attr('data-filter-language'),
- country: input.attr('data-filter-country'),
- geocode: input.attr('data-filter-geocode') != null ? true : false,
- select: function(location){
- if(input.attr('data-select-callback')!=null && input.attr('data-select-callback').length) {
- var select = input.attr('data-select-callback').replace(/[^a-z0-9]/i,'_');
- if(window[select] !=null) window[select](location);
- }
- },
- geocode: function(location){
- $.action({
- action: 'location_detail_search',
- locationId: location.locationId
- }, function(r){
- if(input.attr('data-geocode-callback')!=null && input.attr('data-geocode-callback').length) {
- var geocode = input.attr('data-geocode-callback').replace(/[^a-z0-9]/i,'_');
- if(window[geocode] !=null) window[geocode](r);
- }
- });
- }
- });
- var data = input.data();
- input.removeData();
- input.data({
- type : data.type,
- country : data.country,
- zip : data.zip,
- city : data.city,
- complement : data.complement,
- street : data.street
- });
- break;
- /**
- * data-depth : nb de profondeur de liste (ex: 2, affichera 2 select au maximum), 1 par défaut
- * data-slug : le slug de la liste mère à afficher, listes primaires par défaut
- * data-value : la valeur de l'entité à récup en base
- * data-disable-label : cache le label de sous-liste si mentionné
- * data-hierarchy : si mentionné à false, ne récupère pas
- * data-parent-id : l'id de la liste parente associée
- */
- case 'dictionnary':
- var slug = input.attr('data-slug') ? input.attr('data-slug') : "";
- var parentId = input.attr('data-parent-id') && input.attr('data-parent-id').length ? input.attr('data-parent-id') : "";
- if (!slug.match(/^[a-z\d\-_]+$/i) && parentId == '') return;
- $.action({
- action : 'load_dictionnary_component',
- slug: slug,
- parentId : parentId,
- hierarchy : input.attr('data-hierarchy') == 'false' ? 0 : 1,
- value: input.attr('data-value')
- },function(r){
- var children = r.content.childs ? r.content.childs : r.content;
- input.attr('onchange', 'get_sub_dictionnary(this, "'+input.attr('name')+'",'+1+');');
- input.html('');
- input.append('<option value=""> - </option>');
- $.each(children, function (index, value){
- if (value.selected) {
- input.append('<option value="'+value.id+'" data-parent="'+value.parent+'" data-sublabel="'+value.sublistlabel+'" selected>'+value.label+'</option>');
- get_selected_values(input, value);
- }else{
- input.append('<option value="'+value.id+'" data-parent="'+value.parent+'" data-sublabel="'+value.sublistlabel+'">'+value.label+'</option>');
- }
- });
- });
- break;
- /**
- * data-label : le label affiché dans la zone
- * data-delete : méthode de suppression de doc de l'entité
- * data-save : méthode de sauvegarde de doc de l'entité (si mentionné, save automatique)
- * data-readonly: Empeche l'ajout/suppression de documents
- * data-allowed : les extensions de fichier acceptées
- */
- case 'dropzone':
- if(input.find('form').length != 0 || input.find('ul>li').length) break;
- if(!input.attr('data-action')) input.attr('data-action','action.php?action=upload_temporary_file');
- var readonly = input.attr('data-readonly') == "true" ? true : false;
- if(!input.get(0).hasAttribute('id')) input.attr('id',generate_uuid(10));
- var customTpl = input.find('> *:not(:visible)');
- var customActions = '';
- if(customTpl && customTpl.length){
- $.each(customTpl, function(i, action){
- if(i>2) return;
- var valCalc = readonly ? i*28+3 : i*28+25;
- customActions += $(action).removeClass('hidden').css('right', valCalc).get(0).outerHTML;
- });
- }
- var preview = '<li data-path="{{path}}" data-ext="{{ext}}" data-url="{{url}}" data-name="{{name}}" data-last-modification="{{lastModification}}">'+
- '<a {{#url}}href="{{url}}"{{/url}} target="_blank" title="{{name}}" class="text-decoration-none">';
- preview += input.get(0).hasAttribute('data-preview') ? '<img style="margin: 0 5px;float: left;max-height:100px;max-width:80px;" src="{{url}}"/>' : '<i class="{{icon}} ml-1"></i>';
- preview += ' <span>{{name}}{{lastModification}}</span></a>'+customActions+' <i class="fas fa-times pointer '+(input.attr('data-delete')?'':'hidden')+'" onclick="{{#temporary}}dropzone_delete_file(this);{{/temporary}}{{^temporary}}'+input.attr('data-delete')+'(this){{/temporary}}"></i><div class="clear"></div></li>';
- var valueFiles = input.html()!='' && is_json_string(input.text()) ? JSON.parse(input.text()) : [];
- input.html('');
- var allowed = input.attr('data-allowed');
- if(allowed) allowed = allowed.split(',');
- var save = input.attr('data-save');
- var size = input.attr('data-max-size');
- var maxFile = input.attr('data-max-files');
- maxFile = 100; //maxFile=='' || ! maxFile ? 0 : maxFile;
- input.upload({
- allowed : allowed,
- size : size == '' ? 0 : size,
- readonly: readonly,
- addData: function(){
- return {index: input.attr('id')};
- },
- start: function(){
- if(maxFile!=0 && $('li:visible',files).length >=maxFile ) return -1;
- preload.removeClass('hidden');
- },
- success: function(response){
- if(response.error){
- preload.addClass('hidden');
- $.message('error', response.error, 0);
- return;
- }
- if(response.previews.length && response.previews[0].name) {
- var inputTemp = $('#'+input.attr('id')+'_temporary');
- var currVal = inputTemp.val().length ? JSON.parse(inputTemp.val()) : [];
- for(var i in response.previews){
- files.append(Mustache.render(preview,response.previews[i]));
- currVal.push(response.previews[i]);
- }
- inputTemp.val(JSON.stringify(currVal));
- if(save)
- window[save](response.previews);
- }
- preload.addClass('hidden');
- },
- complete: function(){
- preload.addClass('hidden');
- }
- });
- var preload = $('<div class="preload progress-bar progress-bar-striped progress-bar-animated hidden"></div>');
- input.append(preload);
- var files = $('<ul></ul>');
- input.append(files);
- var filesValues = $('<input type="hidden" name="'+input.attr('id')+'_temporary" id="'+input.attr('id')+'_temporary">');
- input.append(filesValues);
- for(var i in valueFiles) {
- files.append(Mustache.render(preview,valueFiles[i]));
- if(readonly) files.find('li > i.fa-times').remove();
- }
- if(!valueFiles.length && readonly)
- input.append('<div>Aucun document</div>');
- break;
- /**
- * data-simple : Si "true" alors interface avec moins de boutons
- * data-minimal: Si présent alors affichage simple en mode input inline
- */
- case 'wysiwyg':
- var buttons = [
- ['strong','em','underline','del'],
- ['foreColor', 'backColor'],
- ['fontfamily'],
- ['fontsize'],
- ['undo', 'redo'], // Only supported in Blink browsers
- ['formatting'],
- ['superscript', 'subscript'],
- ['link'],
- ['insertImage'],
- ['table'],
- ['justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull'],
- ['unorderedList', 'orderedList'],
- ['horizontalRule'],
- ['removeformat'],
- ['fullscreen'],
- ['viewHTML']
- ]
- if(input.attr('data-simple')!=null || input.attr('data-simple') == 'true'){
- buttons = [
- ['strong','em','underline','del'],
- ['foreColor', 'backColor'],
- ['undo', 'redo'], // Only supported in Blink browsers
- ['formatting'],
- ['link'],
- ['unorderedList', 'orderedList'],
- ['insertImage']
- ]
- }
- if(input.attr('data-buttons')!=null && input.attr('data-buttons')!=''){
- buttons = [ input.attr('data-buttons').split(',') ];
- }
- var defaultOptions = {
- btns: buttons,
- lang: 'fr',
- autogrow: input.attr('data-minimal') == null,
- semantic: false,
- plugins : {}
- };
- var data = input.data();
-
- defaultOptions.tagsToRemove= ['script', 'link'];
- var scriptAllow = input.get(0).hasAttribute('data-script-allow');
- if(scriptAllow){
- defaultOptions.tagsToRemove= [];
- }
- // gestion des mentions
- defaultOptions.plugins.mention = {keys : {}};
- if(input.attr('data-mention-user') == 'true'){
- //mention @
- defaultOptions.plugins.mention.keys['@'] = {
- load : function(data){
- data.event.preventDefault();
- document.execCommand('insertHTML', false, '<b class="mention-user-picker-container">@<input type="text" data-type="user" class="mention-user-picker d-inline-block" value=""></b>');
-
- var inputContainer = $('.mention-user-picker-container');
-
- init_components(inputContainer);
- var picker = $('.mention-user-picker-container input');
-
- picker.focus();
- var timeout = null;
- picker.click(function(){
- clearTimeout(timeout);
- var value = $(this).val();
- inputContainer.remove();
- data.editor.focus();
- data.textarea.trumbowyg('restoreRange');
- document.execCommand('insertHTML', false, '<span class="data-mention-user" data-mention-type="user" data-mention-value="'+value+'">@'+value+'</span> ');
- data.editor.trigger('keyup');
- }).blur(function(){
- //on supprime le composant si blur sans valeur (attente de 200 ms car le blur est trigger avant le click)
- timeout = setTimeout(function(){
- inputContainer.remove();
- data.editor.trigger('keyup');
- },200);
- });
- picker.keydown(function(e){
- var code = e.keyCode || e.which;
- //Si appuis sur espace ça casse l'autocompletion
- if(code == 32){
- e.preventDefault();
- var value = picker.val();
- $('.mention-user-picker-container').remove();
- data.editor.focus();
- data.textarea.trumbowyg('restoreRange');
- document.execCommand('insertHTML', false, '@'+value+' ');
- data.editor.trigger('keyup');
- }
- });
- }
- };
- }
- if(input.attr('data-mention-object') && input.attr('data-mention-object') != ''){
- //mention #
- defaultOptions.plugins.mention.keys['#'] = {
- load : function(data){
- data.event.preventDefault();
- document.execCommand('insertHTML', false, '<b class="mention-object-picker-container">#<input type="text" class="mention-object-picker" value=""></b>');
-
- var picker = $('.mention-object-picker');
- picker.focus();
- picker.keydown(function(e){
- var code = e.keyCode || e.which;
- //Si appuis sur espace ça casse l'autocompletion
- if(code == 32){
- e.preventDefault();
- var value = picker.val();
- $('.mention-object-picker-container').remove();
- data.editor.focus();
- data.textarea.trumbowyg('restoreRange');
- document.execCommand('insertHTML', false, '#'+value+' ');
- data.editor.trigger('keyup');
- }
- });
- var timeout = null;
- picker.autocomplete({
- action : input.attr('data-mention-object'),
- skin : function(item){
- var html = '';
- var re = new RegExp(picker.val(),"gi");
- name = item.name.replace(re, function (x) {
- return '<strong>'+x+'</strong>';
- });
- html += '<div class="pointer"><span>'+name+'</span>';
- html += '<div class="clear"></div>';
- return html;
- },
- highlight : function(item){
- return item;
- },
- onClick : function(selected,element){
- clearTimeout(timeout);
- picker.val('');
- $('.mention-object-picker-container').remove();
- data.textarea.trumbowyg('restoreRange');
- slug = selected.slug ? selected.slug : selected.name;
- document.execCommand('insertHTML', false, '<span class="data-mention-object" data-mention-type="object" title="'+selected.name+'" data-mention-value="'+selected.id+'">#'+slug+'</span> ');
- data.editor.trigger('keyup');
- },
- onBlur : function(selected){
- if(input.val() == '') picker.val('');
- timeout = setTimeout(function(){
- $('.mention-object-picker-container').remove();
- data.editor.trigger('keyup');
- },200);
- }
- });
- }
- };
- }
-
- var options = $.extend(defaultOptions,data);
- var obj = input.trumbowyg(options);
- //fix pour accepter les tags non sémantiques dans la gestion du highlight de bouttons
- trumb = input.data('trumbowyg');
- trumb.tagToButton['b'] = 'strong';
- trumb.tagToButton['i'] = 'em';
- trumb.tagToButton['u'] = 'underline';
- input.data('trumbowyg',trumb);
- obj.data('trumbowyg',trumb);
- obj.on('tbwblur', function(){ input.trigger('blur'); });
- var trumbowygBox = $(input).closest('div.trumbowyg-box');
- trumbowygBox.addClass(input.attr('class')).removeClass('trumbowyg-textarea');
- if(input.attr('required')) trumbowygBox.attr('required', true);
- if(input.val()!='')
- input.trumbowyg('html', input.val());
- if(input.attr('data-minimal') != null){
- trumbowygBox.addClass('trumbowyg-minimal');
- var btnPane = trumbowygBox.find('.trumbowyg-button-pane');
- var editor = trumbowygBox.find('.trumbowyg-editor');
- btnPane.addClass('hidden');
- editor.removeAttr('style').keydown(function(e) {
- $(this).find('*').removeProp('font-size');
- switch (e.keyCode) {
- case 13:
- return false;
- break;
- default:
- return true;
- break;
- }
- }).on('paste',function(e){
- e.preventDefault();
- e.stopImmediatePropagation();
- var text = (e.originalEvent || e).clipboardData.getData('text/plain');
- document.execCommand("insertHTML", false, text);
- });
- }
- break;
- /**
- * Permet la recherche combinatoire multi critères.
- * Voir filter.component.js pour plus d'infos.
- */
- case 'filter':
- var box = new FilterBox(input,input.data());
- break;
- /**
- * data-toggle-event : Pour le moment, que "hover", de base au click
- * data-show-strength: Si indiqué, affiche la barre de force du mot de passe renseigné dans l'input
- * data-generator : Si indiqué, affiche une icône pour géénrer un mdp sécurisé
- */
- case 'password':
- if(input.closest('.password-field').length) return;
- input.attr('type', 'password');
- input.wrap(function() {return '<div class="password-field"></div>';});
- var container = input.parent('.password-field');
- container.append('<i class="fas fa-eye-slash noPrint password-toggler"></i>');
- container.find('i.password-toggler').attr((input.attr('data-toggle-event') == 'hover')?{
- 'onmouseover': 'toggle_password(this);',
- 'onmouseleave': 'toggle_password(this);'
- }:{'onclick': 'toggle_password(this);'});
- if(input.attr('data-generator') !== undefined) {
- container.append('<i class="fas fa-shield-alt noPrint password-generator"></i>')
- container.find('i.password-generator').on('click', function(){
- if(input.val()!='' && !confirm('Attention, un mot de passe est déjà défini.\nVoulez-vous quand même en générer un nouveau ?')) return;
- //regex norme ANSSI
- var strong = new RegExp('^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[=/\()%ยง!@#$%^&*])(?=.{12,})');
- do {
- password = generate_password();
- } while(!strong.test(password))
- input.val(password);
- if(input.attr('data-show-strength') !== undefined)
- check_password_strength(input);
- });
- function generate_password(){
- var password = "";
- var charset = get_characters_set();
- var length = Math.ceil(parseFloat(78) * Math.log(2) / Math.log(charset.length));
- for (var i=0; i<length; ++i)
- password += charset[get_random_int(charset.length)];
- return password;
- }
- }
- if(input.attr('data-show-strength') !== undefined) {
- input.parent('.password-field').append('<div class="strength-lines"><div class="line"></div><div class="line"></div><div class="line"></div></div>');
- // check_password_strength($('input[data-type="password"][data-show-strength]'));
- // Strength validation on keyup-event
- input.on("keyup mouseup", function(e) {
- check_password_strength($(this));
- });
- //Check password strength
- function check_password_strength(input) {
- var value = $(input).val();
- var container = $(input).closest('.password-field');
- $(".line", container).removeClass("strength-low strength-medium strength-hard").addClass("strength-transparent");
- if(!value.length) return;
- var strongRegex = new RegExp('^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[=/\()%ยง!@#$%^&*])(?=.{12,})'),
- mediumRegex = new RegExp('^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})');
- if(strongRegex.test(value)) {
- $(".line", container).removeClass("strength-transparent").addClass("strength-hard");
- } else if (mediumRegex.test(value)) {
- $(".line:not(:last-of-type)", container).removeClass("strength-transparent").addClass("strength-medium");
- } else {
- $(".line:nth-child(1)", container).removeClass("strength-transparent").addClass("strength-low");
- }
- }
- }
- break;
- case 'icon':
- input.addClass('hidden');
- input.next('.component-icon').remove();
- var data = {
- value : input.val(),
- choices : []
- };
- var icons = $.fontAwesome();
- var line = [];
- for(var key in icons){
- if(line.length==15){
- data.choices.push(line);
- line = [];
- }
- line.push(icons[key].icon);
- }
- var selector = $(Mustache.render($('.component-icon.hidden').get(0).outerHTML,data));
-
- selector.addClass(input.attr('class'));
- selector.removeClass('hidden form-control');
- input.after(selector);
- selector.on('show.bs.dropdown', function () {
- setTimeout(function(){selector.find('input.form-control').focus();},0);
- })
- selector.find('.dropdown-icon-item').click(function(){
- selector.find('.dropdown-icon-item').removeClass('hidden');
- selector.find('input.form-control').val('');
- var icon = $(this).attr('data-icon');
- input.val(icon);
- selector.find('.dropdown-toggle i').attr('class',icon);
- input.trigger('change');
- });
- selector.find('input.form-control').keyup(function(){
- var value = $(this).val();
- $('.dropdown-icon-item i',selector).each(function(i,iconElement){
- iconElement = $(iconElement);
- parent = iconElement.parent();
- iconElement.attr('class').indexOf(value)!=-1 ? parent.removeClass('hidden') : parent.addClass('hidden');
- });
- /*var icon = $(this).attr('data-icon');
- input.val(icon);
- selector.find('.dropdown-toggle i').attr('class',icon);*/
- });
- break;
- /**
- * data-title (*) : Le titre du modal
- * data-loaded (*): fonction callback appelée auprès le chargement du modal (bien pour setter des actions custom sur les boutons dans le modal par exemple)
- * data-params : Les paramètres utilisés pour l'appel du callback
- * data-action (*) : Appel de la modal par action et non par ajax
- * data-precall : fonction appelée avant le chargement du modal (méthode de check sur l'UI par exemple)
- * Pour customiser l'icône du quickform, il suffit de placer le contenu que l'on veut dans la div de data-type="quickform"
- */
- case 'quickform':
- if(input.find('span').length) return;
- if(input.attr('disabled')) return;
- var cbLoaded = input.attr('data-loaded');
- // var params = input.attr('data-params') ? input.attr('data-params').split(',') : [];
- var params = input.attr('data-params') ? JSON.parse(input.attr('data-params')) : [];
- var preCb = input.attr('data-precall') ? input.attr('data-precall') : '';
- if(input.find('> *').length){
- input.find('> *').wrap('<span class="tooltip-warning">');
- } else {
- input.append('<span class="tooltip-warning"><i title="Création rapide" class="fas fa-plus-square"></i></span');
- }
- $(document).ready(function(e){
- $('span.tooltip-warning').tooltip({
- track: true,
- tooltipClass: 'quickform-tooltip',
- });
- input.on('click', function(e){
- if(preCb.length && !window[preCb]()) return;
-
- $.action({
- action: input.attr('data-action'),
- data: params
- }, function(r){
- var modal = $('#quickform-modal');
- var title = (r.title && r.title.length ? r.title : (input.attr('data-title')!=null ? input.attr('data-title') : 'Création rapide :'));
- $('#quickform-modal-label', modal).text(title);
- $('.modal-body', modal).html('').append(r.content);
- $('.modal-footer > div:first-of-type', modal).nextAll().remove();
- modal.clear();
- $('form', modal).attr('data-id','');
- if(cbLoaded) window[cbLoaded](params);
- modal.modal('show');
- init_components('#quickform-modal');
- });
- });
- });
- break;
- /**
- * data-class : Classe custom à ajouter au conteneur du l'input
- */
- case 'checkbox':
- //3 cas possibles :
- // - input sans rien, data-type="checkbox" --> on fait tout
- // - input avec coquille sans data-uuid, --> on génère simplement un data-uuid et maj valeur
- // - input avec coquille et data-uuid --> on maj simplement sa valeur
- if(input.get(0).hasAttribute('data-uuid')) return;
- if(input.attr('type') != 'checkbox') input.attr('type', 'checkbox');
- if(!input.closest('label.check-component').length) {
- var labelBox = $('<label class="check-component"></label>');
- var checkbox = $('<div class="box"></div>');
- var id = input.attr('id');
- var title = input.attr('title');
- var customClass = input.attr('data-class');
- if(id) labelBox.attr('for', id);
- if(title) labelBox.attr('title', title);
- if(customClass) labelBox.addClass(customClass);
- if(input.prop('disabled') == true) labelBox.attr('disabled', true);
- input.removeAttr('title data-class').wrap(labelBox);
- input.after(checkbox);
- }
- var uuid = generate_uuid(15);
- input.attr('data-uuid', uuid);
- if(input.get(0).hasAttribute('id')) return;
- input.closest('label.check-component').off('click','div.box').on('click','div.box',function(e){
- var checkboxInput = $('input[data-uuid="'+uuid+'"]');
- checkboxInput.prop('checked', checkboxInput.prop('checked'));
- });
- break;
- /**
- * data-label : Libellé affiché à côté de l'input radio
- * name (*) : Le nom du groupe dont fait partie l'input radio
- */
- case 'radio':
- if(input.get(0).hasAttribute('data-uuid')) return;
- if(input.attr('type') != 'radio') input.attr('type', 'radio');
- var uuid = generate_uuid(15);
- var id = input.get(0).hasAttribute('id')? input.attr('id') : '';
- var title = input.get(0).hasAttribute('title') ? input.attr('title') : '';
- var label = input.attr('data-label');
- var labelBox = $('<label data-uid="'+uuid+'"></label>');
- labelBox.attr({
- 'for': id,
- 'title': title
- });
- if(input.prop('disabled') == true) labelBox.attr('disabled', true);
- input.addClass('radio-component').removeAttr('title data-label').attr('data-uuid', uuid);
- input.after(labelBox);
- if(label) labelBox.after('<label for="'+id+'">'+label+'</label>');
- if(input.attr('id') && input.attr('id').length) return;
- labelBox.click(function(e){
- var radioInput = $('input[data-uuid="'+uuid+'"]');
- if(radioInput.prop('disabled') != true) radioInput.prop('checked', true);
- });
- break;
- /**
- * data-action : l'action php pour récupérer l'UI de la card
- * data-parameters : paramètres à passer avec l'action json encodés
- */
- case 'card':
- if(!input.is(':visible')) return;
- var action = input.attr('data-action');
- if(!action) {
- console.warn('CARD COMPONENT: Need "data-action" to get card content');
- return;
- }
- var showDelay = input.attr('data-show-delay') ? input.attr('data-show-delay') : 0;
- var hideDelay = input.attr('data-hide-delay') ? input.attr('data-hide-delay') : 600;
- var parameters = input.attr('data-parameters');
- var data = parameters ? JSON.parse(parameters) : {};
- data.action = action;
- input.addClass('card-component-container');
- $(document).ready(function(){
- var timeout;
- input.mouseenter(function(event){
- var e = event.target || event.relatedTarget;
- if (e.parentNode != this && e != this) return;
- event.stopImmediatePropagation();
- event.stopPropagation();
- $('*[data-type="card"]').find('.card-component')
- .addClass('card-component-hide')
- .removeClass('card-component-hover')
- .one('webkitAnimationEnd oanimationend msAnimationEnd animationend',
- function(e) {
- $(this).closest('.wrapper').remove();
- });
- timeout = setTimeout(function(){
- var currInput = input;
- if(!currInput.find('.card-component').length) {
- $.action(data, function(r){
- if(!r.content) return;
- //On utilise un wrapper pour gérer les overflows "out of the box"
- var card = $(r.content);
- var topOffset = currInput.offset().top;
- currInput.append(card);
- var cardWidth = card.outerWidth();
- var position = {};
- card.wrap($('<div class="wrapper"></div>'));
- card.addClass('card-component card-component-hover');
- if($('body').width() < (currInput.offset().left + cardWidth))
- position['right'] = cardWidth;
- else
- position['left'] = 0;
- var cardHeight = card.outerHeight();
- var htmlHeight = $('html').height();
- if(htmlHeight-100 < (topOffset + cardHeight)){
- var spaceBottom = htmlHeight-topOffset;
- var height = 0;
- if(spaceBottom > topOffset){
- if(cardHeight > spaceBottom) height = (spaceBottom-100);
- } else {
- position['top'] = -cardHeight;
- if(cardHeight > topOffset){
- height = (topOffset-100);
- position['top'] = -(topOffset-100);
- }
- }
- if(height!=0){
- card.css({
- height: height+'px',
- 'overflow-y': 'auto',
- 'overflow-x': 'hidden'
- });
- }
- }
- currInput.find('.wrapper').css(position);
- });
- } else {
- var card = $(currInput.find('.card-component'));
- card.addClass('card-component-hover').removeClass('card-component-hide');
- }
- clearTimeout(currInput.data('tOutbox'));
- }, showDelay);
- });
- input.add(input.find('.card-component')).mouseleave(function(e){
- // e.stopImmediatePropagation();
- // e.stopPropagation();
- var input = $(this),
- card = input.find('.card-component'),
- tOutbox = setTimeout(function(){
- if(!$('.card-component:hover').length) {
- card.addClass('card-component-hide').removeClass('card-component-hover');
- card.one('webkitAnimationEnd oanimationend msAnimationEnd animationend', function(e) {
- $(this).closest('.wrapper').remove();
- });
- }
- }, hideDelay);
- //Clear du timeout d'apparition
- clearTimeout(timeout);
- //Set du l'id de timeout, permet de clear ce trigger si la souris revient sur l'input
- input.data('tOutbox', tOutbox);
- });
- });
- break;
- /**
- * data-dictionnary : Le slug du dictionnary à utiliser
- */
- case 'dictionnary-table':
- if(input.hasClass('component-dictionnary-table')) return;
- if(!input.attr('data-dictionnary') || !input.attr('data-dictionnary').length) return;
- var tpl = $('.component-dictionnary-table').get(0).outerHTML;
- var inputData = input.data();
- $.action({
- action: 'load_dictionnary_component',
- slug : input.attr('data-dictionnary')
- },function(r){
- var list = $(Mustache.render(tpl,{label:'{{label}}', slug:'{{slug}}', id:'{{id}}',parent:r.content}));
- input.append(list);
- list.removeClass('hidden');
- dictionnary_table_refresh(list);
- //Save
- $(input).on('click','thead .btn-success',function(){
- var line = $(this).closest('tr');
- var data = {
- action: inputData.saveAction ? inputData.saveAction : 'dictionnary_table_save',
- label: line.find('input.list-label').val(),
- id: list.attr('data-id'),
- list: list.attr('data-dictionnary')
- };
- if(list.find('input.list-slug')) data.slug = $('input.list-slug', list).val();
- $.action(data, function(r){
- list.attr('data-id', '');
- line.find('input').val('');
- $.message('success','Enregistré');
- dictionnary_table_refresh(list);
- });
- });
- //Suppression
- $(input).on('click','tbody tr .btn-danger',function(){
- if(!confirm('Êtes-vous sûr de vouloir supprimer cet élément de liste ?')) return;
- var line = $(this).closest('tr');
- $.action({
- action: inputData.deleteAction ? inputData.deleteAction : 'delete_dictionnary',
- id: line.attr('data-id')
- },function(r){
- line.remove();
- line.closest('.edit-field').val('');
- $.message('info', 'Élément de liste supprimé');
- });
- });
- //Édition
- $(input).on('click','tbody tr .btn-edit',function(){
- var line = $(this).closest('tr');
- $.action({
- action: inputData.editAction ? inputData.editAction : 'edit_dictionnary',
- id: line.attr('data-id')
- },function(r){
- list.find('input.list-label').val(r.label);
- if(list.find('input.list-slug')) $('input.list-slug', list).val(r.slug);
- list.attr('data-id',r.id);
- });
- });
- });
- break;
- //Permet aux plugins d'ajouter leurs composants
- //via la fonction init_components_nomcomposant(input);
- default:
- var type = input.attr('data-type').replace(/[^a-z0-9]/i,'_');
- if(window['init_components_'+type] !=null) window['init_components_'+type](input);
- break;
- }
- });
-
- $('[data-tooltip]').each(function(){
- var element = $(this);
- var options = {html:true};
- if(element.attr('data-placement')) options.placement = element.attr('data-placement');
- element.tooltip(options);
- });
- }
- /** PRELOADER **/
- var detached;
- function preloader(parent, mode){
- var mode = mode!=null ? mode : 'add';
- if(['toggle', 'add', 'delete'].indexOf(mode) === -1) return;
- var parent = $(parent);
- var loader = $('<div class="loader-container text-center"><div class="loader"><div class="inner one"></div><div class="inner two"></div><div class="inner three"></div></div></div>');
- switch (mode) {
- case 'add':
- parent.html(loader);
- break;
- case 'delete':
- parent.find('div.loader-container').remove();
- break;
- case 'toggle':
- if(parent.find('div.loader-container').length) {
- parent.find('div.loader-container').remove();
- parent.append(detached);
- } else {
- detached = parent.find('>*').detach();
- parent.html(loader);
- }
- break;
- default:
- break;
- }
- }
- /** BACK TO TOP **/
- $('#scroll-top').click(function() {
- scroll_top(150);
- });
- // Affichage du bouton dès lors où l'on a scrollé
- $(window).on('scroll', function(){
- scrollPos = $(document).scrollTop();
- if (scrollPos >= 100) {
- $('#scroll-top').addClass('active');
- } else {
- $('#scroll-top').removeClass('active');
- }
- });
- //Permet de scroller en haut de page
- function scroll_top(time){
- $('html,body').animate({scrollTop:0},time);
- }
- /** CONTRÔLES DATE ET HEURE **/
- function is_valid_date(string){
- var format = /^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]|(?:Jan|Mar|May|Jul|Aug|Oct|Dec)))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2]|(?:Jan|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec))\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)(?:0?2|(?:Feb))\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9]|(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep))|(?:1[0-2]|(?:Oct|Nov|Dec)))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/;
- return format.test(string);
- }
- function is_valid_hour(string){
- var format = /^(?:\d|[01]\d|2[0-3]):[0-5]\d$/;
- return format.test(string);
- }
- //SHOW/HIDE PASSWORD
- function toggle_password(element){
- if ($(element).hasClass('fa-eye-slash')) {
- $(element).removeClass('fa-eye-slash').addClass('fa-eye');
- $(element).prev('input').attr('type', 'text');
- } else {
- $(element).removeClass('fa-eye').addClass('fa-eye-slash');
- $(element).prev('input').attr('type', 'password');
- }
- }
- /** QUICKFORM **/
- function reset_quickform_modal(){
- $('.modal form').attr('data-id','');
- $('input, textarea', '.modal').each(function(i, v){
- if($(v).attr('type') == 'checkbox')
- $(v).prop('checked', false);
- else
- $(v).val('');
- });
- }
- /** CORE **/
- //LOGIN
- $(document).ready(function(){
- $('.login-form').on('keyup', 'input', function(e){
- if(e.keyCode == 13) core_login(this);
- });
- });
- function core_login(element,parent){
- if(isProcessing) return;
- var parent = parent!=undefined ? parent : '#loginRequest';
- var form = $(element).closest('form');
- var data = form.toJson();
- data.redirect = form.attr('data-redirect');
- data.url = form.attr('data-url');
- var loginBtn = $('#login-button', form);
- prevLoginBtn = loginBtn.html();
- loginBtn.html('<i class="fas fa-spinner fa-pulse"></i> Connexion');
- preloader(parent, 'toggle');
- $('.loader-container').append('<small>Connexion en cours</small>');
- isProcessing = true;
- $.action(data, function(r){
- isProcessing = false;
- if(r.redirect) window.location = r.redirect;
- }, function(r){
- isProcessing = false;
- $('#password',form).val('');
- loginBtn.html(prevLoginBtn);
- preloader(parent, 'toggle');
- });
- }
- // INIT - INDEX
- function init_index(){
- $('#loginHeader #login-button').keypress(function(e){
- var key = e.which;
- if(key == 13){
- $('#login-button').click();
- return false;
- }
- });
- }
- function init_setting(parameter){
- switch(parameter.section){
- case 'plugin':
- search_plugin();
- $('.section-plugin').on('change', 'input.toggle', function(){
- var input = $(this);
- var button = input.closest('.activator');
- var label = $('> label', button).detach();
- var value = input.prop('checked');
- if(!value) {
- if(!confirm("Êtes-vous sûr de vouloir désactiver ce plugin ?\nCela entraînera la suppression de toutes les données associées.")) {
- input.prop('checked',!value);
- button.prepend(label);
- return;
- }
- button.removeClass('btn-danger').addClass('btn-info').text('Activer').prepend(label);
- } else {
- button.addClass('btn-danger').removeClass('btn-info').text('Désactiver').prepend(label);
- }
- $.action({
- action : 'change_plugin_state',
- plugin : input.closest('li').attr('data-id'),
- state: value ? 1 : 0
- }, function(r){
- }, function(r){
- if(button.hasClass('btn-danger'))
- button.removeClass('btn-danger').addClass('btn-info').text('Activer').prepend(label);
- else if(button.hasClass('btn-info'))
- button.removeClass('btn-info').addClass('btn-danger').text('Désactiver').prepend(label);
- input.prop('checked',!value);
- });
- });
- break;
- case 'user':
- search_user();
- break;
- case 'firm':
- search_firm();
- break;
- case 'firmPlugin':
- search_firm_plugin();
- break;
- case 'userfirmrank':
- search_userfirmrank();
- break;
- case 'log':
- $('#logs').sortable_table({
- onSort : search_log
- });
- break;
- case 'rank':
- search_rank();
- break;
- case 'dictionnary':
- search_dictionnary();
- $('#label').blur(function(){
- if($('#label').val() != '' && $('#slug').val() == ''){
- $('#slug').off('click');
- dictionnary_slug_proposal($('#label'), $('#parent'));
- }
- });
- $('#slug').off('click');
- $('#slug').on('click', function(){
- if($('#label').val() != '' && $('#slug').val() == '')
- dictionnary_slug_proposal($('#label'), $('#parent'));
- });
- break;
- case 'right':
- search_right();
- break;
- default:
- if(parameter.section!= null){
- var section = parameter.section.replace(/[^a-z_0-9]/g,'_');
- var init = 'init_setting_'+section;
- if(window[init]!=null) window[init]($.urlParam());
- }
- break;
- }
- }
- /** RIGHT **/
- function right_switch(element){
- $(element).closest('tr').find('input').trigger('click');
- }
- /** FORM **/
- function send_form(element){
- var form = $(element).closest('[data-form]');
- var data = $.getForm(form);
- var data = {};
- for(var key in form.data()){
- if(key!="action" && key != "id") continue;
- data[key] = form.attr('data-'+key);
- }
- $('input,select,textarea',form).each(function(i,element){
- element = $(element);
- if(element.attr('data-id')!=null && element.attr('data-id')!=""){
- if(element.attr("type")=='checkbox' || element.attr("type")=='radio'){
- data[element.attr('data-id')] = (element.is(':checked')?1:0);
- }else{
- data[element.attr('data-id')] = element.val();
- }
- }
- });
- data.action = 'send_form';
- $.action(data,function(r){
- });
- }
- /** LOG **/
- // SEARCH
- function search_log(callback){
- var box = new FilterBox('#filters');
- $('#logs').fill({
- action:'search_log',
- filters : box.filters(),
- sort : $('#logs').sortable_table('get')
- },function(){
- if(callback!=null) callback();
- });
- }
- /** USER FIRM RANK**/
- // SEARCH
- function search_userfirmrank(callback){
- $('#userfirmranks').fill({firm : $('#firm').val(),action:'search_userfirmrank'},function(){
- if(callback!=null) callback();
- });
- }
- // SAVE
- function save_userfirmrank(element){
- if(isProcessing) return;
- var button = $(element);
- var data = $.getForm('#userfirmrankForm');
- data.id = $('#userfirmrankForm').attr('data-id');
- button.html('<i class="fas fa-spin fa-spinner"></i> Enregistrement en cours').addClass('disabled');
- isProcessing = true;
- $.action(data,function(r){
- button.html('<i class="fas fa-check"></i> Enregistrer').removeClass('disabled');
- if(typeof r.success !== 'undefined'){
- for(var i = 0; i<r.success.length; i++)
- $.message('success',r.success[i]);
- }
- if(typeof r.warning !== 'undefined'){
- for(var i = 0; i<r.warning.length; i++)
- $.message('warning',r.warning[i]);
- }
- $('#userfirmrankForm').attr('data-id','');
- $('#userfirmrankForm input').val('');
- init_components('#userfirmrankForm');
- $('#firm').val($("#firm option:first").val());
- $('#rank').val($("#rank option:first").val());
- isProcessing = false;
- search_userfirmrank();
- });
- }
- // EDIT
- function edit_userfirmrank(element){
- var line = $(element).closest('tr');
- $.action({
- action:'edit_userfirmrank',
- id:line.attr('data-id')
- },function(r){
- $.setForm('#userfirmrankForm',r);
- $('#firm').change();
- init_components($('#userfirmrankForm'));
- $('#userfirmrankForm').attr('data-id',r.id);
- });
- }
- // DELETE
- function delete_userfirmrank(element){
- if(!confirm('Êtes vous sûr de vouloir supprimer ce lien Établissement / Utilisateur / Rang ?')) return;
- var line = $(element).closest('tr');
- $.action({
- action : 'delete_userfirmrank',
- id : line.attr('data-id')
- },function(r){
- $.message('info', 'Lien Établissement / Utilisateur / Rang supprimé.')
- line.remove();
- });
- }
- /** FIRM **/
- // SEARCH
- function search_firm(callback){
- $('#firms').fill({action:'search_firm'},function(){
- if(callback!=null) callback();
- });
- }
- // EDIT
- function edit_firm(element){
- var line = $(element).closest('tr');
- window.location = 'firm.php?id='+line.attr('data-id');
- }
- // DELETE
- function delete_firm(element){
- if(!confirm('Êtes vous sûr de vouloir supprimer cet établissement ?')) return;
- var line = $(element).closest('tr');
- $.action({
- action : 'delete_firm',
- id : line.attr('data-id')
- },function(r){
- $.message('info','Établissement supprimé');
- line.remove();
- });
- }
- /** FIRM PLUGINS **/
- // SEARCH
- function search_right(callback){
- $('#ranks').fill({
- action: 'search_right',
- rank: $('#rank').attr('data-rank'),
- firm: $('#firm').val()
- },function(r){
- update_checkboxes(r);
- if(callback!=null) callback(r);
- });
- }
- // TOGGLE RIGHT
- function toggle_right(element){
- var line = $(element).closest('tr');
- $.action({
- action:'toggle_right',
- rank:$('#rank').attr('data-rank'),
- firm:$('#firm').val(),
- section:line.attr('data-section'),
- right:$(element).attr('data-right'),
- state:$(element).prop('checked')?1:0
- });
- }
- // SEARCH
- function search_firm_plugin(callback){
- $('#firmplugins').fill({
- action:'search_firm_plugin',
- firm:$('#firm').val()
- },function(r){
- update_checkboxes(r);
- if(callback!=null) callback(r)
- });
- }
- // ENABLE/DISABLE
- function toggle_firm_plugin(element){
- var line = $(element).closest('tr');
- $.action({
- action:'toggle_firm_plugin',
- firm :$('#firm').val(),
- state : $(element).prop('checked')?1:0,
- plugin: line.attr('data-id')
- });
- }
- function update_checkboxes(response){
- $('input[data-result="0"]').prop('checked',false);
- $('input[data-result="1"]').prop('checked',true);
- $('input[data-result="2"]').prop('indeterminate',true);
- }
- // SUPPRESSION LOGO ÉTABLISSEMENT
- function firm_logo_delete(element){
- if(!confirm('Êtes vous sûr de vouloir supprimer l\'image ?')) return;
- var imageComposer = $(element).parent().find("input[data-type='image']");
- $.action({
- action: 'firm_logo_delete',
- id: $('#firm').val()
- }, function(r){
- imageComposer.wrap('<form>').closest('form').get(0).reset();
- imageComposer.unwrap();
- $(element).next('img').attr('src', $(imageComposer).attr('data-default-src'));
- $(element).remove();
- });
- }
- /** USER **/
- // SEARCH
- function search_user(callback){
- $('#users').fill({action:'search_user'},function(){
- if(callback!=null) callback();
- });
- }
- // SAVE
- function save_user(){
- var form = $('#userFormAdmin');
- var data = $.getForm(form);
- data.id = form.attr('data-id');
- $.action(data,function(r){
- $.message('success','Utilisateur enregistré');
- $('#login').removeAttr('readonly');
- $('input',form).val('');
- form.attr('data-id','');
- init_components(form);
- search_user();
- });
- }
- // EDIT
- function edit_user(element){
- var line = $(element).closest('tr');
- $.action({
- action:'edit_user',
- login:line.attr('data-user')
- },function(r){
- $.setForm('#userFormAdmin',r);
- $('#userFormAdmin').attr('data-id',r.id);
- $('#login').attr('readonly', true);
- init_components('#userFormAdmin');
- scroll_top(150);
- });
- }
- // DELETE
- function delete_user(element){
- if(!confirm('Êtes vous sûr de vouloir supprimer cet utilisateur ?')) return;
- var line = $(element).closest('tr');
- $.action({
- action : 'delete_user',
- login : line.attr('data-user')
- },function(r){
- $.message('info','Utilisateur supprimé');
- $('#userFormAdmin').attr('data-id','');
- reset_inputs($('#userFormAdmin'));
- $('#login').removeAttr('readonly');
- line.remove();
- });
- }
- /* ACCOUNT **/
- function account_lost_password(element){
- if(isProcessing) return;
- var btn = $(element);
- btn.addClass('btn-preloader').attr('disabled', true);
- isProcessing = true;
- $.action({
- action: 'account_lost_password',
- mail : $('#mail').val()
- }, function(r){
- isProcessing = false;
- $.message('success','Confirmation envoyée par e-mail');
- btn.removeAttr('disabled');
- }, function(r){
- isProcessing = false;
- btn.removeAttr('disabled');
- });
-
- }
- function account_save(element){
- var data = $('#user-form').toJson();
- data.login = $('#login').val();
- data.avatar = $('#avatar')[0].files[0];
- data.action = 'account_save';
- $.action(data, function(r){
- $.message('success','Enregistré');
- if(r.warning) $.message('warning',r.warning);
- });
- }
- // SUPPRIME AVATAR USER
- function account_avatar_delete(element){
- if(!confirm('Êtes vous sûr de vouloir supprimer l\'image ?')) return;
- var imageComposer = $(element).parent().find("input[data-type='image']");
- $.action({
- action: 'account_avatar_delete',
- login: $('#login').val()
- }, function(r){
- imageComposer.wrap('<form>').closest('form').get(0).reset();
- imageComposer.unwrap();
- $(element).next('img').attr('src', $(imageComposer).attr('data-default-src'));
- $(element).remove();
- });
- }
- /** RANKS **/
- // SEARCH
- function search_rank(callback){
- $('#ranks').fill({action:'search_rank'},function(){
- if(callback!=null) callback();
- });
- }
- // SAVE
- function save_rank(){
- var data = $.getForm('#rankForm');
- data.id = $('#rankForm').attr('data-id');
- $.action(data,function(r){
- $.message('success','Rang enregistré');
- $('#rankForm input').val('');
- $('#rankForm').attr('data-id','');
- search_rank();
- });
- }
- // EDIT
- function edit_rank(element){
- var line = $(element).closest('tr');
- $.action({action:'edit_rank',id:line.attr('data-id')},function(r){
- $.setForm('#rankForm',r);
- $('#rankForm').attr('data-id',r.id);
- });
- }
- // DELETE
- function delete_rank(element){
- if(!confirm('Êtes vous sûr de vouloir supprimer ce rang ?')) return;
- var line = $(element).closest('tr');
- $.action({
- action : 'delete_rank',
- id : line.attr('data-id')
- },function(r){
- $.message('info','Rang supprimé');
- line.remove();
- });
- }
- /** DICTIONNARY **/
- // SEARCH
- function search_dictionnary(callback){
- var parentValue = $('#parent').val();
- parentValue != "" ? $('#prev-button').removeClass('hidden') : $('#prev-button').addClass('hidden');
- $('#dictionnaries').fill({
- action:'search_dictionnary',
- parent : parentValue
- },function(r){
- reset_inputs($('#dictionnaryForm'), false, true);
- if(callback!=null) callback();
- var tpl = $('#parent').find('option[value="{{id}}"]');
- if(!tpl.parent('span').length) tpl.wrap('<span>').addClass('hidden');
- });
- }
- // SAVE
- function save_dictionnary(){
- var data = $.getForm('#dictionnaryForm');
- data.id = $('#dictionnaryForm').attr('data-id');
- data.parent = $('#parent').val();
- $.action(data,function(r){
- $.message('success','Liste enregistrée');
- $('#dictionnaryForm input').val('');
- $('#dictionnaryForm').attr('data-id','');
- search_dictionnary();
- });
- }
- // EDIT
- function edit_dictionnary(element){
- var line = $(element).closest('tr');
- $.action({
- action: 'edit_dictionnary',
- id: line.attr('data-id')
- },function(r){
- $.setForm('#dictionnaryForm',r);
- $('#dictionnaryForm').attr('data-id',r.id);
- });
- }
- // DELETE
- function delete_dictionnary(element){
- if(!confirm('Êtes-vous sûr de vouloir supprimer cette liste ?')) return;
- var line = $(element).closest('tr');
- $.action({
- action: 'delete_dictionnary',
- id: line.attr('data-id')
- },function(r){
- line.remove();
- $.message('info','Liste supprimée');
- });
- }
- // Remplissage de la liste (select) --> Dans les settings
- function get_dictionnary_items(elem, elemToFill){
- var parent = $(elem).closest('tr');
- var id = $(parent).attr('data-id');
- var parentId = $(parent).attr('data-parent');
- $(elemToFill).fill({
- action:'search_dictionnary',
- parent : parentId.toString()
- },function(){
- $(elemToFill).val(id).change();
- });
- }
- // Ajout de sous-liste --> Dans les settings
- function add_sub_dictionnary(elem){
- reset_inputs($('#dictionnaryForm'), false, true);
- var parent = $(elem).closest('tr');
- var id = $(parent).attr('data-id');
- var value = parent.find(".itemLabel").text();
- if ($("#parent option[value='"+id+"']").length > 0)
- $('#parent').val(id).change();
- else {
- get_dictionnary_items(elem, "#parent");
- $('code').addClass('hidden');
- }
- $('#prev-button').removeClass('hidden');
- }
- // Récupération éléments de la liste précédente --> Dans les settings
- function previous_list_dictionnary(elem){
- var selected = $('#parent > option:selected').val();
- reset_inputs($('#dictionnaryForm'), false, true);
- $.action({
- action: 'get_parent_dictionnary',
- selected: selected
- }, function(r){
- var data = r.rows[0];
- $('#parent option[value!="{{id}}"]').remove();
- if (data.parentId == "") $('#prev-button').addClass('hidden');
- if (data.parents[0].parent == "0") {
- $('#parent').append("<option value='' selected>-</option>");
- $('code').removeClass('hidden');
- }
- $.each(data.parents, function (index, value){
- if (value.id == data.parentId)
- $('#parent').append("<option selected value='"+value.id+"'>"+value.label+"</option>");
- else
- $('#parent').append("<option value='"+value.id+"'>"+value.label+"</option>");
- });
- search_dictionnary();
- });
- }
- // Récupération des sous-listes pour les champ de type "dictionnary" --> Où le module est appelé
- function get_sub_dictionnary(elem, name, currentDepth){
- var input = $(elem);
- var selectValue = input.val();
- var optSubLabel = $('option:selected', elem).attr('data-sublabel');
- var depth = (input.attr('data-depth') && input.attr('data-depth') != "") ? input.attr('data-depth') : "1";
- var fieldName = name == '' ? input.attr('name') : name;
- currentDepth -= currentDepth != 1 ? input.nextAll('select').length : 0;
- if(input.closest('span.dictionnary-container').length != 0){
- var id = input.nextAll().last().attr('id');
- input.attr('id', id).nextAll().remove();
- }
- if (selectValue.length && currentDepth < depth) {
- input.removeAttr('name');
- currentDepth += 1;
- $.action({
- action: 'search_dictionnary',
- parent: selectValue
- }, function(r){
- var option = '';
- if(input.closest('span.dictionnary-container').length == 0) input.wrap('<span class="dictionnary-container"></span>');
- var newSelect = clone_input_dictionnary(input, selectValue, fieldName);
- var currentDepth = input.closest('span.dictionnary-container').children('select').length;
- if (input.attr('data-disable-label') != "" && optSubLabel != "" && optSubLabel != "null") input.after('<label class="label-select">'+optSubLabel+'</label>');
- newSelect.attr('onchange', 'get_sub_dictionnary(this, "'+fieldName+'", '+currentDepth+');');
- newSelect.append('<option value=""> - </option>');
- $.each(r.rows, function(index, value){
- option += '<option value="'+value.id+'" data-parent="'+value.parent+'" data-sublabel="'+value.sublistlabel+'">'+value.label+'</option>';
- });
- newSelect.append(option);
- });
- } else if (!selectValue.length) {
- input.attr('name', fieldName);
- }
- }
- // Récupération des sous-listes depuis l'id du plus petit enfant --> Où le module est appelé
- function get_selected_values(elem, select){
- var input = $(elem);
- if(input.closest('span.dictionnary-container').length == 0) input.wrap('<span class="dictionnary-container"></span>');
- var fieldName = input.attr('name');
- var currentDepth = 1+input.closest('span.dictionnary-container').children('select').length;
- var optSubLabel = select.sublistlabel;
- var option = '';
- if (typeof select.childs !== 'undefined' && select.childs.length > 0) {
- var newSelect = clone_input_dictionnary(input, select.id, fieldName);
- if (newSelect.attr('data-disable-label') != "" && optSubLabel != "" && optSubLabel != "null" && optSubLabel != undefined) input.after('<label class="label-select">'+optSubLabel+'</label>');
- newSelect.append('<option value=""> - </option>');
- }
- $.each(select.childs, function(index, value){
- var selected = '';
- if (value.hasOwnProperty("selected")) {
- input.removeAttr('name');
- get_selected_values(newSelect, value);
- selected = "selected";
- }
- newSelect.attr('onchange', 'get_sub_dictionnary(this,"'+fieldName+'", '+currentDepth+');');
- option += '<option value="'+value.id+'" data-parent="'+value.parent+'" data-sublabel="'+value.sublistlabel+'" '+selected+'>'+value.label+'</option>';
- });
- if(newSelect) newSelect.append(option);
- }
- // Clone du select de type "dictionnary"
- function clone_input_dictionnary(input, id, name){
- var newSelect = input.clone();
- input.removeAttr('id').after(newSelect).after(' ');
- newSelect.removeAttr("data-type").removeAttr('name').removeAttr('data-value');
- // newSelect.attr('id', 'children-select-'+id).attr('name', name);
- newSelect.find('option').remove();
- return newSelect;
- }
- //Rafraîchit la table de la liste donnée
- //En lien avec le composant dictionnary_table
- function dictionnary_table_refresh(elem){
- var id = $(elem).attr('data-dictionnary');
- var table = $(elem).find('table:eq(0)');
- $.action({
- action: 'dictionnary_table_search',
- id: id
- },function(r){
- table.find('tbody tr:visible').remove();
- var tpl = table.find('tbody tr:hidden').get(0).outerHTML;
- for(var key in r.rows){
- var row = r.rows[key];
- var line = $(Mustache.render(tpl,row));
- line.removeClass('hidden');
- table.find('tbody').append(line);
- }
- });
- }
- function dictionnary_slug_proposal(element, parent){
- var line = $(element).closest('tr');
- $.action({
- action : 'dictionnary_slug_proposal',
- id : line.attr('data-id'),
- label : $(element).val(),
- parent : $(parent).val()
- },function(response){
- $('#slug').val(response.slug);
- });
- }
- /** PLUGINS **/
- // SEARCH
- function search_plugin(callback){
- $('#plugins').fill({action:'search_plugin'},function(){
- if(callback!=null) callback();
- });
- }
- // RÉCUPÉRATION PARAMÈTRE URL
- var get_url_parameter = function get_url_parameter(sParam, string) {
- var sPageURL = !string ? decodeURIComponent(window.location.search.substring(1)) : string;
- var sURLVariables = sPageURL.split('&'),
- sParameterName,
- i;
- for (i = 0; i < sURLVariables.length; i++) {
- sParameterName = sURLVariables[i].split('=');
- if (sParameterName[0] === sParam) {
- return sParameterName[1] === undefined ? true : sParameterName[1];
- }
- }
- };
- // DROPZONE
- function dropzone_delete_file(element){
- if(!confirm('Êtes-vous sûr de vouloir supprimer ce fichier ?')) return;
- var elem = $(element);
- var line = elem.closest('li');
- var container = elem.closest('div[data-type="dropzone"]');
- var inputTemp = container.find('#'+container.attr('id')+'_temporary');
- var values = inputTemp.val().length ? JSON.parse(inputTemp.val()) : [];
- for (var i in values) {
- if(values[i]['path'] == line.attr('data-path'))
- values.splice(i, 1);
- }
- line.remove();
- inputTemp.val(JSON.stringify(values));
- }
- /* GENERAL SETTINGS */
- //Sauvegarde de la configuration générale
- function general_settings_save(){
- var data = $('#general-settings').getForm();
- data.logo = $('#logo')[0].files[0];
- data.logo_dark = $('#logo_dark')[0].files[0];
- data.favicon = $('#favicon')[0].files[0];
- data.password_format = $('#password-format-form').attr('data-format');
- $.action(data, function(r){
- $.message('success', 'Configuration enregistrée');
- });
- }
- function general_reset_password_delay(){
- if(!confirm('Êtes-vous sûr de vouloir forcer tous les utilisateurs à réinitialiser leurs mot de passe ?')) return;
- $.action({
- action: 'general_reset_password_delay'
- }, function(r){
- $.message('success', 'Validé');
- });
- }
- function password_settings_format(){
- var patterns = [];
- $('#password-format-form input[data-pattern]:checked').each(function(){
- patterns.push($(this).attr('data-pattern'));
- });
- $('#password-format-form').attr('data-format',JSON.stringify(patterns));
- }
- //Suppression image générale application
- function general_logo_delete(element){
- if(!confirm('Êtes-vous sûr de vouloir supprimer l\'image ?')) return;
- var imageComposer = $(element).parent().find("input[data-type='image']");
- $.action({
- action: 'general_logo_delete'
- }, function(r){
- imageComposer.wrap('<form>').closest('form').get(0).reset();
- imageComposer.unwrap();
- $(element).next('img').attr('src', $(imageComposer).attr('data-default-src'));
- $(element).remove();
- $.message('info', 'Image supprimée');
- });
- }
- //Suppression favicon générale application
- function general_favicon_delete(element){
- if(!confirm('Êtes-vous sûr de vouloir supprimer l\'image ?')) return;
- var imageComposer = $(element).parent().find("input[data-type='image']");
- $.action({
- action: 'general_favicon_delete'
- }, function(r){
- imageComposer.wrap('<form>').closest('form').get(0).reset();
- imageComposer.unwrap();
- $(element).next('img').attr('src', $(imageComposer).attr('data-default-src'));
- $(element).remove();
- $.message('info', 'Favicon supprimée');
- });
- }
- //Active/Désactive la page de maintenance du site
- function toggle_maintenance(){
- var checkbox = $('#maintenance');
- var state = checkbox.is(':checked') ? 'd\'activer' : 'de désactiver';
- if(!confirm("Vous êtes sur le point "+state+" la page de maintenance du site.\nVoulez-vous continuer ?")){
- checkbox.is(':checked') ? checkbox.removeAttr('checked').prop('checked', false) : checkbox.attr('checked', true).prop('checked', true);
- return;
- }
- general_settings_save();
- }
- /* FUNCTIONS */
- //Récupère la plus petite valeur d'un tableau
- function getMinValue(arr) {
- return arr.reduce(function (p, v) {
- return ( p < v ? p : v );
- });
- };
- //Récupère la plus grande valeur d'un tableau
- function getMaxValue(arr) {
- return arr.reduce(function (p, v) {
- return ( p > v ? p : v );
- });
- };
- //Check si la valeur saisie dans l'input
- //est une adresse e-mail bien formatée
- function is_email(email) {
- var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
- return re.test(String(email).toLowerCase());
- }
- //Check si la valeur saisie dans
- //l'input est une url bien formatée
- function is_url(str) {
- regexp = /^(?:(?:https?|ftp):\/\/)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/\S*)?$/;
- if (regexp.test(str))
- return true;
- return false;
- }
- //Check format n° de téléphone
- function is_phone_number(number, required, label){
- if (required && number == ''){
- $.message('error',label+' obligatoire');
- return false;
- }
- if (number != ''){
- number = number.replace(/\s/g, '');
- number = number.replace(/\./g, '');
- number = number.replace(/-/g, '');
- if(is_numeric(number)) {
- if(/^(?:(?:\+|00)\d{2}|0)\s*[1-9](?:[\s.-]*\d{2}){4}$/.test(number) == false){
- $.message('error',' Le format du n° de '+label.toLowerCase()+' est invalide');
- return false;
- }
- } else {
- $.message('error',' Le n° de '+label.toLowerCase()+' contient des caractères interdits');
- return false;
- }
- }
- return true;
- }
- //Check si la valeur de
- //l'input est numérique
- function is_numeric(n) {
- return !isNaN(parseFloat(n)) && isFinite(n);
- }
- function str_price_to_decimal(str){
- return str.replace(/,/g,'.').replace(/ /g,'');
- }
- //Comme la fonction ucfirst de PHP
- function ucfirst(string) {
- return string.charAt(0).toUpperCase() + string.slice(1);
- }
- //Permet de revenir/rester sur l'onglet courant
- //au reload de page, ou au clic sur un lien particulier
- if (location.hash) {
- $('a[href="' + location.hash + '"]').tab('show');
- }
- var activeTab = localStorage.getItem('activeTab');
- if (activeTab) {
- $('a[href="' + activeTab + '"]').tab('show');
- }
- $('body').on('click', 'a[data-toggle="tab"]', function(e){
- e.preventDefault();
- var tab_name = this.getAttribute('href');
- history.pushState ? history.pushState(null, null, tab_name) : location.hash = tab_name;
- localStorage.setItem('activeTab', tab_name);
- $(this).tab('show');
- return false;
- });
- $(window).on('popstate', function () {
- var anchor = location.hash || $('a[data-toggle="tab"]').first().attr('href');
- $('a[data-toggle="tab"][href="' + anchor + '"]').tab('show');
- });
- //Check si la chaîne de caractères
- //fournies est une chaîne JSON
- function is_json_string(str) {
- try {
- JSON.parse(str);
- } catch (e) {
- return false;
- }
- return true;
- }
- //Sélectionne le texte de l'élément passé en paramètre
- function select_text(element, event){
- event.stopImmediatePropagation();
- var sel, range;
- var el = $(element).get(0); //get element id
- if (window.getSelection && document.createRange) { //Browser compatibility
- sel = window.getSelection();
- if(sel.toString() == ''){ //no text selection
- window.setTimeout(function(){
- range = document.createRange(); //range object
- range.selectNodeContents(el); //sets Range
- sel.removeAllRanges(); //remove all ranges from selection
- sel.addRange(range);//add Range to a Selection.
- },1);
- }
- }else if (document.selection) { //older ie
- sel = document.selection.createRange();
- if(sel.text == ''){ //no text selection
- range = document.body.createTextRange();//Creates TextRange object
- range.moveToElementText(el);//sets Range
- range.select(); //make selection.
- }
- }
- }
- //Permet de copier le contenu de l'element dans le presse-papier
- function copy_string(string,element) {
- var temparea = document.createElement('textarea');
- temparea.value = string;
- temparea.setAttribute('readonly', '');
- temparea.style = {position: 'absolute', left: '-9999px'};
- document.body.appendChild(temparea);
- temparea.select();
- document.execCommand('copy');
- document.body.removeChild(temparea);
- if(element){
- element = $(element);
- if(element.data('ui-tooltip')) return;
-
- element.tooltip({
- items: '*',
- tooltipClass: 'quickform-tooltip',
- content: 'Copié dans le presse papier',
- open: {effect:'fade',duration:750},
- close: {effect:'fade',duration:750}
- });
- element.tooltip('open');
- setTimeout(function(){element.tooltip('close');element.tooltip('destroy');}, 2000);
- }
- }
- //Reset des inputs d'un conteneur
- function reset_inputs(container, onlyVisible, domData){
- var container = container ? container : $('body');
- var visibility = onlyVisible ? onlyVisible : false;
- var dom = domData ? domData : false;
- if(dom) container.removeAttr('data-id');
- var classicInputs = visibility==true ? $('input:visible, textarea:visible, select:visible', container) : $('input, textarea, select', container);
- classicInputs.each(function(i, v){
- if($(v).attr('type') == 'checkbox')
- $(v).prop('checked', false);
- else
- $(v).val('');
- });
- var customInputs = visibility==true ? $('*[contenteditable="true"]:visible', container) : $('*[contenteditable="true"]', container);
- customInputs.each(function(j,val){
- $(val).text('');
- });
- }
- //Check si le contenu d'un input est
- //selectionné (en surbrillance avec le curseur)
- function is_text_selected(input) {
- if (typeof input.selectionStart == "number") {
- return input.selectionStart == 0 && input.selectionEnd == input.value.length;
- } else if (typeof document.selection != "undefined") {
- input.focus();
- return document.selection.createRange().text == input.value;
- }
- }
- //Renvoie un tableau en ayant supprimé
- //toutes les valuers dupliquées
- function only_uniq_values(a) {
- var seen = {};
- var out = [];
- var len = a.length;
- var j = 0;
- for(var i = 0; i < len; i++) {
- var item = a[i];
- if(seen[item] !== 1) {
- seen[item] = 1;
- out[j++] = item;
- }
- }
- return out;
- }
- //Contrôle éléments saisis dans input de type number.
- //Autorise ou non les décimales et les nb négatifs
- function input_number_control(e, decimal, relative){
- var authorizedKeys = [
- "Backspace", "Delete", "Tab",
- "ArrowLeft", "ArrowUp", "ArrowRight", "ArrowDown",
- "-", ".", ",",
- "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
- ];
- switch (e.key) {
- case ".":
- case ',':
- return decimal?decimal:false;
- break;
- case '-':
- return relative?relative:false;
- break;
- default:
- return (
- ((e.key == "a" || e.key == "c" || e.key == "v" || e.key == "z") && (e.ctrlKey === true || e.metaKey === true)) ||
- (authorizedKeys.indexOf(e.key) !== -1)
- );
- break;
- }
- }
- //Permet de checker si la saisie est en majuscule ou non
- //Fonction utilisable uniquement dans function callback de listener d'event
- function is_caps(){
- e = window.event;
- return is_phone() ? true : (e.shiftKey !== true && e.metaKey !== true) ? (e.getModifierState("CapsLock") ? true : false) : (e.getModifierState("CapsLock") ? false : true);
- }
- //Check si l'objet est vide ou non
- //Retourne true si vide, false sinon
- function is_empty_obj(obj) {
- for(var key in obj)
- if(obj.hasOwnProperty(key)) return false;
- return true;
- }
- //Permet de retourner une propriété d'un
- //objet de manière totalement aléatoire
- function random_property(obj) {
- var keys = Object.keys(obj)
- return obj[keys[ keys.length * Math.random() << 0]];
- }
- function get_characters_set() {
- var CHARACTER_SETS = [
- ["0123456789"],
- ["abcdefghijklmnopqrstuvwxyz"],
- ["ABCDEFGHIJKLMNOPQRSTUVWXYZ"],
- ["!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"],
- ];
- // Concatène les jeux de caractères
- var rawCharset = "";
- CHARACTER_SETS.forEach(function(entry, i) {
- rawCharset += entry[0];
- });
- // Parse en UTF-16, supprime les doublons, convertit en tableau de string
- var charset = [];
- for (var i = 0; i < rawCharset.length; ++i) {
- var c = rawCharset.charCodeAt(i);
- if (c<0xD800 || c>=0xE000) {//Check si character UTF-16 valide
- var s = rawCharset.charAt(i);
- if (charset.indexOf(s) == -1) charset.push(s);
- continue;
- }
- if (0xD800<=c && c<0xDC00 && i+1<rawCharset.length) {
- var d = rawCharset.charCodeAt(i + 1);
- if (0xDC00<=d && d<0xE000) {
- var s = rawCharset.substring(i, i+2);
- i++;
- if (charset.indexOf(s) == -1) charset.push(s);
- continue;
- }
- }
- throw "Invalid UTF-16";
- }
- return charset;
- }
- //Retourne un entier aléatoire dans la plage [0, n)
- //(2 méthodes utilisées)
- function get_random_int(maxRange) {
- //Récup d'un entier aléatoire via le module Math
- //(fallback si pas de module crypto)
- var x = random_int_math(maxRange);
- //Récupération d'un entier aléatoire via le moule crypto
- x = (x + random_int_crypto(maxRange)) % maxRange;
- return x;
- }
- //Retourne un entier aléatoire
- //Peu sécurisé (car calculable) mais
- //présent sur tous les navigateurs
- function random_int_math(maxRange) {
- var x = Math.floor(Math.random() * maxRange);
- if (x < 0 || x >= maxRange) throw "Arithmetic exception";
- return x;
- }
- //Retourne un entier aléatoire
- //Extrêmement sécurisé, mais pas
- //disponible sur tous les navigateurs
- //+ d'infos ici: https://developer.mozilla.org/fr/docs/Web/API/RandomSource/getRandomValues
- function random_int_crypto(maxRange) {
- var cryptoObject = null
- if ("crypto" in window) {
- //Check si le module crypto est disponible (Chrome, Firefox, Safari)
- cryptoObject = crypto;
- } else if ("msCrypto" in window) {
- //Check si le module crypto est disponible (Edge, IE)
- cryptoObject = msCrypto;
- }
- //Check + récupération propriétés/fonctions nécessaires du module crypto
- if ("getRandomValues" in cryptoObject && "Uint32Array" in window && typeof Uint32Array == "function") {
- //Génère un échantillon impartial/aléatoire
- var x = new Uint32Array(1);
- //Modification des élements du
- //tableau par des nb aléatoires
- do cryptoObject.getRandomValues(x);
- while (x[0] - x[0] % maxRange > 4294967296 - maxRange);
- return x[0] % maxRange;
- } else {
- return 0;
- }
- }
- //Permet de générer un UUID de
- //longueur souhaitée (ou 10 si pas de paramètre)
- function generate_uuid(length){
- var length = length !== undefined ? length : 10;
- //Fallback repeat sur string
- //pour les anciens navigateurs
- if(!String.prototype.repeat){
- String.prototype.repeat = function(length){
- var length = parseInt(length);
- if (length < 1) return '';
- var result = '',
- pattern = this.valueOf();
- while (length > 1) {
- if(length & 1) result += pattern;
- length >>= 1, pattern += pattern;
- }
- return result + pattern;
- };
- }
- var mem = "0x1"+("0".repeat(length));
- return Math.floor((1 + Math.random()) * mem).toString(16).substring(1);
- }
- function readable_size(bytes) {
- var thresh = 1000;
- if(Math.abs(bytes) < thresh) {
- return bytes + ' B';
- }
- var units = ['ko','Mo','Go','To','Po','Eo','Zo','Yo'];
- var u = -1;
- do {
- bytes /= thresh;
- ++u;
- } while(Math.abs(bytes) >= thresh && u < units.length - 1);
- return bytes.toFixed(1)+' '+units[u];
- }
- /**
- * Permet e faire cligner l'onglet
- * navigateur avec un message custom
- * @param {string} message => le message à afficher
- * @param {int} interval => l'intervalle entre 2 clignotement en ms
- * @param {int} repetitions => le nombre de clignotements
- */
- function blink_tab(message, interval, repetitions) {
- interval = interval != undefined && !isNaN(interval) ? interval : 750;
- repetitions = parseInt(repetitions)*2;
- if(isNaN(repetitions)) repetitions = 10;
- if(repetitions%2!==0) repetitions += 1
- var original = document.title,
- timeoutId,
- blink = function() {
- document.title = document.title == message ? original : message;
- if(--repetitions > 0) timeoutId = setTimeout(blink, interval);
- },
- clear = function() {
- clearTimeout(timeoutId);
- document.title = original;
- window.onmousemove = null;
- timeoutId = null;
- };
-
- if(!timeoutId) {
- timeoutId = setTimeout(blink, interval);
- window.onmousemove = clear;
- }
- }
- //Échappe les caractères spéciaux utilisés dans les regexps
- function escape_regex_chars(text){
- //return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
- return text.replace(/[-[\]{}()*+!<=:?.\/\\^$|#\s,]/g, '\\$&');
- }
- //Détecte si le navigateur est un mobile ou non
- function is_phone(){
- var navigatorName = navigator.userAgent||navigator.vendor||window.opera;
- if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(navigatorName)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigatorName.substr(0,4)))
- return true;
- return false;
- }
|