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
# 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
# Returns true if @current_user is member of an Ordergroup.

View File

@ -159,17 +159,4 @@ class OrdersController < ApplicationController
redirect_to @order
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

View File

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

View File

@ -4,6 +4,7 @@ class OrderComment < ActiveRecord::Base
belongs_to :user
validates_presence_of :order_id, :user_id, :text
validates_length_of :text, :minimum => 3
end
# == 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;"}
.box_title
%h2 Kommentare
.column_content#comments
.column_content
#comments
= render :partial => 'shared/comments', :locals => { :comments => @order.comments }
%p
- form_for :comment, :url => { :action => :add_comment, :id => @order } do |form|
%p
%b Neuen Kommentar hinzufügen:
%br/
= form.text_area :text, :cols => 50, :rows => 6
%br/
= submit_tag "Kommentar hinzufügen"
#new_comment= render :partial => 'order_comments/form', :locals => { :order_comment => @order.comments.build(:user => current_user)}
= link_to_top

View File

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

View File

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

View File

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