caboose-cms 0.5.64 → 0.5.66

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +8 -8
  2. data/app/assets/javascripts/caboose/admin.js +1 -1
  3. data/app/assets/javascripts/caboose/admin_edit_order.js +724 -0
  4. data/app/assets/javascripts/caboose/cart2.js +4 -4
  5. data/app/assets/javascripts/caboose/model/index_table.js +122 -80
  6. data/app/assets/stylesheets/caboose/admin_main.css +8 -0
  7. data/app/controllers/caboose/application_controller.rb +1 -1
  8. data/app/controllers/caboose/block_type_sources_controller.rb +1 -1
  9. data/app/controllers/caboose/block_types_controller.rb +1 -1
  10. data/app/controllers/caboose/calendars_controller.rb +1 -1
  11. data/app/controllers/caboose/cart_controller.rb +8 -1
  12. data/app/controllers/caboose/checkout_controller.rb +17 -9
  13. data/app/controllers/caboose/line_items_controller.rb +135 -0
  14. data/app/controllers/caboose/order_packages_controller.rb +304 -0
  15. data/app/controllers/caboose/orders_controller.rb +31 -74
  16. data/app/controllers/caboose/pages_controller.rb +2 -1
  17. data/app/controllers/caboose/product_images_controller.rb +11 -0
  18. data/app/controllers/caboose/products_controller.rb +25 -8
  19. data/app/controllers/caboose/shipping_addresses_controller.rb +46 -0
  20. data/app/controllers/caboose/shipping_packages_controller.rb +125 -54
  21. data/app/controllers/caboose/sites_controller.rb +2 -79
  22. data/app/controllers/caboose/smtp_controller.rb +52 -0
  23. data/app/controllers/caboose/store_controller.rb +94 -0
  24. data/app/controllers/caboose/vendors_controller.rb +25 -4
  25. data/app/models/caboose/address.rb +1 -3
  26. data/app/models/caboose/caboose_plugin.rb +1 -1
  27. data/app/models/caboose/category.rb +18 -0
  28. data/app/models/caboose/core_plugin.rb +21 -19
  29. data/app/models/caboose/order.rb +12 -7
  30. data/app/models/caboose/order_package.rb +5 -2
  31. data/app/models/caboose/order_transaction.rb +25 -0
  32. data/app/models/caboose/page.rb +1 -1
  33. data/app/models/caboose/schema.rb +50 -22
  34. data/app/models/caboose/shipping_calculator.rb +26 -30
  35. data/app/models/caboose/shipping_package.rb +45 -5
  36. data/app/models/caboose/store_config.rb +18 -6
  37. data/app/models/caboose/tax_calculator.rb +6 -5
  38. data/app/views/caboose/blocks/admin_edit.html.erb +1 -1
  39. data/app/views/caboose/line_items/admin_new.html.erb +100 -0
  40. data/app/views/caboose/orders/admin_edit.html.erb +21 -247
  41. data/app/views/caboose/orders/admin_edit_old.html.erb +155 -0
  42. data/app/views/caboose/orders/admin_new.html.erb +8 -23
  43. data/app/views/caboose/products/#Untitled-1# +0 -0
  44. data/app/views/caboose/products/admin_edit_images.html.erb +20 -4
  45. data/app/views/caboose/products/admin_index.html.erb +9 -3
  46. data/app/views/caboose/products/admin_sort.html.erb +138 -142
  47. data/app/views/caboose/roles/index.html.erb +1 -1
  48. data/app/views/caboose/shipping_packages/admin_edit.html.erb +52 -137
  49. data/app/views/caboose/shipping_packages/admin_index.html.erb +56 -19
  50. data/app/views/caboose/sites/_admin_header.html.erb +3 -5
  51. data/app/views/caboose/sites/admin_edit.html.erb +5 -3
  52. data/app/views/caboose/smtp/admin_edit.html.erb +41 -0
  53. data/app/views/caboose/station/index.html.erb +1 -1
  54. data/app/views/caboose/store/admin_edit.html.erb +96 -0
  55. data/app/views/caboose/vendors/admin_edit.html.erb +7 -3
  56. data/app/views/layouts/caboose/_station.html.erb +1 -1
  57. data/config/routes.rb +67 -25
  58. data/lib/caboose/engine.rb +1 -1
  59. data/lib/caboose/version.rb +1 -1
  60. metadata +28 -5
  61. data/app/views/caboose/shipping_packages/admin_new.html.erb +0 -33
  62. data/app/views/caboose/sites/admin_edit_smtp_config.html.erb +0 -51
  63. data/app/views/caboose/sites/admin_edit_store_config.html.erb +0 -77
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmQwMGY4YWE5MTAzMjFjZGMzMzk5ZDM4ODFmNWJkYTA2ZDdlMTQ3MA==
4
+ NjAwYzgzNGY1MmNjMzE4ODI0OGI0NjE4MjIwMWVmN2VlOTZmZDYwZQ==
5
5
  data.tar.gz: !binary |-
