caboose-cms 0.5.69 → 0.5.70

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +8 -8
  2. data/app/assets/javascripts/caboose/admin.js +2 -1
  3. data/app/assets/javascripts/caboose/admin_edit_order.js +0 -13
  4. data/app/assets/javascripts/caboose/admin_main.js +13 -0
  5. data/app/assets/javascripts/caboose/cart.js +145 -161
  6. data/app/assets/javascripts/caboose/cart_old.js +176 -0
  7. data/app/assets/javascripts/caboose/checkout.js +1 -1
  8. data/app/assets/javascripts/caboose/{checkout_step2.js → checkout_addresses.js} +3 -3
  9. data/app/assets/javascripts/caboose/checkout_gift_cards.js +47 -0
  10. data/app/assets/javascripts/caboose/{checkout_step1.js → checkout_login_register.js} +5 -53
  11. data/app/assets/javascripts/caboose/checkout_module.js +3 -4
  12. data/app/assets/javascripts/caboose/{checkout_step4.js → checkout_payment.js} +8 -8
  13. data/app/assets/javascripts/caboose/{checkout_step3.js → checkout_shipping.js} +5 -5
  14. data/app/assets/javascripts/caboose/imageZoom.js +66 -0
  15. data/app/assets/javascripts/caboose/model/attribute.js +2 -1
  16. data/app/assets/javascripts/caboose/model/bound_select.js +15 -6
  17. data/app/assets/javascripts/caboose/product.js +12 -2
  18. data/app/assets/stylesheets/caboose/checkout.css.scss +1 -0
  19. data/app/assets/templates/caboose/checkout/address.jst.ejs +1 -1
  20. data/app/controllers/caboose/cart_controller.rb +60 -8
  21. data/app/controllers/caboose/checkout_controller.rb +42 -71
  22. data/app/controllers/caboose/gift_cards_controller.rb +216 -0
  23. data/app/controllers/caboose/users_controller.rb +2 -2
  24. data/app/helpers/caboose/checkout_helper.rb +6 -5
  25. data/app/models/caboose/core_plugin.rb +2 -1
  26. data/app/models/caboose/discount.rb +8 -13
  27. data/app/models/caboose/gift_card.rb +49 -0
  28. data/app/models/caboose/order.rb +66 -46
  29. data/app/models/caboose/order_package.rb +11 -4
  30. data/app/models/caboose/order_package_calculator.rb +102 -0
  31. data/app/models/caboose/product_image.rb +10 -0
  32. data/app/models/caboose/schema.rb +38 -29
  33. data/app/models/caboose/shipping_calculator.rb +4 -2
  34. data/app/models/caboose/shipping_package.rb +7 -0
  35. data/app/views/caboose/cart/index.html.erb +12 -2
  36. data/app/views/caboose/checkout/#Untitled-1# +2 -0
  37. data/app/views/caboose/checkout/_cart.html.erb +45 -48
  38. data/app/views/caboose/checkout/_cart_old.html.erb +49 -0
  39. data/app/views/caboose/checkout/_confirm.html.erb +6 -4
  40. data/app/views/caboose/checkout/_confirm_table.html.erb +0 -0
  41. data/app/views/caboose/checkout/{step_two.html.erb → addresses.html.erb} +2 -2
  42. data/app/views/caboose/checkout/gift_cards.html.erb +35 -0
  43. data/app/views/caboose/checkout/index.html.erb +53 -42
  44. data/app/views/caboose/checkout/payment.html.erb +108 -75
  45. data/app/views/caboose/checkout/shipping.html.erb +62 -13
  46. data/app/views/caboose/gift_cards/admin_edit.html.erb +89 -0
  47. data/app/views/caboose/gift_cards/admin_index.html.erb +52 -0
  48. data/config/routes.rb +39 -19
  49. data/lib/caboose/engine.rb +1 -0
  50. data/lib/caboose/version.rb +1 -1
  51. metadata +20 -14
  52. data/app/assets/javascripts/caboose/cart2.js +0 -98
  53. data/app/views/caboose/checkout/step_four.html.erb +0 -67
  54. data/app/views/caboose/checkout/step_four_old.html.erb +0 -63
  55. data/app/views/caboose/checkout/step_one.html.erb +0 -54
  56. data/app/views/caboose/checkout/step_one_old.html.erb +0 -13
  57. data/app/views/caboose/checkout/step_three.html.erb +0 -55
  58. data/app/views/caboose/checkout/step_two_old.html.erb +0 -14
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTIzZWY3YjU1ZjI3NWUxNDU1ZjllNmY5OWYxOTllYzdjMGRhYWFlMw==
4
+ N2MzZDNkOTk2YzlkNGQ2ZTNiODlkYmZlM2M2YThkYjAyODgxMjNjNg==
5
5
  data.tar.gz: !binary |-
