修改新建需求界面

This commit is contained in:
baiyu 2013-08-20 16:32:45 +08:00
parent 71d6dc6d21
commit 1290a008fc
16 changed files with 157 additions and 68 deletions

View File

@ -183,33 +183,54 @@ class BidsController < ApplicationController
##新建需求 ##新建需求
def new_bid def new_bid
if params[:bid_title] @bid = Bid.new
if params[:bid_budget].to_s =~ /^(\d+)$|^(\d+).([0-9]{2})$/ @bid.safe_attributes = params[:bid]
if params[:bid_deadline].to_s =~ /^[\d]{4}[-][\d]{1,2}[-][\d]{1,2}$/ # if params[:bid_title]
bid = Bid.creat_bids(params[:bid_budget], params[:bid_deadline], params[:bid_title] , params[:bid_description]) # # if params[:bid_budget].to_s =~ /^(\d+)$|^(\d+).([0-9]{2})$/
unless bid.watched_by?(User.current) # unless params[:bid_reward_type] == "0"
if bid.add_watcher(User.current) # if params[:bid_deadline].to_s =~ /^[\d]{4}[-][\d]{1,2}[-][\d]{1,2}$/
flash[:notice] = l(:label_bid_succeed) # bid = Bid.creat_bids(params[:bid_budget], params[:bid_deadline], params[:bid_title] , params[:bid_description], params[:bid_reward_type].to_i)
end # unless bid.watched_by?(User.current)
end # if bid.add_watcher(User.current)
else # flash[:notice] = l(:label_bid_succeed)
flash[:error] = l(:label_wrong_date) # end
end # end
else # else
flash[:error] = l(:label_wrong_budget) # flash[:error] = l(:label_wrong_date)
end # end
end # else
@limit = 5 # flash[:error] = "wrong"
@bid_count = Bid.count # end
@bid_pages = Paginator.new @bid_count, @limit, params['page'] # # else
@offset ||= @bid_pages.offset # # flash[:error] = l(:label_wrong_budget)
@bids = Bid.offset(@offset).limit(@limit).all # # end
respond_to do |format| # end
# format.html # @limit = 5
format.html { redirect_to :back } # @bid_count = Bid.count
format.js # @bid_pages = Paginator.new @bid_count, @limit, params['page']
# format.api { render_api_ok } # @offset ||= @bid_pages.offset
# @bids = Bid.offset(@offset).limit(@limit).all
# respond_to do |format|
# # format.html
# format.html { redirect_to :back }
# format.js
# # format.api { render_api_ok }
# end
end
def create_bid
@bid = Bid.new
@bid.name = params[:bid][:name]
@bid.description = params[:bid][:description]
@bid.reward_type = params[:bid_reward_type]
@bid.budget = params[:bid][:budget]
@bid.deadline = params[:bid][:deadline]
@bid.author_id = User.current.id
@bid.commit = 0
if @bid.save
redirect_to respond_path(@bid)
end end
render :action => 'new_bid'
end end
def more def more

View File

