spree_backend 2.1.3 → 2.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/admin/admin.js.erb +10 -9
  3. data/app/assets/javascripts/admin/line_items.js.coffee +61 -0
  4. data/app/assets/javascripts/admin/payments/edit.js.coffee +1 -1
  5. data/app/assets/javascripts/admin/product_picker.js +2 -1
  6. data/app/assets/javascripts/admin/progress.coffee +2 -2
  7. data/app/assets/javascripts/admin/shipments.js.erb +242 -0
  8. data/app/assets/javascripts/admin/variant_autocomplete.js.erb +0 -244
  9. data/app/assets/javascripts/admin/variant_management.js.coffee +10 -0
  10. data/app/assets/stylesheets/admin/sections/_log_entries.scss +17 -0
  11. data/app/assets/stylesheets/admin/spree_admin.scss +1 -0
  12. data/app/assets/stylesheets/admin/spree_backend.css +1 -1
  13. data/app/controllers/spree/admin/images_controller.rb +1 -1
  14. data/app/controllers/spree/admin/log_entries_controller.rb +19 -0
  15. data/app/controllers/spree/admin/mail_methods_controller.rb +1 -8
  16. data/app/controllers/spree/admin/orders/customer_details_controller.rb +4 -0
  17. data/app/controllers/spree/admin/orders_controller.rb +9 -14
  18. data/app/controllers/spree/admin/payments_controller.rb +4 -0
  19. data/app/controllers/spree/admin/products_controller.rb +7 -11
  20. data/app/controllers/spree/admin/reports_controller.rb +20 -4
  21. data/app/controllers/spree/admin/resource_controller.rb +6 -3
  22. data/app/controllers/spree/admin/taxons_controller.rb +1 -2
  23. data/app/controllers/spree/admin/variants_including_master_controller.rb +15 -0
  24. data/app/helpers/spree/admin/base_helper.rb +1 -1
  25. data/app/helpers/spree/admin/navigation_helper.rb +5 -2
  26. data/app/helpers/spree/admin/orders_helper.rb +42 -0
  27. data/app/helpers/spree/admin/stock_movements_helper.rb +5 -1
  28. data/app/views/spree/admin/log_entries/_credit_card.html.erb +4 -0
  29. data/app/views/spree/admin/log_entries/index.html.erb +28 -0
  30. data/app/views/spree/admin/mail_methods/_form.html.erb +2 -2
  31. data/app/views/spree/admin/orders/_form.html.erb +9 -1
  32. data/app/views/spree/admin/orders/_line_items.html.erb +46 -0
  33. data/app/views/spree/admin/orders/_risk_analysis.html.erb +47 -0
  34. data/app/views/spree/admin/orders/_shipment.html.erb +11 -3
  35. data/app/views/spree/admin/orders/_shipment_manifest.html.erb +7 -3
  36. data/app/views/spree/admin/orders/customer_details/_form.html.erb +1 -1
  37. data/app/views/spree/admin/orders/customer_details/edit.html.erb +7 -9
  38. data/app/views/spree/admin/orders/index.html.erb +11 -5
  39. data/app/views/spree/admin/payment_methods/_form.html.erb +0 -2
  40. data/app/views/spree/admin/payments/_list.html.erb +2 -2
  41. data/app/views/spree/admin/payments/show.html.erb +2 -1
  42. data/app/views/spree/admin/products/_add_stock_form.html.erb +1 -1
  43. data/app/views/spree/admin/products/_form.html.erb +0 -1
  44. data/app/views/spree/admin/products/stock.html.erb +10 -1
  45. data/app/views/spree/admin/shared/_destroy.js.erb +5 -14
  46. data/app/views/spree/admin/shared/_head.html.erb +6 -2
  47. data/app/views/spree/admin/shared/_order_tabs.html.erb +4 -4
  48. data/app/views/spree/admin/variants/update.js.erb +1 -0
  49. data/config/routes.rb +3 -0
  50. data/vendor/assets/javascripts/spin.js +356 -296
  51. metadata +29 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 12021adfcb10f00a2b98a07f498f4edef06d5d24
