From 42a1a9e0b9a3b68d8209e9b76bfbe580b47823ab Mon Sep 17 00:00:00 2001
From: wanglinchun
Date: Fri, 17 Jan 2014 16:42:31 +0800
Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=A4=8D=E6=8F=90=E4=BA=A4=E9=97=AE?=
=?UTF-8?q?=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controllers/bids_controller.rb | 42 ++++++++++++++++++------------
app/helpers/application_helper.rb | 10 +++++++
app/helpers/attachments_helper.rb | 9 +++++++
app/views/bids/_homework.html.erb | 4 +--
config/locales/zh.yml | 1 +
5 files changed, 47 insertions(+), 19 deletions(-)
diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb
index cc6ea91dd..32878a2cd 100644
--- a/app/controllers/bids_controller.rb
+++ b/app/controllers/bids_controller.rb
@@ -17,6 +17,7 @@ class BidsController < ApplicationController
helper :watchers
helper :attachments
include AttachmentsHelper
+ include ApplicationHelper
helper :projects
helper :words
def index
@@ -723,24 +724,33 @@ class BidsController < ApplicationController
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)
# homework = HomeworkAttach.create(:bid_id => @bid.id, :user_id => User.current.id)
# homework.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
- @homework = HomeworkAttach.new
- @homework.safe_attributes = params[:homeworkattach]
- @homework.bid_id = @bid.id
- @homework.user_id = User.current.id
- @homework.save_attachments(params[:attachments])
- render_attachment_warning_if_needed(@homework)
- if @homework.save
- @homework_flag = l(:label_bidding_homework_succeed)
+
+ if hadcommittedhomework(User.current.id, @bid.id) == true
+ @homework_flag = l(:label_bidding_homework_committed)
else
- @homework_flag = l(:label_bidding_homework_failed)
- end
- if @homework.attachments.empty?
- @homework.delete
- flash[:error] = l(:no_attachmens_allowed)
- @homework_flag = l(:no_attachmens_allowed)
- # else
- end
+ @homework = HomeworkAttach.new
+ @homework.safe_attributes = params[:homeworkattach]
+ @homework.bid_id = @bid.id
+ @homework.user_id = User.current.id
+ @homework.save_attachments(params[:attachments])
+
+ render_attachment_warning_if_needed(@homework)
+
+ if @homework.save
+ @homework_flag = l(:label_bidding_homework_succeed)
+ else
+ @homework_flag = l(:label_bidding_homework_failed)
+ end
+
+ if @homework.attachments.empty?
+ @homework.delete
+ #flash[:error] = l(:no_attachmens_allowed)
+ @homework_flag = l(:no_attachmens_allowed)
+ # else
+ end
+ end
end
+
@homework_list = @bid.homeworks
respond_to do |format|
format.html{
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 97e76a0c9..28df9a281 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1489,4 +1489,14 @@ module ApplicationHelper
obj2 = obj1
end
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
+ return true
+ end
+ end
+ end
+
end
diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb
index 0ba0f3554..421860860 100644
--- a/app/helpers/attachments_helper.rb
+++ b/app/helpers/attachments_helper.rb
@@ -69,5 +69,14 @@ module AttachmentsHelper
def deletable? container, user=User.current
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
end
diff --git a/app/views/bids/_homework.html.erb b/app/views/bids/_homework.html.erb
index 5094d0c0a..eb6b9bbf5 100644
--- a/app/views/bids/_homework.html.erb
+++ b/app/views/bids/_homework.html.erb
@@ -9,9 +9,7 @@
<%= render :partial => 'attachments/form' %>
- <%= submit_tag l(:button_create),
- :onclick => "return true;"
- %>
+ <%= submit_tag l(:button_create), :onclick => "return true" %>
<% end %>