app/assets/javascripts/caboose/admin_edit_order.js in caboose-cms-0.5.162 vs app/assets/javascripts/caboose/admin_edit_order.js in caboose-cms-0.5.163

- old
+ new

@@ -215,12 +215,14 @@ $('#overview_table').empty().append(table).append($('<br />')); table = $('<table/>').addClass('data').css('width', '100%'); that.order_packages_table(table); that.unassigned_line_items_table(table); - that.summary_table(table); + that.summary_table(table); $('#order_table').empty().append(table); + + that.button_controls(); }, overview_table: function() { var that = this; @@ -243,12 +245,12 @@ .append($('<td/>').html(ot.transaction_id )) .append($('<td/>').html(ot.success ? 'Success' : 'Fail')) ); }); fstatus.append(transactions_table); - } - + } + var table = $('<table/>').addClass('data'); table.append($('<tr/>') .append($('<th/>').html('Customer')) .append($('<th/>').html('Shipping Address')) .append($('<th/>').html('Billing Address')) @@ -263,31 +265,13 @@ that.refresh_order(function() { if (a.html() == 'Edit') { that.edit_customer(); a.html('Finished'); } else { that.noneditable_customer(); a.html('Edit'); } }); })) - ) - .append($('<td/>').attr('valign', 'top') - .append($('<div/>').attr('id', 'shipping_address').append(that.noneditable_shipping_address(true))) - .append($('<a/>').attr('href', '#').html('Edit').click(function(e) { - var a = $(this); - that.refresh_order(function() { - if (a.html() == 'Edit') { that.edit_shipping_address(); a.html('Finished'); } - else { that.noneditable_shipping_address(); a.html('Edit'); } - }); - })) - ) - .append($('<td/>').attr('valign', 'top') - .append($('<div/>').attr('id', 'billing_address').append(that.noneditable_billing_address(true))) - .append($('<a/>').attr('href', '#').html('Edit').click(function(e) { - var a = $(this); - that.refresh_order(function() { - if (a.html() == 'Edit') { that.edit_billing_address(); a.html('Finished'); } - else { that.noneditable_billing_address(); a.html('Edit'); } - }); - })) - ) + ) + .append($('<td/>').attr('valign', 'top').attr('id', 'shipping_address' ).append(that.noneditable_shipping_address())) + .append($('<td/>').attr('valign', 'top').attr('id', 'billing_address' ).append(that.noneditable_billing_address())) .append($('<td/>').attr('valign', 'top').append($('<div/>').attr('id', 'order_' + that.order.id + '_status'))) .append($('<td/>').attr('valign', 'top').attr('align', 'center').append(fstatus)) ); return table; }, @@ -325,23 +309,35 @@ { name: 'customer_id', nice_name: 'Customer', type: 'select', value: that.order.customer_id, width: 150, fixed_placeholder: false, options_url: '/admin/users/options' } ] }); }, - noneditable_shipping_address: function(return_element) + noneditable_shipping_address: function() { var that = this; - var sa = that.order.shipping_address; - var str = ''; - str += (sa.first_name ? sa.first_name : '[Empty first name]') + ' '; - str += (sa.last_name ? sa.last_name : '[Empty last name]'); - str += '<br />' + (sa.address1 ? sa.address1 : '[Empty address]'); - if (sa.address2) str += "<br />" + sa.address2; - str += '<br/>' + (sa.city ? sa.city : '[Empty city]') + ", " + (sa.state ? sa.state : '[Empty state]') + " " + (sa.zip ? sa.zip : '[Empty zip]'); - if (return_element) - return str; - $('#shipping_address').empty().append(str); + var div = $('<div/>'); + if (that.has_shippable_items()) + { + var sa = that.order.shipping_address; + str = ''; + str += (sa.first_name ? sa.first_name : '[Empty first name]') + ' '; + str += (sa.last_name ? sa.last_name : '[Empty last name]'); + str += '<br />' + (sa.address1 ? sa.address1 : '[Empty address]'); + if (sa.address2) str += "<br />" + sa.address2; + str += '<br/>' + (sa.city ? sa.city : '[Empty city]') + ", " + (sa.state ? sa.state : '[Empty state]') + " " + (sa.zip ? sa.zip : '[Empty zip]'); + + div.append($('<div/>').attr('id', 'shipping_address').append(str)); + div.append($('<a/>').attr('href', '#').html('Edit').click(function(e) { + var a = $(this); + that.refresh_order(function() { that.edit_shipping_address(); }); + })); + } + else + { + div.append("This order does not require shipping."); + } + return div; }, edit_shipping_address: function() { var that = this; @@ -360,11 +356,16 @@ .append($('<tr/>').append($('<td/>').append($('<table/>').append($('<tr/>') .append($('<td/>').append($('<div/>').attr('id', 'shippingaddress_' + sa.id + '_city'))) .append($('<td/>').append($('<div/>').attr('id', 'shippingaddress_' + sa.id + '_state'))) .append($('<td/>').append($('<div/>').attr('id', 'shippingaddress_' + sa.id + '_zip'))) )))); - $('#shipping_address').empty().append(table); + $('#shipping_address').empty() + .append(table) + .append($('<a/>').attr('href', '#').html('Finished').click(function(e) { + var a = $(this); + that.refresh_order(function() { $('#shipping_address').empty().append(that.noneditable_shipping_address()); }); + })); new ModelBinder({ name: 'ShippingAddress', id: sa.id, update_url: '/admin/orders/' + that.order.id + '/shipping-address', @@ -379,24 +380,31 @@ { name: 'zip' , nice_name: 'Zip' , type: 'text' , value: sa.zip , width: 60, fixed_placeholder: false } ] }); }, - noneditable_billing_address: function(return_element) + noneditable_billing_address: function() { var that = this; + var sa = that.order.billing_address; if (!sa) sa = {}; var str = ''; str += (sa.first_name ? sa.first_name : '[Empty first name]') + ' '; str += (sa.last_name ? sa.last_name : '[Empty last name]'); str += '<br />' + (sa.address1 ? sa.address1 : '[Empty address]'); if (sa.address2) str += "<br />" + sa.address2; str += '<br/>' + (sa.city ? sa.city : '[Empty city]') + ", " + (sa.state ? sa.state : '[Empty state]') + " " + (sa.zip ? sa.zip : '[Empty zip]'); - if (return_element) - return str; - $('#billing_address').empty().append(str); + + var div = $('<div/>') + .append(str) + .append("<br />") + .append($('<a/>').attr('href', '#').html('Edit').click(function(e) { + var a = $(this); + that.refresh_order(function() { that.edit_billing_address(); }); + })); + return div; }, edit_billing_address: function() { var that = this; @@ -416,11 +424,16 @@ .append($('<tr/>').append($('<td/>').append($('<table/>').append($('<tr/>') .append($('<td/>').append($('<div/>').attr('id', 'billingaddress_' + sa.id + '_city'))) .append($('<td/>').append($('<div/>').attr('id', 'billingaddress_' + sa.id + '_state'))) .append($('<td/>').append($('<div/>').attr('id', 'billingaddress_' + sa.id + '_zip'))) )))); - $('#billing_address').empty().append(table); + $('#billing_address').empty() + .append(table) + .append($('<a/>').attr('href', '#').html('Finished').click(function(e) { + var a = $(this); + that.refresh_order(function() { $('#billing_address').empty().append(that.noneditable_billing_address()); }); + })); new ModelBinder({ name: 'BillingAddress', id: sa.id, update_url: '/admin/orders/' + that.order.id + '/billing-address', @@ -591,25 +604,34 @@ table.append($('<tr/>') .append($('<th/>').html('Package' )) .append($('<th/>').html('Item' )) .append($('<th/>').html('Status' )) - .append($('<th/>').html('Unit Price1' )) + .append($('<th/>').html('Unit Price' )) .append($('<th/>').html('Quantity' )) .append($('<th/>').html('Subtotal' )) ); $.each(that.order.line_items, function(i, li) { if (li.order_package_id && li.order_package_id != -1) return true; - var div = $('<div/>').attr('id', 'assign_to_package_' + li.id) - .append('Unpackaged! ') - .append($('<a/>').data('line_item_id', li.id).attr('href', '#').html('Assign to package').click(function(e) { - e.preventDefault(); - e.stopPropagation(); - that.assign_to_package_form($(this).data('line_item_id')); - })); + var div = false; + + if (li.variant.downloadable) + { + div = $('<div/>').append('This item is downloadable.'); + } + else + { + div = $('<div/>').attr('id', 'assign_to_package_' + li.id) + .append('Unpackaged! ') + .append($('<a/>').data('line_item_id', li.id).attr('href', '#').html('Assign to package').click(function(e) { + e.preventDefault(); + e.stopPropagation(); + that.assign_to_package_form($(this).data('line_item_id')); + })); + } var tr = $('<tr/>'); tr.append($('<td/>').append(div)); tr.append($('<td/>') .append(that.line_item_link(li)) @@ -643,11 +665,11 @@ { $.each(that.order.discounts, function(i, d) { table.append($('<tr/>') .append($('<td/>').attr('colspan', '5').attr('align', 'right') .append($('<a/>').attr('href', '#').html('Remove').click(function(e) { that.remove_discount(d.id); })) - .append(' ' + d.name + ' Discount') + .append(' "' + d.gift_card.code + '" Discount') ) .append($('<td/>').attr('align', 'right').html(curr(d.amount))) ); }); } @@ -666,10 +688,39 @@ ) )); } }, + button_controls: function() + { + var that = this; + var p = $('<p/>'); + p.append($('<input/>').attr('type', 'button').val('< Back').click(function() { window.location = '/admin/orders'; })).append(' '); + if (that.order.total > 0) + { + switch (that.order.financial_status) + { + case 'pending': + p.append($('<input/>').attr('type', 'button').val('Send for Authorization').click(function() { that.send_for_authorization(); })).append(' '); + break; + case 'authorized': + p.append($('<input/>').attr('type', 'button').val('Capture Funds').click(function() { that.capture_funds(); })).append(' '); + p.append($('<input/>').attr('type', 'button').val('Void' ).click(function() { that.void_order(); })).append(' '); + break; + case 'captured': + p.append($('<input/>').attr('type', 'button').val('Refund' ).click(function() { that.refund(); })).append(' '); + break; + } + } + //p.append($('<input/>').attr('type', 'button').val('Resend Confirmation' ).click(function() { that.resend_confirmation(); })).append(' '); + p.append($('<input/>').attr('type', 'button').val('Add Item' ).click(function() { that.add_variant(); })).append(' '); + p.append($('<input/>').attr('type', 'button').val('Print Order' ).click(function() { that.print_order(); })).append(' '); + $('#controls').empty().append(p); + }, + + /****************************************************************************/ + add_variant: function(variant_id) { var that = this; if (!variant_id) { @@ -757,11 +808,46 @@ if (resp.error) $('#message').html("<p class='note error'>" + resp.error + "</p>"); if (resp.success) { $('#message').empty(); that.refresh(); } if (resp.refresh) { $('#message').empty(); that.refresh(); } } }); - } - + }, + + send_for_authorization: function(confirm) + { + var that = this; + if (!confirm) + { + var p = $('<p/>').addClass('note confirm') + .append("Are you sure you want to send this order to the customer for authorization? ") + .append($('<input/>').attr('type','button').val('Yes').click(function() { that.send_for_authorization(true); })) + .append(' ') + .append($('<input/>').attr('type','button').val('No').click(function() { $('#message').empty(); })); + $('#message').empty().append(p); + return; + } + $('#message').html("<p class='loading'>Sending for authorization...</p>"); + $.ajax({ + url: '/admin/orders/' + that.order.id + '/send-for-authorization', + success: function(resp) { + if (resp.error) $('#message').html("<p class='note error'>" + resp.error + "</p>"); + if (resp.success) { $('#message').empty(); that.refresh(); } + if (resp.refresh) { $('#message').empty(); that.refresh(); } + } + }); + }, + + has_shippable_items: function() + { + var that = this; + var needs_shipping = false; + $.each(that.order.line_items, function(i, li) { + if (li.variant.downloadable == false) + needs_shipping = true; + }); + return needs_shipping; + }, + //resend_confirmation: function(order_id) //{ // modal.autosize("<p class='loading'>Resending confirmation..</p>"); // $.ajax({ // type: 'post', \ No newline at end of file