6
- OTdiNzNmMzBmN2QzM2Q5ZmY5ZTcwYjU0NTg3ZmYzYTVkNTRiYTBjZQ==
6
+ MWRlZDQwNGIxNGEwODYxMzkzNjZmOTUwMzc5NjljOTRmYjM1OWRlYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OTllMjU1YzUwZTFmYzIyMWI2YTJlNjk5OTZmZGRhODBhZTI3MzZjMjYyNWE3
10
- MDQ3NWIyMGZjOTJlYWI2MTcwYWY5NTNhMmQ1ZTJhMzAyY2JmNjM0ZDhhODRi
11
- ZTE0ZGMwYThhMjFjMWM4MDI3MzZiOGQzY2FiNjViYmViNWVlMmY=
9
+ MTk1NTRiMzNkMjYxNDgxNTEzYzRjNDc2YTRkMmMzMDc3ZTQwZWMxNDQ1OTk0
10
+ Yzg4MWU0MGNmY2Y5NTczMTRiYTgyYzU4YTlmZTU2OWZlY2E4ZGMxYTk1ODc5
11
+ MzA4ZWIwOTNhZDMyMTVmZmRhNTQ3MWIwYjg5YWQzODcyNmM2MTE=
12
12
  data.tar.gz: !binary |-
13
- NTE0Y2U1NzE2NmIwYmY0ZjZjNGU3MDgwY2U1Mjk4MzZmNzI2MjJhZGYyODA2
14
- MTk4MzNmN2M1NjM4ODNlZDJiMzZiZjFmMjM3YjVjYTg2ZjBlOGM2MDU0M2Uz
15
- NWZhOGMzNjI0ZGFhNDRiZjIxMmQxMmI5NDMzNmNhMGJmN2FlM2I=
13
+ MTA4YzQ4YTJmYzA5NzE2OGJhY2M3M2JmYTMxOThhOTYwNjczN2NhYWVlMTc5
14
+ YmM0OGFhYTcxYjc2YWIzNjUzYWJjZmE1NTYyMGU3MzQ3NGY5ZTkzNTgwN2M3
15
+ ZmI2MzBkZjNlOGJkYjg5MWVjMWFmMmU3YzZiNTFlMzJkZTY5M2U=
@@ -15,4 +15,5 @@
15
15
  //= require jquery-ui
16
16
  //= require colorbox-rails
17
17
  //= require caboose/jquery.placeholder
18
- //= require caboose/modal_integration
18
+ //= require caboose/modal_integration
19
+ //= require caboose/admin_main
@@ -1,17 +1,4 @@
1
1
 
2
- function curr(x)
3
- {
4
- if (!x) return '0.00'
5
- var t = typeof x;
6
- if (t == 'boolean') return '0.00';
7
- if (t == 'number') return x.toFixed(2);
8
- if (t == 'string') return parseFloat(x).toFixed(2);
9
- console.log("curr doesn't know what this is:");
10
- console.log(x);
11
- console.log(t);
12
- return 'STAHP'
13
- }
14
-
15
2
  var OrderController = function(params) { this.init(params); }