@ -1,6 +1,7 @@
####by fq ####by fq
class Bid < ActiveRecord::Base class Bid < ActiveRecord::Base
#attr_accessible :author_id, :budget, :deadline, :name, :description #attr_accessible :author_id, :budget, :deadline, :name, :description
include Redmine::SafeAttributes
belongs_to :author, :class_name => 'User', :foreign_key => :author_id belongs_to :author, :class_name => 'User', :foreign_key => :author_id
has_many :biding_projects, :dependent => :destroy has_many :biding_projects, :dependent => :destroy
@ -13,11 +14,13 @@ class Bid < ActiveRecord::Base
validates_length_of :name, :maximum => NAME_LENGTH_LIMIT validates_length_of :name, :maximum => NAME_LENGTH_LIMIT
validates_length_of :description, :maximum => DESCRIPTION_LENGTH_LIMIT validates_length_of :description, :maximum => DESCRIPTION_LENGTH_LIMIT
validates_presence_of :author_id, :name, :deadline validates_presence_of :author_id, :name, :deadline, :budget
validates_presence_of :deadline, :message => 'test' # validates_presence_of :deadline, :message => 'test'
# validates_format_of :deadline, :with => # validates_format_of :deadline, :with =>
validates_format_of :deadline, :with => /^[\d]{4}[-][\d]{1,2}[-][\d]{1,2}$/
validates_format_of :budget, :with => /^(\d+)$|^(\d+).([0-9]{2})|^(\d+).([0-9]{1})$/, :if => Proc.new { |p| p.reward_type == 1 }
validate :validate_user validate :validate_user
validate :validate_reward_type
after_create :act_as_activity after_create :act_as_activity
scope :visible, lambda {|*args| scope :visible, lambda {|*args|
@ -43,14 +46,20 @@ class Bid < ActiveRecord::Base
acts_as_activity_provider :find_options => {:include => [:author]}, acts_as_activity_provider :find_options => {:include => [:author]},
:author_key => :author_id :author_key => :author_id
safe_attributes 'name',
'description',
'budget',
'deadline'
def add_jour(user, notes, reference_user_id = 0) 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) self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id)
end end
def self.creat_bids(budget, deadline, name, description=nil) def self.creat_bids(budget, deadline, name, description=nil, reward_type)
self.create(:author_id => User.current.id, :budget => budget, self.create(:author_id => User.current.id, :budget => budget,
:deadline => deadline, :name => name, :description => description, :commit => 0) :deadline => deadline, :name => name, :description => description, :commit => 0, :reward_type => reward_type)
# self.acts << Activity.new(:user_id => self.author_id) # self.acts << Activity.new(:user_id => self.author_id)
end end
@ -82,6 +91,10 @@ class Bid < ActiveRecord::Base
errors.add :author_id, :invalid if author.nil? || !author.active? errors.add :author_id, :invalid if author.nil? || !author.active?
end end
def validate_reward_type
errors.add :reward_type, :invalid if self.reward_type == 0
end
def act_as_activity def act_as_activity
self.acts << Activity.new(:user_id => self.author_id) self.acts << Activity.new(:user_id => self.author_id)
end end

View File

@ -14,14 +14,19 @@
<td width="500"> <td width="500">
<table border="0"> <table border="0">
<tr> <tr>
<% if bid.reward_type.nil? or bid.reward_type == 1%>
<td style="color: rgb(255, 0, 0);"><strong><%= l(:label_price) %><%= l(:label_RMB_sign) %><%= bid.budget%></strong></td> <td style="color: rgb(255, 0, 0);"><strong><%= l(:label_price) %><%= l(:label_RMB_sign) %><%= bid.budget%></strong></td>
<% elsif bid.reward_type == 2%>
<td style="color: #15bccf;"><strong><%= l(:label_reward) %><%= bid.budget%></strong></td>
<% else %>
<td style="color: rgb(60, 180, 30);"><strong><%= l(:label_grade) %><%= bid.budget%></strong></td>
<% end %>
<td class="font_lighter">(<%= link_to bid.biding_projects.count, project_for_bid_path(bid)%>)<%= l(:label_biding_project) %></td> <td class="font_lighter">(<%= link_to bid.biding_projects.count, project_for_bid_path(bid)%>)<%= l(:label_biding_project) %></td>
<td class="font_lighter">(<%= link_to bid.commit, respond_path(bid)%>)<%= l(:label_responses) %></td> <td class="font_lighter">(<%= link_to bid.commit, respond_path(bid)%>)<%= l(:label_responses) %></td>
<td class="font_lighter">(<%= link_to bid.watcher_users.count, respond_path(bid)%>)<%= l(:label_followers) %></td> <td class="font_lighter">(<%= link_to bid.watcher_users.count, respond_path(bid)%>)<%= l(:label_followers) %></td>
</tr> </tr>
</table></td> </table></td>
<td width="200" align="right" class="a"><a class="font_lighter"> <%= format_time bid.created_on %></a></td> <td width="200" align="right" class="a"><span class="font_lighter"> <%= format_time bid.created_on %></span></td>
</tr> </tr>
<tr> <tr>
<td> <td>

