Guest User

Untitled

a guest
Jan 14th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 1.60 KB | None | 0 0
  1. <div id="order-products" class="order-products">
  2.   <% order.products.each do |product| %>
  3.     <div class="line-keeper">
  4.       <%= render :partial => "distribution_plugin_ordered_product/edit", :locals => {:ordered_product => product, :product => product.product} %>
  5.     </div>
  6.   <% end %>
  7. </div>
  8.  
  9. <div id="res-order-products" class="order-products">
  10. </div>
  11.  
  12. <script id="tmpl-order-products" type="text/html">
  13.   <div>
  14.     <# _.each(products, function (product) { #>
  15.       <span> color <# product.product.name #> </span>
  16.     <# }); #>
  17.   </div>
  18. </script>
  19.  
  20. <% javascript_tag do %>
  21.   var App = {
  22.     Views: {},
  23.     Controllers: {},
  24.     init: function() {
  25.       var controller = new App.Controllers.OrderedProducts();
  26.       controller.index();
  27.       //Backbone.history.start();
  28.     }
  29.   };
  30.  
  31.   var OrderedProduct = Backbone.Model.extend({
  32.     url : function() {
  33.       return "<%= url_for({:controller => :distribution_plugin_ordered_product }) %>";
  34.     }
  35.   });
  36.  
  37.   App.Views.Index = Backbone.View.extend({
  38.     initialize: function() {
  39.       this.products = this.options.products;
  40.       this.render();
  41.     },
  42.  
  43.     render: function() {
  44.       jQuery("#res-order-products").html(
  45.         _.template(jQuery("#tmpl-order-products").text(), {products: this.products}));
  46.     },
  47.   });
  48.  
  49.   App.Controllers.OrderedProducts = Backbone.Router.extend({
  50.     index: function() {
  51.       var data = <%= order.products.all.to_json :include => :product %>;
  52.       var p = _(data).map(function(i) { return new OrderedProduct(i); });
  53.       new App.Views.Index({ products: p });
  54.     },
  55.   });
  56.  
  57.   App.init();
  58.  
  59. <% end %>
Add Comment
Please, Sign In to add comment