if (typeof console == 'undefined'){
window.console = {
log:function(){},
info:function(){},
error:function(){},
warn:function(){}
}
}
function cancelUpload(file){
$('#file_upload').uploadify('cancel', file.id)
$.ajax({
url: "https://naswietlarnia.acad.pl/ftp/cancelUpload",
type: "POST",
data: {session_id: 'sj5pgidpdct12t9srbqpobgf80'},
success: function(response){
console.log(response, 'ftp/cancelUpload');
},
error: function (){}
})
}
function finishUpload(file){
$.ajax({
url: "https://naswietlarnia.acad.pl/ftp/finishUpload",
type: "POST",
data: {session_id: 'sj5pgidpdct12t9srbqpobgf80'},
success: function(response){
console.log(response, 'ftp/finishUpload');
},
error: function (){}
})
}
function unsetCurrentlyEditedOrder(){
$.ajax({
url: 'https://naswietlarnia.acad.pl/main_order/unsetCurrentlyEditedOrder',
dataType: 'json',
async: false,
success: function(response){
console.log(response, 'success');
},
error: function(){
console.log('error');
}
})
}
function beforeUnload(){
console.log(window.location.href);
console.log(window.current_location);
// alert('stop');
// var c = new String(window.current_location);
// var n = new String(window.location);
// if(c != n){
// alert('onbeforeunload: ' + window.current_location);
// }
// if(window.location != window.current_location){
// alert('onbeforeunload: ' + window.current_location);
// }
alert('onbeforeunload: ' + window.current_location);
}
function onLoad(){
window.current_location = window.location;
alert('onLoad: ' + window.current_location);
}
window.__div_backup = new Array()
function ajax(url_sufix, data, div)
{
url = url_sufix;
//url = '/'+url_sufix;
//window.location.hash = data;
console.log(div);
if (typeof(div) != 'object' || !(div instanceof Array) && div != '') {
div = new Array(div);
}
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("");
}
}
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",
global: false,
success: function(values)
{
// console.log(values, 'values');
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('error');
restoreDivs();
document.body.style.cursor = 'default';
}
});
return false;
}
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;
}
function restoreDivs()
{
$.each(window.__div_backup, function(key, value) {$(value[0]).html(value[1])});
window.__div_backup = new Array();
}
$(document).ready(function() {
});
function checkAttachedFiles(){
var attached = $('.ftp_file_list').find('.ids:checked').length;
if(!attached){
setLoadingShadow('check_attacher_files_50', 50);
window.check_attached_files_dialog = new Dialog(
'check_attached_files_dialog',
{
title: 'Informacja o dołaczeniu plików do druku',
width: 450,
close: 'check_attached_files_dialog',
on_close: 'clearLoadingShadow("check_attacher_files_50");',
close_button: false,
}
);
ajax("https://naswietlarnia.acad.pl/ftp/checkAttachedFiles", null, '#check_attached_files_dialog_content');
}else{
window.ftp_dialog.options.no_close_aftre_on_onclose = false;
window.ftp_dialog.options.on_close = '';
window.ftp_dialog.close();
clearLoadingShadow('check_attacher_files_50');
}
}
function openHelp(url, _title){
if(!window.help_dialog || !$('#help_dialog_content').length){
var help_info = '
';
window.help_dialog = new Dialog('help_dialog', { title: _title + ' ' + help_info, resizable: true, width: 400, to_right: true, margin: 10, close: 'help_dialog', background: false });
}
ajax(url, null, '#help_dialog_content');
return false;
}
function call(phone_nr, internal){
console.log(phone_nr, 'phone_nr');
if (phone_nr == '' ){
alert("Wprowadź numer telefonu");
return false;
}
phone_nr = onlyDigit(phone_nr);
// if (phone_nr == '' || (phone_nr.length != 9 && phone_nr.length != 10)){
if (phone_nr == '' || (phone_nr.length < 9 )){
alert("Wprowadź numer telefonu");
return false;
}
var url = 'https://naswietlarnia.acad.pl/telephone/call/phone_nr/' + phone_nr ;
if(internal != undefined){
url += '/internal/'+internal;
}
window.call_dialog = new Dialog('call_dialog', {title: 'Połączenie telefoniczne', width: 550, close: 'call_dialog'});
ajax(url, null, '#call_dialog_content');
return false;
}
function saveAll(ob, url, content_id, collback, lock){
if (content_id == undefined || content_id == '' ){
content_id = 'dialog_loading_id';
}
if (collback == undefined || collback == '' ){
collback = 'console.log("collback")';
}
if (lock == undefined || lock == '' ){
lock = '1';
}
setLoadingShadow()
// $('#dialog_loading_id').html('
');
var post = '';
$(ob).parent().parent().find('input[type="text"], input[type="hidden"], select').each(function(index) {
post += $(this).attr('name') + '=' + $(this).val() + '&';
});
$.ajax({
url: url,
dataType: "json",
cache: false,
data: post + 'lock=' + lock,
type: 'POST',
error: function(jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
clearLoadingShadow();
},
complete: function(response){
clearLoadingShadow();
},
success: function(response) {
var json = eval(response)
lockError(json);
$('#' + content_id).html('');
clearLoadingShadow();
// collback();
}
});
return false;
}
function sendFinishInfo(id){
setLoadingShadow();
$('#main_order_form_id').ajaxForm(
{
success: function(responseText, statusText, xhr, form){
if (statusText == 'success'){
$.ajax({
type: "POST",
url: 'https://naswietlarnia.acad.pl/main_order/sendFinishOrderInformation',
data: 'id=' + id,
dataType: "json",
success: function(values){
var json = eval(values);
if (json.status == true){
alert('Powiadomienie zostało wysłane do klienta');
}
if (json.status == false){
alert('Wystąpił błąd. Powiadomienie nie zostało wysłane do klienta');
}
clearLoadingShadow();
},
error: function(){
console.log('error');
clearLoadingShadow();
}
});
}
clearLoadingShadow();
}
}
);
$('#main_order_form_id').submit();
$('#main_order_form_id').unbind('submit').find('input:submit:not(.print_button),input:image:not(.print_button),button:submit:not(.print_button)').unbind('click');
return false;
}
function setCorrect(obj){
var arr = obj.attr('id').split('_');
var correct = '';
var parent = obj.parent().parent().attr('id');
if (obj.attr('checked')){
//ustaw
correct = arr[1];
if (obj.attr('class') == 'status_cancel'){
$('#' + parent + ' .status_finished').attr('checked', false);
}
if (obj.attr('class') == 'status_finished'){
$('#' + parent + ' .status_cancel').attr('checked', false);
}
}else{
//zdejmij
correct = '0';
}
setLoadingShadow();
$.ajax({
url: "https://naswietlarnia.acad.pl/main_order/remoteSave/id/" + arr[0],
data: obj.attr('name') + '=' + correct,
dataType: 'json',
type: 'POST',
success: function(response){
var json = eval(response)
lockError(json);
clearLoadingShadow();
if (correct == '1'){
$('#' + arr[0] + '_2' ).attr('checked', false);
}
if (correct == '2'){
$('#' + arr[0] + '_1' ).attr('checked', false);
}
},
error: function(response){
clearLoadingShadow();
}
});
}
function sendCheckboxValue(obj, reload){
if (reload == undefined){
reload = false;
}
var arr = obj.attr('id').split('_');
var value = '';
var parent = obj.parent().parent().attr('id');
if (obj.attr('checked')){
//ustaw
value = obj.val();
// value = arr[1];
}else{
//zdejmij
value = '0';
}
setLoadingShadow();
$.ajax({
url: "https://naswietlarnia.acad.pl/main_order/remoteSave/id/" + arr[0],
data: obj.attr('name') + '=' + value,
dataType: 'json',
type: 'POST',
success: function(response){
var json = eval(response)
lockError(json);
if (reload){
location.reload(true);
}
clearLoadingShadow();
},
error: function(response){
clearLoadingShadow();
}
});
}
function unlockOrder(order_id, type){
$.ajax({
url: "https://naswietlarnia.acad.pl/main_order/unlockOrder",
data: 'id=' + order_id + '&user_id=&order_type=' + type,
dataType: 'json',
success: function(response){
history.back();
}
});
}
function automatic(){
$.ajax({
url: "https://naswietlarnia.acad.pl/default/automatic",
data: 'data=null',
dataType: 'json',
success: function(response){
console.log(response,'response');
if(response.show_alert == '1'){
infoWindow("Informacje", response.alert_content, "");
}
}
});
}
function autoSession(){
$.ajax({
url: "https://naswietlarnia.acad.pl/default/autoSession",
data: 'data=null',
dataType: 'json',
success: function(response){
console.log(response,'response');
if(response.show_alert == '1'){
infoWindow("Informacje", response.alert_content, "");
}
}
});
}
//Załadowanie listy adreesów do wysyłi dla konkretnej firmy w zleceniu głównym (mała lista)
function LoadSimpleShipmentList(acad_firma_id){
$('#shipment_adresses_list').html("
");
$('#shipment_adresses_list').load('https://naswietlarnia.acad.pl/shipment/shipmentAddressesList/simple/1/action_from/main_order/acad_firma_id/' + acad_firma_id );
}
// Oznaczenie klasą wybranego adresu dla zlecenia
function setCurrentAddressClass(id){
if($('#shipment_adresses_list .order_list_of_addresses').length){
$("#shipment_adresses_list .order_list_of_addresses tr").removeClass('current_order_address');
$("#shipment_adresses_list .order_list_of_addresses #item_id_" + id).addClass('current_order_address');
}
}
/* wstawienie danyc z dodatkowych adresów dostawy wybieranych z selecta, listy itp */
function setShipmentAdresInfo(shipment_id, parent_id, form_name){
console.log('setShipmentAdresInfo');
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(!$('#shipment_load_box_id').length){
return false;
}
$.ajax({
type: "POST",
url: 'https://naswietlarnia.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;
// data.shipment_company_name = $(parent_id + '#company_name').val().replace(/"/g, '"');
$('#shipment_load_box_id').load('https://naswietlarnia.acad.pl/shipment/setShipmentInfo/form_name/' + form_name, post, function(){
checkShipmentInfoCorrect(parent_id);
//setTextShipmentInfo('#current_shipment_load_box_id');
});
// if ($(parent_id + '#shipment_company_name').length ){
// $(parent_id + '#shipment_company_name').val(data.shipment_company_name.replace(/"/g, '"'));
// }
// if ($(parent_id + '#shipment_address').length ){
// $(parent_id + '#shipment_address').val(data.shipment_address);
// }
// if ($(parent_id + '#shipment_zip_code').length ){
// $(parent_id + '#shipment_zip_code').val(data.shipment_zip_code);
// }
// if ($(parent_id + '#shipment_city').length ){
// $(parent_id + '#shipment_city').val(data.shipment_city);
// }
//
//// if ($(parent_id + '#km').length ){
//// $(parent_id + '#km').val(data.km);
//// }
//
//// if ($(parent_id + '#delivery_price').length ){
//// $(parent_id + '#delivery_price').val(data.delivery_price);
//// }
////
//// if ($(parent_id + '#courier_price').length ){
//// $(parent_id + '#courier_price').val(data.courier_price);
//// }
//
// if ($(parent_id + ' #shipment_first_name').length ){
// $(parent_id + ' #shipment_first_name').val(data.shipment_first_name);
// }
// if ($(parent_id + ' #shipment_last_name').length ){
// $(parent_id + ' #shipment_last_name').val(data.shipment_last_name);
// }
// if ($(parent_id + ' #shipment_phone').length ){
// $(parent_id + ' #shipment_phone').val(data.shipment_phone);
// }
// if ($(parent_id + ' #shipment_phone_internal').length ){
// $(parent_id + ' #shipment_phone_internal').val(data.shipment_phone_internal);
// }
// if ($(parent_id + ' #shipment_mobile').length ){
// $(parent_id + ' #shipment_mobile').val(data.shipment_mobile);
// }
// if ($(parent_id + ' #shipment_email').length ){
// $(parent_id + ' #shipment_email').val(data.shipment_email);
// }
//// if ($(parent_id + ' #shipment_work_time').length ){
//// $(parent_id + ' #shipment_work_time').val(data.shipment_work_time);
//// }
// if ($(parent_id + ' #shipment_info').length ){
// $(parent_id + ' #shipment_info').val(data.shipment_info);
// }
//
// if ($(parent_id + '#shipment_addresses_id').length ){
// $(parent_id + '#shipment_addresses_id').val(data.id);
// }
// checkShipmentInfoCorrect(parent_id);
return;
}
})
}
function checkShipmentInfoCorrect(parent_id){
console.log('checkShipmentInfoCorrect');
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 = '