View File

@ -0,0 +1,12 @@
<!-- fq -->
<%= error_messages_for 'bid' %>
<!--[form:project]-->
<p><%= f.text_field :name, :required => true, :size => 60, :style => "width:490px;", :maxlength => Bid::NAME_LENGTH_LIMIT %></p>
<p style="margin-left:-10px;padding-right: 20px;"><%= f.text_area :description, :rows => 8, :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;", :maxlength => Bid::DESCRIPTION_LENGTH_LIMIT %></p>
<p><%= select_tag 'bid_reward_type', "<option value = '0'>#{l(:label_choose_reward)}</option><option value = '1'>#{l(:label_money)}</option><option value = '2'>#{l(:label_reward_1)}</option><option value = '3'>#{l(:label_grade_1)}</option>".html_safe %>
<%= f.text_field :budget, :required => true, :size => 60, :style => "width:350px;" %>
</p>
<p><%= f.text_field :deadline, :required => true, :size => 60, :style => "width:100px;" %><%= calendar_for('bid_deadline')%>
</p>

View File

@ -46,28 +46,29 @@
<table border="0" width="600px" style="border-left: 1px solid #acaeb1; border-right: 1px solid #acaeb1; <table border="0" width="600px" style="border-left: 1px solid #acaeb1; border-right: 1px solid #acaeb1;
border-top: 1px solid #acaeb1; border-bottom: 1px solid #acaeb1; margin-top: 30px; margin-left: 30px;"> border-top: 1px solid #acaeb1; border-bottom: 1px solid #acaeb1; margin-top: 30px; margin-left: 30px;">
<tr> <tr>
<td><%= text_field_tag 'bid_title', "#{l(:label_requirement_name)}", :class => 'noline', :required => true, :onfocus => "clearInfo('bid_title', '#{l(:label_requirement_name)}')", :onblur => "showInfo('bid_title', '#{l(:label_requirement_name)}')"%></td> <td colspan="2"><%= text_field_tag 'bid_title', "#{l(:label_requirement_name)}", :class => 'noline', :required => true, :onfocus => "clearInfo('bid_title', '#{l(:label_requirement_name)}')", :onblur => "showInfo('bid_title', '#{l(:label_requirement_name)}')"%></td>
</tr> </tr>
<tr> <tr>
<td><div class="tableline"></div></td> <td colspan="2"><div class="tableline"></div></td>
</tr> </tr>
<tr> <tr>
<td><%= text_area_tag 'bid_description', "#{l(:label_requirement_description)}", :class => 'noline', :required => true, :style => "resize: none;", :rows => 6, <td colspan="2"><%= text_area_tag 'bid_description', "#{l(:label_requirement_description)}", :class => 'noline', :required => true, :style => "resize: none;", :rows => 6,
:onfocus => "clearInfo('bid_description', '#{l(:label_requirement_description)}')", :onblur => "showInfo('bid_description', '#{l(:label_requirement_description)}')" %></td> :onfocus => "clearInfo('bid_description', '#{l(:label_requirement_description)}')", :onblur => "showInfo('bid_description', '#{l(:label_requirement_description)}')" %></td>
</tr> </tr>
<tr> <tr>
<td><div class="tableline"></div></td> <td colspan="2"><div class="tableline"></div></td>
</tr> </tr>
<tr> <tr>
<td width="22%"><%= select_tag 'bid_reward_type', "<option value = '0'>#{l(:label_choose_reward)}</option><option value = '1'>#{l(:label_money)}</option><option value = '2'>#{l(:label_reward_1)}</option><option value = '3'>#{l(:label_grade_1)}</option>".html_safe, :class => 'noline' %></td>
<td><%= text_field_tag 'bid_budget', "#{l(:label_requirement_bargain_money)}", :class => 'noline', :required => true, <td><%= text_field_tag 'bid_budget', "#{l(:label_requirement_bargain_money)}", :class => 'noline', :required => true,
:onfocus => "clearInfo('bid_budget', '#{l(:label_requirement_bargain_money)}')", :onblur => "showInfo('bid_budget', '#{l(:label_requirement_bargain_money)}')" %> :onfocus => "clearInfo('bid_budget', '#{l(:label_requirement_bargain_money)}')", :onblur => "showInfo('bid_budget', '#{l(:label_requirement_bargain_money)}')" %>
</td> </td>
</tr> </tr>
<tr> <tr>
<td><div class="tableline"></div></td> <td colspan="2"><div class="tableline"></div></td>
</tr> </tr>
<tr> <tr>
<td><%= text_field_tag 'bid_deadline', "#{l(:label_deadline)}", :class => 'noline', :required => true, <td colspan="2"><%= text_field_tag 'bid_deadline', "#{l(:label_deadline)}", :class => 'noline', :required => true,
:onfocus => "clearInfo('bid_deadline', '#{l(:label_deadline)}')", :onblur => "showInfo('bid_deadline', '#{l(:label_deadline)}')"%> :onfocus => "clearInfo('bid_deadline', '#{l(:label_deadline)}')", :onblur => "showInfo('bid_deadline', '#{l(:label_deadline)}')"%>
<%= calendar_for('bid_deadline')%></td> <%= calendar_for('bid_deadline')%></td>
</tr> </tr>

