Refactored article_categories.

This commit is contained in:
benni 2011-05-18 16:10:30 +02:00
parent 0b1682af7c
commit 0decbb36e1
12 changed files with 39 additions and 118 deletions

View file

@ -12,6 +12,7 @@ gem 'jquery-rails'
gem 'simple_form' gem 'simple_form'
gem 'rails3_acts_as_paranoid' gem 'rails3_acts_as_paranoid'
gem 'meta_where' gem 'meta_where'
gem 'inherited_resources'
group :development do group :development do
gem 'annotate' gem 'annotate'

View file

@ -36,8 +36,12 @@ GEM
exception_notification (2.4.0) exception_notification (2.4.0)
fastercsv (1.5.4) fastercsv (1.5.4)
haml (3.1.1) haml (3.1.1)
has_scope (0.5.0)
hirb (0.3.4) hirb (0.3.4)
i18n (0.5.0) i18n (0.5.0)
inherited_resources (1.2.2)
has_scope (~> 0.5.0)
responders (~> 0.6.0)
jquery-rails (1.0.1) jquery-rails (1.0.1)
railties (~> 3.0) railties (~> 3.0)
thor (~> 0.14) thor (~> 0.14)
@ -84,6 +88,7 @@ GEM
rake (>= 0.8.7) rake (>= 0.8.7)
thor (~> 0.14.4) thor (~> 0.14.4)
rake (0.8.7) rake (0.8.7)
responders (0.6.4)
simple_form (1.3.1) simple_form (1.3.1)
thor (0.14.6) thor (0.14.6)
treetop (1.4.9) treetop (1.4.9)
@ -100,6 +105,7 @@ DEPENDENCIES
fastercsv fastercsv
haml haml
hirb hirb
inherited_resources
jquery-rails jquery-rails
meta_where meta_where
mysql mysql

View file

@ -1,71 +1,15 @@
class ArticleCategoriesController < ApplicationController class ArticleCategoriesController < ApplicationController
inherit_resources # Build default REST Actions via plugin
before_filter :authenticate_article_meta before_filter :authenticate_article_meta
def index
@article_categories = ArticleCategory.all :order => 'name'
end
def new
@article_category = ArticleCategory.new
render :update do |page|
page['category_form'].replace_html :partial => 'article_categories/form'
page['category_form'].show
end
end
def edit
@article_category = ArticleCategory.find(params[:id])
render :update do |page|
page['category_form'].replace_html :partial => 'article_categories/form'
page['category_form'].show
end
end
def create def create
@article_category = ArticleCategory.new(params[:article_category]) create!(:notice => "Die Kategorie wurde gespeichert") { article_categories_path }
if @article_category.save
render :update do |page|
page['category_form'].hide
page['category_list'].replace_html :partial => 'article_categories/list'
page['category_'+@article_category.id.to_s].visual_effect(:highlight,
:duration => 2)
end
else
render :update do |page|
page['category_form'].replace_html :partial => 'article_categories/form'
end
end
end end
def update def update
@article_category = ArticleCategory.find(params[:id]) update!(:notice => "Die Kategorie wurde aktualisiert") { article_categories_path }
if @article_category.update_attributes(params[:article_category])
render :update do |page|
page['category_form'].hide
page['category_list'].replace_html :partial => 'article_categories/list'
page['category_'+@article_category.id.to_s].visual_effect(:highlight,
:duration => 2)
end
else
render :update do |page|
page['category_form'].replace_html :partial => 'article_categories/form'
end
end
end end
def destroy
@article_category = ArticleCategory.find(params[:id])
@article_category.destroy
if @article_category.destroy
render :update do |page|
page['category_'+@article_category.id.to_s].visual_effect :drop_out
end
end
end
end end

View file

