From 781fa32dbb4b4a03d706edfc7920315d8f63ae89 Mon Sep 17 00:00:00 2001 From: fanqiang <316257774@qq.com> Date: Thu, 26 Sep 2013 09:06:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E9=9C=80=E6=B1=82?= =?UTF-8?q?=E7=9A=84fork=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/bids_controller.rb | 44 ++++++++++++++++++- app/helpers/bids_helper.rb | 13 +++++- app/views/bids/_fork_form.html.erb | 20 +++++++++ app/views/bids/fork.html.erb | 10 +++++ app/views/layouts/base_bids.html.erb | 2 +- config/routes.rb | 2 + .../20130926005448_add_parent_id_to_bid.rb | 5 +++ db/schema.rb | 3 +- 8 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 app/views/bids/_fork_form.html.erb create mode 100644 app/views/bids/fork.html.erb create mode 100644 db/migrate/20130926005448_add_parent_id_to_bid.rb diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 2e6f4b59d..d6417df6c 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -6,11 +6,12 @@ class BidsController < ApplicationController menu_item :homework_respond, :only => :homework_respond menu_item :homework_statistics, :only => :homework_statistics #Ended by young - before_filter :find_bid, :only => [:show, :show_project, :create, :destroy, :more, :back, :add, :new, :homework_respond, :add_homework, :homework_statistics] + before_filter :find_bid, :only => [:show, :show_project, :create, :destroy, :more, :back, :add, :new, :homework_respond, :add_homework, :homework_statistics, :fork, :create_fork] helper :watchers helper :attachments include AttachmentsHelper + helper :projects def index # Modified by nie @@ -82,6 +83,46 @@ class BidsController < ApplicationController # end # #end end + + def fork + @new_bid = Bid.new + @new_bid.safe_attributes = params[:bid] + @courses = [] + @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current)) + @membership.each do |membership| + if membership.project.project_type == 1 + @courses << membership.project + end + end + end + + def create_fork + @homework = Bid.new + @homework.name = params[:bid][:name] + @homework.description = params[:bid][:description] + @homework.reward_type = 3 + # @bid.budget = params[:bid][:budget] + @homework.deadline = params[:bid][:deadline] + @homework.budget = 0 + @homework.author_id = User.current.id + @homework.commit = 0 + @homework.homework_type = params[:bid][:homework_type] + @homework.parent_id = @bid.id + @homework.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads])) + # @bid. + if @homework.save + HomeworkForCourse.create(:project_id => params[:course], :bid_id => @homework.id) + unless @bid.watched_by?(User.current) + if @bid.add_watcher(User.current) + flash[:notice] = l(:label_bid_succeed) + end + end + redirect_to respond_path(@homework) + else + @homework.safe_attributes = params[:bid] + render :action => 'fork' + end + end def show @user = @bid.author @@ -426,6 +467,7 @@ class BidsController < ApplicationController def find_bid if params[:id] @bid = Bid.find(params[:id]) + @user = @bid.author end rescue render_404 diff --git a/app/helpers/bids_helper.rb b/app/helpers/bids_helper.rb index 89dbdd85f..8ebd07751 100644 --- a/app/helpers/bids_helper.rb +++ b/app/helpers/bids_helper.rb @@ -37,7 +37,7 @@ module BidsHelper Bid.tagged_with(tag_name).order('updated_on desc') end - def sort_bid(state) + def sort_bid(state) content = ''.html_safe case state when 0 @@ -52,4 +52,15 @@ module BidsHelper content_tag('div', content, :class => "tabs") end + def course_options_for_select(courses) + # + html = '' + courses.each do |course| + html << "" + end + html.html_safe + end + end \ No newline at end of file diff --git a/app/views/bids/_fork_form.html.erb b/app/views/bids/_fork_form.html.erb new file mode 100644 index 000000000..2fbc10b3b --- /dev/null +++ b/app/views/bids/_fork_form.html.erb @@ -0,0 +1,20 @@ + +<%= error_messages_for 'bid' %> + +
<%= l(:label_homeworks_form_new_description) %>
+<%= select_tag 'course', course_options_for_select(@courses) %>
+<%= f.text_field :name, :required => true, :size => 60, :style => "width:490px;", :maxlength => Bid::NAME_LENGTH_LIMIT, :value => @bid.name %>
+ ++<%= f.text_area :description, :rows => 8, :value => @bid.description, :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;", :maxlength => Bid::DESCRIPTION_LENGTH_LIMIT %>
+ +<%= f.text_field :deadline, :required => true, :size => 60, :style => "width:150px;" %><%= calendar_for('bid_deadline')%> +
+<%= f.select :homework_type, homework_type_option %> +
+ \ No newline at end of file diff --git a/app/views/bids/fork.html.erb b/app/views/bids/fork.html.erb new file mode 100644 index 000000000..d87221aca --- /dev/null +++ b/app/views/bids/fork.html.erb @@ -0,0 +1,10 @@ + +