View File

@ -6,9 +6,10 @@
<td width="16%"><span style="margin-left:0px"><%= l(:label_call_list)%></span></td> <td width="16%"><span style="margin-left:0px"><%= l(:label_call_list)%></span></td>
<td valign="center"><% if User.current.logged? %> <td valign="center"><% if User.current.logged? %>
<div class='icon icon-add'> <!-- <div class='icon icon-add'> -->
<%= toggle_link l(:label_new_call), 'put-bid-form', {:focus => 'project_id'} %> <%= link_to(l(:label_new_call), {:controller => 'bids', :action => 'new_bid'}, :class => 'icon icon-add') %>
</div> <!-- <%= toggle_link l(:label_new_call), 'put-bid-form', {:focus => 'project_id'} %> -->
<!-- </div> -->
<% end %></td> <% end %></td>

View File

@ -0,0 +1,10 @@
<!-- fq -->
<h3><%=l(:label_new_call)%></h3>
<%= labelled_form_for @bid, :url => {:controller => 'bids', :action => 'create_bid'} do |f| %>
<div class="box tabular">
<%= render :partial => 'form', :locals => { :f => f } %>
<%= submit_tag l(:button_create) %>
<%= javascript_tag "$('#bid_name').focus();" %>
<% end %>
</div>

View File

@ -7,7 +7,13 @@
<td><h3><%= link_to(@bid.author.name, user_path(@bid.author))%><%= @bid.name %></h3></td> <td><h3><%= link_to(@bid.author.name, user_path(@bid.author))%><%= @bid.name %></h3></td>
</tr> </tr>
<tr> <tr>
<td class="font_lighter"><%= l(:label_price) %><%= @bid.budget %></td> <% if @bid.reward_type.nil? or @bid.reward_type == 1%>
<td class="font_lighter"><%= l(:label_price) %><%= l(:label_RMB_sign) %><%= @bid.budget%></td>
<% elsif @bid.reward_type == 2%>
<td class="font_lighter"><%= l(:label_reward) %><%= @bid.budget%></td>
<% else %>
<td class="font_lighter"><%= l(:label_grade) %><%= @bid.budget%></td>
<% end %>
</tr> </tr>
</table></td> </table></td>
</tr> </tr>

View File