@ -28,8 +28,8 @@ class ArticlesController < ApplicationController
# if somebody uses the search field: # if somebody uses the search field:
conditions = ["articles.name LIKE ?", "%#{params[:query]}%"] unless params[:query].nil? conditions = ["articles.name LIKE ?", "%#{params[:query]}%"] unless params[:query].nil?
@total = @supplier.articles.without_deleted.count(:conditions => conditions) @total = @supplier.articles.count(:conditions => conditions)
@articles = @supplier.articles.without_deleted.paginate( @articles = @supplier.articles.paginate(
:order => sort, :order => sort,
:conditions => conditions, :conditions => conditions,
:page => params[:page], :page => params[:page],

View file

@ -1,8 +1,7 @@
class ArticleCategory < ActiveRecord::Base class ArticleCategory < ActiveRecord::Base
has_many :articles has_many :articles
validates_length_of :name, :in => 2..20 validates :name, :presence => true, :uniqueness => true, :length => { :in => 2..20 }
validates_uniqueness_of :name
end end

View file

@ -0,0 +1,4 @@
= simple_form_for @article_category do |f|
= f.input :name
= f.input :description
= f.submit

View file

@ -1,24 +0,0 @@
<% remote_form_for @article_category,
:before => "Element.show('loader')",
:success => "Element.hide('loader')" do |@f| %>
<%= @f.error_messages %>
<table>
<tr>
<th>Name</th>
<th>Beschreibung</th>
</tr>
<tr>
<td>
<%= @f.text_field :name, :size => 20 %>
</td>
<td>
<%= @f.text_field :description, :size => 30 %>
</td>
</tr>
</table>
<br />
<%= submit_tag "Speichern" %> | <%= link_to_function("Abbrechen", "Element.hide('category_form')") %>
<% end %>

View file

@ -1,27 +0,0 @@
<table>
<tr>
<th>Name</th>
<th>Beschreibung</th>
<th colspan="2"></th>
</tr>
<% for article_category in ArticleCategory.find(:all) -%>
<tr class="<%= cycle("even","odd", :name => 'category') -%>" id="category_<%= article_category.id -%>">
<td><%=h article_category.name -%></td>
<td><%=h article_category.description -%></td>
<td><%= link_to_remote icon(:edit),
:url => edit_article_category_path(article_category),
:method => :get,
:before => "Element.show('loader')",
:success => "Element.hide('loader')" -%></td>
<td><%= link_to_remote icon(:delete),
:url => article_category,
:method => :delete,
:confirm => 'Are you sure?' -%></td>
</tr>
<% end -%>
</table>
<br />
<%= link_to_remote 'Neue Kategorie', :url => new_article_category_path,
:method => :get,
:before => "Element.show('loader')",
:success => "Element.hide('loader')" %>

View file

@ -0,0 +1,3 @@
- title "Kategorie ändern"
= render 'form'

View file

@ -4,5 +4,16 @@
.box_title .box_title
%h2 Artikelkategorien %h2 Artikelkategorien
.column_content#categories .column_content#categories
#category_form.box.edit_form{:style => "display:none;margin-bottom:1em;"} %table
#category_list= render :partial => 'article_categories/list' %tr
%th Name
%th Beschreibung
%th
- for article_category in ArticleCategory.all
%tr{:class => cycle("even","odd", :name => 'category')}[article_category]
%td= article_category.name
%td= article_category.description
%td
= link_to icon(:edit), edit_article_category_path(article_category)
= link_to icon(:delete), article_category, :method => :delete, :confirm => 'Are you sure?'
%p= link_to 'Neue Kategorie anlegen', new_article_category_path

View file

@ -0,0 +1,3 @@
- title "Neue Kategorie anlegen"
= render 'form'

View file

@ -159,6 +159,7 @@ de:
ordergroup: Bestellgruppe ordergroup: Bestellgruppe
task: Aufgabe task: Aufgabe
message: Nachricht message: Nachricht
article_category: Artikelkategorie
attributes: attributes:
article: article:
price: Nettopreis price: Nettopreis