From c7b19d8f2e21a324ab038467e82c39e0157c020a Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Wed, 21 May 2014 14:10:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BD=9C=E4=B8=9A=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_attach_controller.rb | 53 +++++++++++++++---- app/views/homework_attach/edit.html.erb | 0 app/views/homework_attach/new.html.erb | 33 ++++++++++++ config/locales/zh.yml | 5 ++ config/routes.rb | 2 +- 5 files changed, 82 insertions(+), 11 deletions(-) create mode 100644 app/views/homework_attach/edit.html.erb create mode 100644 app/views/homework_attach/new.html.erb diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index ed31f8f7..c3ac1519 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -8,22 +8,50 @@ class HomeworkAttachController < ApplicationController end end - def create - @homework = HomeworkAttach.new(params[:homework]) + def add_users users + if users != nil && users.count > 0 + users.each do |user| + @homework.homework_users.build(:user_id => user.id) + @homework.save + end + end + end - respond_to do |format| - if @homework.save - format.html { redirect_to @homework, notice: 'Post was successfully created.' } - format.json { render json: @homework, status: :created, location: @homework } - else - format.html { render action: "new" } - format.json { render json: @homework.errors, status: :unprocessable_entity } + def create + if User.current.logged? && (!Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',5, 10, 7)).size >0) + user_id = params[:user_id] + bid_id = params[:bid_id] + sta = 0 + name = params[:new_form][:name] + description = params[:new_form][:description] + options = { + :user_id => user_id, + :state => sta, + :name => name, + :description => description, + :bid_id => bid_id + } + + @homework = HomeworkAttach.new(options) + @homework.save_attachments(params[:attachments]) + render_attachment_warning_if_needed(@homework) + + @homework.save + respond_to do |format| + if @homework.save + format.html { redirect_to @homework, notice: 'Post was successfully created.' } + format.json { render json: @homework, status: :created, location: @homework } + else + format.html { render action: "new" } + format.json { render json: @homework.errors, status: :unprocessable_entity } + end end end end def new @homework = HomeworkAttach.new + @bid = Bid.find(params[:id]) respond_to do |format| format.html # new.html.erb @@ -49,7 +77,12 @@ class HomeworkAttachController < ApplicationController end def destroy - + @homework = HomeworkAttach.find(params([:id])) + @homework.destroy + respond_to do |format| + format.html {render @homework} + format.json {render json: @homework} + end end #显示作业信息 diff --git a/app/views/homework_attach/edit.html.erb b/app/views/homework_attach/edit.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/app/views/homework_attach/new.html.erb b/app/views/homework_attach/new.html.erb new file mode 100644 index 00000000..073ab21b --- /dev/null +++ b/app/views/homework_attach/new.html.erb @@ -0,0 +1,33 @@ +

<%=raw l(:label_new_homework)%>

+
+ <%= form_for('new_form', :remote => true, :method => :post, + :url => {:controller => 'homework_attach', + :action => 'create', + :user_id => User.current.id, + :bid_id => @bid + }) do |f|%> +

+ 标题: + <%= f.text_field "name", :required => true, :size => 60, :style => "width:490px;" %> +

+

+ 描述: + + <%= f.text_area "description", :rows => 8, :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;" %> + +

+
+ + <%= l(:label_attachment_plural) %> + +

+ <%= render :partial => 'attachments/form' %> +

+
+ + <%= submit_tag t(:label_new), :sta => 0, :class => "enterprise"%> + <%= submit_tag t(:label_memo_create), :sta => 1, :class => "enterprise"%> + +

+ <% end %> +
\ No newline at end of file diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 666b2874..886a9821 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -580,6 +580,10 @@ zh: label_course_done: 已结束的课程 label_homework_response: 作业咨询 label_bidding_homework: 提交作业 + label_add_homework: 添加作业 + label_edit_homework: 修改作业 + label_delete_homework: 删除作业 + label_new_homework: 创建作业 #end label_my_page: 我的工作台 @@ -962,6 +966,7 @@ zh: button_edit_associated_wikipage: "编辑相关wiki页面: %{page_title}" button_add: 新增 button_change: 修改 + button_ok_and_submit: 确定并提交 button_apply: 查询 button_clear: 清除留言 diff --git a/config/routes.rb b/config/routes.rb index 84b27727..d5317846 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -562,7 +562,7 @@ RedmineApp::Application.routes.draw do match 'calls/new_bid', :controller => 'bids', :action => 'new_bid' match 'contest/new_contest', :controller => 'bids', :action => 'new_contest' #huang match 'calls/:id/show_project', :controller => 'bids', :action => 'show_project', :as => 'project_for_bid' - match 'calls/:id/show_project_homework', :controller => 'bids', :action => 'show_project_homework', :as => 'project_for_bid_homework' # by huang + match 'calls/:id/new_homework', :controller => 'homework_attach', :action => 'new', :as => 'new_homework_attach' match 'calls/:id/add', :controller => 'bids', :action => 'add' match 'calls/:id/delete', :controller => 'bids', :action => 'delete' match 'calls/:id/add_homework', :controller => 'bids', :action => 'add_homework', via: :post