@ -48,7 +48,13 @@
<td><%= l(:label_investor) %><%= link_to(@user, user_path(@user))%></td> <td><%= l(:label_investor) %><%= link_to(@user, user_path(@user))%></td>
</tr> </tr>
<tr> <tr>
<td><%= l(:label_investment_budget) %><%= @bid.budget %></td> <% if @bid.reward_type.nil? or @bid.reward_type == 1%>
<td><%= l(:label_price) %><%= l(:label_RMB_sign) %><%= @bid.budget%></td>
<% elsif @bid.reward_type == 2%>
<td><%= l(:label_reward) %><%= @bid.budget%></td>
<% else %>
<td><%= l(:label_grade) %><%= @bid.budget%></td>
<% end %>
</tr> </tr>
<tr> <tr>
<td><%= l(:label_investment_time_limit) %><%= @bid.deadline%></td> <td><%= l(:label_investment_time_limit) %><%= @bid.deadline%></td>

View File

@ -69,7 +69,7 @@
<%= render :partial => 'users/preferences' %></div> <%= render :partial => 'users/preferences' %></div>
</fieldset> </fieldset>
<!-- added by william --> <!-- added by william -->
<fieldset class="collapsible collapsed" style="width:800px;margin-left: 10px;"> <fieldset class="collapsible collapsed" style="width:800px;margin-left: 10px;display: none;">
<legend onclick="toggleFieldset(this);"> <legend onclick="toggleFieldset(this);">
<%= l(:label_user_extensions)%> <%= l(:label_user_extensions)%>
</legend> </legend>

View File

@ -652,8 +652,8 @@ en:
label_query_plural: Custom queries label_query_plural: Custom queries
label_query_new: New query label_query_new: New query
label_my_queries: My custom queries label_my_queries: My custom queries
label_filter_add: Add query condition label_filter_add: Add filter
label_filter_plural: Filters label_filter_plural: Filter
label_equals: is label_equals: is
label_not_equals: is not label_not_equals: is not
label_in_less_than: in less than label_in_less_than: in less than
@ -1192,8 +1192,8 @@ en:
label_respond_requirement: has respond to the requirement label_respond_requirement: has respond to the requirement
label_deadline: deadline yyyy-mm-dd label_deadline: deadline yyyy-mm-dd
label_requirement_name: give your requirement a name ~~ label_requirement_name: give your requirement a name ~~
label_requirement_description: descriptionshow you requirement>find Witkey to help you>pay the bargain money>check,pay and give comments label_requirement_description: contentdescript your requirement
label_requirement_bargain_money: pay the bargain money(please fill in integer) label_requirement_bargain_money: type in your rewards(ex. money, reward, grade)
label_wrong_budget: The error format of money label_wrong_budget: The error format of money
label_wrong_date: wrong date format, input right date yyyy-mm-dd label_wrong_date: wrong date format, input right date yyyy-mm-dd
button_upload_photo: Upload photo button_upload_photo: Upload photo
@ -1279,9 +1279,9 @@ en:
field_occupation: Occupation field_occupation: Occupation
field_work_experience: Work experience(year) field_work_experience: Work experience(year)
field_zip_code: Zip code field_zip_code: Zip code
label_issue_query_condition: Query condition label_reward: reward
label_issue_query: Query label_grade: grade
label_issue_cancel_query: Cancel query label_choose_reward: choose reward
label_tags_selected: Selected Tags label_money: money
label_tags_related: Related Tags label_reward_1: reward
button_project_tags_add: Add label_grade_1: grade

View File

