Permalink
Browse files

fixing application.js

  • Loading branch information...
1 parent ec91bc6 commit 36d01dfb098013044bb44b7e178c77143cb57637 @subbarao subbarao committed Aug 10, 2011
Showing with 24 additions and 45 deletions.
  1. +0 −2 app/views/home/index.html.erb
  2. +1 −1 app/views/layouts/application.html.erb
  3. +23 −42 public/javascripts/application.js
@@ -1,6 +1,4 @@
<div id="main">
<div id="products">
- <div id="products-list">
- </div>
</div>
</div>
@@ -17,7 +17,7 @@
<link href='http://fonts.googleapis.com/css?family=Corben:700&v2' rel='stylesheet' type='text/css'>
</head>
- <body class="<%= body_class %>">
+ <body class="products products-index">
<%= render '/layouts/flash' %>
<div id="container">
@@ -2,69 +2,50 @@ $(function(){
window.Product = Backbone.Model.extend({
defaults: {name: 'name missing'},
-
- initialize: function(){}
+ initialize: function(){
+ }
});
window.ProductList = Backbone.Collection.extend({
+ el: "#products",
model: Product,
url: '/products.json'
});
- window.Products = new window.ProductList;
-
- window.ProductViewForList = Backbone.View.extend({
+ window.ProductViewForShow = Backbone.View.extend({
initialize: function() {
- this.template = _.template("<a href='products/<%= id %>'><img alt='<%= name %>' class='productImage' height='190' src='/system/pictures/<%= id %>/thumbnail/<%= picture_file_name %>' width='190' /></a> <p class='productName'> <%= name %><a href='/products/<%= id %>'></a></p><p class='productPrice'><%= price %></p>");
+ this.template = _.template("<a href='products/<%= id %>'><img alt='<%= name %>' class='productImage' height='190' src='/system/pictures/<%= id %>/thumbnail/<%= picture_file_name %>' width='190' /></a> <p class='productName'> <%= name %><a href='/products/<%= id %>'></a></p><p class='productPrice'><%= price %></p>");
- },
- template: _.template($('#product-view-for-list-template').html()),
+ _.bindAll(this, 'render');
+ },
className: 'product',
render: function(){
$(this.el).html(this.template(this.model.toJSON()));
return this;
}
});
- window.ProductViewForShow = Backbone.View.extend({
- template: _.template($('#product-view-for-show-template').html()),
-
- render: function(){
- $(this.el).html(this.template(this.model.toJSON()));
- return this;
- }
- });
-
window.AppView = Backbone.View.extend({
- el: $("#products"),
-
- events: {
- "click #products-list .product a": "showProduct"
+ tagName: 'div',
+ id: "products",
+ render: function(){
+ var self = this;
+ this.collection.each(function(element){
+ var view = new ProductViewForShow({model: element});
+ self.el.append(view.render().el);
+ });
},
-
initialize: function(){
- Products.bind('reset', this.addAll, this);
- Products.fetch();
- },
-
- showProduct: function(product) {
- var view = new ProductViewForShow({model: product});
- this.$('#content').html(view.render().el);
- return false;
- },
-
- addOne: function(product){
- var view = new ProductViewForList({model: product});
- var e = view.render().el;
- this.$('#products-list').append(e);
- },
+ _.bindAll(this, 'render');
+ this.render();
+ }
+ });
- addAll: function(){
- Products.each(this.addOne);
+ var products = new ProductList();
+ products.fetch({
+ success: function() {
+ new AppView({ el: $("#products"), collection: products });
}
});
-
- window.app = new AppView;
-
});

0 comments on commit 36d01df

Please sign in to comment.