Changeset 1246
- Timestamp:
- 11/12/06 18:21:27 (2 years ago)
- Files:
-
- peasantonline/app/controllers/admin_controller.rb (modified) (2 diffs)
- peasantonline/app/helpers/admin_helper.rb (modified) (1 diff)
- peasantonline/app/models/product.rb (modified) (1 diff)
- peasantonline/app/views/admin/_product.rhtml (added)
- peasantonline/app/views/admin/_product_column_headings.rhtml (added)
- peasantonline/app/views/admin/_product_pagination_links.rhtml (added)
- peasantonline/app/views/admin/component_product.rhtml (added)
- peasantonline/app/views/admin/list_products.rhtml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
peasantonline/app/controllers/admin_controller.rb
r1242 r1246 5 5 6 6 after_filter :clear_flashes 7 before_filter :update_params_filter 7 before_filter :update_params_filter_order, :only => [:component_order, :component_update_order, :list_orders] 8 before_filter :update_params_filter_product, :only => [:component_product, :component_update_product, :list_products] 9 8 10 9 11 def index 10 12 end 11 13 12 def update_params_filter 14 def update_params_filter_order 13 15 update_params :default_scaffold_id => "order", :default_sort => nil, :default_sort_direction => "asc" 16 end 17 18 def update_params_filter_product 19 update_params :default_scaffold_id => "product", :default_sort => nil, :default_sort_direction => "asc" 14 20 end 15 21 … … 26 32 @categories = Category.find(:all, :order => "name") 27 33 end 34 35 # All posts to change scaffold level variables like sort values or page changes go through this action 36 def component_update_product 37 @show_wrapper = false # don't show the outer wrapper elements if we are just updating an existing scaffold 38 if request.xhr? 39 # If this is an AJAX request then we just want to delegate to the component to rerender itself 40 component_product 41 else 42 # If this is from a client without javascript we want to update the session parameters and then delegate 43 # back to whatever page is displaying the scaffold, which will then rerender all scaffolds with these update parameters 44 return_to_main 45 end 46 end 47 48 def component_product 49 @show_wrapper = true if @show_wrapper.nil? 50 @sort_sql = Product.scaffold_columns_hash[current_sort(params)].sort_sql rescue nil 51 @sort_by = @sort_sql.nil? ? "#{Product.table_name}.#{Product.primary_key} asc" : @sort_sql + " " + current_sort_direction(params) 52 @paginator, @products = paginate(:products, :order => @sort_by, :per_page => default_per_page) 53 54 render :action => "component_product", :layout => false 55 end 56 57 58 28 59 29 60 def component_order peasantonline/app/helpers/admin_helper.rb
r1242 r1246 9 9 def order_scaffold_columns 10 10 Order.scaffold_columns 11 end 12 13 def product_num_columns 14 product_scaffold_columns.length + 1 15 end 16 17 def product_scaffold_columns 18 Product.scaffold_columns 11 19 end 12 20 peasantonline/app/models/product.rb
r1052 r1246 10 10 errors.add(:price, "should be positive") if price.nil? || price <= 0 11 11 end 12 13 @scaffold_columns = [ 14 AjaxScaffold::ScaffoldColumn.new(self, { :name => "id", :label => "ID"}), 15 AjaxScaffold::ScaffoldColumn.new(self, { :name => "name", :label => "Name"}), 16 AjaxScaffold::ScaffoldColumn.new(self, { :name => "price", :label => "Price"}), 17 AjaxScaffold::ScaffoldColumn.new(self, { :name => "designer", :label => "Designer"}), 18 AjaxScaffold::ScaffoldColumn.new(self, { :name => "category", :label => "Category"}), 19 AjaxScaffold::ScaffoldColumn.new(self, { :name => "gender", :label => "Gender"}), 20 AjaxScaffold::ScaffoldColumn.new(self, { :name => "tags", :label => "Tags", :sortable => false}) 21 22 ] 23 12 24 13 25 end peasantonline/app/views/admin/list_products.rhtml
r1067 r1246 1 <h1>Listing products</h1> 2 3 <table> 4 <tr> 5 <% for column in Product.content_columns %> 6 <% 7 column_name = column.name 8 case column_name 9 when /short_description/ 10 when /long_description/ 11 when /size_class/ 12 when /featured_image/ 13 else 14 %> 15 16 <th><%= column.human_name %></th> 17 <% end %> 18 <% end %> 19 <th>Tags</th> 20 <th colspan="3"> </th> 21 </tr> 22 23 <% for product in @products %> 24 <tr> 25 <% 26 for column in Product.content_columns 27 column_name = column.name 28 case column_name 29 30 when /name/ 31 %> 32 <td><%= link_to product.send(column.name), :action => 'show_products', :id => product %></td> 33 34 <% 35 when /designer/ 36 %> 37 <td><%= Designer.find_by_id(product.send(column.name)).name %></td> 38 <% 39 when /category/ 40 %> 41 <td><%= Category.find_by_id(product.send(column.name)).name %></td> 42 <% 43 when /gender/ 44 if product.gender == false 45 gender = "Male" 46 else 47 gender = "Female" 48 end 49 %> 50 <td><%= gender %></td> 51 <% 52 when /short_description/ 53 when /long_description/ 54 when /size_class/ 55 when /featured_image/ 56 else 57 %> 58 59 <td><%=h product.send(column.name) %></td> 60 <% 61 end 62 end 63 %> 64 <td><%= product.tag_names.join("<br />\n") %> 65 <td><%= link_to 'Show', :action => 'show_products', :id => product %></td> 66 <td><%= link_to 'Edit', :action => 'edit_products', :id => product %></td> 67 <td><%= link_to 'Destroy', { :action => 'destroy_products', :id => product }, :confirm => 'Are you sure?', :post => true %></td> 68 </tr> 69 <% end %> 70 </table> 71 72 <%= link_to 'Previous page', { :page => @product_pages.current.previous } if @product_pages.current.previous %> 73 <%= link_to 'Next page', { :page => @product_pages.current.next } if @product_pages.current.next %> 74 75 <br /> 76 77 <%= link_to 'New product', :action => 'new_products' %> 1 <%= render_component :controller => 'admin', :action => 'component_product', :params => params %>