@ -618,7 +618,7 @@ zh:
label_query: 自定义查询 label_query: 自定义查询
label_query_plural: 自定义查询 label_query_plural: 自定义查询
label_query_new: 新建查询 label_query_new: 新建查询
label_filter_add: 增加查询条件 label_filter_add: 增加过滤器
label_filter_plural: 过滤器 label_filter_plural: 过滤器
label_equals: 等于 label_equals: 等于
@ -1188,7 +1188,6 @@ zh:
label_bidding_project: 应标项目 label_bidding_project: 应标项目
button_bidding: 我要应标 button_bidding: 我要应标
label_new_call: 发布需求
label_new_call: 发布需求 label_new_call: 发布需求
label_new_call: 发布需求 label_new_call: 发布需求
label_user_information: "与我相关" label_user_information: "与我相关"
@ -1211,8 +1210,8 @@ zh:
label_respond_requirement: 对需求进行了反馈 label_respond_requirement: 对需求进行了反馈
label_deadline: 投资时限yyyy-mm-dd label_deadline: 投资时限yyyy-mm-dd
label_requirement_name: 为你的需求起个名字~~ label_requirement_name: 为你的需求起个名字~~
label_requirement_description: 内容:说出你的需求>找到威客来帮你>支付担保金让威客开始工作>验收付款并评价 label_requirement_description: 内容:对你的需求进行描述
label_requirement_bargain_money: 支付担保金额(请输入整数 label_requirement_bargain_money: 输入具体奖励方式(如金钱、奖项、学分
button_upload_photo: 上传图片 button_upload_photo: 上传图片
label_leave_me_message: 给我留言了 label_leave_me_message: 给我留言了
label_leave_others_message: 给他留言了 label_leave_others_message: 给他留言了
@ -1300,9 +1299,11 @@ zh:
field_occupation: 学校/公司 field_occupation: 学校/公司
field_work_experience: 工作经验(年) field_work_experience: 工作经验(年)
field_zip_code: 邮编 field_zip_code: 邮编
label_issue_query_condition: 查询条件 label_reward: 奖励:
label_issue_query: 查询 label_grade: 学分:
label_issue_cancel_query: 取消查询 label_choose_reward: 选择奖励方式
label_tags_selected: 已选标签 label_money: 金钱
label_tags_related: 相关标签 label_reward_1: 奖励
button_project_tags_add: 增加 label_grade_1: 学分

View File

@ -439,6 +439,7 @@ RedmineApp::Application.routes.draw do
match 'bids/:id/add', :controller => 'bids', :action => 'add' match 'bids/:id/add', :controller => 'bids', :action => 'add'
match 'words/add_project_respond', :controller => 'words', :action => 'add_project_respond' match 'words/add_project_respond', :controller => 'words', :action => 'add_project_respond'
match 'projects/:id/feedback', :to => 'projects#feedback', :via => :get, :as => 'project_feedback' match 'projects/:id/feedback', :to => 'projects#feedback', :via => :get, :as => 'project_feedback'
match 'bids/create_bid', :to => 'bids#create_bid'
## 测试用 ## 测试用
# match 'test/index', :controller => 'test', :action => 'index' # match 'test/index', :controller => 'test', :action => 'index'
# added by young # added by young

View File

@ -0,0 +1,11 @@
class ChangeTypeForBid < ActiveRecord::Migration
def up
add_column :bids, :reward_type, :integer
change_column :bids, :budget, :string, :null => false
end
def down
remove_column :bids, :reward_type
raise ActiveRecord::IrreversibleMigration
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130814084938) do ActiveRecord::Schema.define(:version => 20130819020004) do
create_table "a_user_watchers", :force => true do |t| create_table "a_user_watchers", :force => true do |t|
t.string "name" t.string "name"
@ -81,13 +81,14 @@ ActiveRecord::Schema.define(:version => 20130814084938) do
create_table "bids", :force => true do |t| create_table "bids", :force => true do |t|
t.string "name" t.string "name"
t.integer "budget" t.string "budget", :null => false
t.integer "author_id" t.integer "author_id"
t.date "deadline" t.date "deadline"
t.string "description" t.string "description"
t.datetime "created_on", :null => false t.datetime "created_on", :null => false
t.datetime "updated_on", :null => false t.datetime "updated_on", :null => false
t.integer "commit" t.integer "commit"
t.integer "reward_type"
end end
create_table "boards", :force => true do |t| create_table "boards", :force => true do |t|

View File

@ -1716,7 +1716,7 @@ input[type='text'].noline {
border: #d5dee9 1px solid; border: #d5dee9 1px solid;
font-size: 12px; font-size: 12px;
color: #ACAEB1; color: #ACAEB1;
padding: 10px 5px; padding: 9px 5px;
width: 98%; width: 98%;
cursor: text; cursor: text;
} }