$(document).ready(function () { all_motos(); }); function all_motos() { $('#motosList table thead td').click(function() { $('#filterF .page').val(1); if ($(this).attr('id') == 'action') return; if ($(this).attr('id') == 'invoices') return; cl = $('#motosList'); 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: 'motos', order: $(this).attr('id'), way: order, filter: $('#filterF').serializeArray() }, function(data) { $('#motosList table.list tbody').replaceWith(data); $('#disabler').fadeOut(); reloadMoto(); }); }); $('#motosList #filterF #clear').click(function() { $('#motosList table thead td').attr('order', '').removeClass('desc').removeClass('asc'); $('#filterF').find(':input').val(''); $('#filterF #isFiltered').val('0'); cl = $('#motosList'); $('#disabler').css('top', 0).css('left', 0).width(cl.width()).height(cl.height()); $('#disabler').fadeIn('fast'); $.get('http://track.acshipping.com/updater.php', { id: 'motos', filter: $('#filterF').serializeArray() }, function(data) { $('#motosList table.list tbody').replaceWith(data); $('#disabler').fadeOut(); reloadMoto(); }); }); $('#motosList #filterF #filter').click(function() { $('#motosList table thead td').attr('order', '').removeClass('desc').removeClass('asc'); $('#filterF #isFiltered').val('1'); cl = $('#motosList'); $('#disabler').css('top', 0).css('left', 0).width(cl.width()).height(cl.height()); $('#disabler').fadeIn('fast'); $.get('http://track.acshipping.com/updater.php', { id: 'motos', filter: $('#filterF').serializeArray() }, function(data) { $('#motosList table.list tbody').replaceWith(data); $('#disabler').fadeOut(); reloadMoto(); }); }); $('#newMoto #submit').click(function() { $.ajax({ type: 'GET', url: 'http://track.acshipping.com/updater.php', data: 'id=newmoto&'+$('#newMotoF').serialize(), success: function(msg) { alert(msg); } }); }); $('#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(); } }); }); viewMoto(); editMoto(); pageMoto(); newMoto(); invoiceViewMoto(); removeMoto(); } function viewMoto() { $('#motosList table tbody a.view').click(function() { id = $(this).attr('nr'); cl = $('#motosList'); $('#disabler').css('top', 0).css('left', 0).width(cl.width()).height(cl.height()); $('#disabler').fadeIn('fast'); $.get('http://track.acshipping.com/updater.php', { id: 'viewmoto', nr: id }, function(data) { $(data).appendTo('#motosList'); $('#viewMoto').fadeIn('fast'); $('#viewMoto').css('top', 0).css('left', 0); $('#viewMoto a.close').click(function() { $('#viewMoto').fadeOut(function(){$('#viewMoto').remove(); $('#disabler').fadeOut();}); }); }); }); } function editMoto() { $('#motosList table tbody a.edit').click(function() { iii = '#editMotoF input[name='; id = $(this).attr('nr'); cl = $('#motosList'); $('#disabler').css('top', 0).css('left', 0).width(cl.width()).height(cl.height()); $('#disabler').fadeIn('fast'); $.get('http://track.acshipping.com/updater.php', { id: 'editmoto', nr: id }, function(data) { $(data).appendTo('#motosList'); $('#editMoto').fadeIn('fast'); $('#editMoto').css('top', 0).css('left', 0); $('#editMoto a.cancel').click(function() { $('#editMoto').fadeOut(function(){$('#editMoto').remove(); $('#disabler').fadeOut();}); }); $('#editMoto a.save').click(function() { $('#editMoto div.feedback').slideUp(function() {$('#editMoto div.feedback').children().remove(); $.ajax({ type: 'GET', url: 'http://track.acshipping.com/updater.php', data: 'id=editmoto&nr='+id+'&save=yes&'+$('#editMotoF').serialize(), success: function(data) { if (data == "OK") { $('
Information successfully saved. Redo your search to see the changes.
').appendTo($('#motosList .feedback')); $('#editMoto').fadeOut(function(){ $('#editMoto').remove(); $('#disabler').fadeOut(); }); $('#motosList .feedback').slideDown(); return; } if (data.substring(0, 6) == "EMPTY ") { $('
There are empty fields left.
').appendTo('#editMoto div.feedback'); $('#editMoto div.feedback').slideDown(); return; } if (data == "ERR") { $('
There was an error.
').appendTo('#editMoto div.feedback'); $('#editMoto div.feedback').slideDown(); return; } } }); }); }); }); }); } function newMoto() { $('#motosList #new').click(function() { cl = $('#motosList'); $('#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=newmoto', success: function(data) { $(data).appendTo('#motosList'); updateHeight(); $('#newMoto').css('top', 0).css('left', 0); $('#newMoto').fadeIn('fast'); $('#newMoto a.cancel').click(function() { $('#newMoto').fadeOut(function(){$('#newMoto').remove(); $('#disabler').fadeOut();}); }); $('#newMoto a.submit').click(function() { $('#newMotoF input').css('background-color', '#FFFFFF'); $('#newMoto div.feedback').slideUp(function() {$('#newMoto div.feedback').children().remove(); $.ajax({ type: 'GET', url: 'http://track.acshipping.com/updater.php', data: 'id=newmoto&'+$('#newMotoF').serialize(), success: function(data) { if (data == 'OK') { $('
New Moto has been successfully created. Click "Filter" to see your new moto in your search.
').appendTo($('#motosList .feedback')); $('#newMoto').fadeOut(function() { $('#disabler').fadeOut(); $('#filterF .vin').val($('#newMotoF .vin').val()); $('#newMoto').remove(); }); $('#motosList .feedback').slideDown(); } else if (data == 'VINERR') { $('
A moto with VIN '+$('#newMotoF .vin').val()+' has already been registered. Please use the filter to find it.
').appendTo($('#newMoto .feedback')); $('#newMoto .feedback').slideDown(); } else if (data.substring(0, 6) == 'EMPTY ') { $('
Some fields are empty.
').appendTo($('#newMoto .feedback')); a = data.split(" "); $.each(a, function() { $('#newMotoF input[name='+this+']').css('background-color', '#FFAAAA'); }); $('#newMoto .feedback').slideDown(); } updateHeight(); } }); }); }); } }); }); } function reloadMoto() { viewMoto(); editMoto(); pageMoto(); load_select('motos'); invoiceViewMoto(); removeMoto(); } function pageMoto() { $('#motosPage .page').click(function () { $('#filterF .page').val($(this).attr('nr')); order = ''; orderby = $('#motosList table thead td[order="asc"]').attr('id'); if (orderby != null) order = 'asc'; else { orderby = $('#motosList table thead td[order="desc"]').attr('id'); if (orderby != null) order = 'desc'; } cl = $('#motosList'); $('#disabler').css('top', 0).css('left', 0).width(cl.width()).height(cl.height()); $('#disabler').fadeIn('fast'); $.get('http://track.acshipping.com/updater.php', { id: 'motos', order: orderby, way: order, filter: $('#filterF').serializeArray() }, function(data) { $('#motosList table.list tbody').replaceWith(data); $('#disabler').fadeOut(); reloadMoto(); }); }); } function invoiceViewMoto() { $('#motosList a.viewInvoice').click(function() { cl = $('#motosList'); $('#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=viewinvoice&nr='+$(this).attr('nr'), success: function(data) { $(data).appendTo('#motosList'); $('#viewInvoice').css('top', 0).css('left', 0); $('#viewInvoice').fadeIn('fast'); if ($('#motosList').height() < $('#viewInvoice').height()) { $('#motosList').height($('#viewInvoice').height()); } $('#viewInvoice a.closeInvoice').click(function() { $('#viewInvoice').fadeOut('fast', function() { $('#viewInvoice').remove(); $('#disabler').fadeOut(); $('#motosList').attr('style', ''); }); }); $('#viewInvoice a.upload').click(function() { addUpload(); }); } }); }); } function removeMoto() { $('#motosList .remove').click(function() { nr = $(this).attr('nr'); line = $(this).parent().parent(); c = confirm('Do you really want to remove this moto?'); if (c) { $('#motosList .feedback').slideUp('fast', function() { $('#motosList .feedback').children().remove(); $.ajax({ type: 'POST', url: 'http://track.acshipping.com/updater.php', data: 'id=removemoto&nr='+nr, success: function (data) { if (data == 'OK') { $('
Moto was removed successfully.
').appendTo('#motosList .feedback'); $('#motosList .feedback').slideDown(); line.fadeOut(); } else if (data == 'USED') { $('
Moto cannot be removed because it is used in invoices.
').appendTo('#motosList .feedback'); $('#motosList .feedback').slideDown(); } else { $('
Unknown error occured
').appendTo('#motosList .feedback'); $('#motosList .feedback').slideDown(); } } }); }); } }); }