作业提交临时解决方案

This commit is contained in:
yanxd 2014-04-08 14:53:11 +08:00
parent 743fee80e3
commit 045b55236f
9 changed files with 63 additions and 22 deletions

View File

@ -353,14 +353,13 @@ class ApplicationController < ActionController::Base
url url
end end
def redirect_back_or_default(default) def redirect_back_or_default(default, options={})
back_url = params[:back_url].to_s back_url = params[:back_url].to_s
if back_url.present? if back_url.present?
begin begin
uri = URI.parse(back_url) uri = URI.parse(back_url)
# do not redirect user to another host or to the login or register page # do not redirect user to another host or to the login or register page
#by young if (uri.relative? || (uri.host == request.host)) && !uri.path.match(%r{/(login|account/register)})
if (uri.relative? || (uri.host == request.host)) && !uri.path.match(%r{/(login|account/register)}) && (uri.path!='/')
redirect_to(back_url) redirect_to(back_url)
return return
end end
@ -368,6 +367,9 @@ class ApplicationController < ActionController::Base
logger.warn("Could not redirect to invalid URL #{back_url}") logger.warn("Could not redirect to invalid URL #{back_url}")
# redirect to default # redirect to default
end end
elsif options[:referer]
redirect_to_referer_or default
return
end end
redirect_to default redirect_to default
false false

View File

@ -736,11 +736,11 @@ class BidsController < ApplicationController
render_attachment_warning_if_needed(@homework) render_attachment_warning_if_needed(@homework)
if @homework.save @homework_flag = if @homework.save
@homework_flag = l(:label_bidding_homework_succeed) l(:label_bidding_homework_succeed)
else else
@homework_flag = l(:label_bidding_homework_failed) l(:label_bidding_homework_failed)
end end
if @homework.attachments.empty? if @homework.attachments.empty?
@homework.delete @homework.delete
@ -754,7 +754,9 @@ class BidsController < ApplicationController
@homework_list = @bid.homeworks @homework_list = @bid.homeworks
respond_to do |format| respond_to do |format|
format.html{ format.html{
redirect_to project_for_bid_path, notice: @homework_flag.to_s #redirect_to project_for_bid_path, notice: @homework_flag.to_s
flash[:notice] = @homework_flag.to_s
redirect_back_or_default(project_for_bid_path)
} }
format.js format.js
end end

View File

@ -144,7 +144,6 @@ class TagsController < ApplicationController
@taggable_type = numbers_to_object_type(params[:taggable_type]) @taggable_type = numbers_to_object_type(params[:taggable_type])
@obj = get_object(@taggable_id,params[:taggable_type]) @obj = get_object(@taggable_id,params[:taggable_type])
logger.debug "==========================================#{@obj}"
@object_flag = params[:taggable_type] @object_flag = params[:taggable_type]
# if can_remove_tag?(User.current,@taggable_id,@taggable_type) # if can_remove_tag?(User.current,@taggable_id,@taggable_type)

View File

