/***************************************************************** * file: remote.js * * Abundatrade calculator communication and processing scripts. * Handles the AJAX calls to the Abundatrade server. * *****************************************************************/ /* jQuery('td:contains("024543525998")').parent() .find('td') .wrapInner('
') .parent() .find('td > div') .slideUp("slow", function(){ jQuery(this).parent().parent().remove(); }); ^^ Hides a row ^^ jQuery('#my_table > tbody > tr') .find('td') .wrapInner('') .parent() .find('td > div') .slideDown("slow", function(){ var $set = jQuery(this); $set.replaceWith($set.contents()); ^^ adds a row ^^ }); */ /** * The number of items [defunct] */ var number_item = 1; /** * A list of items to clean up */ var itemsToDispose = []; /* * function: clear_product_code() * * Format the product code with alphanumerics only. * */ function clean_product_code(element) { element.value = element.value.replace(/\W+/g, ""); } /* * function: validateEmail() * * prevalidates an email address * */ function validateEmail(email, confirm) { if (email.toLowerCase() == confirm.toLowerCase()) { var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(email); } else return 'nomatch'; } /* * function: clear_session() * * Clear out all data for this session, including prior saved data. * Request goes to the backend to clear data. * */ function clear_session(obj) { if (!jQuery(obj).hasClass('disabled')) { jQuery.prompt( 'Are you sure you want to delete the entire listing?', { buttons: { Delete: true, Cancel: false }, callback: function (v, m, f) { if (v) { var request = jQuery.ajax( { type: 'GET', url: 'http://' + abundacalc.server + '/trade/process/request.php', data: 'action=clear_session', dataType: 'jsonp' }); request.done(function (data) { //jQuery('#abundaCalcTbl > tbody').children().remove(); jQuery('#abundaCalcBody_request').children().remove(); data.total_qty = "0.00"; data.currency_for_total = "$"; data.total = "0.00"; display_totals(data); }); request.fail(function (jqXHR, textStatus, errorThrown) { alert("Request failed: " + textStatus + " - " + errorThrown); }); } } } ); } number_item = 1; } /* * function: new_session() * * Give user a new session id. This detaches any prior connection to the backend data. * */ function new_session(this_link) { number_item = 1; var request = jQuery.ajax( { type: 'GET', url: 'http://' + abundacalc.server + '/trade/process/request.php', data: 'action=new_session', dataType: 'jsonp' }); request.done(function (data) { }); request.fail(function (jqXHR, textStatus, errorThrown) { //alert("Request failed: " + textStatus + " - " + errorThrown); please_wait(false); }); } /* * function: display_totals() * * Render the header/footer totals from JSONP data. * */ function display_totals(data) { jQuery('#product_code').val(''); jQuery('#item_count').html(data.total_qty); jQuery('#total_item_count').html(data.total_qty); jQuery('#grand_total').html(data.currency_for_total + data.total); jQuery('#total_prevaluation').html(data.currency_for_total + data.total); // Turn off the UI Lock // please_wait(false); // Enable/Disable Submit based on Total Qty // if (jQuery('#total_item_count').text() > 0) { jQuery('#submitList').removeClass('disabled'); jQuery('#submitList').removeAttr('style'); } else { jQuery('#submitList').addClass('disabled'); jQuery('#submitList').attr('style', 'cursor:default'); } // Set the delete button // jQuery('.delete_this_row').attr('onclick', 'delete_the_row(this); return false;'); jQuery('#product_qty').val('1'); jQuery('#product_code').focus(); } /** * Opens the bulk upload bin real pretty like */ function bulk_open() { //do accordian stuff jQuery("#bulk_button").slideUp(1000); jQuery("#abundaCalcTbl").fadeOut(400).delay(100); jQuery("#second_content").slideUp(500); jQuery("#top_input_section").fadeOut(500); jQuery("#bulk").slideDown(500); } /* Closes the bulk upload bin and reloads the session */ function bulk_close_window() { jQuery("#bulk").slideUp(500); jQuery("#top_input_section").fadeIn(500); jQuery("#second_content").slideDown(500); jQuery("#abundaCalcTbl").delay(100).fadeIn(400); jQuery("#bulk_button").slideDown(1000); load_previous_session(false); } /** Gets the rows for the bulk upload bin */ function rows() { var lines; var TA = jQuery("#bulk_upload").val(); if (document.all) { // IE lines = TA.split("\r\n"); } else { //Mozilla lines = TA.split("\n"); } return lines; } /** The bulk upload final page for submission */ var bulk_final = "
Getting information ...
", buttons: {}} }); /*jQuery('#abunda_please_wait').show(); jQuery('#lookupItem').addClass('disabled'); jQuery('#submitList').addClass('disabled'); jQuery('#delete_all_top').addClass('disabled'); jQuery('#delete_all_bottom').addClass('disabled'); jQuery('.delete_this_row').addClass('disabled');*/ // Go,Go,Go... // } else { //jQuery.prompt.close(); } } /** A regular submission final page */ var regular_display = "Sending your trade request and locking in your quote!
Give our pecking pigeons a second

The values shown on the calculator are a pre-valuation.
Item quality needs to be verified for final valuation.
This valuation is not a commitment.
All data is kept private.
', buttons: [{ title: 'Back', value: -1 }, { title: 'Cancel', value: 0 }, { title: 'Agree and Submit', value: 'submit'}], focus: 2, submit: function (ev, but, message, val) { if (but == "submit") { jQuery.prompt.goToState('finish'); callback_to_submit(val); return false; } if (but != 0) { if (val['scanner'] == 'on') { state += but; } else if (but == -1) { state -= 2; } else { state += but; } jQuery.prompt.goToState('state' + state); return false; } else { jQuery.prompt.close(); } } }, invalid: { html: 'Please enter a valid email address.
', buttons: { OK: true }, focus: 0, submit: function (v, m, f) { jQuery.prompt.goToState('state0'); return false; } }, nomatch: { html: 'Please check your email address to make sure it is correct.
', buttons: { OK: true }, focus: 0, submit: function (v, m, f) { jQuery.prompt.goToState('state0'); return false; } }, finish: { html: final_display, buttons: {} } }; var str = ''; jQuery.prompt(states, { callback: function (ev, v, m, f) { if (v) { } else { please_wait(false); } } }); } /* * function: submit_the_list() * * Submit The List via AJAX request. * */ function submit_the_list(obj) { if (!jQuery(obj).hasClass('disabled') && (jQuery('#total_item_count').text() > 0)) { submit_modal(submit_my_list, regular_display); } } /** Submission of a list done the old fashioned way via jsonp */ function submit_my_list(f) { str = ""; jQuery.each(f, function (i, obj) { str += '&' + i + '=' + obj; }); var request = jQuery.ajax( { type: 'GET', url: 'http://' + abundacalc.server + '/trade/process/submit.php', data: 'action=submit_list' + str, dataType: 'jsonp' }); request.done(function (data) { // No errors // if (data.error == '') { jQuery('#abundaCalcTbl > tbody').children().remove(); display_totals(data); //jQuery.prompt('Your list has been received.No Abunda Value
" : "") + (row.overstocked == true ? "Over Stocked Item" : "") + "
