From 90a37a5f4e8168fea4d3d4c86984643595c22d5e Mon Sep 17 00:00:00 2001 From: yanxd Date: Thu, 2 Jan 2014 17:29:46 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AB=9E=E8=B5=9B=E4=BC=97=E5=8C=85=E7=9A=84?= =?UTF-8?q?=E7=95=99=E8=A8=80=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/bids_controller.rb | 25 ++++++----- app/controllers/projects_controller.rb | 2 +- app/controllers/words_controller.rb | 6 ++- app/models/bid.rb | 10 ++++- app/views/bids/_history.html.erb | 57 +++++++++++++++----------- 5 files changed, 60 insertions(+), 40 deletions(-) diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 078e990ba..538d65abe 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -18,6 +18,7 @@ class BidsController < ApplicationController helper :attachments include AttachmentsHelper helper :projects + helper :words def index @project_type = params[:project_type] # Modified by nie @@ -186,7 +187,7 @@ class BidsController < ApplicationController def show @user = @bid.author - @jours = @bid.journals_for_messages.reverse + @jours = @bid.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') @limit = 10 @feedback_count = @jours.count @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] @@ -195,21 +196,19 @@ class BidsController < ApplicationController @state = false respond_to do |format| - if @bid.reward_type == 3 - format.html { - render :layout => 'base_homework' - } - elsif @bid.reward_type == 1 - format.html { - render :layout => 'base_bids' - } + layout_file = '' + case @bid.reward_type + when 3 + layout_file = 'base_homework' + when 1 + layout_file = 'base_bids' else - format.html { - render :layout => 'base_contest' - } + layout_file = 'base_contest' end + format.html { + render :layout => layout_file + } format.api - end end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 7135610c5..de18c6454 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -280,7 +280,7 @@ class ProjectsController < ApplicationController #Ended by young def feedback - @jours = @project.journals_for_messages.where('m_parent_id IS NULL').reverse + @jours = @project.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') @limit = 10 @feedback_count = @jours.count @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index bb8e6fb0c..1e23197e7 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -175,11 +175,13 @@ class WordsController < ApplicationController def obj_distinguish_url_origin referer = request.headers["Referer"] - obj_id = referer.match((%r|/([0-9]{1,})/|))[1] + obj_id = referer.match(%r(/([0-9]{1,})(/|$)))[1] if referer.match(/project/) obj = Project.find_by_id(obj_id) elsif referer.match(/user/) obj = User.find_by_id(obj_id) + elsif ( referer.match(/bids/) || referer.match(/calls/) ) + obj = Bid.find_by_id(obj_id) else raise 'create reply obj unknow type.' end @@ -192,6 +194,8 @@ class WordsController < ApplicationController obj.add_jour(nil, nil, nil, options) elsif obj.kind_of? Project Project.add_new_jour(nil, nil, obj.id, options) + elsif obj.kind_of? Bid + obj.add_jour(nil, nil, nil, options) else raise 'create reply obj unknow type.' end diff --git a/app/models/bid.rb b/app/models/bid.rb index e1b6b799a..d5177116e 100644 --- a/app/models/bid.rb +++ b/app/models/bid.rb @@ -77,8 +77,14 @@ class Bid < ActiveRecord::Base # safe_attributes 'name', # 'description', # 'deadline' - def add_jour(user, notes, reference_user_id = 0) - self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id) + def add_jour(user, notes, reference_user_id = 0, options = {}) + if options.count == 0 + self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id) + else + jfm = self.journals_for_messages.build(options) + jfm.save + jfm + end end def self.creat_bids(budget, deadline, name, description=nil, reward_type) diff --git a/app/views/bids/_history.html.erb b/app/views/bids/_history.html.erb index e08721c9c..b5b2f9499 100644 --- a/app/views/bids/_history.html.erb +++ b/app/views/bids/_history.html.erb @@ -4,41 +4,52 @@
<%= render :partial => 'new', :locals => {:bid => @bid, :sta => @state} %>
+<% label = ''; + case @bid.reward_type + when 1 + label = l(:label_respond_requirement) + when 2 + label = l(:label_contest_requirement) + when 3 + label = l(:label_question_requirement) + else + end +%> <% if journals.size >0 %>