6
- ODM4ZGYyNmEyZjU1OGEwMjJjMjZmYTRhZTcwMThiNGEwM2Q0Nzk5Yw==
6
+ Mzk0OTQwMTljMjMyZTIzYmRiNTQwODkzYzQzYzdkZjFjN2Y2ZDUxNw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NDc2NGUwMmZjZDcxNWU4NjZlYzMzOTY0NjZhYjRiZjgxMDljOWI2NzgwN2Rj
10
- N2I5ZGI2ZWZhMDdiZWQ4NzIwYjFmYzZmZjlkMDAyNzM5ZTBmYjA2NDNiMDQ0
11
- ZGM5Y2M1M2JjZGZkZmRmNzlhMzg1NjY3ZjI2NzU1NjUxYWZiNTg=
9
+ NzJhMjFjMmIwYzFlMzZkNTA3MjkxMDU3MDZiOWNhOWU4NzlkMmI4ZDcwZDk0
10
+ MGRjNmFjOWZlOWJkZjJjZTJhZWViZjVkZjEwZTlkZWNhNDUxN2RjM2RiNzUw
11
+ M2U0ODAyMDM0NjM1NGY1OWZiODc2NTQ1N2YzNTY4MWY5YmM0N2I=
12
12
  data.tar.gz: !binary |-
