竞赛众包的留言修改

This commit is contained in:
yanxd 2014-01-02 17:29:46 +08:00
parent 6d82d2ce17
commit 90a37a5f4e
5 changed files with 60 additions and 40 deletions

View File

@ -18,6 +18,7 @@ class BidsController < ApplicationController
helper :attachments helper :attachments
include AttachmentsHelper include AttachmentsHelper
helper :projects helper :projects
helper :words
def index def index
@project_type = params[:project_type] @project_type = params[:project_type]
# Modified by nie # Modified by nie
@ -186,7 +187,7 @@ class BidsController < ApplicationController
def show def show
@user = @bid.author @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 @limit = 10
@feedback_count = @jours.count @feedback_count = @jours.count
@feedback_pages = Paginator.new @feedback_count, @limit, params['page'] @feedback_pages = Paginator.new @feedback_count, @limit, params['page']
@ -195,21 +196,19 @@ class BidsController < ApplicationController
@state = false @state = false
respond_to do |format| respond_to do |format|
if @bid.reward_type == 3 layout_file = ''
format.html { case @bid.reward_type
render :layout => 'base_homework' when 3
} layout_file = 'base_homework'
elsif @bid.reward_type == 1 when 1
format.html { layout_file = 'base_bids'
render :layout => 'base_bids'
}
else else
format.html { layout_file = 'base_contest'
render :layout => 'base_contest'
}
end end
format.html {
render :layout => layout_file
}
format.api format.api
end end
end end

View File

@ -280,7 +280,7 @@ class ProjectsController < ApplicationController
#Ended by young #Ended by young
def feedback 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 @limit = 10
@feedback_count = @jours.count @feedback_count = @jours.count
@feedback_pages = Paginator.new @feedback_count, @limit, params['page'] @feedback_pages = Paginator.new @feedback_count, @limit, params['page']

View File

@ -175,11 +175,13 @@ class WordsController < ApplicationController
def obj_distinguish_url_origin def obj_distinguish_url_origin
referer = request.headers["Referer"] 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/) if referer.match(/project/)
obj = Project.find_by_id(obj_id) obj = Project.find_by_id(obj_id)
elsif referer.match(/user/) elsif referer.match(/user/)
obj = User.find_by_id(obj_id) obj = User.find_by_id(obj_id)
elsif ( referer.match(/bids/) || referer.match(/calls/) )
obj = Bid.find_by_id(obj_id)
else else
raise 'create reply obj unknow type.' raise 'create reply obj unknow type.'
end end
@ -192,6 +194,8 @@ class WordsController < ApplicationController
obj.add_jour(nil, nil, nil, options) obj.add_jour(nil, nil, nil, options)
elsif obj.kind_of? Project elsif obj.kind_of? Project
Project.add_new_jour(nil, nil, obj.id, options) Project.add_new_jour(nil, nil, obj.id, options)
elsif obj.kind_of? Bid
obj.add_jour(nil, nil, nil, options)
else else
raise 'create reply obj unknow type.' raise 'create reply obj unknow type.'
end end

View File

@ -77,8 +77,14 @@ class Bid < ActiveRecord::Base
# safe_attributes 'name', # safe_attributes 'name',
# 'description', # 'description',
# 'deadline' # 'deadline'
def add_jour(user, notes, reference_user_id = 0) 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) 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 end
def self.creat_bids(budget, deadline, name, description=nil, reward_type) def self.creat_bids(budget, deadline, name, description=nil, reward_type)

View File

