Refactoring of order comments.

This commit is contained in:
benni 2011-06-19 20:47:27 +02:00
parent 38b5dcba1f
commit 88b268cb0b
14 changed files with 57 additions and 47 deletions

View file

@ -0,0 +1,16 @@
class OrderCommentsController < ApplicationController
def new
@order = Order.find(params[:order_id])
@order_comment = @order.comments.build(:user => current_user)
end
def create
@order_comment = OrderComment.new(params[:order_comment])
if @order_comment.save
render :layout => false
else
render :action => :new, :layout => false
end
end
end

View file

@ -64,19 +64,6 @@ class OrderingController < ApplicationController
end end
end end
# adds a Comment to the Order
def add_comment
order = Order.find(params[:id])
comment = order.comments.build(params[:comment])
comment.user = @current_user
if !comment.text.blank? and comment.save
flash[:notice] = "Kommentar wurde erstellt."
else
flash[:error] = "Kommentar konnte nicht erstellt werden. Leerer Kommentar?"
end
redirect_to :action => 'show', :id => order
end
private private
# Returns true if @current_user is member of an Ordergroup. # Returns true if @current_user is member of an Ordergroup.

View file

@ -159,17 +159,4 @@ class OrdersController < ApplicationController
redirect_to @order redirect_to @order
end end
end end
# adds a Comment to the Order
def add_comment
order = Order.find(params[:id])
comment = order.comments.build(params[:comment])
comment.user = @current_user
if !comment.text.empty? and comment.save
flash[:notice] = "Kommentar wurde erstellt."
else
flash[:error] = "Kommentar konnte nicht erstellt werden. Leerer Kommentar?"
end
redirect_to order
end
end end

View file

@ -0,0 +1,2 @@
module OrderCommentsHelper
end

View file

@ -4,6 +4,7 @@ class OrderComment < ActiveRecord::Base
belongs_to :user belongs_to :user
validates_presence_of :order_id, :user_id, :text validates_presence_of :order_id, :user_id, :text
validates_length_of :text, :minimum => 3
end end
# == Schema Information # == Schema Information

View file

@ -0,0 +1,5 @@
= simple_form_for order_comment, :remote => true, :validate => true do |f|
= f.hidden_field :order_id
= f.hidden_field :user_id
= f.input :text, :input_html => {:size => "50x6"}
= f.submit

View file

@ -0,0 +1 @@
$('#comments').html('<%= escape_javascript(render(:partial => 'shared/comments', :locals => { :comments => @order_comment.order.comments })) %>');

View file

@ -0,0 +1 @@
$('#new_comment').html('<%= escape_javascript(render('form', :locals => { :order_comment => @order_comment})) %>');

View file

@ -104,14 +104,8 @@
.single_column{:style => "width:70em;"} .single_column{:style => "width:70em;"}
.box_title .box_title
%h2 Kommentare %h2 Kommentare
.column_content#comments .column_content
= render :partial => 'shared/comments', :locals => { :comments => @order.comments } #comments
%p = render :partial => 'shared/comments', :locals => { :comments => @order.comments }
- form_for :comment, :url => { :action => :add_comment, :id => @order } do |form| #new_comment= render :partial => 'order_comments/form', :locals => { :order_comment => @order.comments.build(:user => current_user)}
%p
%b Neuen Kommentar hinzufügen:
%br/
= form.text_area :text, :cols => 50, :rows => 6
%br/
= submit_tag "Kommentar hinzufügen"
= link_to_top = link_to_top

View file

@ -79,15 +79,8 @@
.single_column{:style => "width:70em;"} .single_column{:style => "width:70em;"}
.box_title .box_title
%h2 Kommentare %h2 Kommentare
.column_content#comments .column_content
= render :partial => "/shared/comments", :locals => { :comments => @order.comments } #comments
%p = render :partial => 'shared/comments', :locals => { :comments => @order.comments }
- form_for :comment, :url => add_comment_order_path(@order) do |form| #new_comment= render :partial => 'order_comments/form', :locals => { :order_comment => @order.comments.build(:user => current_user)}
%p
%b Neuen Kommentar hinzufügen:
%br/
= form.text_area :text, :cols => 50, :rows => 6
%br/
= submit_tag "Kommentar hinzufügen"
= link_to_top = link_to_top

View file

@ -164,6 +164,8 @@ de:
delivery: Lieferung delivery: Lieferung
stock_taking: Inventur stock_taking: Inventur
financial_transaction: Kontotransaktion financial_transaction: Kontotransaktion
order: Bestellung
order_comment: Kommentar
attributes: attributes:
article: article:
price: Nettopreis price: Nettopreis
@ -283,6 +285,8 @@ de:
user: user:
nick: "Benutzername" nick: "Benutzername"
last_name: "Nachname" last_name: "Nachname"
order_comment:
text: 'Kommentar'
hints: hints:
tax: 'In Prozent, Standard sind 7,0' tax: 'In Prozent, Standard sind 7,0'

View file

@ -1,5 +1,9 @@
Foodsoft::Application.routes.draw do Foodsoft::Application.routes.draw do
get "order_comments/new"
get "comments/new"
get "sessions/new" get "sessions/new"
root :to => redirect("/#{Foodsoft.env}") root :to => redirect("/#{Foodsoft.env}")
@ -44,6 +48,8 @@ Foodsoft::Application.routes.draw do
end end
match '/ordering' => 'ordering#index', :as => 'ordering' match '/ordering' => 'ordering#index', :as => 'ordering'
resources :order_comments, :only => [:new, :create]
############ Foodcoop orga ############ Foodcoop orga
resources :invites, :only => [:new, :create] resources :invites, :only => [:new, :create]

View file

@ -0,0 +1,9 @@
require 'test_helper'
class OrderCommentsControllerTest < ActionController::TestCase
test "should get new" do
get :new
assert_response :success
end
end

View file

@ -0,0 +1,4 @@
require 'test_helper'
class OrderCommentsHelperTest < ActionView::TestCase
end