@ -103,6 +103,7 @@ class WelcomeController < ApplicationController
@fake_filter = true @fake_filter = true
end end
# 骗子方法
def _fake def _fake
instance_variables.map { |variable| instance_variables.map { |variable|
if variable.to_s =~ /Count$/ if variable.to_s =~ /Count$/

View File

@ -1474,12 +1474,8 @@ module ApplicationHelper
def hadcommittedhomework(cur,curb) def hadcommittedhomework(cur,curb)
@attaches=HomeworkAttach.find_by_sql("select * from homework_attaches where(bid_id = #{curb})") attaches = HomeworkAttach.where(bid_id: curb)
@attaches.each do |attach| attaches.map(&:user_id).include? cur
if attach.user_id == cur
return true
end
end
end end
def render_dynamic_nav def render_dynamic_nav

View File

@ -1,11 +1,20 @@
####by fq ####by fq
=begin =begin
bid一类多用reward_type字段分类 bid一类多用reward_type字段分类
reward == 1 reward_type == 1
reward == 2 reward_type == 2
reward == 3 reward_type == 3
homework_type作业类型
homework_type == 1
homework_type == 2 Project提交
=end =end
class Bid < ActiveRecord::Base class Bid < ActiveRecord::Base
Enterprise = 1
Contest = 2
Homework = 3
HomeworkFile = 1
HomeworkProject = 2
attr_accessible :author_id, :budget, :deadline, :name, :description, :homework_type, :password attr_accessible :author_id, :budget, :deadline, :name, :description, :homework_type, :password
include Redmine::SafeAttributes include Redmine::SafeAttributes

View File

@ -14,6 +14,9 @@
<span class="font_lighter"><%= l(:label_user_create_project_homework) %></span> <span class="font_lighter"><%= l(:label_user_create_project_homework) %></span>
<span><%= link_to(bid.name, respond_path(bid), :class => 'bid_path') %></span> <span><%= link_to(bid.name, respond_path(bid), :class => 'bid_path') %></span>
<span style="float: right"> <span style="float: right">
<%# 提交作业按钮,上传文件的作业直接显示上传框,关联项目的作业跳转到新页面 %>
<%= 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 %>
<% if (User.current.admin?||User.current.id==bid.author_id) %> <% if (User.current.admin?||User.current.id==bid.author_id) %>
<%= link_to( <%= link_to(
l(:button_edit), l(:button_edit),
@ -29,7 +32,6 @@
) %></span> ) %></span>
<% end %> <% end %>
</td> </td>
</tr> </tr>
<tr> <tr>
<td colspan="2"><span class="font_lighter"> <td colspan="2"><span class="font_lighter">
@ -62,6 +64,11 @@
<tr> <tr>
<td colspan="2" width="580px" ><span class="font_description"><%= bid.description %></span></td> <td colspan="2" width="580px" ><span class="font_description"><%= bid.description %></span></td>
</tr> </tr>
<tr><%# 提交作业partial %>
<td class="hidden" id="bid-submit-homework-<%=bid.id%>" >
<%= render partial: 'homeworkupload', locals: {bid: bid} %>
</td>
</tr>
<tr> <tr>
<td align="left"><span class="font_lighter"><span> <%= l(:label_create_time) %> :&nbsp; <%=format_time bid.created_on %></span><span style="float: right"> <%= l(:field_deadline) %> :&nbsp; <%=bid.deadline %></span></td> <td align="left"><span class="font_lighter"><span> <%= l(:label_create_time) %> :&nbsp; <%=format_time bid.created_on %></span><span style="float: right"> <%= l(:field_deadline) %> :&nbsp; <%=bid.deadline %></span></td>
<td></td> <td></td>

View File

@ -0,0 +1,22 @@
<% if hadcommittedhomework(User.current.id, bid.id) %>
<%#= l(:label_bidding_homework_committed) %>
<span class="font_color_orange" > 作业已经提交 </span>
<% else %>
<% if bid.reward_type==Bid::Homework &&
bid.homework_type==Bid::HomeworkFile %>
<%= form_for HomeworkAttach.new, :url => {:controller => 'bids', :action => 'add_homework', id: bid.id, back_url: request.url() }, :update => "bidding_project_list", :complete => '$("#put-bid-form").hide();', :html => {:multipart => true, :id => 'add_homework_form'} do |f| %>
<div style="padding: 20px 0 10px;" >
<fieldset>
<legend>
作业文件上传
</legend>
<p id="put-bid-form-partial">
<%= render :partial => 'attachments/form' %>
</p>
</fieldset>
</div>
<%= submit_tag l(:button_create), :onclick => "return true" %>
<% end %>
<% end %>
<% end %>

View File

@ -58,6 +58,9 @@
.hidden { .hidden {
display: none; display: none;
} }
.font_color_orange{
color: #E8770D;
}
* { * {
font-family: Helvetica, Tahoma, Arial, "Microsoft YaHei", "微软雅黑", SimSun, "宋体", STXihei, "华文细黑", Heiti, "黑体", sans-serif; font-family: Helvetica, Tahoma, Arial, "Microsoft YaHei", "微软雅黑", SimSun, "宋体", STXihei, "华文细黑", Heiti, "黑体", sans-serif;