window.__div_backup = new Array(); function ajax(url_sufix, data, div) { url = url_sufix; //url = '/'+url_sufix; //window.location.hash = data; if (typeof(div) != 'object' || !(div instanceof Array) && div != '') { div = $(div); } if (div != ''){ div.html('
'); } // if (div != ''){ // // for(i = 0; i < div.length; i++) // { // marg_l = ($(div[i]).width() - 32) / 2; // marg_t = ($(div[i]).height() - 32) / 2; // window.__div_backup[i] = new Array(div[i], $(div[i]).html()); // $(div[i]).html("Ładowanie danych..."); // $(div[i]).html("
Ładowanie danych...
"); // } // } window.__url = url; window.__data = data; window.__div = div; document.body.style.cursor = 'wait'; $.ajax( { type: "POST", url: url, data: data, async: true, // dataType: "json", dataType: "html", global: false, success: function(values) { if(div.length) { // $(div).html(values); div.html(values); } else { alert('Błąd ładowania danych! Brak elementu HTML.'); } // if (!values[0]['div']) values[0]['div'] = window.__div; // openMessages(values); // $( ".home_item a, input[type='submit']" ).button(); document.body.style.cursor = 'default'; }, error: function() { console.log('AJAX error'); // restoreDivs(); document.body.style.cursor = 'default'; } }); return false; } function restoreDivs() { $.each(window.__div_backup, function(key, value) {$(value[0]).html(value[1])}); window.__div_backup = new Array(); } function openMessages(values) { if(values) { $.each(values, function(key, value) { if (value['message'] == 'go_to_location') { window.location = value['location']; } else if (value['message'] == 'restore_divs') { restoreDivs(); } else // =html { value['div'] = value['div'] + ''; $(value['div']).html(value['html']); //$(value['div']).css("opacity", 1.0); } }); } return true; } /* wstawienie danych z dodatkowych adresów dostawy wybieranych z selecta, listy itp */ function setShipmentAdresInfo(shipment_id, parent_id, form_name){ if (parent_id == undefined){ parent_id = ' '; }else{ parent_id = parent_id + ' '; } if (form_name === undefined){ form_name = 'provider'; if($('#provider_form_id').length){ form_name = 'provider'; } if($('#realize_order_box_id').length){ form_name = 'query'; } if($('#generate_order_box_id').length){ form_name = 'query'; } if($('#view_order_box_id').length){ form_name = 'query'; } } if(!$('#shipment_load_box_id').length){ return false; } $.ajax({ type: "POST", url: 'https://acad.pl/shipment/getById/id/' + shipment_id, dataType: 'json', success: function(response){ if(response.status == 'EMPTY' || response.data == null){ clearShipmentInfo(parent_id); return; } var data = response.data; var post = new Object(); post.data = data; $('#shipment_load_box_id').load('https://acad.pl/shipment/setShipmentInfo/form_name/' + form_name, post, function(){ checkShipmentInfoCorrect(parent_id); }); return; } }) } function checkShipmentInfoCorrect(parent_id){ if (parent_id == undefined){ parent_id = ' '; }else{ parent_id = parent_id + ' '; } var log = true; if ($(parent_id + '#shipment_company_name').length && $(parent_id + '#shipment_company_name').val() == ''){ log = false; $(parent_id + '#shipment_company_name').css('border', '2px solid red'); }else{ $(parent_id + '#shipment_company_name').css('border', '1px solid red'); } if ($(parent_id + '#shipment_address').length && $(parent_id + '#shipment_address').val() == ''){ log = false; $(parent_id + '#shipment_address').css('border', '2px solid red'); }else{ $(parent_id + '#shipment_address').css('border', '1px solid red'); } if ($(parent_id + '#shipment_zip_code').length && $(parent_id + '#shipment_zip_code').val() == ''){ log = false; $(parent_id + '#shipment_zip_code').css('border', '2px solid red'); }else{ $(parent_id + '#shipment_zip_code').css('border', '1px solid red'); } if ($(parent_id + '#shipment_city').length && $(parent_id + '#shipment_city').val() == ''){ log = false; $(parent_id + '#shipment_city').css('border', '2px solid red'); }else{ $(parent_id + '#shipment_city').css('border', '1px solid red'); } var html = ''; if(log){ html = '
Dane dostawy są kompletne
' }else{ html = '
Dane dostawy są nie kompletne
' } $(parent_id + '#shipment_information').html(html); } //Załadowanie listy adreesów do wysyłi dla konkretnej(mała lista) function LoadSimpleShipmentList(){ console.log('LoadSimpleShipmentList'); $('#shipment_adresses_list').html('
'); // LoadToElement('#shipment_adresses_list', 'https://acad.pl/shipment/shipmentAddressesList/order_simple_list/1', '', ''); // $('#shipment_adresses_list').html("Ładowanie danych..."); $('#shipment_adresses_list').load('https://acad.pl/shipment/shipmentAddressesList/order_simple_list/1'); } function automatic(){ $.ajax({ url: "https://acad.pl/default/automatic", data: 'data=null', dataType: 'json', success: function(response){ console.log(response,'response'); if(response.show_alert == '1'){ window.login_info_window = new BSDialog(); window.login_info_window.init('login_info_window', "Informacje",'template', "Zamknij okno"); window.login_info_window.get_content('body').html(response.alert_content); window.login_info_window.open(); } } }); }