caboose-cms 0.5.162 → 0.5.163

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzQ0ZGYxZDUzOWE3ODliMGRmYWM4ZGMwN2E1ZjY2ZjlhMDI5MDMzMg==
4
+ MzljZTYxYTU2ZTZmY2QwMzMwNjE0YTY0NzQzNzc5N2FjNmJlZjE3Yw==
5
5
  data.tar.gz: !binary |-
6
- MDhlNmIwZWE3Njc4NDk1MDgwYjlkNjhlZTU5YzJjN2EwYWUxZDA4Ng==
6
+ ZWUzZDNkNWQ4MGZhNzk3NTMzYjgzZDNiZmJjMzk0ZmNjNDkzMTRjYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDMyY2RjNWNjOWQ4MTFhYzc2YzFhM2EyMjEwZjhhOTFhZjI3YTAwOGQzYzFm
10
- M2E1OWY2NzQzZTIxN2U4YjAzNmFlYTY1ODViYTA5ZGU2ZTQ1MWQ1ODgxMmYz
11
- Zjg0ODhlZGY5ZWY2YzNmOGU4ZmNjMDU3YzRiNjBhNGM5YjRhMzI=
9
+ YzhiN2FjNjEwZDExNmE5YTczMjQ2OTRhMGVjNWQwNDEyMjIwNWRiOWYwMDk1
10
+ ZDI0Yzg1MzUyZGYxZTYyMDAyYTdlMDg3MWE5NGYxYTNjM2Y2MTQ4YzEyNTll
11
+ NTVkYWEzODNkMzU4YzQ4YjVjYjM1ZTc1MjQyYzRjMjc4MDE3MDY=
12
12
  data.tar.gz: !binary |-
13
- NzhlYjYxYjQ5NjRkYWVkODJmYzljMWMyMGZkOWExNmQ4NmQ0ZGVmNWJmZGI2
14
- ODczYTNjNjliZjM4OWFiYTQ4YmQ5MjRhMTg5ZWU4MDA2MDQxMjU0Y2NhMThl
15
- N2IzNjVmM2FhOTU4ODdiODcxNzUyNzY3YjM5YWQ5MmZhMjdiMTc=
13
+ ZjE1OWU3Nzg2ZDQ3ZWJkMjU4MmVjZjQ1MGEyZTQ0MWYyMTJhNzc1Y2Y4ODU2
14
+ YTgxMGU0NzhhNzRhMmY3MWFlODYwNjk4NGExODYwMmNjMDFiOTFiMGZkY2Q1
15
+ ZDQwNTU1NTU3MDZhN2FiNzNmYTViODFlY2E0MTNjZTFiZDU1NTc=
@@ -217,8 +217,10 @@ OrderController.prototype = {
217
217
  table = $('<table/>').addClass('data').css('width', '100%');
218
218
  that.order_packages_table(table);
219
219
  that.unassigned_line_items_table(table);
220
- that.summary_table(table);
220
+ that.summary_table(table);
221
221
  $('#order_table').empty().append(table);
222
+
223
+ that.button_controls();
222
224
  },
223
225
 
224
226
  overview_table: function()
@@ -245,8 +247,8 @@ OrderController.prototype = {
245
247
  );
246
248
  });
247
249
  fstatus.append(transactions_table);
248
- }
249
-
250
+ }
251
+
250
252
  var table = $('<table/>').addClass('data');
251
253
  table.append($('<tr/>')
252
254
  .append($('<th/>').html('Customer'))
@@ -265,27 +267,9 @@ OrderController.prototype = {
265
267
  else { that.noneditable_customer(); a.html('Edit'); }
266
268
  });
267
269
  }))
268
- )
269
- .append($('<td/>').attr('valign', 'top')
270
- .append($('<div/>').attr('id', 'shipping_address').append(that.noneditable_shipping_address(true)))
271
- .append($('<a/>').attr('href', '#').html('Edit').click(function(e) {
272
- var a = $(this);
273
- that.refresh_order(function() {
274
- if (a.html() == 'Edit') { that.edit_shipping_address(); a.html('Finished'); }
275
- else { that.noneditable_shipping_address(); a.html('Edit'); }
276
- });
277
- }))
278
- )
279
- .append($('<td/>').attr('valign', 'top')
280
- .append($('<div/>').attr('id', 'billing_address').append(that.noneditable_billing_address(true)))
281
- .append($('<a/>').attr('href', '#').html('Edit').click(function(e) {
282
- var a = $(this);
283
- that.refresh_order(function() {
284
- if (a.html() == 'Edit') { that.edit_billing_address(); a.html('Finished'); }
285
- else { that.noneditable_billing_address(); a.html('Edit'); }
286
- });
287
- }))
288
- )
270
+ )
271
+ .append($('<td/>').attr('valign', 'top').attr('id', 'shipping_address' ).append(that.noneditable_shipping_address()))
272
+ .append($('<td/>').attr('valign', 'top').attr('id', 'billing_address' ).append(that.noneditable_billing_address()))
289
273
  .append($('<td/>').attr('valign', 'top').append($('<div/>').attr('id', 'order_' + that.order.id + '_status')))
290
274
  .append($('<td/>').attr('valign', 'top').attr('align', 'center').append(fstatus))
291
275
  );
@@ -327,19 +311,31 @@ OrderController.prototype = {
327
311
  });
328
312
  },
329
313
 
