$(document).ready(function(){ var _lastRCGeneration=0; $('form input.recaptcha-id').each(function(){ fieldRc=this; $(this).closest('form').bind('submit',function(e,d,f){ if(grecaptcha && ((new Date().getTime()-_lastRCGeneration)/1000)>60){ e.preventDefault(); _lastRCGeneration=new Date().getTime(); v=grecaptcha.enterprise.ready( async() => { const token = await grecaptcha.enterprise.execute(recaptchaKey, {action: 'LOGIN'}); $(fieldRc).val(token); $(this).submit(); }); } }); }); if(_ajaxSubmitForm){ $('form.ajax-submit').bind('submit',function(e,d,f){ _ajaxSubmitForm(this); return false;}); } // $('.container-uploader > .uploader-group').dropzone({ // maxFiles: 2000, // url: "/admin/changeLogo_"+$(".profil-logo").data('userid'), // success: function (file, response) { // if(response.err==0){ // $('.empty-logo').hide(); // $('.content-filed-logo').prop('src',response.file); // $('#id_logo_field').val(response.file.replace(/^.*[\\\/]/, '')); // $('.filled-logo').show(); // }else{ // _displayMessage(response.title,response.lib,'error'); // } // } // }); }); function _ajaxSubmitForm(e,callbackfct){ _displayLoader($(e)); $(e).ajaxSubmit({ url: ($(e).attr('action')!='') ? $(e).attr('action') : window.location, dataType: 'json', error: function(response, statusText, xhr, $form) { _hideLoader($(e)); _displayMessage('An error occured','If it persists, please contact the admin','error'); }, success: function(response, statusText, xhr, $form) { _hideLoader($(e)); // if(typeof(callbackfct)=='function') callbackfct(response); if(callbackfct) response.callback= (response.callback) ? response.callback+"var a="+callbackfct.toString()+'(response)' : "var a="+callbackfct.toString()+'(response)'; _treatJSONReturn(response); } }); return false; } function _hideLoader(e){ if(e.hasClass('card')){ var finalElement=e; }else{ var finalElement=(e.closest('.card').length) ? e.closest('.card')[0] : null; // } if($(finalElement).find('div.overlay').length>0){ $(finalElement).find('div.overlay').remove(); } } function _displayLoader(e){ if(e.hasClass('card')){ var finalElement=e; }else{ var finalElement=(e.closest('.card').length) ? e.closest('.card')[0] : null; // } if($(finalElement).find('div.overlay').length==0){ $(finalElement).append('
'); } } function _treatJSONReturn(response){ callback=function(t){}; if(typeof(response.callback)=='string' && response.callback.trim()!=''){ eval('var callback=function(response){'+response.callback+"}"); } if(response.err==0){ if(response.lib && response.lib!=''){ // console.log('ok'); // console.log(callback); _displayMessage(response.title,response.lib,'success',callback,response); }else{ callback(response); } }else{ var title= (response.title && response.title!='') ? response.title : 'Error'; if(response.lib && response.lib!=''){ _displayMessage(response.title,response.lib,'error',callback,response); }else{ callback(); } } } if(typeof tinymce !== "undefined"){ tinymce.init({ selector: "textarea.wysiwyg-basic", height: 200, menubar:false, statusbar: false, plugins: [ "advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker", "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking", "save table contextmenu directionality emoticons template paste textcolor", ], toolbar: "undo redo | bold italic | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent", }); } function _displayMessage(title,Message,type,callback,param){ if(type=='error'){ Swal.fire({ title: title, text: Message, icon: "error", confirmButtonColor: "#556ee6", }).then((result) => { if(callback){ callback(param); } }) // swal({"title": title,"text": Message,"type": 'error'},callback);//.then(callback); }else{ Swal.fire({ title: title, text: Message, icon: "success", confirmButtonColor: "#556ee6", }).then((result) => { if(callback){ callback(param); } }) } } function initToolTipster(elem){ elem.find('.tooltipster').each(function(){ select=$(this).data('tooltipstertarget'); $(this).tooltipster({ content: $(select).html(), contentAsHTML: true, theme: 'actuccitt', }); $(select).remove(); }); } function initSwapButton(elem){ // elem.find('.button-switch').click(function(){ if($(this).hasClass('btn-outline-secondary') && ! $(this).hasClass('btn-switch-disabled')){ var butonSelect=$(this).closest('.field-switchbuttons').find('.btn-secondary'); butonSelect.removeClass('btn-secondary'); butonSelect.addClass('btn-outline-secondary'); $(this).addClass('btn-secondary'); $(this).removeClass('btn-outline-secondary'); $(this).closest('.field-switchbuttons').find('input[type="hidden"]').val($(this).data('value')); } }); } function initCheckboxShowHide(elem){ elem.find('.hide-oncheck').click(function(){ if(this.checked){ $($(this).data('target')).hide(); }else{ $($(this).data('target')).show(); } }); elem.find('.hide-oncheck').each(function(){ if(this.checked){ $($(this).data('target')).hide(); }else{ $($(this).data('target')).show(); } }); } var callbackLitigeAdded=function(){ }; function sendEmail(template,idcustomer,idobj,callback){ $('#send-email-modal').remove(); obj={}; if(template) obj['template']=template; if(idcustomer) obj['idcustomer']=idcustomer; if(idobj) obj['idobj']=idobj; $.ajax({ url: "/admin/sendemail.html", context: document.body, "type": "POST", data: obj, }).done(function(f,e) { if(f.err==1){ _treatJSONReturn(f); return false; } $(f).appendTo('body'); if(typeof tinymce !== "undefined"){ tinymce.remove(); tinymce.init({ selector: "textarea.wysiwyg-basic-email", height: 200, menubar:false, statusbar: false, plugins: [ "advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker", "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking", "save table contextmenu directionality emoticons template paste textcolor", ], toolbar: "undo redo | bold italic | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent", }); } $('#send-email-modal form.ajax-submit').bind('submit',function(e,d,f){ _ajaxSubmitForm(this,callback); return false;}); var drpZone=$('#send-email-modal .container-uploader > .uploader-group.profil-email-upload').dropzone({ maxFiles: 2000, url: "/admin/uploademailattached.php", success: function (file, response) { $('#send-email-modal .file-container-email').append(getFileContainerForLitige(response.filename,response.filesize)); } }); $('#send-email-modal').modal('show'); }); } function addNewLitigeToCustomer(idcustomer){ $('#add-litige-modal').remove(); $.ajax({ url: "/admin/addcustomerlitige_"+idcustomer+".html", context: document.body }).done(function(e,f) { $(e).appendTo('body'); $('#add-litige-modal form.ajax-submit').bind('submit',function(e,d,f){ _ajaxSubmitForm(this); return false;}); var drpZone=$('#add-litige-modal .container-uploader > .uploader-group.profil-doclitige-upload').dropzone({ maxFiles: 2000, url: "/admin/uploadcustomerlitige_"+idcustomer+'.php', success: function (file, response) { $('#add-litige-modal .file-container-litige').append(getFileContainerForLitige(response.filename,response.filesize)); } }); $('#add-litige-modal').modal('show'); }); } function getFileContainerForLitige(filename,size){ html='
'; html=html+''; html=html+'
'; html=html+'
'+filename+'
Poids: '+size+'
'; html=html+'
'; html=html+'
'; return html; } $(document).ready(function(){ initToolTipster($(document)); initCheckboxShowHide($(document)); initSwapButton($(document)); });