diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 8ef719241..5b66361bb 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -183,33 +183,54 @@ class BidsController < ApplicationController ##新建需求 def new_bid - if params[:bid_title] - if params[:bid_budget].to_s =~ /^(\d+)$|^(\d+).([0-9]{2})$/ - if params[:bid_deadline].to_s =~ /^[\d]{4}[-][\d]{1,2}[-][\d]{1,2}$/ - bid = Bid.creat_bids(params[:bid_budget], params[:bid_deadline], params[:bid_title] , params[:bid_description]) - unless bid.watched_by?(User.current) - if bid.add_watcher(User.current) - flash[:notice] = l(:label_bid_succeed) - end - end - else - flash[:error] = l(:label_wrong_date) - end - else - flash[:error] = l(:label_wrong_budget) - end - end - @limit = 5 - @bid_count = Bid.count - @bid_pages = Paginator.new @bid_count, @limit, params['page'] - @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 } + @bid = Bid.new + @bid.safe_attributes = params[:bid] + # if params[:bid_title] + # # if params[:bid_budget].to_s =~ /^(\d+)$|^(\d+).([0-9]{2})$/ + # unless params[:bid_reward_type] == "0" + # if params[:bid_deadline].to_s =~ /^[\d]{4}[-][\d]{1,2}[-][\d]{1,2}$/ + # bid = Bid.creat_bids(params[:bid_budget], params[:bid_deadline], params[:bid_title] , params[:bid_description], params[:bid_reward_type].to_i) + # unless bid.watched_by?(User.current) + # if bid.add_watcher(User.current) + # flash[:notice] = l(:label_bid_succeed) + # end + # end + # else + # flash[:error] = l(:label_wrong_date) + # end + # else + # flash[:error] = "wrong" + # end + # # else + # # flash[:error] = l(:label_wrong_budget) + # # end + # end + # @limit = 5 + # @bid_count = Bid.count + # @bid_pages = Paginator.new @bid_count, @limit, params['page'] + # @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 + render :action => 'new_bid' end def more diff --git a/app/models/bid.rb b/app/models/bid.rb index d1ea8f7e1..f04e5436c 100644 --- a/app/models/bid.rb +++ b/app/models/bid.rb @@ -1,6 +1,7 @@ ####by fq class Bid < ActiveRecord::Base #attr_accessible :author_id, :budget, :deadline, :name, :description + include Redmine::SafeAttributes belongs_to :author, :class_name => 'User', :foreign_key => :author_id 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 :description, :maximum => DESCRIPTION_LENGTH_LIMIT - validates_presence_of :author_id, :name, :deadline - validates_presence_of :deadline, :message => 'test' + validates_presence_of :author_id, :name, :deadline, :budget + # validates_presence_of :deadline, :message => 'test' # 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_reward_type after_create :act_as_activity scope :visible, lambda {|*args| @@ -43,14 +46,20 @@ class Bid < ActiveRecord::Base acts_as_activity_provider :find_options => {:include => [:author]}, :author_key => :author_id + + + safe_attributes 'name', + 'description', + 'budget', + '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) 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, - :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) end @@ -82,6 +91,10 @@ class Bid < ActiveRecord::Base errors.add :author_id, :invalid if author.nil? || !author.active? end + def validate_reward_type + errors.add :reward_type, :invalid if self.reward_type == 0 + end + def act_as_activity self.acts << Activity.new(:user_id => self.author_id) end diff --git a/app/views/bids/_bid_show.html.erb b/app/views/bids/_bid_show.html.erb index 474d59071..c76043317 100644 --- a/app/views/bids/_bid_show.html.erb +++ b/app/views/bids/_bid_show.html.erb @@ -14,14 +14,19 @@
<%= l(:label_price) %><%= l(:label_RMB_sign) %><%= bid.budget%> | + <% elsif bid.reward_type == 2%> +<%= l(:label_reward) %><%= bid.budget%> | + <% else %> +<%= l(:label_grade) %><%= bid.budget%> | + <% end %>(<%= link_to bid.biding_projects.count, project_for_bid_path(bid)%>)<%= l(:label_biding_project) %> | (<%= link_to bid.commit, respond_path(bid)%>)<%= l(:label_responses) %> | (<%= link_to bid.watcher_users.count, respond_path(bid)%>)<%= l(:label_followers) %> |
<%= f.text_field :name, :required => true, :size => 60, :style => "width:490px;", :maxlength => Bid::NAME_LENGTH_LIMIT %>
+ +<%= f.text_area :description, :rows => 8, :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;", :maxlength => Bid::DESCRIPTION_LENGTH_LIMIT %>
+<%= select_tag 'bid_reward_type', "".html_safe %> + <%= f.text_field :budget, :required => true, :size => 60, :style => "width:350px;" %> +
+<%= f.text_field :deadline, :required => true, :size => 60, :style => "width:100px;" %><%= calendar_for('bid_deadline')%> +
\ No newline at end of file diff --git a/app/views/bids/_new_bid.html.erb b/app/views/bids/_new_bid.html.erb index 8f005f259..b37928699 100644 --- a/app/views/bids/_new_bid.html.erb +++ b/app/views/bids/_new_bid.html.erb @@ -46,28 +46,29 @@<%= 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)}')"%> | +<%= 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)}')"%> | ||
+ | |||
<%= text_area_tag 'bid_description', "#{l(:label_requirement_description)}", :class => 'noline', :required => true, :style => "resize: none;", :rows => 6, + | <%= 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)}')" %> | ||
+ | |||
<%= select_tag 'bid_reward_type', "".html_safe, :class => 'noline' %> | <%= 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)}')" %> | ||
+ | |||
<%= text_field_tag 'bid_deadline', "#{l(:label_deadline)}", :class => 'noline', :required => true, + | <%= 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)}')"%> <%= calendar_for('bid_deadline')%> | <%= l(:label_call_list)%> | <% if User.current.logged? %>
-
- <%= 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') %>
+
+
<% end %> |
diff --git a/app/views/bids/new_bid.html.erb b/app/views/bids/new_bid.html.erb
new file mode 100644
index 000000000..f00b786cc
--- /dev/null
+++ b/app/views/bids/new_bid.html.erb
@@ -0,0 +1,10 @@
+
+<%= link_to(@bid.author.name, user_path(@bid.author))%>:<%= @bid.name %> |
<%= l(:label_price) %><%= @bid.budget %> | + <% if @bid.reward_type.nil? or @bid.reward_type == 1%> +<%= l(:label_price) %><%= l(:label_RMB_sign) %><%= @bid.budget%> | + <% elsif @bid.reward_type == 2%> +<%= l(:label_reward) %><%= @bid.budget%> | + <% else %> +<%= l(:label_grade) %><%= @bid.budget%> | + <% end %>