330
- noneditable_shipping_address: function(return_element)
314
+ noneditable_shipping_address: function()
331
315
  {
332
316
  var that = this;
333
- var sa = that.order.shipping_address;
334
- var str = '';
335
- str += (sa.first_name ? sa.first_name : '[Empty first name]') + ' ';
336
- str += (sa.last_name ? sa.last_name : '[Empty last name]');
337
- str += '<br />' + (sa.address1 ? sa.address1 : '[Empty address]');
338
- if (sa.address2) str += "<br />" + sa.address2;
339
- str += '<br/>' + (sa.city ? sa.city : '[Empty city]') + ", " + (sa.state ? sa.state : '[Empty state]') + " " + (sa.zip ? sa.zip : '[Empty zip]');
340
- if (return_element)
341
- return str;
342
- $('#shipping_address').empty().append(str);
317
+ var div = $('<div/>');
318
+ if (that.has_shippable_items())
319
+ {
320
+ var sa = that.order.shipping_address;
321
+ str = '';
322
+ str += (sa.first_name ? sa.first_name : '[Empty first name]') + ' ';
323
+ str += (sa.last_name ? sa.last_name : '[Empty last name]');
324
+ str += '<br />' + (sa.address1 ? sa.address1 : '[Empty address]');
325
+ if (sa.address2) str += "<br />" + sa.address2;
326
+ str += '<br/>' + (sa.city ? sa.city : '[Empty city]') + ", " + (sa.state ? sa.state : '[Empty state]') + " " + (sa.zip ? sa.zip : '[Empty zip]');
327
+
328
+ div.append($('<div/>').attr('id', 'shipping_address').append(str));
329
+ div.append($('<a/>').attr('href', '#').html('Edit').click(function(e) {
330
+ var a = $(this);
331
+ that.refresh_order(function() { that.edit_shipping_address(); });
332
+ }));
333
+ }
334
+ else
335
+ {
336
+ div.append("This order does not require shipping.");
337
+ }
338
+ return div;
343
339
  },
344
340
 
345
341
  edit_shipping_address: function()
@@ -362,7 +358,12 @@ OrderController.prototype = {
362
358
  .append($('<td/>').append($('<div/>').attr('id', 'shippingaddress_' + sa.id + '_state')))
363
359
  .append($('<td/>').append($('<div/>').attr('id', 'shippingaddress_' + sa.id + '_zip')))
364
360
  ))));
365
- $('#shipping_address').empty().append(table);
361
+ $('#shipping_address').empty()
362
+ .append(table)
363
+ .append($('<a/>').attr('href', '#').html('Finished').click(function(e) {
364
+ var a = $(this);
365
+ that.refresh_order(function() { $('#shipping_address').empty().append(that.noneditable_shipping_address()); });
366
+ }));
366
367
 
367
368
  new ModelBinder({
368
369
  name: 'ShippingAddress',
@@ -381,9 +382,10 @@ OrderController.prototype = {
381
382
  });
382
383
  },
383
384
 
384
- noneditable_billing_address: function(return_element)
385
+ noneditable_billing_address: function()
385
386
  {
386
387
  var that = this;
388
+
387
389
  var sa = that.order.billing_address;
388
390
  if (!sa) sa = {};
389
391
  var str = '';
@@ -392,9 +394,15 @@ OrderController.prototype = {
392
394
  str += '<br />' + (sa.address1 ? sa.address1 : '[Empty address]');
393
395
  if (sa.address2) str += "<br />" + sa.address2;
394
396
  str += '<br/>' + (sa.city ? sa.city : '[Empty city]') + ", " + (sa.state ? sa.state : '[Empty state]') + " " + (sa.zip ? sa.zip : '[Empty zip]');
395
- if (return_element)
396
- return str;
397
- $('#billing_address').empty().append(str);
397
+
398
+ var div = $('<div/>')
399
+ .append(str)
400
+ .append("<br />")
401
+ .append($('<a/>').attr('href', '#').html('Edit').click(function(e) {
402
+ var a = $(this);
403
+ that.refresh_order(function() { that.edit_billing_address(); });
404
+ }));
405
+ return div;
398
406
  },
399
407
 
400
408
  edit_billing_address: function()
@@ -418,7 +426,12 @@ OrderController.prototype = {
418
426
  .append($('<td/>').append($('<div/>').attr('id', 'billingaddress_' + sa.id + '_state')))
419
427
  .append($('<td/>').append($('<div/>').attr('id', 'billingaddress_' + sa.id + '_zip')))
420
428
  ))));
421
- $('#billing_address').empty().append(table);
429
+ $('#billing_address').empty()
430
+ .append(table)
431
+ .append($('<a/>').attr('href', '#').html('Finished').click(function(e) {
432
+ var a = $(this);
433
+ that.refresh_order(function() { $('#billing_address').empty().append(that.noneditable_billing_address()); });
434
+ }));
422
435
 
