caboose-cms 0.4.151 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +8 -8
  2. data/app/assets/javascripts/caboose/admin_products.js +79 -0
  3. data/app/assets/javascripts/caboose/application.js +2 -1
  4. data/app/assets/javascripts/caboose/cart.js +168 -0
  5. data/app/assets/javascripts/caboose/checkout.js +151 -0
  6. data/app/assets/javascripts/caboose/checkout_module.js +312 -0
  7. data/app/assets/javascripts/caboose/checkout_step1.js +179 -0
  8. data/app/assets/javascripts/caboose/checkout_step2.js +39 -0
  9. data/app/assets/javascripts/caboose/checkout_step3.js +34 -0
  10. data/app/assets/javascripts/caboose/checkout_step4.js +97 -0
  11. data/app/assets/javascripts/caboose/main.js +99 -8
  12. data/app/assets/javascripts/caboose/product.js +284 -0
  13. data/app/assets/stylesheets/caboose/admin_products.css +86 -0
  14. data/app/assets/templates/caboose/cart/add_to_cart.jst.ejs +7 -0
  15. data/app/assets/templates/caboose/cart/line_items.jst.ejs +41 -0
  16. data/app/assets/templates/caboose/checkout/address.jst.ejs +53 -0
  17. data/app/assets/templates/caboose/checkout/forms/guest.jst.ejs +8 -0
  18. data/app/assets/templates/caboose/checkout/forms/register.jst.ejs +11 -0
  19. data/app/assets/templates/caboose/checkout/forms/signin.jst.ejs +7 -0
  20. data/app/assets/templates/caboose/checkout/line_items.jst.ejs +31 -0
  21. data/app/assets/templates/caboose/checkout/login.jst.ejs +21 -0
  22. data/app/assets/templates/caboose/checkout/payment.jst.ejs +5 -0
  23. data/app/assets/templates/caboose/checkout/shipping.jst.ejs +18 -0
  24. data/app/assets/templates/caboose/product/images.jst.ejs +8 -0
  25. data/app/assets/templates/caboose/product/options.jst.ejs +19 -0
  26. data/app/controllers/caboose/application_controller.rb +29 -1
  27. data/app/controllers/caboose/cart_controller.rb +52 -0
  28. data/app/controllers/caboose/categories_controller.rb +108 -0
  29. data/app/controllers/caboose/checkout_controller.rb +325 -0
  30. data/app/controllers/caboose/orders_controller.rb +439 -0
  31. data/app/controllers/caboose/product_images_controller.rb +38 -0
  32. data/app/controllers/caboose/products_controller.rb +737 -0
  33. data/app/controllers/caboose/reviews_controller.rb +15 -0
  34. data/app/controllers/caboose/variants_controller.rb +218 -0
  35. data/app/controllers/caboose/vendors_controller.rb +73 -0
  36. data/app/helpers/caboose/application_helper.rb +4 -0
  37. data/app/helpers/caboose/categories_helper.rb +82 -0
  38. data/app/helpers/caboose/checkout_helper.rb +20 -0
  39. data/app/helpers/caboose/products_helper.rb +8 -0
  40. data/app/mailers/caboose/orders_mailer.rb +30 -0
  41. data/app/models/caboose/address.rb +26 -0
  42. data/app/models/caboose/category.rb +89 -0
  43. data/app/models/caboose/category_membership.rb +10 -0
  44. data/app/models/caboose/core_plugin.rb +15 -37
  45. data/app/models/caboose/customization_membership.rb +10 -0
  46. data/app/models/caboose/discount.rb +16 -0
  47. data/app/models/caboose/line_item.rb +81 -0
  48. data/app/models/caboose/message.rb +20 -0
  49. data/app/models/caboose/order.rb +191 -0
  50. data/app/models/caboose/order_discount.rb +10 -0
  51. data/app/models/caboose/order_pdf.rb +78 -0
  52. data/app/models/caboose/payment_processors/authorizenet.rb +53 -0
  53. data/app/models/caboose/payment_processors/base.rb +39 -0
  54. data/app/models/caboose/payment_processors/payscape.rb +94 -0
  55. data/app/models/caboose/product.rb +145 -0
  56. data/app/models/caboose/product_image.rb +62 -0
  57. data/app/models/caboose/product_image_variant.rb +10 -0
  58. data/app/models/caboose/review.rb +13 -0
  59. data/app/models/caboose/schema.rb +205 -1
  60. data/app/models/caboose/search_filter.rb +191 -0
  61. data/app/models/caboose/shipping_calculator.rb +81 -0
  62. data/app/models/caboose/states.rb +61 -52
  63. data/app/models/caboose/tax_calculator.rb +23 -0
  64. data/app/models/caboose/tax_line.rb +9 -0
  65. data/app/models/caboose/variant.rb +99 -0
  66. data/app/models/caboose/vendor.rb +22 -0
  67. data/app/views/caboose/cart/index.html.erb +8 -0
  68. data/app/views/caboose/categories/admin_edit.html.erb +79 -0
  69. data/app/views/caboose/categories/admin_index.html.erb +11 -0
  70. data/app/views/caboose/categories/admin_new.html.erb +62 -0
  71. data/app/views/caboose/checkout/_address_form.html.erb +111 -0
  72. data/app/views/caboose/checkout/_billing_form.html.erb +47 -0
  73. data/app/views/caboose/checkout/_cart.html.erb +52 -0
  74. data/app/views/caboose/checkout/_confirm.html.erb +61 -0
  75. data/app/views/caboose/checkout/_order_discount.html.erb +40 -0
  76. data/app/views/caboose/checkout/_shipping_address.html.erb +10 -0
  77. data/app/views/caboose/checkout/_shipping_method.html.erb +2 -0
  78. data/app/views/caboose/checkout/_shipping_method_form.html.erb +21 -0
  79. data/app/views/caboose/checkout/billing.html.erb +11 -0
  80. data/app/views/caboose/checkout/discount.html.erb +11 -0
  81. data/app/views/caboose/checkout/empty.html.erb +2 -0
  82. data/app/views/caboose/checkout/error.html.erb +2 -0
  83. data/app/views/caboose/checkout/index.html.erb +43 -0
  84. data/app/views/caboose/checkout/login.html.erb +2 -0
  85. data/app/views/caboose/checkout/payment.html.erb +79 -0
  86. data/app/views/caboose/checkout/relay.html.erb +23 -0
  87. data/app/views/caboose/checkout/relay_old.html.erb +12 -0
  88. data/app/views/caboose/checkout/relay_postMessage.html.erb +19 -0
  89. data/app/views/caboose/checkout/shipping.html.erb +15 -0
  90. data/app/views/caboose/checkout/step_four.html.erb +93 -0
  91. data/app/views/caboose/checkout/step_one.html.erb +56 -0
  92. data/app/views/caboose/checkout/step_one_old.html.erb +13 -0
  93. data/app/views/caboose/checkout/step_three.html.erb +23 -0
  94. data/app/views/caboose/checkout/step_two.html.erb +52 -0
  95. data/app/views/caboose/checkout/step_two_old.html.erb +14 -0
  96. data/app/views/caboose/checkout/thanks.html.erb +5 -0
  97. data/app/views/caboose/orders/_admin_footer.html.erb +2 -0
  98. data/app/views/caboose/orders/_admin_header.html.erb +31 -0
  99. data/app/views/caboose/orders/_quickbooks_order.html.erb +0 -0
  100. data/app/views/caboose/orders/admin_delete_form.html.erb +21 -0
  101. data/app/views/caboose/orders/admin_edit.html.erb +271 -0
  102. data/app/views/caboose/orders/admin_index.html.erb +89 -0
  103. data/app/views/caboose/orders/admin_new.html.erb +42 -0
  104. data/app/views/caboose/orders/admin_print.html.erb +72 -0
  105. data/app/views/caboose/orders_mailer/customer_new_order.html.erb +1 -0
  106. data/app/views/caboose/orders_mailer/customer_status_updated.html.erb +1 -0
  107. data/app/views/caboose/orders_mailer/fulfillment_new_order.html.erb +1 -0
  108. data/app/views/caboose/orders_mailer/shipping_order_ready.html.erb +1 -0
  109. data/app/views/caboose/products/_admin_footer.html.erb +2 -0
  110. data/app/views/caboose/products/_admin_header.html.erb +32 -0
  111. data/app/views/caboose/products/_sort_options.html.erb +19 -0
  112. data/app/views/caboose/products/admin_add_upcs.html.erb +58 -0
  113. data/app/views/caboose/products/admin_delete_form.html.erb +21 -0
  114. data/app/views/caboose/products/admin_edit_categories.html.erb +73 -0
  115. data/app/views/caboose/products/admin_edit_category_images.html.erb +233 -0
  116. data/app/views/caboose/products/admin_edit_description.html.erb +38 -0
  117. data/app/views/caboose/products/admin_edit_general.html.erb +104 -0
  118. data/app/views/caboose/products/admin_edit_images.html.erb +236 -0
  119. data/app/views/caboose/products/admin_edit_options.html.erb +51 -0
  120. data/app/views/caboose/products/admin_edit_seo.html.erb +37 -0
  121. data/app/views/caboose/products/admin_edit_variant_columns.html.erb +75 -0
  122. data/app/views/caboose/products/admin_edit_variant_sort_order.html.erb +63 -0
  123. data/app/views/caboose/products/admin_edit_variants.html.erb +171 -0
  124. data/app/views/caboose/products/admin_edit_variants_single.html.erb +68 -0
  125. data/app/views/caboose/products/admin_group_variants.html.erb +433 -0
  126. data/app/views/caboose/products/admin_index.html.erb +95 -0
  127. data/app/views/caboose/products/admin_new.html.erb +41 -0
  128. data/app/views/caboose/products/admin_sort.html copy.erb +155 -0
  129. data/app/views/caboose/products/admin_sort.html.erb +254 -0
  130. data/app/views/caboose/products/details.html.erb +438 -0
  131. data/app/views/caboose/products/index.html.erb +46 -0
  132. data/app/views/caboose/products/not_available.html.erb +35 -0
  133. data/app/views/caboose/variants/admin_edit.html.erb +82 -0
  134. data/app/views/caboose/variants/admin_group.html.erb +184 -0
  135. data/app/views/caboose/variants/admin_new.html.erb +59 -0
  136. data/app/views/caboose/vendors/admin_edit.html.erb +24 -0
  137. data/app/views/caboose/vendors/admin_index.html.erb +30 -0
  138. data/app/views/caboose/vendors/admin_new.html.erb +34 -0
  139. data/app/views/layouts/caboose/store/_banner.html.erb +10 -0
  140. data/app/views/layouts/caboose/store/_banner2.html.erb +10 -0
  141. data/app/views/layouts/caboose/store/_footer.html.erb +55 -0
  142. data/app/views/layouts/caboose/store/_header.html.erb +69 -0
  143. data/app/views/layouts/caboose/store/_sidebar.html.erb +27 -0
  144. data/app/views/layouts/caboose/store/application.html.erb +33 -0
  145. data/app/views/layouts/caboose/store/authorize_net.erb +18 -0
  146. data/app/views/layouts/caboose/store/layout_about.html.erb +42 -0
  147. data/app/views/layouts/caboose/store/layout_blog.html.erb +159 -0
  148. data/app/views/layouts/caboose/store/layout_confirm.html.erb +85 -0
  149. data/app/views/layouts/caboose/store/layout_contact.html.erb +38 -0
  150. data/app/views/layouts/caboose/store/layout_default.html.erb +10 -0
  151. data/app/views/layouts/caboose/store/layout_detail.html.erb +114 -0
  152. data/app/views/layouts/caboose/store/layout_order.html.erb +77 -0
  153. data/app/views/layouts/caboose/store/layout_pricing.html.erb +182 -0
  154. data/app/views/layouts/caboose/store/layout_product.html.erb +110 -0
  155. data/app/views/layouts/caboose/store/layout_profile.html.erb +55 -0
  156. data/app/views/layouts/caboose/store/layout_single.html.erb +3 -0
  157. data/app/views/layouts/caboose/store/layout_testimonial.html.erb +110 -0
  158. data/app/views/layouts/caboose/store/layout_testing.html.erb +4 -0
  159. data/config/routes.rb +126 -0
  160. data/lib/caboose.rb +46 -1
  161. data/lib/caboose/engine.rb +39 -1
  162. data/lib/caboose/version.rb +1 -1
  163. data/lib/tasks/caboose.rake +12 -0
  164. metadata +151 -4
  165. data/app/assets/javascripts/caboose/admin_page_edit_content_bak.js +0 -164
  166. data/app/assets/javascripts/caboose/model/#Untitled-1# +0 -2
