edit_variants.html.erb 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <!-- BEGIN CONTAINER -->
  2. <div class="page-container">
  3. <!-- BEGIN CONTENT -->
  4. <div class="page-content-wrapper">
  5. <!-- BEGIN CONTENT BODY -->
  6. <!-- BEGIN PAGE HEAD-->
  7. <div class="page-head">
  8. <div class="container-fluid">
  9. <!-- BEGIN PAGE TITLE -->
  10. <div class="page-title">
  11. <h1> Producto </h1>
  12. </div>
  13. <!-- END PAGE TITLE -->
  14. </div>
  15. </div>
  16. <!-- END PAGE HEAD-->
  17. <!-- BEGIN PAGE CONTENT BODY -->
  18. <div class="page-content">
  19. <div class="container-fluid">
  20. <%= link_to products_path(:filter => @filter, :current_page => @current_page), { class: "fr-space btn blue-hoki pull-right margin-bottom-10" } do %>
  21. <i class="fa fa-angle-left "></i>
  22. Regresar
  23. <% end %>
  24. <!-- BEGIN PAGE BREADCRUMBS -->
  25. <ul class="page-breadcrumb breadcrumb">
  26. <%= render_breadcrumbs :tag => :li, :separator => ' <i class="fa fa-circle"></i> ' %>
  27. </ul>
  28. <!-- END PAGE BREADCRUMBS -->
  29. <!-- BEGIN PAGE CONTENT INNER -->
  30. <div class="page-content-inner">
  31. <div id="notice"><%= notice %></div>
  32. <div class="row">
  33. <div class="col-md-12">
  34. <%= form_tag(product_update_variants_path(@product.id), :multipart => true, :class => "form-horizontal", :id => "form") do |f| %>
  35. <div class="portlet light">
  36. <div class="portlet-title">
  37. <div class="caption">
  38. <i class="fa fa-edit font-blue-sharp"></i>
  39. <span class="caption-subject font-blue-sharp bold uppercase">Modificar variantes del producto</span>
  40. <span class="caption-helper"></span>
  41. </div>
  42. </div>
  43. <div class="portlet-body">
  44. <div class="row">
  45. <div class="col-md-6">
  46. <div class="row static-info">
  47. <div class="col-md-4 name"> SKU: </div>
  48. <div class="col-md-8 value"> <%= @product.sku %></div>
  49. </div>
  50. <div class="row static-info">
  51. <div class="col-md-4 name"> Producto: </div>
  52. <div class="col-md-8 value"> <%= @product.name %> </div>
  53. </div>
  54. <% unless @product.parent_id.nil? %>
  55. <div class="row static-info">
  56. <div class="col-md-4 name"> Presentación: </div>
  57. <div class="col-md-8 value"> <%= @product.display_attributes %> </div>
  58. </div>
  59. <% end %>
  60. <div class="row static-info">
  61. <div class="col-md-4 name"> Descripción: </div>
  62. <div class="col-md-8 value"> <%= @product.description %> </div>
  63. </div>
  64. <div class="row static-info">
  65. <div class="col-md-4 name"> Unidad de medida: </div>
  66. <div class="col-md-8 value"> <%= @product.unit.unit %> </div>
  67. </div>
  68. <div class="row static-info">
  69. <div class="col-md-4 name"> Status: </div>
  70. <div class="col-md-8 value"> <% if @product.status == "active" %> <span class="badge badge-success"> Activo</span> <% else %> <span class="badge badge-danger"> Inactivo</span> <% end %></div>
  71. </div>
  72. </div>
  73. <div class="col-md-6">
  74. <div class="row static-info">
  75. <div class="col-md-4 name"> Inventariado: </div>
  76. <div class="col-md-8 value"> <% if @product.inventory %> <span class="label label-success"> Si</span> <% else %> <span class="label label-danger"> No</span> <% end %> </div>
  77. </div>
  78. <div class="row static-info">
  79. <div class="col-md-4 name"> Categoría: </div>
  80. <div class="col-md-8 value">
  81. <span class="badge badge-default badge-roundless"> <%= @product.category.category %> </span>
  82. </div>
  83. </div>
  84. <% if current_user.usertype == "A" || current_user.usertype == "SS" %>
  85. <div class="row static-info">
  86. <div class="col-md-4 name"> Precio compra: </div>
  87. <div class="col-md-8 value"><%= (@product.is_in_dollars? ? "#{number_to_currency(@product.price_base_dollars, precision: 2)} USD" : "#{number_to_currency(@product.price_base, precision: 2)} MXN") %> </div>
  88. </div>
  89. <% end %>
  90. <div class="row static-info">
  91. <div class="col-md-4 name"> Precio venta base: </div>
  92. <div class="col-md-8 value"> $ <%= @product.price_sale %> </div>
  93. </div>
  94. </div>
  95. </div><br>
  96. <h4 class="form-section presentaciones">Variantes</h4><hr>
  97. <div class="col-md-9 col-md-offset-3">
  98. <div class="alert alert-warning hidden">
  99. Son <strong id="variantes"></strong> variantes del producto.
  100. </div>
  101. </div>
  102. <div class="form-group ">
  103. <%= label_tag :size_list, "Tallas", {:class=>"col-md-3 control-label"} %>
  104. <div class="col-md-9 div_sizes">
  105. <button class="btn btn-primary btn-sm margin-bottom-10 add_size">Agregar talla</button>
  106. <% @product.sizes.each_with_index do |s, i| %>
  107. <%= text_field_tag "#{s.id}", s.name, :class => "form-control input-medium margin-bottom-10 sizes" %>
  108. <!-- < %= hidden_field_tag "size_#{s.id}", s.name %> -->
  109. <% end %>
  110. <%= hidden_field_tag "new_size_list", @product.sizes.to_json.to_s %>
  111. </div>
  112. </div>
  113. <div class="form-group ">
  114. <%= label_tag :color_list, "Colores", {:class=>"col-md-3 control-label"} %>
  115. <div class="col-md-9 div_colors">
  116. <button class="btn btn-primary btn-sm margin-bottom-10 add_color">Agregar color</button>
  117. <% @product.colors.each_with_index do |s, i| %>
  118. <%= text_field_tag "#{s.id}", s.name, :class => "form-control input-medium margin-bottom-10 colors" %>
  119. <!-- < %= hidden_field_tag "color_#{s.id}", s.name %> -->
  120. <% end %>
  121. <%= hidden_field_tag "new_color_list", @product.colors.to_json %>
  122. </div>
  123. </div>
  124. <div class="form-group ">
  125. <%= label_tag :style_list, "Estilos", {:class=>"col-md-3 control-label"} %>
  126. <div class="col-md-9 div_styles">
  127. <button class="btn btn-primary btn-sm margin-bottom-10 add_style">Agregar estilo</button>
  128. <% @product.styles.each_with_index do |s, i| %>
  129. <%= text_field_tag "#{s.id}", s.name, :class => "form-control input-medium margin-bottom-10 styles" %>
  130. <!-- < %= hidden_field_tag "style_#{s.id}", s.name %> -->
  131. <% end %>
  132. <%= hidden_field_tag "new_style_list", @product.styles.to_json %>
  133. </div>
  134. </div>
  135. <hr>
  136. <div class="form-actions">
  137. <div class="row">
  138. <div class="col-md-9">
  139. <%= submit_tag 'Guardar', {:class=>"btn green"} %>
  140. <%= link_to 'Cancelar', products_path(:filter => @filter, :current_page => @current_page), {:class=>"btn default"} %>
  141. </div>
  142. </div>
  143. </div>
  144. <%= hidden_field_tag :variants %>
  145. </div>
  146. </div>
  147. <% end %>
  148. </div>
  149. </div>
  150. </div>
  151. <!-- END PAGE CONTENT INNER -->
  152. </div>
  153. </div>
  154. <!-- END PAGE CONTENT BODY -->
  155. <!-- END CONTENT BODY -->
  156. </div>
  157. <!-- END CONTENT -->
  158. </div>
  159. <!-- END CONTAINER -->
  160. <script>
  161. $("#form").submit(function(e) {
  162. var self = this;
  163. e.preventDefault();
  164. <% if @product.sizes.count > 0 %>
  165. var sizes = JSON.parse($('#new_size_list').val());
  166. $('.sizes').each(function () {
  167. // console.log(this);
  168. for (var i = 0; i < sizes.length ; i++) {
  169. if(sizes[i].id == this.name){
  170. sizes[i].name = this.value;
  171. }
  172. };
  173. });
  174. $('#new_size_list').val(JSON.stringify(sizes));
  175. <% end %>
  176. <% if @product.colors.count > 0 %>
  177. var colors = JSON.parse($('#new_color_list').val());
  178. $('.colors').each(function () {
  179. // console.log(this);
  180. for (var i = 0; i < colors.length ; i++) {
  181. if(colors[i].id == this.name){
  182. colors[i].name = this.value;
  183. }
  184. };
  185. });
  186. $('#new_color_list').val(JSON.stringify(colors));
  187. <% end %>
  188. <% if @product.styles.count > 0 %>
  189. var styles = JSON.parse($('#new_style_list').val());
  190. $('.styles').each(function () {
  191. // console.log(this);
  192. for (var i = 0; i < styles.length ; i++) {
  193. if(styles[i].id == this.name){
  194. styles[i].name = this.value;
  195. }
  196. };
  197. });
  198. $('#new_style_list').val(JSON.stringify(styles));
  199. <% end %>
  200. self.submit();
  201. return false; //is superfluous, but I put it here as a fallback
  202. });
  203. $(document).ready(function() {
  204. var x = 1; //initlal text box count
  205. $('.add_size').click(function(e){ //on add input button click
  206. e.preventDefault();
  207. x++; //text box increment
  208. $('.div_sizes').append('<div class="margin-bottom-10"><div class="input-group"><input type="text" name="mynewsizes[]" class="form-control input-medium "/><a href="#" class="remove_field btn btn-icon-only red"><i class="fa fa-times"></i></a></div></div>'); //add input box
  209. });
  210. $('.div_sizes').on("click",".remove_field", function(e){ //user click on remove text
  211. e.preventDefault(); $(this).parent('div').remove(); x--;
  212. });
  213. var y = 1;
  214. $('.add_color').click(function(e){ //on add input button click
  215. e.preventDefault();
  216. y++; //text box increment
  217. $('.div_colors').append('<div class="margin-bottom-10"><div class="input-group"><input type="text" name="mynewcolors[]" class="form-control input-medium "/><a href="#" class="remove_field btn btn-icon-only red"><i class="fa fa-times"></i></a></div></div>'); //add input box
  218. });
  219. $('.div_colors').on("click",".remove_field", function(e){ //user click on remove text
  220. e.preventDefault(); $(this).parent('div').remove(); y--;
  221. });
  222. var z = 1;
  223. $('.add_style').click(function(e){ //on add input button click
  224. e.preventDefault();
  225. z++; //text box increment
  226. $('.div_styles').append('<div class="margin-bottom-10"><div class="input-group"><input type="text" name="mynewstyles[]" class="form-control input-medium "/><a href="#" class="remove_field btn btn-icon-only red"><i class="fa fa-times"></i></a></div></div>'); //add input box
  227. });
  228. $('.div_styles').on("click",".remove_field", function(e){ //user click on remove text
  229. e.preventDefault(); $(this).parent('div').remove(); z--;
  230. });
  231. });
  232. </script>