From 1b6cdeac05b7682f861094d8beba58c4c4926dbe Mon Sep 17 00:00:00 2001 From: yanxd Date: Wed, 9 Apr 2014 11:06:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=97=E8=A1=A8=E4=B8=8A=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A=EF=BC=8C=E5=A4=A7=E6=A6=82=E5=A5=BD=E4=BA=86?= =?UTF-8?q?=E5=90=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/bids_controller.rb | 11 +++ app/helpers/application_helper.rb | 16 ++++- app/helpers/attachments_helper.rb | 9 --- app/views/bids/_bid_homework_show.html.erb | 11 +-- app/views/bids/homework_ajax_modal.js.erb | 3 + app/views/layouts/_base_footer.html.erb | 1 + app/views/projects/_homeworkupload.html.erb | 41 +++++------ .../_homeworkupload_homeworkfile.html.erb | 17 +++++ .../_homeworkupload_homeworkproject.html.erb | 41 +++++++++++ app/views/projects/homework.html.erb | 69 ++++++++++--------- config/routes.rb | 6 +- public/stylesheets/nyan.css | 27 ++++---- 12 files changed, 164 insertions(+), 88 deletions(-) create mode 100644 app/views/bids/homework_ajax_modal.js.erb create mode 100644 app/views/projects/_homeworkupload_homeworkfile.html.erb create mode 100644 app/views/projects/_homeworkupload_homeworkproject.html.erb diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index dfe8b9b0..2b0ed762 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -20,6 +20,17 @@ class BidsController < ApplicationController include ApplicationHelper helper :projects helper :words + helper :welcome + + def homework_ajax_modal + @bid = Bid.find_by_id(params[:id]) + # find_bid + respond_to do |format| + format.js + end + end + + def index @project_type = params[:project_type] # Modified by nie diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 7bdb1918..0ad4404d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1474,8 +1474,20 @@ module ApplicationHelper def hadcommittedhomework(cur,curb) - attaches = HomeworkAttach.where(bid_id: curb) - attaches.map(&:user_id).include? cur + bid = Bid.find_by_id(curb) + return true if bid.nil? + + case bid.homework_type + when Bid::HomeworkFile + attaches = HomeworkAttach.where(bid_id: curb) + attaches.map(&:user_id).include? cur + when Bid::HomeworkProject + attaches = BidingProject.where(user_id: User.current, bid_id: bid) + attaches.count > 0 # > 0 则有提交记录 + else + true + end + end def render_dynamic_nav diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb index 7d5db301..495c0508 100644 --- a/app/helpers/attachments_helper.rb +++ b/app/helpers/attachments_helper.rb @@ -70,15 +70,6 @@ module AttachmentsHelper User.current.logged? && (container.author == user || user.admin?) end - def hadcommittedhomework(cur,curb) - @attaches=HomeworkAttach.find_by_sql("select * from homework_attaches where(bid_id = #{curb})") - @attaches.each do |attach| - if attach.user_id == cur - retrun true - end - end - end - # this method is used to get all projects that tagged one tag # added by william def get_attachments_by_tag(tag_name) diff --git a/app/views/bids/_bid_homework_show.html.erb b/app/views/bids/_bid_homework_show.html.erb index b0f62bc9..27766e41 100644 --- a/app/views/bids/_bid_homework_show.html.erb +++ b/app/views/bids/_bid_homework_show.html.erb @@ -14,9 +14,7 @@ <%= link_to(bid.name, respond_path(bid), :class => 'bid_path') %> <%# 提交作业按钮,上传文件的作业直接显示上传框,关联项目的作业跳转到新页面 %> - <%= link_to "模态窗口", '#OpenWindow', rel: 'leanModal', onclick: "showSubH(#{bid.id});" if Rails.env.development? %> - <%= link_to l(:label_commit_homework), 'javascript:void(0);', onclick: "$('#bid-submit-homework-#{bid.id}').toggle();" if bid.homework_type==Bid::HomeworkFile %> - <%= link_to(l(:label_commit_homework), respond_path(bid), :class => 'bid_path', target: "_blank") if bid.homework_type==Bid::HomeworkProject %> + <%= link_to l(:label_commit_homework), '#OpenWindow', rel: 'leanModal', onclick: "showSubH(#{bid.id}, '#{bid.name}');" if Rails.env.development? %> <% if (User.current.admin?||User.current.id==bid.author_id) %> <%= link_to( l(:button_edit), @@ -63,12 +61,7 @@ <%= bid.description %> - - <%# 提交作业partial %> - - <%= render partial: 'homeworkupload', locals: {bid: bid} %> - - + <%= l(:label_create_time) %> :  <%=format_time bid.created_on %> <%= l(:field_deadline) %> :  <%=bid.deadline %> diff --git a/app/views/bids/homework_ajax_modal.js.erb b/app/views/bids/homework_ajax_modal.js.erb new file mode 100644 index 00000000..c95e4aad --- /dev/null +++ b/app/views/bids/homework_ajax_modal.js.erb @@ -0,0 +1,3 @@ +$('#OpenWindow-content').html(' <%= + j(render partial: "projects/homeworkupload", locals: {bid: @bid}) + %>'); \ No newline at end of file diff --git a/app/views/layouts/_base_footer.html.erb b/app/views/layouts/_base_footer.html.erb index 6de055d0..422f2dbd 100644 --- a/app/views/layouts/_base_footer.html.erb +++ b/app/views/layouts/_base_footer.html.erb @@ -1,4 +1,5 @@ +