4
- data.tar.gz: 4d536e1bc06c6e6ad0920efa39c156a401b5a6a6
3
+ metadata.gz: ec214ff2a06feab677374b259cbe3ed5117788ba
4
+ data.tar.gz: 8e262166c0c7cc2184fed2a7bca15521e236efba
5
5
  SHA512:
6
- metadata.gz: e1e3f510b20c7c7243503752495bea80ce72982bd284c9e569cbe43f5a4539dc3864a4e279c92c84ce82c5a718870ff00db70bfa927eb25ecba4139acf4d3589
7
- data.tar.gz: 50227ecf97ee5deb2ff786c43ea1190738882a39e3992e9a8f7a4feb2a5b0aad34313f7c5f4530399abc49ff0bbc2da2daa63f2e68883007ce4f66285b818bc8
6
+ metadata.gz: 5138ae5ce5036521d3e75b276aef5a25876bdb16fdab647e241a7c503f98f3052b1f02679681b832499aded94cbc97f7c9da6730adef60b11865db284032c970
7
+ data.tar.gz: c4053f45aebe4441685eb8d02565ffdb66e7afaac1d9a1caaff565470a4752d8dd5ba587246b9ca6f2c95d4807cc2cb7a9463a702e84d245a4fede9c797759a2
@@ -78,15 +78,16 @@ jQuery(function($) {
78
78
 
79
79
  $.fn.visible = function(cond) { this[cond ? 'show' : 'hide' ]() };
80
80
 
81
- show_flash_error = function(message) {
82
- var error_div = $('.flash.error');
83
- if (error_div.length == 0) {
84
- error_div = $('<div class="flash error" />');
85
- $('#wrapper').prepend(error_div);
81
+ show_flash = function(type, message) {
82
+ var flash_div = $('.flash.' + type);
83
+ if (flash_div.length == 0) {
84
+ flash_div = $('<div class="flash ' + type + '" />');
85
+ $('#wrapper').prepend(flash_div);
86
86
  }
87
- error_div.html(message).show().fadeOut(5000);
87
+ flash_div.html(message).show().delay(5000).fadeOut(500);
88
88
  }
89
89
 
90
+
90
91
  // Apply to individual radio button that makes another element visible when checked
91
92
  $.fn.radioControlsVisibilityOfElement = function(dependentElementSelector){
92
93
  if(!this.get(0)){ return }
@@ -169,12 +170,12 @@ $(document).ready(function(){
169
170
  _method: 'delete',
170
171
  authenticity_token: AUTH_TOKEN
171
172
  },
172
- dataType: 'html',
173
+ dataType: 'script',
173
174
  success: function(response) {
174
175
  el.parents("tr").fadeOut('hide');
175
176
  },
176
177
  error: function(response, textStatus, errorThrown) {
177
- show_flash_error(response.responseText);
178
+ show_flash('error', response.responseText);
178
179
  }
179
180
  });
180
181
  }
@@ -199,7 +200,7 @@ $(document).ready(function(){
199
200
  el.parents("tr").fadeOut('hide');
200
201
  },
201
202
  error: function(response, textStatus, errorThrown) {
202
- show_flash_error(response.responseText);
203
+ show_flash('error', response.responseText);
203
204
  }
204
205
 
205
206
  })
@@ -0,0 +1,61 @@
1
+ $(document).ready ->
2
+ #handle edit click
3
+ $('a.edit-line-item').click toggleLineItemEdit
4
+
5
+ #handle cancel click
6
+ $('a.cancel-line-item').click toggleLineItemEdit
7
+
8
+ #handle save click
9
+ $('a.save-line-item').click ->
10
+ save = $ this
11
+ line_item_id = save.data('line-item-id')
12
+ quantity = parseInt(save.parents('tr').find('input.line_item_quantity').val())
13
+
14
+ toggleItemEdit()
15
+ adjustLineItem(line_item_id, quantity)
16
+ false
17
+
18
+ # handle delete click
19
+ $('a.delete-line-item').click ->
20
+ if confirm(Spree.translations.are_you_sure_delete)
21
+ del = $(this);
22
+ line_item_id = del.data('line-item-id');
23
+
24
+ toggleItemEdit()
25
+ deleteLineItem(line_item_id)
26
+
27
+ toggleLineItemEdit = ->
28
+ link = $(this);
29
+ link.parent().find('a.edit-line-item').toggle();
30
+ link.parent().find('a.cancel-line-item').toggle();
31
+ link.parent().find('a.save-line-item').toggle();
32
+ link.parent().find('a.delete-line-item').toggle();
33
+ link.parents('tr').find('td.line-item-qty-show').toggle();
34
+ link.parents('tr').find('td.line-item-qty-edit').toggle();
35
+
36
+ false
37
+
38
+ lineItemURL = (line_item_id) ->
39
+ url = Spree.routes.orders_api + "/" + order_number + "/line_items/" + line_item_id + ".json"
40
+
41
+ adjustLineItem = (line_item_id, quantity) ->
42
+ url = lineItemURL(line_item_id)
43
+ $.ajax(
44
+ type: "PUT",
45
+ url: Spree.url(url),
46
+ data:
47
+ line_item:
48
+ quantity: quantity
49
+ ).done (msg) ->
50
+ advanceOrder()
51
+
52
+ deleteLineItem = (line_item_id) ->
53
+ url = lineItemURL(line_item_id)
54
+ $.ajax(
55
+ type: "DELETE"
56
+ url: Spree.url(url)
57
+ ).done (msg) ->
58
+ $('#line-item-' + line_item_id).remove()
59
+ if $('.line-items tr.line-item').length == 0
60
+ $('.line-items').remove()
61
+ advanceOrder()
@@ -19,7 +19,7 @@ jQuery ($) ->
19
19
  @data = data
20
20
  jqXHR.fail ->
21
21
  response = $.parseJSON(jqXHR.responseText)
22
- show_flash_error(response.error)
22
+ show_flash('error', response.error)
23
23
 
24
24
  amount: -> @data.amount
25
25
  display_amount: -> @data.display_amount
@@ -24,8 +24,9 @@ $.fn.productAutocomplete = function () {
24
24
  };
25
25
  },
26
26
  results: function (data, page) {
27
+ var products = data.products ? data.products : [];
27
28
  return {
28
- results: data.products
29
+ results: products
29
30
  };
30
31
  }
31
32
  },
