$(document).ready(function () { all_customers(); }); function all_customers() { $('#customerList table thead td').click(function() { $('#filterF .page').val(1); if ($(this).attr('id') == 'action') return; cl = $('#customerList'); order = $(this).attr('order'); if (order == 'asc') { $(this).parent().children().attr('order', '').removeClass('desc').removeClass('asc'); $(this).attr('order', 'desc').addClass('desc'); order = 'desc'; } else { $(this).parent().children().attr('order', '').removeClass('desc').removeClass('asc'); $(this).attr('order', 'asc').addClass('asc'); order = 'asc'; } $('#disabler').css('top', 0).css('left', 0).width(cl.width()).height(cl.height()); $('#disabler').fadeIn('fast'); $.get('http://track.acshipping.com/updater.php', { id: 'customers', order: $(this).attr('id'), way: order, filter: $('#filterF').serializeArray() }, function(data) { $('#customerList table.list tbody').replaceWith(data); $('#disabler').fadeOut(); reloadCustomer(); }); }); $('#customerList #filterF #clear').click(function() { $('#customerList table thead td').attr('order', '').removeClass('desc').removeClass('asc'); $('#filterF').find(':input').val(''); $('#filterF #isFiltered').val('0'); cl = $('#customerList'); $('#disabler').css('top', 0).css('left', 0).width(cl.width()).height(cl.height()); $('#disabler').fadeIn('fast'); $.get('http://track.acshipping.com/updater.php', { id: 'customers', filter: $('#filterF').serializeArray() }, function(data) { $('#customerList table.list tbody').replaceWith(data); $('#disabler').fadeOut(); reloadCustomer(); }); }); $('#customerList #filterF #filter').click(function() { $('#customerList table thead td').attr('order', '').removeClass('desc').removeClass('asc'); $('#filterF #isFiltered').val('1'); cl = $('#customerList'); $('#disabler').css('top', 0).css('left', 0).width(cl.width()).height(cl.height()); $('#disabler').fadeIn('fast'); $('#filterF input[name=page]').val(0); $.get('http://track.acshipping.com/updater.php', { id: 'customers', filter: $('#filterF').serializeArray() }, function(data) { $('#customerList table.list tbody').replaceWith(data); $('#disabler').fadeOut(); reloadCustomer(); }); }); $('#settingsF #submit').click(function() { cl = $('#settingsDIV'); $('#disabler').css('top', 0).css('left', 0).width(cl.width()).height(cl.height()); $('#disabler').fadeIn('fast'); $.ajax({ type: 'POST', url: 'http://track.acshipping.com/updater.php', data: 'id=settings&'+$('#settingsF').serialize(), success: function(msg) { $('#disabler').fadeOut(); } }); }); $('#registerContainer #register').click(function() { cl = $('#registerContainer'); $('#disabler').css('top', 0).css('left', 0).width(cl.width()).height(cl.height()); $('#disabler').fadeIn('fast'); $('.feedback').slideUp('fast', function() { $('.feedback').children().remove(); $('#registerF input').css('background-color', '#FFFFFF'); $.ajax({ type: 'POST', url: 'http://track.acshipping.com/updater.php', data: 'id=register&'+$('#registerF').serialize(), success: function(msg) { if (msg == 'OK') { $('
Your registration is successfull. Service operator will contact you by email or phone you have provided.
').appendTo($('.feedback')); } else if (msg == 'SECURITY') { $('
Security code you entered is not correct.
').appendTo($('.feedback')); $('#security').css('background-color', '#FFAAAA'); } else if (msg.substring(0, 6) == 'EMPTY ') { $('
Some fields are empty.
').appendTo($('.feedback')); $('#secImg').attr('src', 'http://track.acshipping.com/images/CaptchaSecurityImages.php'); $('#security').val(''); a = msg.split(" "); $.each(a, function() { $('#registerF input[name='+this+']').css('background-color', '#FFAAAA'); }); } else { $('
Error occured
').appendTo('.feedback'); } $('.feedback').slideDown(); $('#disabler').fadeOut(); } }); }); }); $('#registerF #selectType').change(function() { if ($('#registerF #selectType').val() == 'person') { $('input.person').attr('disabled', false); $('input.firm').attr('disabled', true); } else { $('input.person').attr('disabled', true); $('input.firm').attr('disabled', false); } }); viewCustomer(); editCustomer(); pageCustomer(); newCustomer(); removeCustomer(); } function viewCustomer() { $('#customerList table tbody a.view').click(function() { id = $(this).attr('nr'); cl = $('#customerList'); $('#disabler').css('top', 0).css('left', 0).width(cl.width()).height(cl.height()); $('#disabler').fadeIn('fast'); $.get('http://track.acshipping.com/updater.php', { id: 'viewcustomer', nr: id }, function(data) { $(data).appendTo('#customerList'); $('#viewCustomer').fadeIn('fast'); $('#viewCustomer').css('top', 0).css('left', 0); if ($('#customerList').height() < $('#viewCustomer').height()) { $('#customerList').height($('#viewCustomer').height()); } $('#viewCustomer a.close').click(function() { $('#viewCustomer').fadeOut(function(){$('#viewCustomer').remove(); $('#disabler').fadeOut();}); $('#customerList').attr('style', ''); }); updateHeight(); }); }); } function editCustomer() { $('#customerList table tbody a.edit').click(function() { iii = '#editCustomerF input[name='; id = $(this).attr('nr'); cl = $('#customerList'); $('#disabler').css('top', 0).css('left', 0).width(cl.width()).height(cl.height()); $('#disabler').fadeIn('fast'); $.get('http://track.acshipping.com/updater.php', { id: 'editcustomer', nr: id }, function(data) { $(data).appendTo('#customerList'); $('#editCustomer').fadeIn('fast'); $('#editCustomer').css('top', 0).css('left', 0); if ($('#customerList').height() < $('#editCustomer').height()) { $('#customerList').height($('#editCustomer').height()); } $('#editCustomer a.cancel').click(function() { $('#editCustomer').fadeOut(function(){$('#editCustomer').remove(); $('#disabler').fadeOut();}); $('#customerList').attr('style', ''); }); updateHeight(); $('#editCustomer a.savePers').click(function() { $('#editCustomer div.feedback').slideUp(function() {$('#editCustomer div.feedback').children().remove(); }); $.ajax({ type: 'GET', url: 'http://track.acshipping.com/updater.php', data: 'id=saveperson&nr='+id+'&save=yes&name='+$('#editCustomerF input[name=name]').val()+ '&surname='+$('#editCustomerF input[name=surname]').val()+ '&dateofbirth='+$('#editCustomerF input[name=birthdate]').val()+ '&code='+$('#editCustomerF input[name=code]').val()+ '&short_name='+$('#editCustomerF input[name=short_name]').val(), success: function(data) { if (data == "OK") { $('
Info successfully saved.
').appendTo('#editCustomer div.feedback'); $('#customerList').attr('style', ''); return; } if (data == "EMPTY") { $('
There are empty fields left.
').appendTo('#editCustomer div.feedback'); $('#editCustomer div.feedback').slideDown(); return; } if (data == "ERR") { $('
There was an error.
').appendTo('#editCustomer div.feedback'); $('#editCustomer div.feedback').slideDown(); return; } updateHeight(); } }); }); }); }); } function reloadCustomer() { viewCustomer(); editCustomer(); pageCustomer(); removeCustomer(); getCustomerInformation(); load_cust(); } function pageCustomer() { $('#customerPage .page').click(function () { $('#filterF .page').val($(this).attr('nr')); order = ''; orderby = $('#customerList table thead td[order="asc"]').attr('id'); if (orderby != null) order = 'asc'; else { orderby = $('#customerList table thead td[order="desc"]').attr('id'); if (orderby != null) order = 'desc'; } cl = $('#customerList'); $('#disabler').css('top', 0).css('left', 0).width(cl.width()).height(cl.height()); $('#disabler').fadeIn('fast'); $.get('http://track.acshipping.com/updater.php', { id: 'customers', order: orderby, way: order, filter: $('#filterF').serializeArray() }, function(data) { $('#customerList table.list tbody').replaceWith(data); $('#disabler').fadeOut(); reloadCustomer(); }); }); } function newCustomer() { $('#customerList a#newCust').click(function() { cl = $('#customerList'); $('#disabler').css('top', 0).css('left', 0).width(cl.width()).height(cl.height()); $('#disabler').fadeIn('fast'); $.ajax({ type: 'GET', url: 'http://track.acshipping.com/updater.php', data: 'id=newcustomer', success: function(data) { $(data).appendTo('#customerList'); $('#newCustomer').css('top', 0).css('left', 0); $('#newCustomer').fadeIn(); $('#newCustomer #cancel').click(function() { $('#newCustomer').fadeOut(function() { $('#newCustomer').remove(); $('#disabler').fadeOut('fast'); updateHeight(); }); }); updateHeight(); $('#newCustomer #register').click(function() { cl = $('#newCustomer'); $('#newCustDisabler').css('top', 0).css('left', 0).width(cl.width()).height(cl.height()); $('#newCustDisabler').fadeIn('fast'); $('#newCustomer .feedback').slideUp('fast', function() { $('#newCustomer .feedback').children().remove(); $('#newCustomerF input').css('background-color', '#FFFFFF'); $.ajax({ type: 'POST', url: 'http://track.acshipping.com/updater.php', data: 'id=register&'+$('#newCustomerF').serialize(), success: function(msg) { if (msg == 'OK') { $('
Customer successfully created.
').appendTo($('#customerList .feedback')); $('#customerList .feedback').slideDown(); $('#newCustomer').fadeOut('fast', function() { $('#newCustomer').remove(); $('#disabler').fadeOut(); }); } else if (msg.substring(0, 6) == 'EMPTY ') { $('
Some fields are empty.
').appendTo($('#newCustomer .feedback')); a = msg.split(" "); $.each(a, function() { $('#registerF input[name='+this+']').css('background-color', '#FFAAAA'); }); $('#newCustomer .feedback').slideDown(); } else { $('
Error occured
').appendTo('#newCustomer .feedback'); $('#newCustomer .feedback').slideDown(); } $('#newCustDisabler').fadeOut(); updateHeight(); } }); }); }); $('#newCustomer #selectType').change(function() { if ($('#newCustomerF #selectType').val() == 'person') { $('input.person').attr('disabled', false); $('input.firm').attr('disabled', true); } else { $('input.person').attr('disabled', true); $('input.firm').attr('disabled', false); } updateHeight(); }); } }); }); } function removeCustomer() { $('#customerList .remove').click(function() { nr = $(this).attr('nr'); line = $(this).parent().parent(); c = confirm('Do you really want to remove this customer?'); if (c) { $('#customerList .feedback').slideUp('fast', function() { $('#customerList .feedback').children().remove(); $.ajax({ type: 'POST', url: 'http://track.acshipping.com/updater.php', data: 'id=removecustomer&nr='+nr, success: function (data) { if (data == 'OK') { $('
Customer was removed successfully.
').appendTo('#customerList .feedback'); $('#customerList .feedback').slideDown(); line.fadeOut(); } else if (data == 'USED') { $('
Customer cannot be removed because it is used in invoices.
').appendTo('#customerList .feedback'); $('#customerList .feedback').slideDown(); } else { $('
Unknown error occured
').appendTo('#customerList .feedback'); $('#customerList .feedback').slideDown(); } } }); }); } }); }