@ -4,14 +4,7 @@
<div id='leave-message'> <div id='leave-message'>
<%= render :partial => 'new', :locals => {:bid => @bid, :sta => @state} %> <%= render :partial => 'new', :locals => {:bid => @bid, :sta => @state} %>
</div> </div>
<% label = '';
<% if journals.size >0 %>
<ul class="message-for-user">
<% for journal in journals%>
<li id='word_li_<%= journal.id.to_s %>' class="outer-message-for-user">
<span class="portrait"><%= image_tag(url_to_avatar(journal.user), :class => "avatar") %></span>
<% label = '';
case @bid.reward_type case @bid.reward_type
when 1 when 1
label = l(:label_respond_requirement) label = l(:label_respond_requirement)
@ -21,24 +14,42 @@
label = l(:label_question_requirement) label = l(:label_question_requirement)
else else
end end
%> %>
<% if journals.size >0 %>
<ul class="message-for-user">
<% for journal in journals%>
<li id='word_li_<%= journal.id.to_s %>' class="outer-message-for-user">
<span class="portrait"><%= image_tag(url_to_avatar(journal.user), :class => "avatar") %></span>
<span class="body"> <span class="body">
<span class="user"><%= link_to journal.user, user_path(journal.user)%></span> <span class="user"><%= link_to journal.user, user_path(journal.user)%></span>
<span class="font_lighter"><%= label %></span> <span class="font_lighter"><%= label %></span>
<%= textilizable journal.notes%> <div> <%= textilizable journal.notes%> </div>
<span class="font_lighter"><%= l(:label_bids_published) %>&nbsp;<%= time_tag(journal.created_on).html_safe %>&nbsp;<%= l(:label_bids_published_ago) %></span> <span class="font_lighter"><%= l(:label_bids_published) %>&nbsp;<%= time_tag(journal.created_on).html_safe %>&nbsp;<%= l(:label_bids_published_ago) %></span>
<span><% if @user==User.current|| User.current.admin? %> <% ids = 'project_respond_form_'+ journal.id.to_s%>
<%= link_to(l(:label_bid_respond_quote), {:controller => 'bids', :action => 'new', :id => bid, :journal_id => journal}, :remote => true, <span>
<%= link_to(l(:button_quote), {:controller => 'bids', :action => 'new', :id => bid, :journal_id => journal}, :remote => true,
:method => 'post', :title => l(:button_quote))%> :method => 'post', :title => l(:button_quote))%>
<%= link_to(l(:label_bid_respond_delete), {:controller => 'bids', :action => 'destroy', :object_id => journal, :id => bid},:confirm => l(:label_delete_confirm), <%= link_to l(:label_bid_respond_quote),'',
{:focus => 'project_respond', :onclick => "toggleAndSettingWordsVal($('##{ids}'), $('##{ids} textarea'), '#{l(:label_reply_plural)} #{journal.user.show_name}: '); $('##{ids} textarea') ;return false;"}
%>
<% if @user==User.current|| User.current.admin? %>
<%#= link_to(l(:label_bid_respond_delete), {:controller => 'bids', :action => 'destroy', :object_id => journal, :id => bid},:confirm => l(:label_delete_confirm),
:remote => true, :method => 'delete', :class => "delete", :confirm => l(:text_are_you_sure), :title => l(:button_delete)) %> :remote => true, :method => 'delete', :class => "delete", :confirm => l(:text_are_you_sure), :title => l(:button_delete)) %>
<% else %> <%= link_to(l(:label_bid_respond_delete), {:controller => 'words', :action => 'destroy', :object_id => journal, :user_id => user}, :remote => true, :confirm => l(:text_are_you_sure), :method => 'delete', :class => "delete", :title => l(:button_delete)) %>
<%= link_to(l(:label_bid_respond_quote), {:controller => 'bids', :action => 'new', :id => bid, :journal_id => journal}, :remote => true, <% end %>
:method => 'post', :title => l(:button_quote))%>
<% end %>
</span> </span>
</span> </span>
<div style="clear: both;"></div> <div style="clear: both;"></div>
<% ids = 'project_respond_form_'+ journal.id.to_s%>
<div id='<%= ids %>' class="respond-form">
<%= render :partial => 'words/new_respond', :locals => {:journal => journal, :m_reply_id => journal} %>
</div>
<div style="clear: both;"></div>
<div>
<%= render :partial => "words/journal_reply", :locals => {:journal => journal } %>
</div>
</li> </li>
<% end %> <% end %>
</ul> </ul>