列表上提交作业,大概好了吧

This commit is contained in:
yanxd 2014-04-09 11:06:13 +08:00
parent 3fad5abb5c
commit 1b6cdeac05
12 changed files with 164 additions and 88 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -14,9 +14,7 @@
<span><%= link_to(bid.name, respond_path(bid), :class => 'bid_path') %></span>
<span style="float: right">
<%# 提交作业按钮,上传文件的作业直接显示上传框,关联项目的作业跳转到新页面 %>
<%= 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),
@ -64,11 +62,6 @@
<tr>
<td colspan="2" width="580px" ><span class="font_description"><%= bid.description %></span></td>
</tr>
<tr><%# 提交作业partial %>
<td class="hidden" id="bid-submit-homework-<%=bid.id%>" >
<%= render partial: 'homeworkupload', locals: {bid: bid} %>
</td>
</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></td>

View File

@ -0,0 +1,3 @@
$('#OpenWindow-content').html(' <%=
j(render partial: "projects/homeworkupload", locals: {bid: @bid})
%>');

View File

@ -1,4 +1,5 @@
<!--add by huang-->
<div class="clearfix"></div>
<div id="footer" style="margin-left:-5px;padding-top: 50px;clear: both;">
<div style="border-top:solid 1px #C6E9F1;width:940px;margin-left:auto;margin-right:auto;margin-bottom: 5px;margin-top: -10px;"></div>
<div class="base_footer"><div align="center">

View File

@ -1,22 +1,23 @@
<div style='width:100%;'>
<% 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 %>
<div style='width:150px; margin:10px auto;'>
<span class="font_color_orange" > 作业已经提交 </span>
<%= link_to "查看详情", project_for_bid_path(bid) %>
</div>
<% end %>
<% end %>
<% elsif bid.reward_type==Bid::Homework &&
bid.homework_type==Bid::HomeworkFile %>
<%= render partial: 'projects/homeworkupload_homeworkfile', locals: {bid: bid} %>
<% elsif bid.reward_type==Bid::Homework &&
bid.homework_type==Bid::HomeworkProject %>
<%= render partial: 'projects/homeworkupload_homeworkproject', locals: {bid: bid} %>
<% else %>
<div style='width:150px; margin:10px auto;'>
<span class="font_color_orange" > Unkown Error </span>
<%= link_to "我要反馈" , suggestion_send_path, target: '_blank' %>
</div>
<% end -%>
</div>

View File

@ -0,0 +1,17 @@
<%= form_for HomeworkAttach.new,
:url => {:controller => 'bids', :action => 'add_homework', id: bid.id, back_url: homework_project_path(bid.try(:courses).try(:first)) },
: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 %>

View File

@ -0,0 +1,41 @@
<%
membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
option = []
membership.each do |member|
unless(member.project.project_type==1)
member.member_roles.each{|role|
if(role.role_id == 3)
option << member.project
end
}
end
end
%>
<div id="put-bid-form">
<%= form_for "bid_for_save",
:url => {:controller => 'bids', :action => 'add'},
:update => "bidding_project_list" do |f| %>
<table id="bidding_table" border="0" width="100%">
<tr>
<td>
<%= select_tag 'bid', options_for_select(select_option_helper(option)), :name => 'bid', :class => 'grayline', style:'width:83%;' %>
<div class="font_lighter" style="display:inline-block;font-size: 13px;">
<%= link_to '创建项目', new_project_path(course: 0, project_type: 0), :target=>'_blank'%>
</div>
</td>
</tr>
<tr>
<td><%= f.text_area :bid_message, :id => "bid_message", :required => true, :rows => 4, :cols => 40, :placeholder => l(:label_bid_reason_homework), :style => "resize: none;", :class => 'noline'%></td>
</tr>
<tr>
<td align="right">
<%= submit_tag l(:label_commit_homework), :name => nil , :class => "enterprise"%>
</td>
</tr>
</table>
<% end %>
</div>

View File

@ -1,3 +1,9 @@
<style type="text/css">
#attachments_fields input.description {
width: auto;
}
</style>
<%= javascript_include_tag 'attachments' %>
<!-- fq -->
<!--modified by huang-->
<div class="content-title-top">
@ -9,46 +15,45 @@
<%= render :partial => 'bids/bid_homework_show', :locals => {:bids => @bids, :bid_pages => @bid_pages} %>
</div>
<a href="#OpenWindow" rel='leanModal'> 打开窗口 </a>
<div id="OpenWindow">
<div id="signup-ct">
<div id="OpenWindow-header">
<h2> 上传作业 </h2>
<p>
It's simple, and free.</p>
<a href="#" class="modal_close"></a>
</div>
<form action="">
<div class="txt-fld">
<label for="">
Username</label>
<input type="text" name="" class="good_input" id="" />
</div>
<div class="txt-fld">
<label for="">
Email address</label>
<input type="text" name="" id="" />
</div>
<div class="txt-fld">
<label for="">
Password</label>
<input type="text" name="" id="" />
</div>
<div class="btn-fld">
<button type="submit">
Sign Up »</button>
</div>
</form>
<div id="OpenWindow">
<div id="signup-ct">
<div id="OpenWindow-header">
<h1> 课程: <%= @project.name%> </h1>
<p id='bid-desc'> 上传作业 </p>
<a href="javascript:void(0);" class="modal_close"></a>
</div>
<div id="OpenWindow-content">
</div>
</div>
</div>
<script type="text/javascript">
$("a[rel*=leanModal]").leanModal({
top:100,
closeButton: ".modal_close"
});
function showSubH(id){
console.log(id);
function showSubH(/* ... */){
var id, name, numargs = arguments.length;
id = arguments[0];
name = arguments[1];
$("#OpenWindow").find("#bid-desc").html('作业名: '+name);
post_url = '/bids/' + id + '/homework_ajax_modal.js'
function deal_post (data, textStatus, xhr) {
if(textStatus == 'success'){
eval(data);
}
if(textStatus != 'success'){
$('#OpenWindow-content').html('<span class=\"font_color_orange\" > ' + textStatus + ' <\/span>\n');
}
}
function deal_error (argument) {
$('#OpenWindow-content').html('<span class=\"font_color_orange\" > ' + argument.status + argument.statusText + ' <\/span>\n');
}
$.post(post_url,{}, deal_post).error(deal_error);
}
</script>

View File

@ -171,7 +171,11 @@ RedmineApp::Application.routes.draw do
post 'issues/:object_id/watchers', :to => 'watchers#create', :object_type => 'issue'
delete 'issues/:object_id/watchers/:user_id' => 'watchers#destroy', :object_type => 'issue'
resources :bids, :only=>[:edit,:update,:show]
resources :bids, :only=>[:edit,:update,:show] do
member do
match 'homework_ajax_modal'
end
end
resources :projects do
member do
post 'finishcourse'

View File

@ -79,20 +79,7 @@
background: #000;
display: none;
}
#OpenWindow{
background: none repeat scroll 0 0 #ffffff;
border-radius: 5px;
box-shadow: 0 0 4px rgba(0,0,0,0.7);
display: none;
padding-bottom: 2px;
width: 404px;
z-index: 11000;
left: 50%;
margin-left: -202px;
opacity: 1;
position: fixed;
top: 200px;
}
#OpenWindow {
background: none repeat scroll 0 0 #FFFFFF;
border-radius: 5px 5px 5px 5px;
@ -100,7 +87,7 @@
display: none;
padding-bottom: 2px;
width: 404px;
z-index: 11000;
z-index: 100;
left: 50%;
margin-left: -202px;
opacity: 1;
@ -114,6 +101,16 @@
border-top-right-radius: 5px;
padding: 18px 18px 14px;
}
#OpenWindow-content{
-webkit-transition: all 0.2s linear 1s;
-o-transition: all 0.2s linear 1s;
-moz-transition: all 0.2s linear 1s;
transition: all 0.2s linear 1s;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
padding: 18px 18px 14px;
}
.modal_close {
background: url("/images/showmodal/modal_close.png") repeat scroll 0 0 transparent;
display: block;