423
436
  new ModelBinder({
424
437
  name: 'BillingAddress',
@@ -593,7 +606,7 @@ OrderController.prototype = {
593
606
  .append($('<th/>').html('Package' ))
594
607
  .append($('<th/>').html('Item' ))
595
608
  .append($('<th/>').html('Status' ))
596
- .append($('<th/>').html('Unit Price1' ))
609
+ .append($('<th/>').html('Unit Price' ))
597
610
  .append($('<th/>').html('Quantity' ))
598
611
  .append($('<th/>').html('Subtotal' ))
599
612
  );
@@ -601,13 +614,22 @@ OrderController.prototype = {
601
614
  $.each(that.order.line_items, function(i, li) {
602
615
  if (li.order_package_id && li.order_package_id != -1) return true;
603
616
 
604
- var div = $('<div/>').attr('id', 'assign_to_package_' + li.id)
605
- .append('Unpackaged! ')
606
- .append($('<a/>').data('line_item_id', li.id).attr('href', '#').html('Assign to package').click(function(e) {
607
- e.preventDefault();
608
- e.stopPropagation();
609
- that.assign_to_package_form($(this).data('line_item_id'));
610
- }));
617
+ var div = false;
618
+
619
+ if (li.variant.downloadable)
620
+ {
621
+ div = $('<div/>').append('This item is downloadable.');
622
+ }
623
+ else
624
+ {
625
+ div = $('<div/>').attr('id', 'assign_to_package_' + li.id)
626
+ .append('Unpackaged! ')
627
+ .append($('<a/>').data('line_item_id', li.id).attr('href', '#').html('Assign to package').click(function(e) {
628
+ e.preventDefault();
629
+ e.stopPropagation();
630
+ that.assign_to_package_form($(this).data('line_item_id'));
631
+ }));
632
+ }
611
633
 
612
634
  var tr = $('<tr/>');
613
635
  tr.append($('<td/>').append(div));
@@ -645,7 +667,7 @@ OrderController.prototype = {
645
667
  table.append($('<tr/>')
646
668
  .append($('<td/>').attr('colspan', '5').attr('align', 'right')
647
669
  .append($('<a/>').attr('href', '#').html('Remove').click(function(e) { that.remove_discount(d.id); }))
648
- .append(' ' + d.name + ' Discount')
670
+ .append(' "' + d.gift_card.code + '" Discount')
649
671
  )
650
672
  .append($('<td/>').attr('align', 'right').html(curr(d.amount)))
651
673
  );
@@ -668,6 +690,35 @@ OrderController.prototype = {
668
690
  }
669
691
  },
670
692
 
693
+ button_controls: function()
694
+ {
695
+ var that = this;
696
+ var p = $('<p/>');
697
+ p.append($('<input/>').attr('type', 'button').val('< Back').click(function() { window.location = '/admin/orders'; })).append(' ');
698
+ if (that.order.total > 0)
699
+ {
700
+ switch (that.order.financial_status)
701
+ {
702
+ case 'pending':
703
+ p.append($('<input/>').attr('type', 'button').val('Send for Authorization').click(function() { that.send_for_authorization(); })).append(' ');
704
+ break;
705
+ case 'authorized':
706
+ p.append($('<input/>').attr('type', 'button').val('Capture Funds').click(function() { that.capture_funds(); })).append(' ');
707
+ p.append($('<input/>').attr('type', 'button').val('Void' ).click(function() { that.void_order(); })).append(' ');
708
+ break;
709
+ case 'captured':
710
+ p.append($('<input/>').attr('type', 'button').val('Refund' ).click(function() { that.refund(); })).append(' ');
711
+ break;
712
+ }
713
+ }
714
+ //p.append($('<input/>').attr('type', 'button').val('Resend Confirmation' ).click(function() { that.resend_confirmation(); })).append(' ');
715
+ p.append($('<input/>').attr('type', 'button').val('Add Item' ).click(function() { that.add_variant(); })).append(' ');
716
+ p.append($('<input/>').attr('type', 'button').val('Print Order' ).click(function() { that.print_order(); })).append(' ');
717
+ $('#controls').empty().append(p);
718
+ },
719
+
720
+ /****************************************************************************/
721
+
671
722
  add_variant: function(variant_id)
672
723
  {
673
724
  var that = this;
@@ -759,8 +810,43 @@ OrderController.prototype = {
759
810
  if (resp.refresh) { $('#message').empty(); that.refresh(); }
760
811
  }
761
812
  });
762
- }
763
-
813
+ },
814
+
815
+ send_for_authorization: function(confirm)
816
+ {
817
+ var that = this;
818
+ if (!confirm)
819
+ {
820
+ var p = $('<p/>').addClass('note confirm')
821
+ .append("Are you sure you want to send this order to the customer for authorization? ")
822
+ .append($('<input/>').attr('type','button').val('Yes').click(function() { that.send_for_authorization(true); }))
823
+ .append(' ')
824
+ .append($('<input/>').attr('type','button').val('No').click(function() { $('#message').empty(); }));
825
+ $('#message').empty().append(p);
826
+ return;
827
+ }
828
+ $('#message').html("<p class='loading'>Sending for authorization...</p>");
829
+ $.ajax({
830
+ url: '/admin/orders/' + that.order.id + '/send-for-authorization',
831
+ success: function(resp) {
832
+ if (resp.error) $('#message').html("<p class='note error'>" + resp.error + "</p>");
833
+ if (resp.success) { $('#message').empty(); that.refresh(); }
834
+ if (resp.refresh) { $('#message').empty(); that.refresh(); }
835
+ }
836
+ });
837
+ },
838
+
839
+ has_shippable_items: function()
840
+ {
841
+ var that = this;
842
+ var needs_shipping = false;
843
+ $.each(that.order.line_items, function(i, li) {
844
+ if (li.variant.downloadable == false)
845
+ needs_shipping = true;
846
+ });
847
+ return needs_shipping;
848
+ },
849
+
764
850
  //resend_confirmation: function(order_id)
765
851
  //{
766
852
  // modal.autosize("<p class='loading'>Resending confirmation..</p>");
@@ -64,7 +64,8 @@ Caboose.Store.Modules.CheckoutLoginRegister = (function() {
64
64
  self.current_form = form;
65
65
  };
66
66
 
67
- self.login_form_submit_handler = function(event) {
67
+ self.login_form_submit_handler = function(event) {
68
+ event.preventDefault();
68
69
  $('#message').html("<p class='loading'>Logging in...</p>");
69
70
  $.ajax({
70
71
  url: '/login',
@@ -88,22 +89,29 @@ Caboose.Store.Modules.CheckoutLoginRegister = (function() {
88
89
  return false;
89
90
  };
90
91
 
91
- self.register_form_submit_handler = function(event) {
92
+ self.register_form_submit_handler = function(event) {
93
+ event.preventDefault();
92
94
  $('#message').html("<p class='loading'>Registering...</p>");
93
95
  $.ajax({
94
96
  url: '/register',
95
97
  type: 'post',
96
98
  data: $('#register_form').serialize(),
97
99
  success: function(resp) {
98
- if (resp.error) $('#message').html("<p class='note error'>" + resp.error + "</p>");
99
- $.ajax({
100
- url: '/checkout/attach-user',
101
- type: 'post',
102
- success: function(resp2) {
103
- if (resp2.error) $('#message').html("<p class='note error'>" + resp2.error + "</p>");
104
- else window.location = '/checkout/addresses';
105
- }
106
- });
100
+ if (resp.error)
101
+ $('#message').html("<p class='note error'>" + resp.error + "</p>");
102
+ else
103
+ {
104
+ $.ajax({
105
+ url: '/checkout/attach-user',
106
+ type: 'post',
107
+ success: function(resp2) {
108
+ if (resp2.error)
109
+ $('#message').html("<p class='note error'>" + resp2.error + "</p>");
110
+ else
111
+ window.location = '/checkout/addresses';
112
+ }
113
+ });
114
+ }
107
115
  }
108
116
  });
109
117
  return false;
@@ -215,3 +215,20 @@ window.States = {
215
215
  "WI": "Wisconsin",
216
216
  "WY": "Wyoming"
217
217
  };
218
+
219
+ function curr(x)
220
+ {
221
+ if (!x) return '0.00'
222
+ var t = typeof x;
223
+ if (t == 'boolean') return '0.00';
224
+ if (t == 'number') return x.toFixed(2);
225
+ if (t == 'string') return parseFloat(x).toFixed(2);
226
+ console.log("curr doesn't know what this is:");
227
+ console.log(x);
228
+ console.log(t);
229
+ return 'STAHP'
230
+ }
231
+
232
+ function capitalize_first_letter(string) {
233
+ return string.charAt(0).toUpperCase() + string.slice(1);
234
+ }
@@ -0,0 +1,490 @@
1
+
2
+ var MyAccountOrderController = function(params) { this.init(params); }
3
+
4
+ MyAccountOrderController.prototype = {
5
+
6
+ order_id: false,
7
+ order: false,
8
+ authenticity_token: false,
9
+
10
+ init: function(params)
11
+ {
12
+ for (var i in params)
13
+ this[i] = params[i];
14
+
15
+ var that = this;
16
+ $('#payment_form').hide();
17
+ $(document).ready(function() { that.refresh(); });
18
+ },
19
+
20
+ refresh: function()
21
+ {
22
+ var that = this;
23
+ that.refresh_order(function() {
24
+ $('#order_table').html("<p class='loading'>Getting order...</p>");
25
+ that.print();
26
+ });
27
+ },
28
+
29
+ refresh_order: function(after)
30
+ {
31
+ var that = this;
32
+ $.ajax({
33
+ url: '/my-account/orders/' + that.order_id + '/json',
34
+ success: function(order) {
35
+ that.order = order;
36
+ if (after) after();
37
+ }
38
+ });
39
+ },
40
+
41
+ /******************************************************************************/
42
+
43
+ line_items_for_order_package: function(order_package_id)
44
+ {
45
+ var that = this;
46
+ var line_items = [];
47
+ $.each(that.order.line_items, function(i, li) {
48
+ if (li.order_package_id == order_package_id)
49
+ line_items.push(li);
50
+ });
51
+ return line_items;
52
+ },
53
+
54
+ print: function()
55
+ {
56
+ var that = this;
57
+
58
+ if (that.order.line_items && that.order.line_items.length > 0)
59
+ {
60
+ var count_packaged = 0;
61
+ var count_unpackaged = 0;
62
+ var count_downloadable = 0;
63
+ $.each(that.order.line_items, function(i, li) {
64
+ if (li.order_package_id)
65
+ count_packaged++;
66
+ else if (li.variant.downloadable == true)
67
+ count_downloadable++;
68
+ else
69
+ count_unpackaged++;
70
+ });
71
+
72
+ var table = that.overview_table();
73
+ $('#overview_table').empty().append(table).append($('<br />'));
74
+
75
+ table = $('<table/>').addClass('order').css('width', '100%');
76
+ if (count_packaged > 0) that.packaged_line_items_table(table);
77
+ if (count_unpackaged > 0) that.unpackaged_line_items_table(table);
78
+ if (count_downloadable > 0) that.downloadable_line_items_table(table);
79
+ that.summary_table(table);
80
+ $('#order_table').empty().append(table);
81
+ }
82
+ else
83
+ {
84
+ $('#overview_table').empty();
85
+ $('#order_table').empty();
86
+ $('#message').empty().html("This order is empty.");
87
+ }
88
+ },
89
+
90
+ overview_table: function()
91
+ {
92
+ var that = this;
93
+
94
+ var fstatus = $('<div/>').append($('<p/>').html(capitalize_first_letter(that.order.financial_status)));
95
+ if (that.order.financial_status == 'pending')
96
+ {
97
+ fstatus.append($('<p/>').append($('<input/>').attr('type', 'button').addClass('btn').val('Pay now').click(function(e) { e.preventDefault(); that.payment_form(); })));
98
+ }
99
+
100
+ var table = $('<table/>').addClass('order');
101
+ table.append($('<tr/>')
102
+ .append($('<th/>').html('Customer'))
103
+ .append($('<th/>').html('Shipping Address'))
104
+ .append($('<th/>').html('Billing Address'))
105
+ .append($('<th/>').html('Order Status'))
106
+ .append($('<th/>').html('Payment Status'))
107
+ );
108
+ table.append($('<tr/>')
109
+ .append($('<td/>').attr('valign', 'top').attr('id', 'customer' ).append(that.noneditable_customer()))
110
+ .append($('<td/>').attr('valign', 'top').attr('id', 'shipping_address' ).append(that.noneditable_shipping_address()))
111
+ .append($('<td/>').attr('valign', 'top').attr('id', 'billing_address' ).append(that.noneditable_billing_address()))
112
+ .append($('<td/>').attr('valign', 'top').attr('align', 'center').append($('<p/>').html(capitalize_first_letter(that.order.status))))
113
+ .append($('<td/>').attr('valign', 'top').attr('align', 'center').append(fstatus))
114
+ );
115
+ return table;
116
+ },
117
+
118
+ noneditable_customer: function()
119
+ {
120
+ var that = this;
121
+ c = that.order.customer;
122
+ str = '';
123
+ if (c)
124
+ {
125
+ str = c.first_name + ' ' + c.last_name;
126
+ if (c.email) str += '<br /><a href="mailto:' + c.email + '">' + c.email + '</a>';
127
+ if (c.phone) str += '<br />' + c.phone;
128
+ }
129
+ else
130
+ str = '[Empty]';
131
+ return str;
132
+ },
133
+
134
+ noneditable_shipping_address: function()
135
+ {
136
+ var that = this;
137
+ var div = $('<div/>');
138
+ if (that.has_shippable_items())
139
+ {
140
+ var sa = that.order.shipping_address;
141
+ str = '';
142
+ str += (sa.first_name ? sa.first_name : '[Empty first name]') + ' ';
143
+ str += (sa.last_name ? sa.last_name : '[Empty last name]');
144
+ str += '<br />' + (sa.address1 ? sa.address1 : '[Empty address]');
145
+ if (sa.address2) str += "<br />" + sa.address2;
146
+ str += '<br/>' + (sa.city ? sa.city : '[Empty city]') + ", " + (sa.state ? sa.state : '[Empty state]') + " " + (sa.zip ? sa.zip : '[Empty zip]');
147
+
148
+ div.append($('<div/>').attr('id', 'shipping_address').append(str));
149
+ div.append($('<a/>').attr('href', '#').html('Edit').click(function(e) {
150
+ var a = $(this);
151
+ that.refresh_order(function() { that.edit_shipping_address(); });
152
+ }));
153
+ }
154
+ else
155
+ {
156
+ div.append("This order does not require shipping.");
157
+ }
158
+ return div;
159
+ },
160
+
161
+ edit_shipping_address: function()
162
+ {
163
+ var that = this;
164
+ var sa = that.order.shipping_address;
165
+ var table = $('<table/>').addClass('shipping_address')
166
+ .append($('<tr/>').append($('<td/>').append($('<table/>').append($('<tr/>')
167
+ .append($('<td/>').append($('<div/>').attr('id', 'shippingaddress_' + sa.id + '_first_name')))
168
+ .append($('<td/>').append($('<div/>').attr('id', 'shippingaddress_' + sa.id + '_last_name')))
169
+ ))))
170
+ .append($('<tr/>').append($('<td/>').append($('<table/>').append($('<tr/>')
171
+ .append($('<td/>').append($('<div/>').attr('id', 'shippingaddress_' + sa.id + '_address1')))
172
+ ))))
173
+ .append($('<tr/>').append($('<td/>').append($('<table/>').append($('<tr/>')
174
+ .append($('<td/>').append($('<div/>').attr('id', 'shippingaddress_' + sa.id + '_address2')))
175
+ ))))
176
+ .append($('<tr/>').append($('<td/>').append($('<table/>').append($('<tr/>')
177
+ .append($('<td/>').append($('<div/>').attr('id', 'shippingaddress_' + sa.id + '_city')))
178
+ .append($('<td/>').append($('<div/>').attr('id', 'shippingaddress_' + sa.id + '_state')))
179
+ .append($('<td/>').append($('<div/>').attr('id', 'shippingaddress_' + sa.id + '_zip')))
180
+ ))));
181
+ $('#shipping_address').empty()
182
+ .append(table)
183
+ .append($('<a/>').attr('href', '#').html('Finished').click(function(e) {
184
+ var a = $(this);
185
+ that.refresh_order(function() { $('#shipping_address').empty().append(that.noneditable_shipping_address()); });
186
+ }));
187
+
188
+ new ModelBinder({
189
+ name: 'ShippingAddress',
190
+ id: sa.id,
191
+ update_url: '/my-account/orders/' + that.order.id + '/shipping-address',
192
+ authenticity_token: that.authenticity_token,
193
+ attributes: [
194
+ { name: 'first_name' , nice_name: 'First Name' , type: 'text' , value: sa.first_name , width: 150, fixed_placeholder: false },
195
+ { name: 'last_name' , nice_name: 'Last Name' , type: 'text' , value: sa.last_name , width: 150, fixed_placeholder: false },
196
+ { name: 'address1' , nice_name: 'Address 1' , type: 'text' , value: sa.address1 , width: 320, fixed_placeholder: false },
197
+ { name: 'address2' , nice_name: 'Address 2' , type: 'text' , value: sa.address2 , width: 320, fixed_placeholder: false },
198
+ { name: 'city' , nice_name: 'City' , type: 'text' , value: sa.city , width: 180, fixed_placeholder: false },
199
+ { name: 'state' , nice_name: 'State' , type: 'text' , value: sa.state , width: 40, fixed_placeholder: false },
200
+ { name: 'zip' , nice_name: 'Zip' , type: 'text' , value: sa.zip , width: 60, fixed_placeholder: false }
201
+ ]
202
+ });
203
+ },
204
+
205
+ noneditable_billing_address: function()
206
+ {
207
+ var that = this;
208
+
209
+ var sa = that.order.billing_address;
210
+ if (!sa) sa = {};
211
+ var str = '';
212
+ str += (sa.first_name ? sa.first_name : '[Empty first name]') + ' ';
213
+ str += (sa.last_name ? sa.last_name : '[Empty last name]');
214
+ str += '<br />' + (sa.address1 ? sa.address1 : '[Empty address]');
215
+ if (sa.address2) str += "<br />" + sa.address2;
216
+ str += '<br/>' + (sa.city ? sa.city : '[Empty city]') + ", " + (sa.state ? sa.state : '[Empty state]') + " " + (sa.zip ? sa.zip : '[Empty zip]');
217
+
218
+ var div = $('<div/>')
219
+ .append(str)
220
+ .append("<br />")
221
+ .append($('<a/>').attr('href', '#').html('Edit').click(function(e) {
222
+ var a = $(this);
223
+ that.refresh_order(function() { that.edit_billing_address(); });
224
+ }));
225
+ return div;
226
+ },
227
+
228
+ edit_billing_address: function()
229
+ {
230
+ var that = this;
231
+ var sa = that.order.billing_address;
232
+ if (!sa) sa = { id: 1 };
233
+ var table = $('<table/>').addClass('billing_address')
234
+ .append($('<tr/>').append($('<td/>').append($('<table/>').append($('<tr/>')
235
+ .append($('<td/>').append($('<div/>').attr('id', 'billingaddress_' + sa.id + '_first_name')))
236
+ .append($('<td/>').append($('<div/>').attr('id', 'billingaddress_' + sa.id + '_last_name')))
237
+ ))))
238
+ .append($('<tr/>').append($('<td/>').append($('<table/>').append($('<tr/>')
239
+ .append($('<td/>').append($('<div/>').attr('id', 'billingaddress_' + sa.id + '_address1')))
240
+ ))))
241
+ .append($('<tr/>').append($('<td/>').append($('<table/>').append($('<tr/>')
242
+ .append($('<td/>').append($('<div/>').attr('id', 'billingaddress_' + sa.id + '_address2')))
243
+ ))))
244
+ .append($('<tr/>').append($('<td/>').append($('<table/>').append($('<tr/>')
245
+ .append($('<td/>').append($('<div/>').attr('id', 'billingaddress_' + sa.id + '_city')))
246
+ .append($('<td/>').append($('<div/>').attr('id', 'billingaddress_' + sa.id + '_state')))
247
+ .append($('<td/>').append($('<div/>').attr('id', 'billingaddress_' + sa.id + '_zip')))
248
+ ))));
249
+ $('#billing_address').empty()
250
+ .append(table)
251
+ .append($('<a/>').attr('href', '#').html('Finished').click(function(e) {
252
+ var a = $(this);
253
+ that.refresh_order(function() { $('#billing_address').empty().append(that.noneditable_billing_address()); });
254
+ }));
255
+
256
+ new ModelBinder({
257
+ name: 'BillingAddress',
258
+ id: sa.id,
259
+ update_url: '/my-account/orders/' + that.order.id + '/billing-address',
260
+ authenticity_token: that.authenticity_token,
261
+ attributes: [
262
+ { name: 'first_name' , nice_name: 'First Name' , type: 'text' , value: sa.first_name , width: 150, fixed_placeholder: false },
263
+ { name: 'last_name' , nice_name: 'Last Name' , type: 'text' , value: sa.last_name , width: 150, fixed_placeholder: false },
264
+ { name: 'address1' , nice_name: 'Address 1' , type: 'text' , value: sa.address1 , width: 320, fixed_placeholder: false },
265
+ { name: 'address2' , nice_name: 'Address 2' , type: 'text' , value: sa.address2 , width: 320, fixed_placeholder: false },
266
+ { name: 'city' , nice_name: 'City' , type: 'text' , value: sa.city , width: 180, fixed_placeholder: false },
267
+ { name: 'state' , nice_name: 'State' , type: 'text' , value: sa.state , width: 40, fixed_placeholder: false },
268
+ { name: 'zip' , nice_name: 'Zip' , type: 'text' , value: sa.zip , width: 60, fixed_placeholder: false }
269
+ ]
270
+ });
271
+ },
272
+
273
+ // Show all the packages and the line items in each package
274
+ packaged_line_items_table: function(table)
275
+ {
276
+ var that = this;
277
+ $.each(that.order.order_packages, function(i, op) {
278
+ var line_items = that.line_items_for_order_package(op.id);
279
+ if (line_items && line_items.length > 0)
280
+ {
281
+ table.append($('<tr/>').append($('<th/>').attr('colspan', '5').addClass('package_header').html("Package " + (i+1) + ": " + op.shipping_method.service_name + "<br />" + op.status)));
282
+ table.append($('<tr/>')
283
+ .append($('<th/>').html('Item'))
284
+ .append($('<th/>').html('Status'))
285
+ .append($('<th/>').html('Unit Price'))
286
+ .append($('<th/>').html('Quantity'))
287
+ .append($('<th/>').html('Subtotal'))
288
+ );
289
+ $.each(line_items, function(j, li) {
290
+ var tr = $('<tr/>');
291
+ tr.append($('<td/>').addClass('line_item_details' ).append(that.line_item_details(li)));
292
+ tr.append($('<td/>').addClass('line_item_status' ).attr('align', 'center').html(li.status));
293
+ tr.append($('<td/>').addClass('line_item_unit_price').attr('align', 'right' ).html(curr(li.unit_price)));
294
+ tr.append($('<td/>').addClass('line_item_quantity' ).attr('align', 'right' ).html(li.quantity));
295
+ tr.append($('<td/>').addClass('line_item_subtotal' ).attr('align', 'right' ).html(curr(li.subtotal)));
296
+ table.append(tr);
297
+ });
298
+ }
299
+ });
300
+ },
301
+
302
+ // Show all the packages and the line items in each package
303
+ unpackaged_line_items_table: function(table)
304
+ {
305
+ var that = this;
306
+ $.each(that.order.order_packages, function(i, op) {
307
+ var line_items = that.line_items_for_order_package(op.id);
308
+ if (line_items && line_items.length > 0)
309
+ {
310
+ table.append($('<tr/>').append($('<th/>').attr('colspan', '5').addClass('package_header').html("Unpackaged Items")));
311
+ table.append($('<tr/>')
312
+ .append($('<th/>').html('Item'))
313
+ .append($('<th/>').html('Status'))
314
+ .append($('<th/>').html('Unit Price'))
315
+ .append($('<th/>').html('Quantity'))
316
+ .append($('<th/>').html('Subtotal'))
317
+ );
318
+ $.each(line_items, function(j, li) {
319
+ var tr = $('<tr/>');
320
+ tr.append($('<td/>').addClass('line_item_details' ).append(that.line_item_details(li)));
321
+ tr.append($('<td/>').addClass('line_item_status' ).attr('align', 'center').html(li.status));
322
+ tr.append($('<td/>').addClass('line_item_unit_price').attr('align', 'right' ).html(curr(li.unit_price)));
323
+ tr.append($('<td/>').addClass('line_item_quantity' ).attr('align', 'right' ).html(li.quantity));
324
+ tr.append($('<td/>').addClass('line_item_subtotal' ).attr('align', 'right' ).html(curr(li.subtotal)));
325
+ table.append(tr);
326
+ });
327
+ }
328
+ });
329
+ },
330
+
331
+ downloadable_line_items_table: function(table)
332
+ {
333
+ var that = this;
334
+ $.each(that.order.order_packages, function(i, op) {
335
+ var line_items = that.line_items_for_order_package(op.id);
336
+ if (line_items && line_items.length > 0)
337
+ {
338
+ table.append($('<tr/>').append($('<th/>').attr('colspan', '5').addClass('package_header').html("Downloadable Items")));
339
+ table.append($('<tr/>')
340
+ .append($('<th/>').html('Item'))
341
+ .append($('<th/>').html('Status'))
342
+ .append($('<th/>').html('Unit Price'))
343
+ .append($('<th/>').html('Quantity'))
344
+ .append($('<th/>').html('Subtotal'))
345
+ );
346
+ $.each(line_items, function(j, li) {
347
+ var tr = $('<tr/>');
348
+ tr.append($('<td/>').addClass('line_item_details' ).append(that.line_item_details(li)));
349
+ tr.append($('<td/>').addClass('line_item_status' ).attr('align', 'center').html(li.status));
350
+ tr.append($('<td/>').addClass('line_item_unit_price').attr('align', 'right' ).html(curr(li.unit_price)));
351
+ tr.append($('<td/>').addClass('line_item_quantity' ).attr('align', 'right' ).html(li.quantity));
352
+ tr.append($('<td/>').addClass('line_item_subtotal' ).attr('align', 'right' ).html(curr(li.subtotal)));
353
+ table.append(tr);
354
+ });
355
+ }
356
+ });
357
+ },
358
+
359
+ line_item_details: function(li)
360
+ {
361
+ var that = this;
362
+ var v = li.variant;
363
+ var name = ''
364
+ if (!v || !v.product)
365
+ name = v ? v.sku : 'Unknown variant';
366
+ else
367
+ {
368
+ name = v.product.title;
369
+ if (v.sku && v.sku.length > 0) name += '<br />' + v.sku;
370
+ if (v.title && v.title.length > 0) name += '<br />' + v.title;
371
+ }
372
+
373
+ var div = $('<div/>').append($('<p/>').append($('<a/>').attr('href', '/products/' + li.variant.product_id).html(name)));
374
+ if (li.is_gift)
375
+ {
376
+ div.append($('<ul/>').addClass('gift_options')
377
+ .append($('<li/>').html("This item is a gift."))
378
+ .append($('<li/>').html("Gift wrap? " + (li.gift_wrap ? 'Yes' : 'No')))
379
+ .append($('<li/>').html("Hide prices? " + (li.hide_prices ? 'Yes' : 'No')))
380
+ .append($('<li/>').html("Gift message: " + (li.gift_message && li.gift_message.length > 0 ? li.gift_message : '[Empty]')))
381
+ );
382
+ }
383
+ else
384
+ {
385
+ div.append($('<p/>').html("This item is not a gift."));
386
+ }
387
+ if (li.variant.downloadable)
388
+ {
389
+ div.append($('<p/>').append($('<a/>').attr('href', '/my-account/orders/' + that.order.id + '/line-items/' + li.id + '/download').html('Download')));
390
+ }
391
+
392
+ return div;
393
+ },
394
+
395
+ // Show the order summary
396
+ summary_table: function(table)
397
+ {
398
+ var that = this;
399
+ table.append($('<tr/>').append($('<th/>').attr('colspan', '5').addClass('totals_header').html('Totals')));
400
+ table.append($('<tr/>').addClass('totals_row').append($('<td/>').attr('colspan', '4').attr('align', 'right').html('Subtotal' )).append($('<td/>').attr('align', 'right').attr('id', 'subtotal').html(curr(that.order.subtotal ))));
401
+ table.append($('<tr/>').addClass('totals_row').append($('<td/>').attr('colspan', '4').attr('align', 'right').html('Tax' )).append($('<td/>').attr('align', 'right').attr('id', 'tax' ).html(curr(that.order.tax ))));
402
+ table.append($('<tr/>').addClass('totals_row').append($('<td/>').attr('colspan', '4').attr('align', 'right').html('Shipping' )).append($('<td/>').attr('align', 'right').attr('id', 'shipping').html(curr(that.order.shipping ))));
403
+ table.append($('<tr/>').addClass('totals_row').append($('<td/>').attr('colspan', '4').attr('align', 'right').html('Handling' )).append($('<td/>').attr('align', 'right').attr('id', 'handling').html(curr(that.order.handling ))));
404
+ if (that.order.discounts)
405
+ {
406
+ $.each(that.order.discounts, function(i, d) {
407
+ table.append($('<tr/>').addClass('totals_row')
408
+ .append($('<td/>').attr('colspan', '4').attr('align', 'right').append(' "' + d.gift_card.code + '" Discount'))
409
+ .append($('<td/>').attr('align', 'right').html(curr(d.amount)))
410
+ );
411
+ });
412
+ }
413
+ table.append($('<tr/>').addClass('totals_row').append($('<td/>').attr('colspan', '4').attr('align', 'right').html('Discount')).append($('<td/>').attr('align', 'right').attr('id', 'custom_discount').html(curr(that.order.custom_discount))));
414
+ table.append($('<tr/>').addClass('totals_row').append($('<td/>').attr('colspan', '4').attr('align', 'right').html('Total' )).append($('<td/>').attr('align', 'right').attr('id', 'total' ).html(curr(that.order.total))));
415
+ },
416
+
417
+ /****************************************************************************/
418
+
419
+ payment_form: function()
420
+ {
421
+ var that = this;
422
+ var ba = that.order.billing_address;
423
+ if (ba == null || ba == false ||
424
+ ba.first_name.length == 0 ||
425
+ ba.last_name.length == 0 ||
426
+ ba.address1.length == 0 ||
427
+ ba.city.length == 0 ||
428
+ ba.state.length == 0 ||
429
+ ba.zip.length == 0
430
+ ) {
431
+ $('#payment_message').empty().html("<p class='note error'>Your billing address must be valid before making payment. Please review and try again.</p>");
432
+ return;
433
+ }
434
+ var form = $('#payment_form');
435
+ if (!form.is(':visible'))
436
+ {
437
+ $('#payment_message').empty();
438
+ form.slideDown();
439
+ }
440
+ else
441
+ form.slideUp();
442
+ },
443
+
444
+ submit_payment: function()
445
+ {
446
+ $('#payment_message').empty().html("<p class='loading'>Processing payment...</p>");
447
+ $('#payment_form').slideUp();
448
+ },
449
+
450
+ send_for_authorization: function(confirm)
451
+ {
452
+ var that = this;
453
+ if (!confirm)
454
+ {
455
+ var p = $('<p/>').addClass('note confirm')
456
+ .append("Are you sure you want to send this order to the customer for authorization? ")
457
+ .append($('<input/>').attr('type','button').val('Yes').click(function() { that.send_for_authorization(true); }))
458
+ .append(' ')
459
+ .append($('<input/>').attr('type','button').val('No').click(function() { $('#message').empty(); }));
460
+ $('#message').empty().append(p);
461
+ return;
462
+ }
463
+ $('#message').html("<p class='loading'>Sending for authorization...</p>");
464
+ $.ajax({
465
+ url: '/my-account/orders/' + that.order.id + '/send-for-authorization',
466
+ success: function(resp) {
467
+ if (resp.error) $('#message').html("<p class='note error'>" + resp.error + "</p>");
468
+ if (resp.success) { $('#message').empty(); that.refresh(); }
469
+ if (resp.refresh) { $('#message').empty(); that.refresh(); }
470
+ }
471
+ });
472
+ },
473
+
474
+ has_shippable_items: function()
475
+ {
476
+ var that = this;
477
+ var needs_shipping = false;
478
+ $.each(that.order.line_items, function(i, li) {
479
+ if (li.variant.downloadable == false)
480
+ needs_shipping = true;
481
+ });
482
+ return needs_shipping;
483
+ },
484
+
485
+ };
486
+
487
+ function relay_handler(resp)
488
+ {
489
+
490
+ }