修改作业界面、功能修改以及增加js验证

This commit is contained in:
sw 2014-10-09 10:10:40 +08:00
parent 0a0a5d6714
commit f83668bf73
4 changed files with 98 additions and 36 deletions

View File

@ -839,8 +839,18 @@ class BidsController < ApplicationController
def update
@bid = Bid.find(params[:id])
@course = @bid.courses.first#Project.find(params[:course_id])
@bid.name = params[:bid][:name]
@bid.description = params[:bid][:description]
@bid.is_evaluation = params[:bid][:is_evaluation]
@bid.proportion = params[:bid][:proportion]
@bid.reward_type = 3
@bid.deadline = params[:bid][:deadline]
@bid.budget = 0
@bid.author_id = User.current.id
@bid.commit = 0
@bid.homework_type = 1
@bid.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
if @bid.update_attributes(params[:bid]) && @bid.save
if @bid.save
flash[:notice] = l(:label_update_homework_succeed)
redirect_to course_homework_path(@course)
else

View File

@ -1,44 +1,45 @@
<!-- fq -->
<script type="text/javascript" language="javascript">
function show(id, id_t, label_reward, label_money, label_credit, label_content) {
var text = $('#' + id);
var text_t = $('#' + id_t);
if (text.val() == 0) {
text_t.attr("placeholder", label_reward);
}
if (text.val() == 1) {
text_t.attr("placeholder", label_money);
}
if (text.val() == 3) {
text_t.attr("placeholder", label_credit);
}
if (text.val() == 2) {
text_t.attr("placeholder", label_content);
}
return content;
}
function show(id, id_t, label_reward, label_money, label_credit, label_content) {
var text = $('#' + id);
var text_t = $('#' + id_t);
if (text.val() == 0) {
text_t.attr("placeholder", label_reward);
}
if (text.val() == 1) {
text_t.attr("placeholder", label_money);
}
if (text.val() == 3) {
text_t.attr("placeholder", label_credit);
}
if (text.val() == 2) {
text_t.attr("placeholder", label_content);
}
return content;
}
</script>
<%= error_messages_for 'bid' %>
<!--[form:project]-->
<p><%= l(:label_homeworks_form_new_description) %></p>
<p><%= f.text_field :name, :required => true, :size => 60, :style => "width:490px;", :maxlength => Bid::NAME_LENGTH_LIMIT %></p>
<p>
<%= f.text_field :name, :required => true, :size => 60, :style => "width:490px;", :maxlength => Bid::NAME_LENGTH_LIMIT, :onblur => "regexName();" %>
<p style="margin-left:-10px;padding-right: 20px;"><%= f.text_area :description, :rows => 8, :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;", :maxlength => Bid::DESCRIPTION_LENGTH_LIMIT %></p>
<!-- <p><%#= select_tag 'bid_reward_type', "<option value = '0'>#{l(:label_choose_reward)}</option><option value = '1'>#{l(:label_money)}</option><option value = '3'>#{l(:label_bids_credit)}</option><option value = '2'>#{l(:label_reward_1)}</option>".html_safe,
:onChange => "show('bid_reward_type', 'bid_budget', '"+l(:label_bids_reward_what)+"','"+l(:label_bids_new_money)+"','"+l(:label_bids_new_credit)+"','"+l(:label_bids_new_content)+"')" %>
<%#= f.text_field :budget, :required => true, :size => 60, :style => "width:350px;", :placeholder => l(:label_bids_reward_what) %>
</p> -->
<p><%= f.text_field :deadline, :required => true, :size => 60, :style => "width:150px;" %><%= calendar_for('bid_deadline')%>
</p>
<!--
<p><%#= f.select :homework_type, homework_type_option %>
<p><span id="bid_name_span"></span></p>
<p><%= f.text_area :description, :rows => 8, :class => 'wiki-edit', :style => "font-size:small;width:490px;", :maxlength => Bid::DESCRIPTION_LENGTH_LIMIT %></p>
<p><%= f.text_field(:deadline, :required => true, :size => 60, :style => "width:150px;", :onchange => "regexDeadLine();") %>
<%= calendar_for('bid_deadline')%>
<span id="bid_deadline_span">
</span>
</p>
-->
<p><%= f.select :is_evaluation, is_evaluation_option %>
<p><%= hidden_field_tag 'course_id', @project_id %>
</p>
<p><%= f.select :proportion, proportion_option %>
</p>
<p><%= hidden_field_tag 'course_id', @course.id %>
</p>
<fieldset><legend><%= l(:label_attachment_plural) %></legend>
<div class="tabDiv"><%= render :partial => 'attachments/form', :locals => {:container => @bid} %></div>
<p><%= render :partial => 'attachments/form', :locals => {:container => @homework} %></p>
</fieldset>

View File

@ -1,9 +1,60 @@
<script type="text/javascript">
function regexName()
{
var name = $("#bid_name").val();
if(name=="")
{
$("#bid_name_span").text("名称不能为空");
$("#bid_name_span").css('color','#ff0000');
return false;
}
else
{
$("#bid_name_span").text("填写正确");
$("#bid_name_span").css('color','#008000');
return true;
}
}
function regexDeadLine()
{
var deadline = $("#bid_deadline").val();
var regex = /^\d{4}-\d{2}-\d{2}$/;
if(deadline=="")
{
$("#bid_deadline_span").text("截止日期不能为空");
$("#bid_deadline_span").css('color','#ff0000');
return false;
}
else if(regex.test(deadline))
{
$("#bid_deadline_span").text("填写正确");
$("#bid_deadline_span").css('color','#008000');
return true;
}
else
{
$("#bid_deadline_span").text("截止日期格式错误");
$("#bid_deadline_span").css('color','#ff0000');
return false;
}
}
function submitHomework(id)
{
if(regexDeadLine()&&regexName())
{
$("#edit_bid_" + id).submit();
}
}
</script>
<h3><%= l(:label_edit_homework) %></h3>
<%= labelled_form_for @bid do |f| %>
<div class="box tabular">
<%= render :partial => 'homework_form', :locals => { :f => f } %>
<%= submit_tag l(:button_create) %>
<%= javascript_tag "$('#bid_name').focus();" %>
<%#= render :partial => 'homework_form', :locals => { :f => f } %>
<%= render :partial => 'homework_form', :locals => { :f => f } %>
<input type="button" onclick="submitHomework(<%= @bid.id%>);" value="<%= l(:button_create)%>" class="enterprise">
<% end %>
</div>

View File

@ -34,9 +34,9 @@
<%#= f.text_field :budget, :required => true, :size => 60, :style => "width:350px;", :placeholder => l(:label_bids_reward_what) %>
</p> -->
<% time = (Time.now + 3600 * 24).strftime('%Y-%m-%d') %>
<p><%= f.text_field(:deadline, :required => true, :size => 60, :style => "width:150px;",:value => "#{time}", :onchange => "regexDeadLine();") %><%= calendar_for('bid_deadline')%>
<p><%= f.text_field(:deadline, :required => true, :size => 60, :style => "width:150px;",:value => "#{time}", :onchange => "regexDeadLine();") %>
<%= calendar_for('bid_deadline')%>
<span id="bid_deadline_span">
</span>
</p>
<p><%= f.select :is_evaluation, is_evaluation_option %>