13
- OGYzNTg5NjAxNjNjZWRkM2RlMGY3ODFhNzhhMDhhOWEzZDZjOGU1MTZhOGQ2
14
- NjcxYWQyNDcwMTM1NmRhODhjYTQzMDU0MDY5MDMxZGU2ZjNiZjdmMDI4ZjFj
15
- ZjBiZDgxMzU3ZTYxMjk5NTJiMDQ4ZWRkM2YwN2I0MmZkZGYwZjE=
13
+ MDEzM2E0Y2NlODU2MWY5NDRmYmZiZTE5ZGM4N2EwYzUwZjQwOWZmZjAyOGQw
14
+ MjU1YzQ4YzcwY2E4NDAxMzVkZmM0MDNhMWJkMWU4YmIyMzA2MWQyOTQzNGQ3
15
+ OTg1YzA4ZWZkNTg2NzQzMmJmZmM1NjY3YjA5NDMwNDk1NDg3YTc=
@@ -15,4 +15,4 @@
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
@@ -0,0 +1,724 @@
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
+ var OrderController = function(params) { this.init(params); }
16
+
17
+ OrderController.prototype = {
18
+
19
+ order_id: false,
20
+ order: false,
21
+ authenticity_token: false,
22
+
23
+ init: function(params)
24
+ {
25
+ for (var i in params)
26
+ this[i] = params[i];
27
+
28
+ var that = this;
29
+ $(document).ready(function() { that.refresh(); });
30
+ },
31
+
32
+ refresh: function()
33
+ {
34
+ var that = this;
35
+ that.refresh_order(function() {
36
+ $('#order_table').html("<p class='loading'>Getting order...</p>");
37
+ that.print();
38
+ that.make_editable();
39
+ });
40
+ },
41
+
42
+ refresh_order: function(after)
43
+ {
44
+ var that = this;
45
+ $.ajax({
46
+ url: '/admin/orders/' + that.order_id + '/json',
47
+ success: function(order) {
48
+ that.order = order;
49
+ if (after) after();
50
+ }
51
+ });
52
+ },
53
+
54
+ make_editable: function()
55
+ {
56
+ var that = this;
57
+ $.each(that.order.order_packages, function(i, op) {
58
+ new ModelBinder({
59
+ name: 'OrderPackage',
60
+ id: op.id,
61
+ update_url: '/admin/orders/' + op.order_id + '/packages/' + op.id,
62
+ authenticity_token: that.authenticity_token,
63
+ attributes: [
64
+ { name: 'status' , nice_name: 'Status' , type: 'select' , value: op.status , width: 300, fixed_placeholder: true , options_url: '/admin/orders/line-items/status-options' },
65
+ { name: 'package_method' , nice_name: 'Package/Method' , type: 'select' , value: op.shipping_package_id + '_' + op.shipping_method_id , width: 300, fixed_placeholder: false, options_url: '/admin/shipping-packages/package-method-options' },
66
+ { name: 'tracking_number' , nice_name: 'Tracking Number' , type: 'text' , value: op.tracking_number , width: 300, fixed_placeholder: true, align: 'right' },
67
+ { name: 'total' , nice_name: 'Shipping Total' , type: 'text' , value: curr(op.total) , width: 300, fixed_placeholder: true, align: 'right' }
68
+ ]
69
+ });
70
+ });
71
+ $.each(that.order.line_items, function(i, li) {
72
+ new ModelBinder({
73
+ name: 'Lineitem',
74
+ id: li.id,
75
+ update_url: '/admin/orders/' + li.order_id + '/line-items/' + li.id,
76
+ authenticity_token: that.authenticity_token,
77
+ attributes: [
78
+ { name: 'status' , nice_name: 'Status' , type: 'select' , align: 'left' , value: li.status , text: li.status, width: 150, fixed_placeholder: false, options_url: '/admin/orders/line-items/status-options' },
79
+ { name: 'tracking_number' , nice_name: 'Tracking Number' , type: 'text' , align: 'left' , value: li.tracking_number , width: 200, fixed_placeholder: false },
80
+ { name: 'quantity' , nice_name: 'Quantity' , type: 'text' , align: 'right', value: li.quantity , width: 75, fixed_placeholder: false, after_update: function() { that.refresh(); } }
81
+ ]
82
+ });
83
+ });
84
+ new ModelBinder({
85
+ name: 'Order',
86
+ id: that.order.id,
87
+ update_url: '/admin/orders/' + that.order.id,
88
+ authenticity_token: that.authenticity_token,
89
+ attributes: [
90
+ { name: 'status' , nice_name: 'Status' , type: 'select', value: that.order.status , width: 100, fixed_placeholder: false, options_url: '/admin/orders/status-options' },
91
+ { name: 'tax' , nice_name: 'Tax' , type: 'text' , value: curr(that.order.tax) , width: 100, fixed_placeholder: false, align: 'right' },
92
+ { name: 'handling' , nice_name: 'Handling' , type: 'text' , value: curr(that.order.handling) , width: 100, fixed_placeholder: false, align: 'right' },
93
+ { name: 'custom_discount', nice_name: 'Discount' , type: 'text' , value: curr(that.order.custom_discount) , width: 100, fixed_placeholder: false, align: 'right' }
94
+ ]
95
+ });
96
+ },
97
+
98
+ assign_to_package_form: function(li_id)
99
+ {
100
+ var that = this;
101
+ if (!that.order.order_packages)
102
+ that.order.order_packages = [];
103
+ if (that.order.order_packages.length == 0)
104
+ {
105
+ that.assign_to_new_package_form(li_id);
106
+ return;
107
+ }
108
+
109
+ var select = $('<select/>').attr('id', 'order_package_id').css('width', '300px').change(function(e) {
110
+ var order_package_id = $(this).val();
111
+ if (order_package_id == -1)
112
+ that.assign_to_new_package_form(li_id);
113
+ else
114
+ that.assign_to_package(li_id, order_package_id);
115
+ });
116
+ select.append($('<option/>').val(-1).html('-- Select a package --'));
117
+ $.each(that.order.order_packages, function(i, op) {
118
+ var sp = op.shipping_package;
119
+ var sm = op.shipping_method;
120
+ var name = [];
121
+ if (sp.name) name.push(sp.name);
122
+ name.push(sp.outside_length + 'x' + sp.outside_width + 'x' + sp.outside_height);
123
+ name.push(sm.carrier);
124
+ name.push(sm.service_name);
125
+ name = name.join(' - ');
126
+ select.append($('<option/>').val(op.id).html(name));
127
+ });
128
+ select.append($('<option/>').val(-1).html('New Package'));
129
+ var p = $('<p/>').append(select);
130
+ $('#assign_to_package_' + li_id).empty().append(p);
131
+ },
132
+
133
+ assign_to_new_package_form: function(li_id)
134
+ {
135
+ var that = this;
136
+ $('#assign_to_package_' + li_id).html("<p class='loading'>Getting packages...</p>");
137
+ $.ajax({
138
+ url: '/admin/shipping-packages/json',
139
+ type: 'get',
140
+ success: function(resp) {
141
+ var select = $('<select/>')
142
+ .attr('id', 'package_id')
143
+ .css('width', '400px')
144
+ .change(function(e) { // Create the new order package
145
+ var arr = $(this).val().split('_');
146
+ $.ajax({
147
+ url: '/admin/orders/' + that.order.id + '/packages',
148
+ type: 'post',
149
+ data: { shipping_package_id: arr[0], shipping_method_id: arr[1] },
150
+ success: function(resp) {
151
+ that.assign_to_package(li_id, resp.new_id);
152
+ }
153
+ });
154
+ }
155
+ );
156
+ select.append($('<option/>').val('').html('-- Select a package and shipping method --'));
157
+ $.each(resp.models, function(i, sp) {
158
+ var name = [];
159
+ if (sp.name) name.push(sp.name);
160
+ name.push(sp.outside_length + 'x' + sp.outside_width + 'x' + sp.outside_height);
161
+ name = name.join(' - ');
162
+ var optgroup = $('<optgroup/>').attr('label', name);
163
+ $.each(sp.shipping_methods, function(j, sm) {
164
+ optgroup.append($('<option/>').val('' + sp.id + '_' + sm.id).html(sm.carrier + ' - ' + sm.service_name));
165
+ });
166
+ select.append(optgroup);
167
+ });
168
+
169
+ var p = $('<p/>')
170
+ .append(select).append('<br/>')
171
+ .append($('<input/>').attr('type', 'button').val('Cancel').click(function(e) { that.refresh(); }));
172
+ $('#assign_to_package_' + li_id).empty().append(p);
173
+ }
174
+ });
175
+ },
176
+
177
+ assign_to_package: function(li_id, order_package_id)
178
+ {
179
+ var that = this;
180
+ $.ajax({
181
+ url: '/admin/orders/' + that.order.id + '/line-items/' + li_id,
182
+ type: 'put',
183
+ data: { order_package_id: order_package_id },
184
+ success: function(resp) {
185
+ if (resp.error) $('#assign_to_package_' + li_id).html("<p class='note error'>" + resp.error + "</p>");
186
+ else that.refresh();
187
+ }
188
+ });
189
+ },
190
+
191
+ unassign_from_package: function(li_id)
192
+ {
193
+ var that = this;
194
+ $.ajax({
195
+ url: '/admin/orders/' + that.order.id + '/line-items/' + li_id,
196
+ type: 'put',
197
+ data: { order_package_id: -1 },
198
+ success: function(resp) {
199
+ if (resp.error) $('#message').html("<p class='note error'>" + resp.error + "</p>");
200
+ else that.refresh();
201
+ }
202
+ });
203
+ },
204
+
205
+ /******************************************************************************/
206
+
207
+ print_order: function(order_id)
208
+ {
209
+ window.open('/admin/orders/' + order_id + '/print');
210
+ },
211
+
212
+ line_items_for_order_package: function(order_package_id)
213
+ {
214
+ var that = this;
215
+ var line_items = [];
216
+ $.each(that.order.line_items, function(i, li) {
217
+ if (li.order_package_id == order_package_id)
218
+ line_items.push(li);
219
+ });
220
+ return line_items;
221
+ },
222
+
223
+ print: function()
224
+ {
225
+ var that = this;
226
+
227
+ var table = that.overview_table();
228
+ $('#overview_table').empty().append(table).append($('<br />'));
229
+
230
+ table = $('<table/>').addClass('data').css('width', '100%');
231
+ that.order_packages_table(table);
232
+ that.unassigned_line_items_table(table);
233
+ that.summary_table(table);
234
+ $('#order_table').empty().append(table);
235
+ },
236
+
237
+ overview_table: function()
238
+ {
239
+ var that = this;
240
+
241
+ var fstatus = $('<div/>').append(that.order.financial_status);
242
+ if (that.order.order_transactions.length > 0)
243
+ {
244
+ var transactions_table = $('<table/>').addClass('data');
245
+ $.each(that.order.order_transactions, function(i, ot) {
246
+ var d = new Date(ot.date_processed);
247
+ var h = d.getHours();
248
+ var ampm = 'am';
249
+ if (h >= 12) ampm = 'pm';
250
+ if (h > 12) h = h - 12;
251
+ d = '' + (d.getMonth()+1) + '/' + d.getDate() + '/' + d.getYear() + '<br/>' + h + ':' + d.getMinutes() + ' ' + ampm;
252
+ transactions_table.append($('<tr/>')
253
+ .append($('<td/>').html(d ))
254
+ .append($('<td/>').html(ot.transaction_type ))
255
+ .append($('<td/>').html(curr(ot.amount) ))
256
+ .append($('<td/>').html(ot.transaction_id ))
257
+ .append($('<td/>').html(ot.success ? 'Success' : 'Fail'))
258
+ );
259
+ });
260
+ fstatus.append(transactions_table);
261
+ }
262
+
263
+ var table = $('<table/>').addClass('data');
264
+ table.append($('<tr/>')
265
+ .append($('<th/>').html('Customer'))
266
+ .append($('<th/>').html('Shipping Address'))
267
+ .append($('<th/>').html('Order Status'))
268
+ .append($('<th/>').html('Payment Status'))
269
+ );
270
+ table.append($('<tr/>')
271
+ .append($('<td/>').attr('valign', 'top')
272
+ .append($('<div/>').attr('id', 'customer').append(that.noneditable_customer(true)))
273
+ .append($('<a/>').attr('href', '#').html('Edit').click(function(e) {
274
+ var a = $(this);
275
+ that.refresh_order(function() {
276
+ if (a.html() == 'Edit') { that.edit_customer(); a.html('Finished'); }
277
+ else { that.noneditable_customer(); a.html('Edit'); }
278
+ });
279
+ }))
280
+ )
281
+ .append($('<td/>').attr('valign', 'top')
282
+ .append($('<div/>').attr('id', 'shipping_address').append(that.noneditable_shipping_address(true)))
283
+ .append($('<a/>').attr('href', '#').html('Edit').click(function(e) {
284
+ var a = $(this);
285
+ that.refresh_order(function() {
286
+ if (a.html() == 'Edit') { that.edit_shipping_address(); a.html('Finished'); }
287
+ else { that.noneditable_shipping_address(); a.html('Edit'); }
288
+ });
289
+ }))
290
+ )
291
+ .append($('<td/>').attr('valign', 'top').append($('<div/>').attr('id', 'order_' + that.order.id + '_status')))
292
+ .append($('<td/>').attr('valign', 'top').attr('align', 'center').append(fstatus))
293
+ );
294
+ return table;
295
+ },
296
+
297
+ noneditable_customer: function(return_element)
298
+ {
299
+ var that = this;
300
+ c = that.order.customer;
301
+ str = '';
302
+ if (c)
303
+ {
304
+ str = c.first_name + ' ' + c.last_name;
305
+ if (c.email) str += '<br /><a href="mailto:' + c.email + '">' + c.email + '</a>';
306
+ if (c.phone) str += '<br />' + c.phone;
307
+ }
308
+ else
309
+ str = '[Empty]';
310
+ if (return_element)
311
+ return str;
312
+ $('#customer').empty().append(str);
313
+ },
314
+
315
+ edit_customer: function()
316
+ {
317
+ var that = this;
318
+ var div = $('<div/>').attr('id', 'order_' + that.order.id + '_customer_id');
319
+ $('#customer').empty().append(div);
320
+
321
+ new ModelBinder({
322
+ name: 'Order',
323
+ id: that.order.id,
324
+ update_url: '/admin/orders/' + that.order.id,
325
+ authenticity_token: that.authenticity_token,
326
+ attributes: [
327
+ { name: 'customer_id', nice_name: 'Customer', type: 'select', value: that.order.customer_id, width: 150, fixed_placeholder: false, options_url: '/admin/users/options' }
328
+ ]
329
+ });
330
+ },
331
+
332
+ noneditable_shipping_address: function(return_element)
333
+ {
334
+ var that = this;
335
+ var sa = that.order.shipping_address;
336
+ var str = '';
337
+ str += (sa.first_name ? sa.first_name : '[Empty first name]') + ' ';
338
+ str += (sa.last_name ? sa.last_name : '[Empty last name]');
339
+ str += '<br />' + (sa.address1 ? sa.address1 : '[Empty address]');
340
+ if (sa.address2) str += "<br />" + sa.address2;
341
+ str += '<br/>' + (sa.city ? sa.city : '[Empty city]') + ", " + (sa.state ? sa.state : '[Empty state]') + " " + (sa.zip ? sa.zip : '[Empty zip]');
342
+ if (return_element)
343
+ return str;
344
+ $('#shipping_address').empty().append(str);
345
+ },
346
+
347
+ edit_shipping_address: function()
348
+ {
349
+ var that = this;
350
+ var sa = that.order.shipping_address;
351
+ var table = $('<table/>').addClass('shipping_address')
352
+ .append($('<tr/>').append($('<td/>').append($('<table/>').append($('<tr/>')
353
+ .append($('<td/>').append($('<div/>').attr('id', 'shippingaddress_' + sa.id + '_first_name')))
354
+ .append($('<td/>').append($('<div/>').attr('id', 'shippingaddress_' + sa.id + '_last_name')))
355
+ ))))
356
+ .append($('<tr/>').append($('<td/>').append($('<table/>').append($('<tr/>')
357
+ .append($('<td/>').append($('<div/>').attr('id', 'shippingaddress_' + sa.id + '_address1')))
358
+ ))))
359
+ .append($('<tr/>').append($('<td/>').append($('<table/>').append($('<tr/>')
360
+ .append($('<td/>').append($('<div/>').attr('id', 'shippingaddress_' + sa.id + '_address2')))
361
+ ))))
362
+ .append($('<tr/>').append($('<td/>').append($('<table/>').append($('<tr/>')
363
+ .append($('<td/>').append($('<div/>').attr('id', 'shippingaddress_' + sa.id + '_city')))
364
+ .append($('<td/>').append($('<div/>').attr('id', 'shippingaddress_' + sa.id + '_state')))
365
+ .append($('<td/>').append($('<div/>').attr('id', 'shippingaddress_' + sa.id + '_zip')))
366
+ ))));
367
+ $('#shipping_address').empty().append(table);
368
+
369
+ new ModelBinder({
370
+ name: 'ShippingAddress',
371
+ id: sa.id,
372
+ update_url: '/admin/orders/' + that.order.id + '/shipping-address',
373
+ authenticity_token: that.authenticity_token,
374
+ attributes: [
375
+ { name: 'first_name' , nice_name: 'First Name' , type: 'text' , value: sa.first_name , width: 150, fixed_placeholder: false },
376
+ { name: 'last_name' , nice_name: 'Last Name' , type: 'text' , value: sa.last_name , width: 150, fixed_placeholder: false },
377
+ { name: 'address1' , nice_name: 'Address 1' , type: 'text' , value: sa.address1 , width: 320, fixed_placeholder: false },
378
+ { name: 'address2' , nice_name: 'Address 2' , type: 'text' , value: sa.address2 , width: 320, fixed_placeholder: false },
379
+ { name: 'city' , nice_name: 'City' , type: 'text' , value: sa.city , width: 180, fixed_placeholder: false },
380
+ { name: 'state' , nice_name: 'State' , type: 'text' , value: sa.state , width: 40, fixed_placeholder: false },
381
+ { name: 'zip' , nice_name: 'Zip' , type: 'text' , value: sa.zip , width: 60, fixed_placeholder: false }
382
+ ]
383
+ });
384
+ },
385
+
386
+ // Show all the packages and the line items in each package
387
+ order_packages_table: function(table)
388
+ {
389
+ var that = this;
390
+ $.each(that.order.order_packages, function(i, op) {
391
+ var line_items = that.line_items_for_order_package(op.id);
392
+ if (line_items && line_items.length > 0)
393
+ {
394
+ table.append($('<tr/>')
395
+ .append($('<th/>').html('Package' ))
396
+ .append($('<th/>').html('Item' ))
397
+ .append($('<th/>').html('Status' ))
398
+ .append($('<th/>').html('Unit Price' ))
399
+ .append($('<th/>').html('Quantity' ))
400
+ .append($('<th/>').html('Subtotal' ))
401
+ );
402
+ $.each(line_items, function(j, li) {
403
+ var tr = $('<tr/>');
404
+ if (j == 0)
405
+ {
406
+ tr.append($('<td/>').attr('rowspan', line_items.length)
407
+ .append($('<div/>').attr('id', 'orderpackage_' + op.id + '_package_method'))
408
+ .append($('<div/>').attr('id', 'orderpackage_' + op.id + '_status'))
409
+ .append($('<div/>').attr('id', 'orderpackage_' + op.id + '_tracking_number'))
410
+ .append($('<div/>').attr('id', 'orderpackage_' + op.id + '_total'))
411
+ );
412
+ }
413
+ var v = li.variant;
414
+ tr.append($('<td/>').append(that.line_item_link(li)).append($('<div/>').attr('id', 'line_item_' + li.id + '_message')));
415
+ tr.append($('<td/>').append($('<div/>').attr('id', 'lineitem_' + li.id + '_status')))
416
+ tr.append($('<td/>').attr('align', 'right').html(curr(v.price)));
417
+ tr.append($('<td/>').attr('align', 'right').append($('<div/>').attr('id', 'lineitem_' + li.id + '_quantity')));
418
+ tr.append($('<td/>').attr('align', 'right').attr('id', 'li_' + li.id + '_subtotal').html(curr(li.price)));
419
+ table.append(tr);
420
+ });
421
+ }
422
+ else
423
+ {
424
+ table
425
+ .append($('<tr/>')
426
+ .append($('<th/>').html('Package' ))
427
+ .append($('<th/>').attr('colspan', '5').html('&nbsp;'))
428
+ )
429
+ .append($('<tr/>')
430
+ .append($('<td/>')
431
+ .append($('<div/>').attr('id', 'orderpackage_' + op.id + '_package_method'))
432
+ .append($('<div/>').attr('id', 'orderpackage_' + op.id + '_status'))
433
+ .append($('<div/>').attr('id', 'orderpackage_' + op.id + '_tracking_number'))
434
+ .append($('<div/>').attr('id', 'orderpackage_' + op.id + '_total'))
435
+ )
436
+ .append($('<td/>').attr('colspan', '5')
437
+ .append($('<p>')
438
+ .append("This package is empty. ")
439
+ .append($('<a/>').attr('href', '#').html('Delete Package').data('op_id', op.id).click(function(e) { e.preventDefault(); that.delete_order_package($(this).data('op_id')); }))
440
+ )
441
+ )
442
+ );
443
+ }
444
+ });
445
+ },
446
+
447
+ line_item_link: function(li)
448
+ {
449
+ var that = this;
450
+ var v = li.variant;
451
+ var name = ''
452
+ if (!v || !v.product)
453
+ name = v ? v.sku : 'Unknown variant';
454
+ else
455
+ {
456
+ name = v.product.title;
457
+ if (v.sku && v.sku.length > 0) name += '<br />' + v.sku;
458
+ if (v.title && v.title.length > 0) name += '<br />' + v.title;
459
+ }
460
+ var link = $('<a/>').attr('href', '#').html(name)
461
+ .data('li_id', li.id)
462
+ .data('order_package_id', li.order_package_id)
463
+ .click(function(e) {
464
+ e.preventDefault();
465
+ that.line_item_options($(this).data('li_id'), $(this).data('order_package_id'));
466
+ });
467
+ return link;
468
+ },
469
+
470
+ line_item_options: function(li_id, order_package_id)
471
+ {
472
+ var that = this;
473
+ var ul = $('<ul/>').addClass('line_item_controls');
474
+ ul.append($('<li/>').append($('<a/>')
475
+ .html('View Product')
476
+ .attr('href', '/admin/orders/' + that.order.id + '/line-items/' + li_id + '/highlight')
477
+ ))
478
+ if (order_package_id && order_package_id != -1)
479
+ {
480
+ ul.append($('<li/>').append($('<a/>')
481
+ .html('Remove from Package')
482
+ .attr('href', '#')
483
+ .data('li_id', li_id)
484
+ .click(function(e) { e.preventDefault(); that.unassign_from_package($(this).data('li_id')); })
485
+ ));
486
+ }
487
+ ul.append($('<li/>').append($('<a/>')
488
+ .html('Remove from Order')
489
+ .attr('href', '#')
490
+ .data('li_id', li_id)
491
+ .click(function(e) { e.preventDefault(); that.delete_line_item($(this).data('li_id')); })
492
+ ));
493
+ var el = $('#line_item_' + li_id + '_message');
494
+ if (el.is(':empty'))
495
+ el.hide().empty().append(ul).slideDown();
496
+ else
497
+ el.slideUp(function() { $(this).empty(); });
498
+ },
499
+
500
+ // Show all the line items not assigned to a package
501
+ unassigned_line_items_table: function(table)
502
+ {
503
+ var that = this;
504
+
505
+ var has_unassigned_line_items = false
506
+ $.each(that.order.line_items, function(i, li) {
507
+ if (!li.order_package_id || li.order_package_id == -1)
508
+ {
509
+ has_unassigned_line_items = true;
510
+ return false;
511
+ }
512
+ });
513
+ if (!has_unassigned_line_items)
514
+ return;
515
+
516
+ table.append($('<tr/>')
517
+ .append($('<th/>').html('Package' ))
518
+ .append($('<th/>').html('Item' ))
519
+ .append($('<th/>').html('Status' ))
520
+ .append($('<th/>').html('Unit Price1' ))
521
+ .append($('<th/>').html('Quantity' ))
522
+ .append($('<th/>').html('Subtotal' ))
523
+ );
524
+
525
+ $.each(that.order.line_items, function(i, li) {
526
+ if (li.order_package_id && li.order_package_id != -1) return true;
527
+ var v = li.variant;
528
+
529
+ var div = $('<div/>').attr('id', 'assign_to_package_' + li.id)
530
+ .append('Unpackaged! ')
531
+ .append($('<a/>').data('line_item_id', li.id).attr('href', '#').html('Assign to package').click(function(e) {
532
+ e.preventDefault();
533
+ e.stopPropagation();
534
+ that.assign_to_package_form($(this).data('line_item_id'));
535
+ }));
536
+
537
+ var tr = $('<tr/>');
538
+ tr.append($('<td/>').append(div));
539
+ tr.append($('<td/>').append(that.line_item_link(li)).append($('<div/>').attr('id', 'line_item_' + li.id + '_message')));
540
+ tr.append($('<td/>').append($('<div/>').attr('id', 'lineitem_' + li.id + '_status')))
541
+ tr.append($('<td/>').attr('align', 'right').html(curr(v.price)));
542
+ tr.append($('<td/>').attr('align', 'right').append($('<div/>').attr('id', 'lineitem_' + li.id + '_quantity')));
543
+ tr.append($('<td/>').attr('align', 'right').attr('id', 'li_' + li.id + '_subtotal').html(curr(li.price)));
544
+ table.append(tr);
545
+ });
546
+ },
547
+
548
+ // Show the order summary
549
+ summary_table: function(table)
550
+ {
551
+ var that = this;
552
+ if (that.order.line_items.length > 0 || that.order.order_packages.length > 0)
553
+ {
554
+ table.append($('<tr/>').append($('<th/>').attr('colspan', '6').html('&nbsp;')));
555
+ }
556
+
557
+ if (that.order.line_items.length > 0)
558
+ {
559
+ table.append($('<tr/>').append($('<td/>').attr('colspan', '5').attr('align', 'right').html('Subtotal' )).append($('<td/>').attr('align', 'right').attr('id', 'subtotal').html(curr(that.order.subtotal))));
560
+ table.append($('<tr/>').append($('<td/>').attr('colspan', '5').attr('align', 'right').html('Tax' )).append($('<td/>').attr('align', 'right').append($('<div/>').attr('id', 'order_' + that.order.id + '_tax'))));
561
+ table.append($('<tr/>').append($('<td/>').attr('colspan', '5').attr('align', 'right').html('Shipping' )).append($('<td/>').attr('align', 'right').attr('id', 'shipping').html(curr(that.order.shipping))));
562
+ table.append($('<tr/>').append($('<td/>').attr('colspan', '5').attr('align', 'right').html('Handling' )).append($('<td/>').attr('align', 'right').append($('<div/>').attr('id', 'order_' + that.order.id + '_handling'))));
563
+ if (that.order.discounts)
564
+ {
565
+ $.each(that.order.discounts, function(i, d) {
566
+ table.append($('<tr/>')
567
+ .append($('<td/>').attr('colspan', '5').attr('align', 'right')
568
+ .append($('<a/>').attr('href', '#').html('Remove').click(function(e) { that.remove_discount(d.id); }))
569
+ .append(' ' + d.name + ' Discount')
570
+ )
571
+ .append($('<td/>').attr('align', 'right').html(curr(d.amount)))
572
+ );
573
+ });
574
+ }
575
+ table.append($('<tr/>').append($('<td/>').attr('colspan', '5').attr('align', 'right').html('Discount')).append($('<td/>').attr('align', 'right').append($('<div/>').attr('id', 'order_' + that.order.id + '_custom_discount'))));
576
+ table.append($('<tr/>').append($('<td/>').attr('colspan', '5').attr('align', 'right').html('Total' )).append($('<td/>').attr('align', 'right').attr('id', 'total').html(curr(that.order.total))));
577
+ }
578
+ else
579
+ {
580
+ table.append($('<tr/>').append($('<td/>').attr('colspan', '6')
581
+ .append($('<p/>')
582
+ .append('There are no items in this order. ')
583
+ .append($('<a/>').attr('href','#').html('Add one!').click(function(e) {
584
+ e.preventDefault();
585
+ that.add_variant();
586
+ }))
587
+ )
588
+ ));
589
+ }
590
+ },
591
+
592
+ add_variant: function(variant_id)
593
+ {
594
+ var that = this;
595
+ if (!variant_id)
596
+ {
597
+ caboose_modal_url('/admin/orders/' + this.order.id + '/line-items/new');
598
+ return;
599
+ }
600
+ $.ajax({
601
+ url: '/admin/orders/' + that.order.id + '/line-items',
602
+ type: 'post',
603
+ data: { variant_id: variant_id },
604
+ success: function(resp) {
605
+ if (resp.error) $('#message').html("<p class='note error'>" + resp.error + "</p>");
606
+ else that.refresh();
607
+ }
608
+ });
609
+ },
610
+
611
+ delete_order_package: function(order_package_id)
612
+ {
613
+ var that = this;
614
+ $.ajax({
615
+ url: '/admin/orders/' + that.order.id + '/packages/' + order_package_id,
616
+ type: 'delete',
617
+ success: function(resp) {
618
+ if (resp.error) $('#message').html("<p class='note error'>" + resp.error + "</p>");
619
+ else that.refresh();
620
+ }
621
+ });
622
+ },
623
+
624
+ delete_line_item: function(li_id)
625
+ {
626
+ var that = this;
627
+ $.ajax({
628
+ url: '/admin/orders/' + that.order.id + '/line-items/' + li_id,
629
+ type: 'delete',
630
+ success: function(resp) {
631
+ if (resp.error) $('#message').html("<p class='note error'>" + resp.error + "</p>");
632
+ else that.refresh();
633
+ }
634
+ });
635
+ }
636
+
637
+ //resend_confirmation: function(order_id)
638
+ //{
639
+ // modal.autosize("<p class='loading'>Resending confirmation..</p>");
640
+ // $.ajax({
641
+ // type: 'post',
642
+ // url: '/admin/orders/' + order_id + '/resend-confirmation',
643
+ // success: function(resp) {
644
+ // if (resp.error) modal.autosize("<p class='note error'>" + resp.error + "</p>");
645
+ // if (resp.success) modal.autosize("<p class='note success'>" + resp.success + "</p>");
646
+ // }
647
+ // });
648
+ //},
649
+ //
650
+ //capture_funds: function(order_id, confirm)
651
+ //{
652
+ // total = $('#total').html();
653
+ // if (!confirm)
654
+ // {
655
+ // var p = $('<p/>').addClass('note confirm')
656
+ // .append("Are you sure you want to charge " + total + " to the customer? ")
657
+ // .append($('<input/>').attr('type','button').val('Yes').click(function() { capture_funds(order_id, true); }))
658
+ // .append(' ')
659
+ // .append($('<input/>').attr('type','button').val('No').click(function() { $('#message').empty(); modal.autosize(); }));
660
+ // modal.autosize(p);
661
+ // return;
662
+ // }
663
+ // modal.autosize("<p class='loading'>Capturing funds...</p>");
664
+ // $.ajax({
665
+ // url: '/admin/orders/' + order_id + '/capture',
666
+ // success: function(resp) {
667
+ // if (resp.error) modal.autosize("<p class='note error'>" + resp.error + "</p>");
668
+ // if (resp.success) modal.autosize("<p class='note success'>" + resp.success + "</p>");
669
+ // if (resp.refresh) window.location.reload(true);
670
+ // }
671
+ // });
672
+ //},
673
+ //
674
+ //void_order: function(order_id, confirm)
675
+ //{
676
+ // if (!confirm)
677
+ // {
678
+ // var p = $('<p/>').addClass('note confirm')
679
+ // .append("Are you sure you want to void this order? ")
680
+ // .append($('<input/>').attr('type','button').val('Yes').click(function() { void_order(order_id, true); }))
681
+ // .append(' ')
682
+ // .append($('<input/>').attr('type','button').val('No').click(function() { $('#message').empty(); modal.autosize(); }));
683
+ // modal.autosize(p);
684
+ // return;
685
+ // }
686
+ // modal.autosize("<p class='loading'>Voiding...</p>");
687
+ // $.ajax({
688
+ // url: '/admin/orders/' + order_id + '/void',
689
+ // success: function(resp) {
690
+ // if (resp.error) modal.autosize("<p class='note error'>" + resp.error + "</p>");
691
+ // if (resp.success) modal.autosize("<p class='note success'>" + resp.success + "</p>");
692
+ // if (resp.refresh) window.location.reload(true);
693
+ // }
694
+ // });
695
+ //},
696
+ //
697
+ //refund_order: function(order_id, confirm)
698
+ //{
699
+ // if (!confirm)
700
+ // {
701
+ // var p = $('<p/>').addClass('note confirm')
702
+ // .append("Are you sure you want to refund this order? ")
703
+ // .append($('<input/>').attr('type','button').val('Yes').click(function() { refund_order(order_id, true); }))
704
+ // .append(' ')
705
+ // .append($('<input/>').attr('type','button').val('No').click(function() { $('#message').empty(); modal.autosize(); }));
706
+ // modal.autosize(p);
707
+ // return;
708
+ // }
709
+ // modal.autosize("<p class='loading'>Refunding...</p>");
710
+ // $.ajax({
711
+ // url: '/admin/orders/' + order_id + '/refund',
712
+ // success: function(resp) {
713
+ // if (resp.error) modal.autosize("<p class='note error'>" + resp.error + "</p>");
714
+ // if (resp.success) modal.autosize("<p class='note success'>" + resp.success + "</p>");
715
+ // if (resp.refresh) window.location.reload(true);
716
+ // }
717
+ // });
718
+ //},
719
+
720
+ };
721
+
722
+
723
+
724
+