16
3
 
17
4
  OrderController.prototype = {
@@ -0,0 +1,13 @@
1
+
2
+ function curr(x)
3
+ {
4
+ if (!x) return '0.00'
5
+ var t = typeof x;
6
+ if (t == 'boolean') return '0.00';
7
+ if (t == 'number') return x.toFixed(2);
8
+ if (t == 'string') return parseFloat(x).toFixed(2);
9
+ console.log("curr doesn't know what this is:");
10
+ console.log(x);
11
+ console.log(t);
12
+ return 'STAHP'
13
+ }
@@ -1,176 +1,160 @@
1
- //
2
- // Cart
3
- //
4
1
 
5
- Caboose.Store.Modules.Cart = (function() {
6
- var self = {
7
- templates: {
8
- line_items: JST['caboose/cart/line_items'],
9
- add_to_cart: JST['caboose/cart/add_to_cart']
10
- }
11
- };
12
-
13
- //
14
- // Initialize
15
- //
2
+ Cart = function(params) { this.init(params); };
3
+
4
+ Cart.prototype = {
16
5
 
17
- self.initialize = function() {
18
- self.render_add_to_cart();
19
- self.render_item_count();
20
- self.$cart = $('#cart');
21
- if (!self.$cart.length) return false;
22
- self.$cart.on('click', '#remove-from-cart', self.remove_handler);
23
- self.$cart.on('keyup', 'input', self.update_handler);
24
- self.render();
25
- };
6
+ order: false,
7
+ allow_edit_line_items: true,
8
+ allow_edit_gift_cards: true,
9
+ show_total: true,
10
+ show_shipping: true,
11
+ show_tax: true,
12
+ show_discounts: true,
13
+
14
+ init: function(params)
15
+ {
16
+ for (var i in params)
17
+ this[i] = params[i];
18
+ this.refresh();
19
+ },
26
20
 
27
- //
28
- // Set Variant
29
- //
21
+ refresh: function()
22
+ {
23
+ var that = this;
24
+ $('#message').html("<p class='loading'>Getting cart...</p>");
25
+ $.ajax({
26
+ url: '/cart/items',
27
+ success: function(resp) {
28
+ that.order = resp;
29
+ $('#message').empty();
30
+ that.print();
31
+ }
32
+ });
33
+ },
30
34
 
31
- self.set_variant = function(variant) {
32
- if (self.$add_to_cart) {
33
- self.$add_to_cart.find('input[name=variant_id]').val(variant ? variant.id : "");
34
- self.$add_to_cart.trigger('change');
35
+ print: function()
36
+ {
37
+ var that = this;
38
+ if (!this.order || !this.order.line_items || this.order.line_items.length == 0)
39
+ {
40
+ $('#cart').html("<p class='note'>You don't have any items in your shopping cart. <a href='/products'>Continue shopping.</a></p>");
41
+ return;
35
42
  }
36
- };
37
-
38
- //
39
- // Render
40
- //
41
-
42
- self.render = function() {
43
- $.get('/cart/items', function(response) {
44
- self.$cart.empty().html(self.templates.line_items({ order: response.order }));
45
- self.$cart.removeClass('loading');
43
+
44
+ var tbody = $('<tbody/>')
45
+ .append($('<tr/>')
46
+ .append($('<th/>').attr('colspan', '2').html('Item'))
47
+ .append($('<th/>').html('Unit Price'))
48
+ .append($('<th/>').html('Quantity'))
49
+ .append($('<th/>').html('Subtotal'))
50
+ );
51
+
52
+ $.each(this.order.line_items, function(i, li) {
53
+ var v = li.variant;
54
+ var p = v.product;
55
+ var img = v.product_images && v.product_images.length > 0 ? v.product_images[0] : (p.product_images && p.product_images.length > 0 ? p.product_images[0] : false);
56
+ img = img ? $('<img/>').attr('src', img.urls.tiny) : '&nbsp;';
57
+
58
+ var item = $('<td/>').attr('valign', 'top').append(p.title + '<br/>' + v.title);
59
+ if (that.allow_edit_line_items == true)
60
+ item.append('<br/>').append($('<a/>').attr('href','#').html('Remove').click(function(e) { e.preventDefault(); that.remove_item(li.id); }));
61
+ var qty = $('<td/>').css('text-align', 'right');
62
+ if (that.allow_edit_line_items == true)
63
+ qty.append($('<div/>').attr('id', 'lineitem_' + li.id + '_quantity'));
64
+ else
65
+ qty.append(li.quantity);
66
+
67
+ tbody.append($('<tr/>').data('id', li.id)
68
+ .append($('<td/>').attr('valign', 'top').append(img))
69
+ .append(item)
70
+ .append($('<td/>').css('text-align', 'right').html('$' + parseFloat(v.price).toFixed(2)))
71
+ .append(qty)
72
+ .append($('<td/>').css('text-align', 'right').html('$' + (v.price * li.quantity).toFixed(2)))
73
+ );
46
74
  });
47
- };
48
-
49
- self.render_add_to_cart = function() {
50
- self.$add_to_cart = $('#add-to-cart');
51
- if (!self.$add_to_cart.length) return false;
52
- self.$add_to_cart.empty().html(self.templates.add_to_cart());
53
- //$('input[name=quantity]', self.$add_to_cart).on('keyup', self.qty_keyup_handler);
54
- //$('input[name=quantity,type=hidden,value=1]', self.$add_to_cart);
55
- $('form', self.$add_to_cart).on('submit', self.add_handler);
56
- };
57
-
58
- self.render_item_count = function(item_count) {
59
- var $link = $('#cart-link, .cart-link');
60
- //if (!$link.length) return false;
61
-
62
- function set_count(count) {
63
- if ($('#cart_item_count').length > 0)
64
- $('#cart_item_count').html(count);
65
- else if ($link.length > 0)
66
- {
67
- if ($link.children('i') && count < 1) { $link.children('i').remove(); }
68
- else if ($link.children('i').length) { $link.children('i').empty().text(count); }
69
- else { $link.append($('<i/>').text(count)); }
70
- }
71
- };
72
-
73
- if (item_count) {
74
- set_count(item_count);
75
- } else {
76
- $.get('/cart/item-count', function(response) {
77
- set_count(response.item_count);
78
- });
75
+ tbody.append($('<tr/>')
76
+ .append($('<td/>').css('text-align', 'right').attr('colspan', 4).html('Subtotal'))
77
+ .append($('<td/>').css('text-align', 'right').html('$' + parseFloat(that.order.subtotal).toFixed(2)))
78
+ );
79
+ if (that.show_shipping)
80
+ {
81
+ tbody.append($('<tr/>')
82
+ .append($('<td/>').css('text-align', 'right').attr('colspan', 4).html('Shipping &amp; Handling'))
83
+ .append($('<td/>').css('text-align', 'right').html('$' + parseFloat(that.order.shipping + that.order.handling).toFixed(2)))
84
+ );
79
85
  }
80
- };
81
-
82
- //
83
- // Event Handlers
84
- //
85
-
86
- self.qty_keyup_handler = function(event) {
87
- var $quantity = $(event.target);
88
- $quantity.val($quantity.val().match(/\d*\.?\d+/));
89
- };
90
-
91
- self.add_handler = function(event) {
92
- event.preventDefault();
93
- var $form = $(event.target);
94
-
95
- if ($form.find('input[name=variant_id]').val().trim() == "") {
96
- alert('Must select all options');
97
- } else {
98
- $.ajax({
99
- type: $form.attr('method'),
100
- url: $form.attr('action'),
101
- data: $form.serialize(),
102
- success: function(response) {
103
- if (response.success) {
104
- self.render_item_count(response.item_count);
105
- if (self.$add_to_cart.length) self.$add_to_cart.trigger('added');
86
+ if (that.show_tax)
87
+ {
88
+ tbody.append($('<tr/>')
89
+ .append($('<td/>').css('text-align', 'right').attr('colspan', 4).html('Tax'))
90
+ .append($('<td/>').css('text-align', 'right').html('$' + parseFloat(that.order.tax).toFixed(2)))
91
+ );
92
+ }
93
+ if (that.show_discounts && that.order.discounts.length > 0)
94
+ {
95
+ $.each(that.order.discounts, function(i, d) {
96
+
97
+ var gctd = $('<td/>').css('text-align', 'right').attr('colspan', 4);
98
+ if (that.allow_edit_gift_cards)
99
+ gctd.append($('<a/>').data('discount_id', d.id).attr('href', '#').html('(remove)').click(function(e) { e.preventDefault(); that.remove_discount($(this).data('discount_id')); })).append(' ');
100
+ gctd.append('Gift Card (' + d.gift_card.code + ')');
106
101
 
107
- if (!self.$add_to_cart.find('.message').length) {
108
- self.$add_to_cart
109
- .append($('<div/>').hide().addClass('message')
110
- .append($('<p/>').text('Successfully added to cart'))
111
- .append($('<p/>')
112
- .append($('<a/>').attr('href', '/cart').html('View cart')).append(' | ')
113
- .append($('<a/>').attr('href', '/checkout').html('Continue to checkout'))
114
- )
115
- );
116
- self.$add_to_cart.find('.message').fadeIn();
117
- Caboose.Store.Modules.Product.$product.trigger('added-to-cart');
118
-
119
- //setTimeout(function() {
120
- // self.$add_to_cart.find('.message').fadeOut(function() { $(this).remove() });
121
- //}, 5000);
122
- }
123
- } else {
124
- alert(response.errors[0]);
125
- }
126
- }
102
+ tbody.append($('<tr/>')
103
+ .append(gctd)
104
+ .append($('<td/>').css('text-align', 'right').html('$' + parseFloat(d.amount).toFixed(2)))
105
+ );
127
106
  });
107
+ if (that.order.custom_discount && that.order.custom_discount > 0)
108
+ {
109
+ tbody.append($('<tr/>')
110
+ .append($('<td/>').css('text-align', 'right').attr('colspan', 4).html('Discount'))
111
+ .append($('<td/>').css('text-align', 'right').html('$' + parseFloat(that.order.custom_discount).toFixed(2)))
112
+ );
113
+ }
128
114
  }
129
- };
130
-
131
- self.update_handler = function(event) {
132
- var $quantity = $(event.target)
133
- var $line_item = $quantity.parents('li').first();
134
-
135
- $quantity.val($quantity.val().match(/\d*\.?\d+/));
136
- if ($quantity.val() == "") return false;
137
-
138
- delay(function() {
139
- $.ajax({
140
- type: 'put',
141
- url: '/cart/items/' + $line_item.data('id'),
142
- data: { quantity: $quantity.val() },
143
- success: function(response) {
144
- if (response.success) {
145
- $line_item.find('.price').empty().text('$' + response.line_item.price);
146
- if (self.$cart.find('.subtotal').length) self.$cart.find('.subtotal').empty().text('$' + response.order_subtotal);
147
- } else {
148
- alert(response.errors[0]);
149
- }
150
- }
115
+ if (that.show_total)
116
+ {
117
+ tbody.append($('<tr/>')
118
+ .append($('<td/>').css('text-align', 'right').attr('colspan', 4).html('Total'))
119
+ .append($('<td/>').css('text-align', 'right').html('$' + parseFloat(that.order.total).toFixed(2)))
120
+ );
121
+ }
122
+ $('#cart').empty().append($('<table/>').append(tbody));
123
+
124
+ if (that.allow_edit_line_items)
125
+ {
126
+ $.each(this.order.line_items, function(i, li) {
127
+ m = new ModelBinder({
128
+ name: 'LineItem',
129
+ id: li.id,
130
+ update_url: '/cart/' + li.id,
131
+ authenticity_token: that.form_authenticity_token,
132
+ attributes: [
133
+ { name: 'quantity', nice_name: 'Qty', type: 'text', value: li.quantity, width: 50, fixed_placeholder: false, after_update: function() { that.refresh(); } }
134
+ ]
135
+ });
151
136
  });
152
- }, 1000);
153
- };
137
+ }
138
+ },
154
139
 
155
- self.remove_handler = function(event) {
156
- var $line_item = $(event.target).parents('li').first();
157
-
140
+ remove_item: function(li_id)
141
+ {
142
+ var that = this;
158
143
  $.ajax({
159
- type: 'delete',
160
- url: '/cart/items/' + $line_item.data('id'),
161
- success: function(response) {
162
- if (response.success) {
163
- self.render();
164
- self.render_item_count(response.item_count);
165
- }
166
- }
167
- });
168
- };
144
+ url: '/cart/' + li_id,
145
+ type: 'delete',
146
+ success: function(resp) { that.refresh(); }
147
+ });
148
+ },
169
149
 
170
- self.redirect_handler = function(event) {
171
- event.preventDefault();
172
- window.location = $(event.target).attr('href');
173
- };
150
+ remove_discount: function(discount_id)
151
+ {
152
+ var that = this;
153
+ $.ajax({
154
+ url: '/cart/discounts/' + discount_id,
155
+ type: 'delete',
156
+ success: function(resp) { that.refresh(); }
157
+ });
158
+ }
174
159
 
175
- return self;
176
- }).call(Caboose.Store);
160
+ };
@@ -0,0 +1,176 @@
1
+ //
2
+ // Cart
3
+ //
4
+
5
+ Caboose.Store.Modules.Cart = (function() {
6
+ var self = {
7
+ templates: {
8
+ line_items: JST['caboose/cart/line_items'],
9
+ add_to_cart: JST['caboose/cart/add_to_cart']
10
+ }
11
+ };
12
+
13
+ //
14
+ // Initialize
15
+ //
16
+
17
+ self.initialize = function() {
18
+ self.render_add_to_cart();
19
+ self.render_item_count();
20
+ self.$cart = $('#cart');
21
+ if (!self.$cart.length) return false;
22
+ self.$cart.on('click', '#remove-from-cart', self.remove_handler);
23
+ self.$cart.on('keyup', 'input', self.update_handler);
24
+ self.render();
25
+ };
26
+
27
+ //
28
+ // Set Variant
29
+ //
30
+
31
+ self.set_variant = function(variant) {
32
+ if (self.$add_to_cart) {
33
+ self.$add_to_cart.find('input[name=variant_id]').val(variant ? variant.id : "");
34
+ self.$add_to_cart.trigger('change');
35
+ }
36
+ };
37
+
38
+ //
39
+ // Render
40
+ //
41
+
42
+ self.render = function() {
43
+ $.get('/cart/items', function(response) {
44
+ self.$cart.empty().html(self.templates.line_items({ order: response.order }));
45
+ self.$cart.removeClass('loading');
46
+ });
47
+ };
48
+
49
+ self.render_add_to_cart = function() {
50
+ self.$add_to_cart = $('#add-to-cart');
51
+ if (!self.$add_to_cart.length) return false;
52
+ self.$add_to_cart.empty().html(self.templates.add_to_cart());
53
+ //$('input[name=quantity]', self.$add_to_cart).on('keyup', self.qty_keyup_handler);
54
+ //$('input[name=quantity,type=hidden,value=1]', self.$add_to_cart);
55
+ $('form', self.$add_to_cart).on('submit', self.add_handler);
56
+ };
57
+
58
+ self.render_item_count = function(item_count) {
59
+ var $link = $('#cart-link, .cart-link');
60
+ //if (!$link.length) return false;
61
+
62
+ function set_count(count) {
63
+ if ($('#cart_item_count').length > 0)
64
+ $('#cart_item_count').html(count);
65
+ else if ($link.length > 0)
66
+ {
67
+ if ($link.children('i') && count < 1) { $link.children('i').remove(); }
68
+ else if ($link.children('i').length) { $link.children('i').empty().text(count); }
69
+ else { $link.append($('<i/>').text(count)); }
70
+ }
71
+ };
72
+
73
+ if (item_count) {
74
+ set_count(item_count);
75
+ } else {
76
+ $.get('/cart/item-count', function(response) {
77
+ set_count(response.item_count);
78
+ });
79
+ }
80
+ };
81
+
82
+ //
83
+ // Event Handlers
84
+ //
85
+
86
+ self.qty_keyup_handler = function(event) {
87
+ var $quantity = $(event.target);
88
+ $quantity.val($quantity.val().match(/\d*\.?\d+/));
89
+ };
90
+
91
+ self.add_handler = function(event) {
92
+ event.preventDefault();
93
+ var $form = $(event.target);
94
+
95
+ if ($form.find('input[name=variant_id]').val().trim() == "") {
96
+ alert('Must select all options');
97
+ } else {
98
+ $.ajax({
99
+ type: $form.attr('method'),
100
+ url: $form.attr('action'),
101
+ data: $form.serialize(),
102
+ success: function(response) {
103
+ if (response.success) {
104
+ self.render_item_count(response.item_count);
105
+ if (self.$add_to_cart.length) self.$add_to_cart.trigger('added');
106
+
107
+ if (!self.$add_to_cart.find('.message').length) {
108
+ self.$add_to_cart
109
+ .append($('<div/>').hide().addClass('message')
110
+ .append($('<p/>').text('Successfully added to cart'))
111
+ .append($('<p/>')
112
+ .append($('<a/>').attr('href', '/cart').html('View cart')).append(' | ')
113
+ .append($('<a/>').attr('href', '/checkout').html('Continue to checkout'))
114
+ )
115
+ );
116
+ self.$add_to_cart.find('.message').fadeIn();
117
+ Caboose.Store.Modules.Product.$product.trigger('added-to-cart');
118
+
119
+ //setTimeout(function() {
120
+ // self.$add_to_cart.find('.message').fadeOut(function() { $(this).remove() });
121
+ //}, 5000);
122
+ }
123
+ } else {
124
+ alert(response.errors[0]);
125
+ }
126
+ }
127
+ });
128
+ }
129
+ };
130
+
131
+ self.update_handler = function(event) {
132
+ var $quantity = $(event.target)
133
+ var $line_item = $quantity.parents('li').first();
134
+
135
+ $quantity.val($quantity.val().match(/\d*\.?\d+/));
136
+ if ($quantity.val() == "") return false;
137
+
138
+ delay(function() {
139
+ $.ajax({
140
+ type: 'put',
141
+ url: '/cart/items/' + $line_item.data('id'),
142
+ data: { quantity: $quantity.val() },
143
+ success: function(response) {
144
+ if (response.success) {
145
+ $line_item.find('.price').empty().text('$' + response.line_item.price);
146
+ if (self.$cart.find('.subtotal').length) self.$cart.find('.subtotal').empty().text('$' + response.order_subtotal);
147
+ } else {
148
+ alert(response.errors[0]);
149
+ }
150
+ }
151
+ });
152
+ }, 1000);
153
+ };
154
+
155
+ self.remove_handler = function(event) {
156
+ var $line_item = $(event.target).parents('li').first();
157
+
158
+ $.ajax({
159
+ type: 'delete',
160
+ url: '/cart/items/' + $line_item.data('id'),
161
+ success: function(response) {
162
+ if (response.success) {
163
+ self.render();
164
+ self.render_item_count(response.item_count);
165
+ }
166
+ }
167
+ });
168
+ };
169
+
170
+ self.redirect_handler = function(event) {
171
+ event.preventDefault();
172
+ window.location = $(event.target).attr('href');
173
+ };
174
+
175
+ return self;
176
+ }).call(Caboose.Store);