@@ -0,0 +1,38 @@
1
+ <%
2
+ p = @product
3
+ %>
4
+ <%= render :partial => 'caboose/products/admin_header' %>
5
+ <div id='message'><%= raw flash[:message] ? flash[:message] : "" %></div>
6
+
7
+ <p><div id='product_<%= p.id %>_description'></div></p>
8
+
9
+ <%= render :partial => 'caboose/products/admin_footer' %>
10
+
11
+ <% content_for :caboose_js do %>
12
+ <script type='text/javascript'>
13
+
14
+ $(document).ready(function() {
15
+ m = new ModelBinder({
16
+ name: 'Product',
17
+ id: <%= p.id %>,
18
+ update_url: '/admin/products/<%= p.id %>',
19
+ authenticity_token: '<%= form_authenticity_token %>',
20
+ attributes: [{
21
+ name: 'description',
22
+ nice_name: 'Description',
23
+ type: 'richtext',
24
+ value: <%= raw Caboose.json(p.description) %>,
25
+ width: 500
26
+ }]
27
+ });
28
+ });
29
+
30
+ var modal = false;
31
+ $(window).load(function() {
32
+ modal = new CabooseModal(800);
33
+ });
34
+
35
+ </script>
36
+ <script src="//tinymce.cachefly.net/4.0/tinymce.min.js"></script>
37
+ <%= tinymce :caboose, :width => '575px', :height => '240px' %>
38
+ <% end %>
@@ -0,0 +1,104 @@
1
+ <%
2
+ p = @product
3
+ %>
4
+ <%= render :partial => 'caboose/products/admin_header' %>
5
+
6
+ <p>
7
+ <strong>Vendor:</strong>
8
+
9
+ <select id="vendor" data-product-id="<%= @product.id %>">
10
+ <option>-- Select a Vendor --</option>
11
+
12
+ <% Caboose::Vendor.all.each do |vendor| %>
13
+ <option value="<%= vendor.id %>" <%= 'selected' if p.vendor_id && p.vendor_id == vendor.id %>><%= vendor.name%></option>
14
+ <% end %>
15
+ </select>
16
+ </p>
17
+
18
+
19
+ <% if p.vendor %>
20
+ <p>
21
+ <strong>Vendor Status (<%= p.vendor.name %>):</strong>
22
+ <select id="vendor-status" data-vendor-id="<%= p.vendor.id %>">
23
+ <% ['Active', 'Inactive'].each do |status| %>
24
+ <option value="<%= status %>" <%= 'selected' if p.vendor.status == status %>><%= status %></option>
25
+ <% end %>
26
+ </select>
27
+ </p>
28
+ <% end %>
29
+
30
+ <p><div id='product_<%= p.id %>_title'></div></p>
31
+ <p><div id='product_<%= p.id %>_caption'></div></p>
32
+ <p><div id='product_<%= p.id %>_handle'></div></p>
33
+ <p><div id='product_<%= p.id %>_featured'></div></p>
34
+ <p><div id='product_<%= p.id %>_seo_title'></div></p>
35
+ <p><div id='product_<%= p.id %>_seo_description'></div></p>
36
+ <p><div id='product_<%= p.id %>_status'></div></p>
37
+ <p><div id='product_<%= p.id %>_alternate_id'></div></p>
38
+ <p><div id='product_<%= p.id %>_date_available'></div></p>
39
+
40
+ <div id='message'><%= raw flash[:message] ? flash[:message] : "" %></div>
41
+
42
+ <%= render :partial => 'caboose/products/admin_footer' %>
43
+
44
+ <% content_for :caboose_js do %>
45
+ <script type='text/javascript'>
46
+ <%
47
+ date_available = p.date_available ? p.date_available.strftime('%F') : ''
48
+ %>
49
+ $(document).ready(function() {
50
+ $('#vendor').on('change', function(event) {
51
+ event.preventDefault();
52
+
53
+ var $target = $(event.target)
54
+ , vendor_id = $target.val()
55
+ , product_id = $target.data('product-id');
56
+
57
+ console.log(vendor_id, product_id);
58
+
59
+ $.ajax({
60
+ type: 'put',
61
+ url: '/admin/products/' + product_id + '/update-vendor',
62
+ data: { vendor_id: vendor_id },
63
+ success: function(response) {
64
+ console.log(response);
65
+ }
66
+ })
67
+ });
68
+
69
+ $('#vendor-status').on('change', function(e) {
70
+ $select = $(e.target)
71
+
72
+ $.ajax({
73
+ type: 'put',
74
+ url: '/admin/products/update-vendor-status/' + $select.data('vendor-id'),
75
+ data: { status: $select.val() }
76
+ });
77
+ });
78
+
79
+ m = new ModelBinder({
80
+ name: 'Product',
81
+ id: <%= p.id %>,
82
+ update_url: '/admin/products/<%= p.id %>',
83
+ authenticity_token: '<%= form_authenticity_token %>',
84
+ attributes: [
85
+ { name: 'title' , nice_name: 'Title' , type: 'text' , value: <%= raw Caboose.json(p.title ) %>, width: 500 },
86
+ { name: 'caption' , nice_name: 'Caption' , type: 'text' , value: <%= raw Caboose.json(p.caption ) %>, width: 500 },
87
+ { name: 'status' , nice_name: 'Status' , type: 'select' , value: <%= raw Caboose.json(p.status ) %>, width: 500, text: <%= raw Caboose.json(p.status) %>, options_url: '/admin/products/status-options' },
88
+ { name: 'handle' , nice_name: 'URL Handle' , type: 'text' , value: <%= raw Caboose.json(p.handle ) %>, width: 500 },
89
+ { name: 'seo_title' , nice_name: 'SEO Page Title' , type: 'text' , value: <%= raw Caboose.json(p.seo_title ) %>, width: 500 },
90
+ { name: 'seo_description' , nice_name: 'SEO Meta Description' , type: 'textarea' , value: <%= raw Caboose.json(p.seo_description ) %>, width: 500, height: 150 },
91
+ { name: 'alternate_id' , nice_name: 'Alternate ID' , type: 'text' , value: <%= raw Caboose.json(p.alternate_id ) %>, width: 500 },
92
+ { name: 'date_available' , nice_name: 'Date Available' , type: 'text' , value: <%= raw Caboose.json(date_available ) %>, width: 500 },
93
+ { name: 'featured' , nice_name: 'Featured' , type: 'checkbox' , value: <%= raw Caboose.json(p.featured ) %>, width: 500 }
94
+ ]
95
+ });
96
+ });
97
+
98
+ var modal = false;
99
+ $(window).load(function() {
100
+ modal = new CabooseModal(800);
101
+ });
102
+
103
+ </script>
104
+ <% end %>
@@ -0,0 +1,236 @@
1
+ <%
2
+ p = @product
3
+ %>
4
+ <%= render :partial => 'caboose/products/admin_header' %>
5
+
6
+ <form action='/admin/products/<%= p.id %>/images' method='post' enctype='multipart/form-data' id='new_image_form' target='new_image_iframe'>
7
+ <input type='hidden' name='authenticity_token' value="<%= form_authenticity_token %>" />
8
+ <p><input type='file' name='new_image' id='new_image' />
9
+ <input type='submit' value='Add Image' onclick='add_image();' /></p>
10
+ </form>
11
+ <div id='new_image_message'></div>
12
+ <iframe id='new_image_iframe' name='new_image_iframe' style='display: none;'></iframe>
13
+ <div id='message'></div>
14
+
15
+ <div id='images'>
16
+ <% if p.product_images.count > 0 %>
17
+ <% p.product_images.each do |img| %>
18
+ <%
19
+ #url = "https://s3.amazonaws.com/tuskwear/products/#{img.product_id}_#{img.id}_tiny.jpg"
20
+ url = img.image.url(:tiny)
21
+ %>
22
+ <div id='img_<%= img.id %>_container'><a href="javascript:select_image(<%= img.id %>);"><img src='<%= url %>' width='75' /></a></div>
23
+ <% end %>
24
+ <% else %>
25
+ <p>This product doesn't have any images yet.</p>
26
+ <% end %>
27
+ </div>
28
+ <div id='variants'></div>
29
+
30
+ <%= render :partial => 'caboose/products/admin_footer' %>
31
+
32
+ <% content_for :caboose_css do %>
33
+ <style type='text/css'>
34
+ #variants input[type='checkbox'] { position: relative; margin: 0; padding: 0; }
35
+ #variants table td { border: 0; font-size: 85%; margin: 0; padding: 0px 8px; }
36
+ #variants label { padding: 0; }
37
+ #images div { display: inline-block; }
38
+ #images div img { border: #000 4px solid; }
39
+ #images div.selected img { border: #ff3333 4px solid; }
40
+ </style>
41
+ <% end %>
42
+ <% content_for :caboose_js do %>
43
+ <script type='text/javascript'>
44
+
45
+ var modal = false;
46
+ $(window).load(function() {
47
+ modal.autosize();
48
+ });
49
+
50
+ $(document).ready(function() {
51
+ modal = new CabooseModal(900);
52
+ <% if p.product_images.count > 0 %>
53
+ select_image(<%= p.product_images[0].id %>);
54
+ <% end %>
55
+ });
56
+
57
+ variants = false;
58
+ image_variant_ids = {};
59
+
60
+ function variant_option_value(variant_id, option_index)
61
+ {
62
+ var val = false;
63
+ $.each(variants, function(i, v) {
64
+ if (v.id == variant_id)
65
+ {
66
+ if (option_index == 1) val = v.option1;
67
+ if (option_index == 2) val = v.option2;
68
+ if (option_index == 3) val = v.option3;
69
+ return;
70
+ }
71
+ });
72
+ return val;
73
+ }
74
+
75
+ function select_image(image_id, confirm)
76
+ {
77
+ if (!variants)
78
+ {
79
+ modal.autosize("<p class='loading'>Getting attached product variants...</p>", 'variants');
80
+ $.ajax({
81
+ url: '/admin/products/<%= p.id %>/variants/json',
82
+ success: function(resp) { variants = resp; select_image(image_id); }
83
+ });
84
+ return;
85
+ }
86
+ if (!confirm)
87
+ {
88
+ $.ajax({
89
+ url: '/admin/product-images/' + image_id + '/variant-ids',
90
+ success: function(resp) { image_variant_ids = resp; select_image(image_id, true); }
91
+ });
92
+ return;
93
+ }
94
+
95
+ $('#images div').removeClass('selected');
96
+ $('#img_' + image_id + '_container').addClass('selected');
97
+
98
+ var x = Math.ceil(variants.length/3);
99
+ var tbl1 = variants_subtable(image_id, 0, x);
100
+ var tbl2 = variants_subtable(image_id, x, x*2);
101
+ var tbl3 = variants_subtable(image_id, x*2, variants.length);
102
+
103
+ var tr = $('<tr/>');
104
+ tr.append($('<td/>').attr('valign','top').append(tbl1));
105
+ tr.append($('<td/>').attr('valign','top').append(tbl2));
106
+ tr.append($('<td/>').attr('valign','top').append(tbl3));
107
+ var tbl = $('<table/>').append($('<tbody/>').append(tr));
108
+
109
+ $('#variants').empty().append('<br/>');
110
+ $('#variants').append($('<div/>').attr('id','delete_message'));
111
+ $('#variants').append($('<input/>').attr('type','button').val('Delete Image').click(function() { delete_image(image_id); }));
112
+ $('#variants').append(tbl);
113
+ modal.autosize();
114
+ }
115
+
116
+ function variants_subtable(image_id, x, y)
117
+ {
118
+ var tbody = $('<tbody/>');
119
+ for (var i=x; i<y; i++)
120
+ {
121
+ var v = variants[i];
122
+ if (!v) break;
123
+ checked = image_is_attached_to_variant(v.id);
124
+
125
+ //var a = $('<a/>')
126
+ // .attr('href', '#')
127
+ // .attr('id', 'v_' + v.id)
128
+ // .html(variant_title(v))
129
+ // .click(function(e) {
130
+ // e.preventDefault();
131
+ // variant_id = $(this).attr('id').split('_')[1];
132
+ // var attach = false;
133
+ // if ($(this).hasClass('selected')) { attach = false; $(this).removeClass('selected'); }
134
+ // else { attch = true; $(this).addClass('selected'); }
135
+ // attach_image_to_variant(image_id, variant_id, attach);
136
+ // });
137
+ //tbody.append($('<tr/>').append($('<td/>').append(a)));
138
+
139
+ tbody.append($('<tr/>')
140
+ .append($('<td/>')
141
+ .append($('<input/>')
142
+ .attr('type','checkbox')
143
+ .attr('id', 'v_' + v.id)
144
+ .attr('checked', checked)
145
+ .css('position','relative')
146
+ .val('1')
147
+ .click(function() {
148
+ variant_id = $(this).attr('id').split('_')[1];
149
+ attach_image_to_variant(image_id, variant_id, $(this).is(':checked'));
150
+ })
151
+ )
152
+ )
153
+ .append($('<td/>').append($('<label/>').attr('for','v_' + v.id).html(variant_title(v))))
154
+ );
155
+ }
156
+ return $('<table/>').append(tbody);
157
+ }
158
+
159
+ function image_is_attached_to_variant(variant_id)
160
+ {
161
+ has_value = false;
162
+ $.each(image_variant_ids, function(i, vid) { if (vid == variant_id) { has_value = true; return; }});
163
+ return has_value;
164
+ }
165
+
166
+ function variant_title(v)
167
+ {
168
+ arr = [];
169
+ if (v.option1) arr[arr.length] = v.option1;
170
+ if (v.option2) arr[arr.length] = v.option2;
171
+ if (v.option3) arr[arr.length] = v.option3;
172
+ return arr.join(' / ');
173
+ }
174
+
175
+ function attach_image_to_variant(image_id, variant_id, attach)
176
+ {
177
+ attach = attach || true;
178
+
179
+ if (attach)
180
+ image_variant_ids[image_variant_ids.length] = variant_id;
181
+ else
182
+ {
183
+ var i = image_variant_ids.indexOf(variant_id);
184
+ image_variant_ids.splice(i, 1);
185
+ }
186
+ $.ajax({
187
+ url: '/admin/variants/' + variant_id + '/' + (attach ? 'attach-to-image' : 'unattach-from-image'),
188
+ type: 'put',
189
+ data: { product_image_id: image_id },
190
+ success: function(resp) {}
191
+ });
192
+ }
193
+
194
+ function add_image()
195
+ {
196
+ $('#new_image_message').html("<p class='loading'>Adding image...</p>");
197
+ modal.autosize();
198
+ }
199
+
200
+ function delete_image(image_id, confirm)
201
+ {
202
+ if (!confirm)
203
+ {
204
+ var p = $('<p/>').addClass('note error').css('margin-bottom', '10px')
205
+ .append("Are you sure you want to delete the image?<br />This can't be undone.<br /><br />")
206
+ .append($('<input/>').attr('type', 'button').val('Yes').click(function() { delete_image(image_id, true); })).append(' ')
207
+ .append($('<input/>').attr('type', 'button').val('No').click(function() { $('#delete_message').empty(); modal.autosize(); }));
208
+ modal.autosize(p, 'delete_message');
209
+ return;
210
+ }
211
+ modal.autosize("<p class='loading'>Deleting the image...</p>", 'delete_message');
212
+ $.ajax({
213
+ url: '/admin/product-images/' + image_id,
214
+ type: 'delete',
215
+ success: function(resp) {
216
+ if (resp.error)
217
+ modal.autosize("<p class='note error'>" + resp.error + "</p>", 'delete_message');
218
+ else
219
+ window.location.reload(true);
220
+ }
221
+ });
222
+ }
223
+
224
+ function array_unique(a)
225
+ {
226
+ b = [];
227
+ $.each(a, function(i, x) {
228
+ var e = false;
229
+ $.each(b, function(j, y) { if (x == y) { e = true; return; }});
230
+ if (!e) b[b.length] = x;
231
+ });
232
+ return b;
233
+ }
234
+
235
+ </script>
236
+ <% end %>
@@ -0,0 +1,51 @@
1
+ <%
2
+ p = @product
3
+ has_options = p.options && p.options.count > 0
4
+ may_delete1 = p.variants.collect{|v| v.option1 }.uniq.count == 1
5
+ may_delete2 = p.variants.collect{|v| v.option2 }.uniq.count == 1
6
+ may_delete3 = p.variants.collect{|v| v.option3 }.uniq.count == 1
7
+ %>
8
+ <%= render :partial => 'caboose/products/admin_header' %>
9
+
10
+ <p class='note' style='font-size: 85%; font-weight: normal; line-height: 140%;'>Product options allow you to present a group of similar products as a single
11
+ product to the end user. Common options include color, size, and style.
12
+ But an option can be anything. So for example, you could create a "Sleave" option for
13
+ shirts that are either long or short sleeved. Or you could create a "Tip" option
14
+ for chopsticks that are either rounded or squared at the tip. It's up to you.</p>
15
+
16
+ <table>
17
+ <tr><td><div id='product_<%= p.id %>_option1'></div></td><td><div id='product_<%= p.id %>_default1'></div></td></tr>
18
+ <tr><td><div id='product_<%= p.id %>_option2'></div></td><td><div id='product_<%= p.id %>_default2'></div></td></tr>
19
+ <tr><td><div id='product_<%= p.id %>_option3'></div></td><td><div id='product_<%= p.id %>_default3'></div></td></tr>
20
+ </table>
21
+
22
+ <div id='message'></div>
23
+
24
+ <%= render :partial => 'caboose/products/admin_footer' %>
25
+ <% content_for :caboose_js do %>
26
+ <script type='text/javascript'>
27
+
28
+ var modal = false;
29
+ $(window).load(function() {
30
+ modal = new CabooseModal(800);
31
+ });
32
+
33
+ $(document).ready(function() {
34
+ m = new ModelBinder({
35
+ name: 'Product',
36
+ id: <%= p.id %>,
37
+ update_url: '/admin/products/<%= p.id %>',
38
+ authenticity_token: '<%= form_authenticity_token %>',
39
+ attributes: [
40
+ { name: 'option1' , nice_name: 'Option 1' , type: 'text', value: <%= raw Caboose.json(p.option1) %>, width: 250, fixed_placeholder: true },
41
+ { name: 'option2' , nice_name: 'Option 2' , type: 'text', value: <%= raw Caboose.json(p.option2) %>, width: 250, fixed_placeholder: true },
42
+ { name: 'option3' , nice_name: 'Option 3' , type: 'text', value: <%= raw Caboose.json(p.option3) %>, width: 250, fixed_placeholder: true },
43
+ { name: 'default1' , nice_name: 'Default value' , type: 'text', value: <%= raw Caboose.json(p.default1) %>, width: 285, fixed_placeholder: true },
44
+ { name: 'default2' , nice_name: 'Default value' , type: 'text', value: <%= raw Caboose.json(p.default2) %>, width: 285, fixed_placeholder: true },
45
+ { name: 'default3' , nice_name: 'Default value' , type: 'text', value: <%= raw Caboose.json(p.default3) %>, width: 285, fixed_placeholder: true }
46
+ ]
47
+ });
48
+ });
49
+
50
+ </script>
51
+ <% end %>
@@ -0,0 +1,37 @@
1
+ <%
2
+ p = @product
3
+ %>
4
+ <%= render :partial => 'caboose/products/admin_header' %>
5
+
6
+ <p><div id='product_<%= p.id %>_handle'></div></p>
7
+ <p><div id='product_<%= p.id %>_seo_title'></div></p>
8
+ <p><div id='product_<%= p.id %>_seo_description'></div></p>
9
+
10
+ <div id='message'><%= raw flash[:message] ? flash[:message] : "" %></div>
11
+
12
+ <%= render :partial => 'caboose/products/admin_footer' %>
13
+
14
+ <% content_for :caboose_js do %>
15
+ <script type='text/javascript'>
16
+
17
+ $(document).ready(function() {
18
+ m = new ModelBinder({
19
+ name: 'Product',
20
+ id: <%= p.id %>,
21
+ update_url: '/admin/products/<%= p.id %>',
22
+ authenticity_token: '<%= form_authenticity_token %>',
23
+ attributes: [
24
+ { name: 'handle' , nice_name: 'URL Handle' , type: 'text' , value: <%= raw Caboose.json(p.handle ) %>, width: 500 },
25
+ { name: 'seo_title' , nice_name: 'SEO Page Title' , type: 'text' , value: <%= raw Caboose.json(p.seo_title ) %>, width: 500 },
26
+ { name: 'seo_description' , nice_name: 'SEO Meta Description' , type: 'textarea' , value: <%= raw Caboose.json(p.seo_description ) %>, width: 500, height: 200 }
27
+ ]
28
+ });
29
+ });
30
+
31
+ var modal = false;
32
+ $(window).load(function() {
33
+ modal = new CabooseModal(800);
34
+ });
35
+
36
+ </script>
37
+ <% end %>