From 96504d6806aaef9b082e879164c17e69693e819f Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Thu, 29 May 2014 20:02:02 +0800 Subject: [PATCH] =?UTF-8?q?1.=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=EF=BC=8C=202.=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BD=9C=E4=B8=9A=E3=80=81=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E6=96=B9=E6=B3=95=203.=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E9=A1=B5=E9=9D=A2=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_attach_controller.rb | 18 ++++----- app/helpers/homework_attach_helper.rb | 10 +++++ app/views/bids/_homework.html.erb | 3 +- app/views/bids/_homework_list.html.erb | 39 ++++++++++++++----- app/views/homework_attach/_app_link.html.erb | 2 + app/views/homework_attach/edit.html.erb | 36 +++++++++++++++++ app/views/homework_attach/new.html.erb | 34 ++++++++-------- app/views/homework_attach/show.html.erb | 23 ++++++----- db/schema.rb | 14 +++---- 9 files changed, 126 insertions(+), 53 deletions(-) create mode 100644 app/helpers/homework_attach_helper.rb diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index 64bfe5c40..18da32d81 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -18,7 +18,7 @@ class HomeworkAttachController < ApplicationController end 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) + #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 @@ -46,7 +46,7 @@ class HomeworkAttachController < ApplicationController format.json { render json: @homework.errors, status: :unprocessable_entity } end end - end + #end end def new @@ -66,7 +66,7 @@ class HomeworkAttachController < ApplicationController def update @homework = HomeworkAttach.find(params[:id]) respond_to do |format| - if @post.update_attributes(params[:homework]) + if @homework.update_attributes(params[:homework]) format.html { redirect_to @homework, notice: 'Homework was successfully updated.' } format.json { head :no_content } else @@ -77,12 +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 + #@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/helpers/homework_attach_helper.rb b/app/helpers/homework_attach_helper.rb new file mode 100644 index 000000000..1abac35d6 --- /dev/null +++ b/app/helpers/homework_attach_helper.rb @@ -0,0 +1,10 @@ +module HomeworkAttachHelper + def attach_delete(project) + if User.current.logged? && (User.current.admin? || (!Member.where('user_id = ? and project_id = ?', User.current.id, project.bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, project.bid.courses.first.id).first.roles&Role.where('id = ? or id = ?', 3, 7)).size >0) || project.user_id == User.current.id) + true + else + false + end + + end +end \ No newline at end of file diff --git a/app/views/bids/_homework.html.erb b/app/views/bids/_homework.html.erb index eb6b9bbf5..d9ce738d8 100644 --- a/app/views/bids/_homework.html.erb +++ b/app/views/bids/_homework.html.erb @@ -25,7 +25,8 @@ <% 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) %>
- <%= link_to l(:label_commit_homework), new_submit_homework_path, :onclick => "$('#put-bid-form').slideToggle(); this.blur(); return false;" %> + + <%= link_to l(:label_course_new_homework),new_homework_attach_path %>
<% end %> diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index aa4140f95..57e3fe686 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -32,17 +32,28 @@ - - + + +
+   作业   :  - <% attachments = homework.attachments.map %> - <% for attachment in attachments %> - <% if attachments.count > 1 && attachment != attachments.first %> -
- <% for item in 1..7 %> -   + <% if homework.name == nil || homework.name == "" %> + <% attachments = homework.attachments.map %> + <% for attachment in attachments %> + <% if attachments.count > 1 %> + <% homework_filename = attachment.filename + "等" + attachments.count.to_s + "个文件" %> + <% else %> + <% homework_filename = attachment.filename %> <% end %> + <% end %> - <%= link_to_attachment attachment , :download => true -%> + <%= homework_filename %> + <% else %> + <%= homework.name %> <% end %>
@@ -76,12 +87,21 @@
  +   <% if is_cur_course_user? @bid %> <%= l(:label_bidding_user_studentcode) %>  : <%= homework.user.user_extensions.student_id%> <% end %> + <% if (User.current == homework.user) || (!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 =?',3,7, 9)).size >0) %> + <%= link_to l(:button_edit), edit_homework_attach_path(homework) %> + <%= link_to(l(:label_bid_respond_delete), {:controller => 'homework_attach', :action => 'destroy', :object_id => homework}, + :remote => true, :confirm => l(:text_are_you_sure), :title => l(:button_delete)) %> + <% end %> +
diff --git a/app/views/homework_attach/_app_link.html.erb b/app/views/homework_attach/_app_link.html.erb index 702421dbd..48f116ce6 100644 --- a/app/views/homework_attach/_app_link.html.erb +++ b/app/views/homework_attach/_app_link.html.erb @@ -8,4 +8,6 @@ :controller => 'attachments', :action => 'show', :id => attachment, :filename => attachment.filename %> <% end %> + <%= h(" - #{attachment.description}") unless attachment.description.blank? %> + (<%= number_to_human_size attachment.filesize %>) <% end -%> diff --git a/app/views/homework_attach/edit.html.erb b/app/views/homework_attach/edit.html.erb index e69de29bb..1456af650 100644 --- a/app/views/homework_attach/edit.html.erb +++ b/app/views/homework_attach/edit.html.erb @@ -0,0 +1,36 @@ +

<%=raw l(:label_new_homework)%>

+
+ <%= @homework.attachments.count %> + <%= form_for(@homework) 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;" %> + +

+

+

+

+ <% options = {:author => true, :deletable => attach_delete(@homework)} %> + <%= render :partial => 'attachments/links', + :locals => {:attachments => @homework.attachments, :options => options} %> +

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

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

+
+

+

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

+ <% end %> +
\ No newline at end of file diff --git a/app/views/homework_attach/new.html.erb b/app/views/homework_attach/new.html.erb index 073ab21b2..c1851343b 100644 --- a/app/views/homework_attach/new.html.erb +++ b/app/views/homework_attach/new.html.erb @@ -1,32 +1,34 @@

<%=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"%> +

+

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

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

+
+

+

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

<% end %> diff --git a/app/views/homework_attach/show.html.erb b/app/views/homework_attach/show.html.erb index 9c39e84f1..2b2ec5cce 100644 --- a/app/views/homework_attach/show.html.erb +++ b/app/views/homework_attach/show.html.erb @@ -25,7 +25,6 @@ 发布人员:<%= link_to @homework.user, user_path(@homework.user)%> 发布时间:<%=format_time @homework.created_at %> - @@ -58,15 +57,19 @@
作业描述:
- <% @homework.attachments.map do |attachment| %> - <% if attachment.description != nil && attachment.description != "" %> - - -
<%= attachment.description %>
- - - <% end %> - <% end %> + + +
+ <% if @homework.description != nil && @homework.description != "" %> + <%= @homework.description %> + <% else %> +
+ 该作业无任何描述! +
+ <% end %> +
+ + diff --git a/db/schema.rb b/db/schema.rb index 12bcab886..230709ce8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140522025721) do +ActiveRecord::Schema.define(:version => 20140527060344) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -57,14 +57,11 @@ ActiveRecord::Schema.define(:version => 20140522025721) do add_index "attachments", ["container_id", "container_type"], :name => "index_attachments_on_container_id_and_container_type" add_index "attachments", ["created_on"], :name => "index_attachments_on_created_on" - create_table "attachmentstypes", :id => false, :force => true do |t| - t.integer "id", :null => false - t.integer "typeId" + create_table "attachmentstypes", :force => true do |t| + t.integer "typeId", :null => false t.string "typeName", :limit => 50 end - add_index "attachmentstypes", ["id"], :name => "id" - create_table "auth_sources", :force => true do |t| t.string "type", :limit => 30, :default => "", :null => false t.string "name", :limit => 60, :default => "", :null => false @@ -482,12 +479,13 @@ ActiveRecord::Schema.define(:version => 20140522025721) do t.text "notes" t.integer "status" t.integer "reply_id" - t.datetime "created_on", :null => false - t.datetime "updated_on", :null => false + t.datetime "created_on", :null => false + t.datetime "updated_on", :null => false t.string "m_parent_id" t.boolean "is_readed" t.integer "m_reply_count" t.integer "m_reply_id" + t.integer "is_comprehensive_evaluation" end create_table "member_roles", :force => true do |t|