var name_local_storage = 'reservedarea'; var loadScript = function (path) { var result = $.Deferred(); var script = document.createElement("script"); script.async = "async"; script.type = "text/javascript"; script.src = path; script.onload = script.onreadystatechange = function(_, isAbort) { if (!script.readyState || /loaded|complete/.test(script.readyState)) { if (isAbort) result.reject(); else result.resolve(); } }; script.onerror = function () { result.reject(); }; $("head")[0].appendChild(script); return result.promise(); } var init = function() { var lang = $(document).find('#box-areariservata').attr('data-lang'); var lang_id = $(document).find('#box-areariservata').attr('data-lang_id'); $.ajax({ type: "POST", url: 'https://www.viniventurini.com/area/admin/includes/ajax/ajax_frontend.php', data: { type: "init", module: "reservedarea", lang_id: lang_id, }, context: this, dataType: 'json', }) .done(function(datiJSON){ $('#box-areariservata').html(datiJSON.output); jtable_init(); }); } function getCookie(cname) { var name = cname + "="; var decodedCookie = decodeURIComponent(document.cookie.replace(/\+/g, ' ')); var ca = decodedCookie.split(';'); for(var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } var parseQueryString = function() { var str = window.location.search; var objURL = {}; str.replace( new RegExp( "([^?=&]+)(=([^&]*))?", "g" ), function( $0, $1, $2, $3 ){ objURL[ $1 ] = $3; } ); return objURL; }; function clear_dt_view() { var last_url = localStorage.getItem(name_local_storage); var params = parseQueryString(); var actual_url = window.location.pathname+"?page="+params['page']; if (last_url != actual_url) { reset_dt_view(); localStorage.setItem(name_local_storage,actual_url); } } function save_dt_view(name_local_storage,oSettings,oData) { localStorage.setItem(name_local_storage,JSON.stringify(oData)); } function load_dt_view(name_local_storage,oSettings) { return JSON.parse(localStorage.getItem(name_local_storage)); } function reset_dt_view(name_local_storage) { localStorage.removeItem(name_local_storage); } function rowCallback(row, data, index) {} function tableInit() { collapsedRows = []; $(document).find('#tableResult').show(); $(document).find(".dataTables_wrapper").hide(); $(document).find(".tableResult").hide(); } // solo l'url dell'immagine e della pagina raggruppando per pagina function getTable() { var menu_id = $(document).find('#jtable_reservedarea').attr('data-idx'); var lang = $(document).find('#box-areariservata').attr('data-lang'); var lang_id = $(document).find('#box-areariservata').attr('data-lang_id'); url = 'https://www.viniventurini.com/area/admin/includes/ajax/ajax_frontend.php?module=reservedarea&type=table&menu_id='+menu_id+'&lang=1'; url_lang = "https://www.viniventurini.com/area/modules/reservedarea/js/dataTables."+lang+".txt"; $(document).find('#jtable_reservedarea').DataTable({ "destroy": true, "sPaginationType": "full_numbers", "responsive": false, "bProcessing": true, "bServerSide": true, "bStateSave": true, "bAutoWidth": false, "order": [[ 2, 'desc' ]], "aoColumns": [ { "sTitle": "File" }, { "sTitle": "Descrizione" }, { "sTitle": "Data" }, null ], "oLanguage": { "sUrl": url_lang }, "sAjaxSource": url, "bStateSave": true, "fnStateSaveCallback": function(oSettings, oData) { save_dt_view(name_local_storage,oSettings, oData); }, "fnStateLoadCallback": function(oSettings) { return load_dt_view(name_local_storage,oSettings); }, "rowCallback": function( row, data, index ) { rowCallback(row, data, index); }, "drawCallback": function() { $(document).find('#jtable_reservedarea_wrapper').show(); $(document).find('#jtable_reservedarea').show(); } }); } var jtable_init = function() { if ($(document).find('#jtable_reservedarea').length > 0) { tableInit(); getTable(); } } $( document ).on('removeEvent.reservedareaDownload', function() { $(document).off('click', '[data-fx-download]'); $(document).off('removeEvent.reservedareaDownload'); }); $(document).on('click', '[data-fx-download]', function(){ var id = $(this).data('fx-download'); var formData = new FormData(); formData.append('id', id); $.ajax({ type: "POST", url: 'https://www.viniventurini.com/area/admin/includes/ajax/ajax_frontend.php?module=reservedarea&type=download_file', data: formData, contentType: false, // The content type used when sending data to the server. cache: false, // To unable request pages to be cached processData:false, // To send DOMDocument or non processed data file it is set to false }) .done(function(data){ datiJSON = JSON.parse(data); if (datiJSON.hasOwnProperty('file')) { var a = document.createElement("a"); if (typeof a.download === 'undefined') { window.location = datiJSON.file; } else { a.href = datiJSON.file; a.target = "_blank"; a.setAttribute('data-no-swup', ''); a.download = datiJSON.file.substring(datiJSON.file.lastIndexOf('/')+1); document.body.appendChild(a); a.click(); } } else { alert(datiJSON.error); } }) .fail(function(data) { alert("errore ajax"); }); }); loadScript("https://www.viniventurini.com/area/modules/reservedarea/js/jquery.datatable.min.js").then(function() { $('', { rel: 'stylesheet', type: 'text/css', href: 'https://www.viniventurini.com/area/modules/reservedarea/css/datatable.min.css' }).appendTo('head'); $('', { rel: 'stylesheet', type: 'text/css', href: 'https://www.viniventurini.com/area/modules/reservedarea/css/style.css' }).appendTo('head'); }); $( document ).on('click', '.reservedarea_logout', function() { $.ajax({ type: "POST", url: 'https://www.viniventurini.com/area/admin/includes/ajax/ajax_frontend.php', data: { type: "logout" }, context: this, dataType: 'text' }) .done(function(data){ init(); }); }); loadScript("https://www.viniventurini.com/area/js/vendor.js").then(function() { init(); $('document').find('#form_reservedarea_login_ajax').before(''); }); $( document ).on('submit', '#form_reservedarea_login_ajax', function (e) { e.preventDefault(); $('#alert-code-'+this.id).remove(); $('#upload_container_'+this.id).show(); var formData1 = new FormData(); $(this).find( ':input' ).each( function( index, el ) { formData1.append(el.name, el.value); } ); $.ajax({ type: "POST", url: 'https://www.viniventurini.com/area/admin/includes/ajax/ajax_frontend.php', content: this, data: formData1, // Data sent to server, a set of key/value pairs (i.e. form fields and values) contentType: false, // The content type used when sending data to the server. cache: false, // To unable request pages to be cached processData:false // To send DOMDocument or non processed data file it is set to false }) .done(function(data){ $('#upload_container_'+this.content.id).hide(); datiJSON = JSON.parse(data); // errore if (datiJSON.hasOwnProperty('error_code')) { $( this.content ).before('

'+datiJSON.error_code+'

'); $( "#alert-code-"+this.content.id )[0].scrollIntoView(); } // azione non legato a risposta positiva if (datiJSON.hasOwnProperty('action')) { init(); } }) .fail(function(data, textStatus, errorThrown) { $('#upload_container_'+this.content.id).hide(); $( this.content ).before('

Errore nell\'invio. Riprovare piĆ¹ tardi.
Comunicare all\'amministratore del sito le seguenti informazioni:
- Status: '+data.status+' '+textStatus+'
- Error: '+errorThrown+'

'); }); });