Refactoring of order comments.
This commit is contained in:
parent
38b5dcba1f
commit
88b268cb0b
14 changed files with 57 additions and 47 deletions
16
app/controllers/order_comments_controller.rb
Normal file
16
app/controllers/order_comments_controller.rb
Normal 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
|
|
@ -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.
|
||||
|
|
|
@ -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
|
2
app/helpers/order_comments_helper.rb
Normal file
2
app/helpers/order_comments_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
module OrderCommentsHelper
|
||||
end
|
|
@ -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
|
||||
|
|
5
app/views/order_comments/_form.html.haml
Normal file
5
app/views/order_comments/_form.html.haml
Normal 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
|
1
app/views/order_comments/create.js.erb
Normal file
1
app/views/order_comments/create.js.erb
Normal file
|
@ -0,0 +1 @@
|
|||
$('#comments').html('<%= escape_javascript(render(:partial => 'shared/comments', :locals => { :comments => @order_comment.order.comments })) %>');
|
1
app/views/order_comments/new.js.erb
Normal file
1
app/views/order_comments/new.js.erb
Normal file
|
@ -0,0 +1 @@
|
|||
$('#new_comment').html('<%= escape_javascript(render('form', :locals => { :order_comment => @order_comment})) %>');
|
|
@ -104,14 +104,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 => { :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"
|
||||
.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
|
||||
|
|
|
@ -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
|
|
@ -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'
|
||||
|
|
|
@ -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]
|
||||
|
|
9
test/functional/order_comments_controller_test.rb
Normal file
9
test/functional/order_comments_controller_test.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
require 'test_helper'
|
||||
|
||||
class OrderCommentsControllerTest < ActionController::TestCase
|
||||
test "should get new" do
|
||||
get :new
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
end
|
4
test/unit/helpers/order_comments_helper_test.rb
Normal file
4
test/unit/helpers/order_comments_helper_test.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
require 'test_helper'
|
||||
|
||||
class OrderCommentsHelperTest < ActionView::TestCase
|
||||
end
|
Loading…
Reference in a new issue