@@ -16,11 +16,11 @@ $(document).ready ->
16
16
  top: 'auto'
17
17
  left: 'auto'
18
18
 
19
- target = document.getElementById("spinner")
19
+ target = document.getElementById("spinner")
20
+ spinner = new Spinner(opts).spin(target)
20
21
 
21
22
  $(document).ajaxStart ->
22
23
  $("#progress").stop(true, true).fadeIn()
23
- spinner = new Spinner(opts).spin(target)
24
24
 
25
25
  $(document).ajaxStop ->
26
26
  $("#progress").fadeOut()
@@ -2,6 +2,62 @@
2
2
  $(document).ready(function () {
3
3
  'use strict';
4
4
 
5
+ // handle variant selection, show stock level.
6
+ $('#add_variant_id').change(function(){
7
+ var variant_id = $(this).val();
8
+
9
+ var variant = _.find(window.variants, function(variant){
10
+ return variant.id == variant_id
11
+ })
12
+ $('#stock_details').html(variantStockTemplate({variant: variant}));
13
+ $('#stock_details').show();
14
+
15
+ $('button.add_variant').click(addVariantFromStockLocation);
16
+
17
+ // Add some tips
18
+ $('.with-tip').powerTip({
19
+ smartPlacement: true,
20
+ fadeInTime: 50,
21
+ fadeOutTime: 50,
22
+ intentPollInterval: 300
23
+ });
24
+
25
+ });
26
+
27
+ //handle edit click
28
+ $('a.edit-item').click(toggleItemEdit);
29
+
30
+ //handle cancel click
31
+ $('a.cancel-item').click(toggleItemEdit);
32
+
33
+ //handle split click
34
+ $('a.split-item').click(startItemSplit);
35
+
36
+ //handle save click
37
+ $('a.save-item').click(function(){
38
+ var save = $(this);
39
+ var shipment_number = save.data('shipment-number');
40
+ var variant_id = save.data('variant-id');
41
+
42
+ var quantity = parseInt(save.parents('tr').find('input.line_item_quantity').val());
43
+
44
+ toggleItemEdit();
45
+ adjustShipmentItems(shipment_number, variant_id, quantity);
46
+ return false;
47
+ });
48
+
49
+ //handle delete click
50
+ $('a.delete-item').click(function(){
51
+ if (confirm(Spree.translations.are_you_sure_delete)) {
52
+ var del = $(this);
53
+ var shipment_number = del.data('shipment-number');
54
+ var variant_id = del.data('variant-id');
55
+
56
+ toggleItemEdit();
57
+ adjustShipmentItems(shipment_number, variant_id, 0);
58
+ }
59
+ });
60
+
5
61
  // handle ship click
6
62
  $('[data-hook=admin_order_edit_form] a.ship').on('click', function () {
7
63
  var link = $(this);
@@ -72,3 +128,189 @@ $(document).ready(function () {
72
128
  });
73
129
 
74
130
  });
131
+
132
+ adjustShipmentItems = function(shipment_number, variant_id, quantity){
133
+ var shipment = _.findWhere(shipments, {number: shipment_number + ''});
134
+ var inventory_units = _.where(shipment.inventory_units, {variant_id: variant_id});
135
+
136
+ var url = Spree.routes.orders_api + "/" + order_number + "/shipments/" + shipment_number;
137
+
138
+ var new_quantity = 0;
139
+ if(inventory_units.length<quantity){
140
+ url += "/add"
141
+ new_quantity = (quantity - inventory_units.length);
142
+ }else if(inventory_units.length>quantity){
143
+ url += "/remove"
144
+ new_quantity = (inventory_units.length - quantity);
145
+ }
146
+ url += '.json';
147
+
148
+ if(new_quantity!=0){
149
+ $.ajax({
150
+ type: "PUT",
151
+ url: Spree.url(url),
152
+ data: { variant_id: variant_id, quantity: new_quantity }
153
+ }).done(function( msg ) {
154
+ advanceOrder();
155
+ });
156
+ }
157
+ }
158
+
159
+ toggleTrackingEdit = function(){
160
+ var link = $(this);
161
+ link.parents('tbody').find('tr.edit-tracking').toggle();
162
+ link.parents('tbody').find('tr.show-tracking').toggle();
163
+ }
164
+
165
+ toggleMethodEdit = function(){
166
+ var link = $(this);
167
+ link.parents('tbody').find('tr.edit-method').toggle();
168
+ link.parents('tbody').find('tr.show-method').toggle();
169
+ }
170
+
171
+ toggleItemEdit = function(){
172
+ var link = $(this);
173
+ link.parent().find('a.edit-item').toggle();
174
+ link.parent().find('a.cancel-item').toggle();
175
+ link.parent().find('a.split-item').toggle();
176
+ link.parent().find('a.save-item').toggle();
177
+ link.parent().find('a.delete-item').toggle();
178
+ link.parents('tr').find('td.item-qty-show').toggle();
179
+ link.parents('tr').find('td.item-qty-edit').toggle();
180
+
181
+ return false;
182
+ }
183
+
184
+ startItemSplit = function(event){
185
+ event.preventDefault();
186
+ var link = $(this);
187
+ link.parent().find('a.edit-item').toggle();
188
+ link.parent().find('a.split-item').toggle();
189
+ link.parent().find('a.delete-item').toggle();
190
+ var variant_id = link.data('variant-id');
191
+
192
+ var variant = {};
193
+ $.ajax({
194
+ type: "GET",
195
+ async: false,
196
+ url: Spree.url(Spree.routes.variants_api),
197
+ data: {
198
+ q: {
199
+ "id_eq": variant_id
200
+ }
201
+ }
202
+ }).success(function( data ) {
203
+ variant = data['variants'][0];
204
+ }).error(function( msg ) {
205
+ console.log(msg);
206
+ });
207
+
208
+ var max_quantity = link.closest('tr').data('item-quantity');
209
+ var split_item_template = Handlebars.compile($('#variant_split_template').text());
210
+ link.closest('tr').after(split_item_template({ variant: variant, shipments: shipments, max_quantity: max_quantity }));
211
+ $('a.cancel-split').click(cancelItemSplit);
212
+ $('a.save-split').click(completeItemSplit);
213
+
214
+ // Add some tips
215
+ $('.with-tip').powerTip({
216
+ smartPlacement: true,
217
+ fadeInTime: 50,
218
+ fadeOutTime: 50,
219
+ intentPollInterval: 300
220
+ });
221
+ $('#item_stock_location').select2({ width: 'resolve', placeholder: 'Choose Location' });
222
+ }
223
+
224
+ completeItemSplit = function(event) {
225
+ event.preventDefault();
226
+ var link = $(this);
227
+ var order_number = link.closest('tbody').data('order-number');
228
+ var stock_item_row = link.closest('tr');
229
+ var variant_id = stock_item_row.data('variant-id');
230
+ var quantity = stock_item_row.find('#item_quantity').val();
231
+
232
+ var stock_location_id = stock_item_row.find('#item_stock_location').val();
233
+ var original_shipment_number = link.closest('tbody').data('shipment-number');
234
+
235
+ var selected_shipment = stock_item_row.find($('#item_stock_location').select2('data').element);
236
+ var target_shipment_number = selected_shipment.data('shipment-number');
237
+ var new_shipment = selected_shipment.data('new-shipment');
238
+
239
+ if (stock_location_id != 'new_shipment') {
240
+ // first remove item(s) from original shipment
241
+ $.ajax({
242
+ type: "PUT",
243
+ async: false,
244
+ url: Spree.url(Spree.routes.orders_api + "/" + order_number + "/shipments/" + original_shipment_number + "/remove.json"),
245
+ data: { variant_id: variant_id, quantity: quantity }
246
+ });
247
+
248
+ if (new_shipment != undefined) {
249
+ $.ajax({
250
+ type: "POST",
251
+ async: false,
252
+ url: Spree.url(Spree.routes.orders_api + "/" + order_number + "/shipments.json"),
253
+ data: { variant_id: variant_id, quantity: quantity, stock_location_id: stock_location_id }
254
+ }).done(function(msg) {
255
+ advanceOrder();
256
+ });
257
+ } else {
258
+ $.ajax({
259
+ type: "PUT",
260
+ async: false,
261
+ url: Spree.url(Spree.routes.orders_api + "/" + order_number + "/shipments/" + target_shipment_number + "/add.json"),
262
+ data: { variant_id: variant_id, quantity: quantity }
263
+ }).done(function(msg) {
264
+ advanceOrder();
265
+ });
266
+ }
267
+ }
268
+ }
269
+
270
+ advanceOrder = function() {
271
+ $.ajax({
272
+ type: "PUT",
273
+ async: false,
274
+ url: Spree.url(Spree.routes.checkouts_api + "/" + order_number + "/advance")
275
+ }).done(function() {
276
+ window.location.reload();
277
+ });
278
+ }
279
+
280
+ cancelItemSplit = function(event) {
281
+ event.preventDefault();
282
+ var link = $(this);
283
+ var prev_row = link.closest('tr').prev();
284
+ link.closest('tr').remove();
285
+ prev_row.find('a.edit-item').toggle();
286
+ prev_row.find('a.split-item').toggle();
287
+ prev_row.find('a.delete-item').toggle();
288
+ }
289
+
290
+ addVariantFromStockLocation = function() {
291
+ $('#stock_details').hide();
292
+
293
+ var variant_id = $('input.variant_autocomplete').val();
294
+ var stock_location_id = $(this).data('stock-location-id');
295
+ var quantity = $("input.quantity[data-stock-location-id='" + stock_location_id + "']").val();
296
+
297
+ var shipment = _.find(shipments, function(shipment){
298
+ return shipment.stock_location_id == stock_location_id && (shipment.state == 'ready' || shipment.state == 'pending');
299
+ });
300
+
301
+ if(shipment==undefined){
302
+ $.ajax({
303
+ type: "POST",
304
+ url: Spree.url(Spree.routes.orders_api + "/" + order_number + "/shipments.json"),
305
+ data: { variant_id: variant_id, quantity: quantity, stock_location_id: stock_location_id }
306
+ }).done(function( msg ) {
307
+ advanceOrder();
308
+ }).error(function( msg ) {
309
+ console.log(msg);
310
+ });
311
+ }else{
312
+ //add to existing shipment
313
+ adjustShipmentItems(shipment.number, variant_id, quantity);
314
+ }
315
+ return 1
316
+ }
@@ -6,253 +6,9 @@ $(document).ready(function() {
6
6
  if ($('#variant_autocomplete_template').length > 0) {
7
7
  window.variantTemplate = Handlebars.compile($('#variant_autocomplete_template').text());
8
8
  window.variantStockTemplate = Handlebars.compile($('#variant_autocomplete_stock_template').text());
9
-
10
- // handle variant selection, show stock level.
11
- $('#add_variant_id').change(function(){
12
- var variant_id = $(this).val();
13
-
14
- var variant = _.find(window.variants, function(variant){
15
- return variant.id == variant_id
16
- })
17
- $('#stock_details').html(variantStockTemplate({variant: variant}));
18
- $('#stock_details').show();
19
-
20
- $('button.add_variant').click(addVariantFromStockLocation);
21
-
22
- // Add some tips
23
- $('.with-tip').powerTip({
24
- smartPlacement: true,
25
- fadeInTime: 50,
26
- fadeOutTime: 50,
27
- intentPollInterval: 300
28
- });
29
-
30
- });
31
-
32
- //handle edit click
33
- $('a.edit-item').click(toggleItemEdit);
34
-
35
- //handle cancel click
36
- $('a.cancel-item').click(toggleItemEdit);
37
-
38
- //handle split click
39
- $('a.split-item').click(startItemSplit);
40
-
41
- //handle save click
42
- $('a.save-item').click(function(){
43
- var save = $(this);
44
- var shipment_number = save.data('shipment-number');
45
- var variant_id = save.data('variant-id');
46
-
47
- var quantity = parseInt(save.parents('tr').find('input.line_item_quantity').val());
48
-
49
- toggleItemEdit();
50
-
51
- adjustItems(shipment_number, variant_id, quantity);
52
- return false;
53
- });
54
-
55
- //handle delete click
56
- $('a.delete-item').click(function(){
57
- if (confirm(Spree.translations.are_you_sure_delete)) {
58
- var del = $(this);
59
- var shipment_number = del.data('shipment-number');
60
- var variant_id = del.data('variant-id');
61
-
62
- toggleItemEdit();
63
-
64
- adjustItems(shipment_number, variant_id, 0);
65
- }
66
- });
67
9
  }
68
10
  });
69
11
 
70
- adjustItems = function(shipment_number, variant_id, quantity){
71
- var shipment = _.findWhere(shipments, {number: shipment_number + ''});
72
- var inventory_units = _.where(shipment.inventory_units, {variant_id: variant_id});
73
-
74
- var url = Spree.routes.orders_api + "/" + order_number + "/shipments/" + shipment_number;
75
-
76
- var new_quantity = 0;
77
- if(inventory_units.length<quantity){
78
- url += "/add"
79
- new_quantity = (quantity - inventory_units.length);
80
- }else if(inventory_units.length>quantity){
81
- url += "/remove"
82
- new_quantity = (inventory_units.length - quantity);
83
- }
84
- url += '.json';
85
-
86
- if(new_quantity!=0){
87
- $.ajax({
88
- type: "PUT",
89
- url: Spree.url(url),
90
- data: { variant_id: variant_id, quantity: new_quantity }
91
- }).done(function( msg ) {
92
- advanceOrder();
93
- });
94
- }
95
- }
96
-
97
- toggleTrackingEdit = function(){
98
- var link = $(this);
99
- link.parents('tbody').find('tr.edit-tracking').toggle();
100
- link.parents('tbody').find('tr.show-tracking').toggle();
101
- }
102
-
103
- toggleMethodEdit = function(){
104
- var link = $(this);
105
- link.parents('tbody').find('tr.edit-method').toggle();
106
- link.parents('tbody').find('tr.show-method').toggle();
107
- }
108
-
109
- toggleItemEdit = function(){
110
- var link = $(this);
111
- link.parent().find('a.edit-item').toggle();
112
- link.parent().find('a.cancel-item').toggle();
113
- link.parent().find('a.split-item').toggle();
114
- link.parent().find('a.save-item').toggle();
115
- link.parent().find('a.delete-item').toggle();
116
- link.parents('tr').find('td.item-qty-show').toggle();
117
- link.parents('tr').find('td.item-qty-edit').toggle();
118
-
119
- return false;
120
- }
121
-
122
- startItemSplit = function(event){
123
- event.preventDefault();
124
- var link = $(this);
125
- link.parent().find('a.edit-item').toggle();
126
- link.parent().find('a.split-item').toggle();
127
- link.parent().find('a.delete-item').toggle();
128
- var variant_id = link.data('variant-id');
129
-
130
- var variant = {};
131
- $.ajax({
132
- type: "GET",
133
- async: false,
134
- url: Spree.url(Spree.routes.variants_api),
135
- data: {
136
- q: {
137
- "id_eq": variant_id
138
- }
139
- }
140
- }).success(function( data ) {
141
- variant = data['variants'][0];
142
- }).error(function( msg ) {
143
- console.log(msg);
144
- });
145
-
146
- var max_quantity = link.closest('tr').data('item-quantity');
147
- var split_item_template = Handlebars.compile($('#variant_split_template').text());
148
- link.closest('tr').after(split_item_template({ variant: variant, shipments: shipments, max_quantity: max_quantity }));
149
- $('a.cancel-split').click(cancelItemSplit);
150
- $('a.save-split').click(completeItemSplit);
151
-
152
- // Add some tips
153
- $('.with-tip').powerTip({
154
- smartPlacement: true,
155
- fadeInTime: 50,
156
- fadeOutTime: 50,
157
- intentPollInterval: 300
158
- });
159
- $('#item_stock_location').select2({ width: 'resolve', placeholder: 'Choose Location' });
160
- }
161
-
162
- completeItemSplit = function(event) {
163
- event.preventDefault();
164
- var link = $(this);
165
- var order_number = link.closest('tbody').data('order-number');
166
- var stock_item_row = link.closest('tr');
167
- var variant_id = stock_item_row.data('variant-id');
168
- var quantity = stock_item_row.find('#item_quantity').val();
169
-
170
- var stock_location_id = stock_item_row.find('#item_stock_location').val();
171
- var original_shipment_number = link.closest('tbody').data('shipment-number');
172
-
173
- var selected_shipment = stock_item_row.find($('#item_stock_location').select2('data').element);
174
- var target_shipment_number = selected_shipment.data('shipment-number');
175
- var new_shipment = selected_shipment.data('new-shipment');
176
-
177
- if (stock_location_id != 'new_shipment') {
178
- // first remove item(s) from original shipment
179
- $.ajax({
180
- type: "PUT",
181
- async: false,
182
- url: Spree.url(Spree.routes.orders_api + "/" + order_number + "/shipments/" + original_shipment_number + "/remove.json"),
183
- data: { variant_id: variant_id, quantity: quantity }
184
- });
185
-
186
- if (new_shipment != undefined) {
187
- $.ajax({
188
- type: "POST",
189
- async: false,
190
- url: Spree.url(Spree.routes.orders_api + "/" + order_number + "/shipments.json"),
191
- data: { variant_id: variant_id, quantity: quantity, stock_location_id: stock_location_id }
192
- }).done(function(msg) {
193
- advanceOrder();
194
- });
195
- } else {
196
- $.ajax({
197
- type: "PUT",
198
- async: false,
199
- url: Spree.url(Spree.routes.orders_api + "/" + order_number + "/shipments/" + target_shipment_number + "/add.json"),
200
- data: { variant_id: variant_id, quantity: quantity }
201
- }).done(function(msg) {
202
- advanceOrder();
203
- });
204
- }
205
- }
206
- }
207
-
208
- advanceOrder = function() {
209
- $.ajax({
210
- type: "PUT",
211
- async: false,
212
- url: Spree.url(Spree.routes.checkouts_api + "/" + order_number + "/advance")
213
- }).done(function() {
214
- window.location.reload();
215
- });
216
- }
217
-
218
- cancelItemSplit = function(event) {
219
- event.preventDefault();
220
- var link = $(this);
221
- var prev_row = link.closest('tr').prev();
222
- link.closest('tr').remove();
223
- prev_row.find('a.edit-item').toggle();
224
- prev_row.find('a.split-item').toggle();
225
- prev_row.find('a.delete-item').toggle();
226
- }
227
-
228
- addVariantFromStockLocation = function() {
229
- $('#stock_details').hide();
230
-
231
- var variant_id = $('input.variant_autocomplete').val();
232
- var stock_location_id = $(this).data('stock-location-id');
233
- var quantity = $("input.quantity[data-stock-location-id='" + stock_location_id + "']").val();
234
-
235
- var shipment = _.find(shipments, function(shipment){
236
- return shipment.stock_location_id == stock_location_id && (shipment.state == 'ready' || shipment.state == 'pending');
237
- });
238
-
239
- if(shipment==undefined){
240
- $.ajax({
241
- type: "POST",
242
- url: Spree.url(Spree.routes.orders_api + "/" + order_number + "/shipments.json"),
243
- data: { variant_id: variant_id, quantity: quantity, stock_location_id: stock_location_id }
244
- }).done(function( msg ) {
245
- advanceOrder();
246
- }).error(function( msg ) {
247
- console.log(msg);
248
- });
249
- }else{
250
- //add to existing shipment
251
- adjustItems(shipment.number, variant_id, quantity);
252
- }
253
- return 1
254
- }
255
-
256
12
  formatVariantResult = function(variant) {
257
13
  if (variant["images"][0] != undefined && variant["images"][0].urls != undefined) {
258
14
  variant.image = variant.images[0].urls.mini
@@ -0,0 +1,10 @@
1
+ jQuery ->
2
+ $('.track_inventory_checkbox').on 'click', ->
3
+ $(@).siblings('.variant_track_inventory').val($(@).is(':checked'))
4
+ $(@).parent('form').submit()
5
+ $('.toggle_variant_track_inventory').on 'submit', ->
6
+ $.ajax
7
+ type: @method
8
+ url: @action
9
+ data: $(@).serialize()
10
+ false
@@ -0,0 +1,17 @@
1
+ .log_entry {
2
+ &.success {
3
+ background: lighten($color-2, 15);
4
+
5
+ td h4 {
6
+ color: darken($color-body-text, 25);
7
+ }
8
+ }
9
+
10
+ &.fail {
11
+ background: lighten($color-5, 25);
12
+
13
+ td h4 {
14
+ color: lighten($color-body-text, 50);
15
+ }
16
+ }
17
+ }