diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index 719195cb3..debda938f 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -5,7 +5,7 @@ class ContestsController < ApplicationController menu_item :project, :only => :show_project menu_item :application, :only => :show_softapplication menu_item :attendingcontest, :only => :show_attendingcontest - before_filter :find_contest, :only => [:show_contest, :show_project, :show_softapplication, :show_attendingcontest, :create,:destroy,:more,:back,:add,:add_softapplication,:new,:show_results, :set_reward, + before_filter :find_contest, :only => [:show_contest, :show_project, :show_softapplication, :show_attendingcontest, :set_reward_project, :set_reward_softapplication, :create,:destroy,:more,:back,:add,:add_softapplication,:new,:show_results, :set_reward, :show_contest_project, :show_contest_user, :join_in_contest, :unjoin_in_contest, :new_join,:show_participator, :settings] # added by fq @@ -355,6 +355,44 @@ class ContestsController < ApplicationController end ###end + + def set_reward_project + @c_p = nil + @contesting_project_id = nil + + if params[:set_reward_project][:reward]&&((User.current.id==@contest.author_id)||User.current.admin) + # @bid_id = params[:id] + @contesting_project_id = params[:set_reward_project][:c_id] + @c_p = ContestingProject.find_by_id(@contesting_project_id) + + # 把字段存进表中 + @c_p.update_reward(params[:set_reward_project][:reward].to_s) + end + + respond_to do |format| + format.js + end + end + + def set_reward_softapplication + @c_sa = nil + @contesting_softapplication_id = nil + + if params[:set_reward_softapplication][:reward]&&((User.current.id==@contest.author_id)||User.current.admin) + # @bid_id = params[:id] + @contesting_softapplication_id = params[:set_reward_softapplication][:c_id] + @c_sa = ContestingSoftapplication.find_by_id(@contesting_softapplication_id) + + # 把字段存进表中 + @c_sa.update_reward(params[:set_reward_softapplication][:reward].to_s) + end + + respond_to do |format| + format.js + end + end + + ###添加已创建的参赛项目 def add project = Project.find(params[:contest]) diff --git a/app/helpers/contests_helper.rb b/app/helpers/contests_helper.rb index 36f2351cb..fff2f785a 100644 --- a/app/helpers/contests_helper.rb +++ b/app/helpers/contests_helper.rb @@ -91,6 +91,10 @@ module ContestsHelper def get_prize(c_project) c_project.get_reward end + + def get_prize(c_softapplication) + c_softapplication.get_reward + end def count_contest_project contests = Contest.find(:id) diff --git a/app/models/contesting_softapplication.rb b/app/models/contesting_softapplication.rb index 37ba198b8..f880818d9 100644 --- a/app/models/contesting_softapplication.rb +++ b/app/models/contesting_softapplication.rb @@ -16,5 +16,13 @@ class ContestingSoftapplication < ActiveRecord::Base self.create(:user_id => User.current.id, :contest_id => contest_id, :softapplication_id => softapplication_id) end + + def update_reward(which) + self.update_attribute(:reward,which) + end + + def get_reward + self.reward + end end diff --git a/app/views/contests/set_reward.js.erb b/app/views/contests/set_reward_project.js.erb similarity index 87% rename from app/views/contests/set_reward.js.erb rename to app/views/contests/set_reward_project.js.erb index d6d8c4f9f..c0de3e2ef 100644 --- a/app/views/contests/set_reward.js.erb +++ b/app/views/contests/set_reward_project.js.erb @@ -1,15 +1,14 @@ $('#reward_result_<%= @contesting_project_id %>').html('<%= j( -if get_prize(@b_p).nil? or get_prize(@b_p) == "" +if get_prize(@c_p).nil? or get_prize(@c_p) == "" if @contest.deadline < Date.today puts '未评奖' end else - case get_prize(@b_p) + case get_prize(@c_p) when '-1' image_tag("/images/bid/special_reward.png") - when '1' when '0' image_tag("/images/bid/first_reward.png") when '1' @@ -22,7 +21,7 @@ else image_tag("/images/bid/fifth_reward.png") when '5' image_tag("/images/bid/qualified.png") - end + end end ) diff --git a/app/views/contests/set_reward_softapplication.js.erb b/app/views/contests/set_reward_softapplication.js.erb new file mode 100644 index 000000000..a8cf0d486 --- /dev/null +++ b/app/views/contests/set_reward_softapplication.js.erb @@ -0,0 +1,30 @@ +$('#reward_result_<%= @contesting_softapplication_id %>').html('<%= j( + +if get_prize(@c_sa).nil? or get_prize(@c_sa) == "" + if @contest.deadline < Date.today + puts '未评奖' + end +else + + case get_prize(@c_sa) + when '-1' + image_tag("/images/bid/special_reward.png") + when '0' + image_tag("/images/bid/first_reward.png") + when '1' + image_tag("/images/bid/second_reward.png") + when '2' + image_tag("/images/bid/third_reward.png") + when '3' + image_tag("/images/bid/forth_reward.png") + when '4' + image_tag("/images/bid/fifth_reward.png") + when '5' + image_tag("/images/bid/qualified.png") + end + +end +) +%>') + +$('#<%= @contesting_softapplication_id %>').hide() diff --git a/app/views/contests/show_attendingcontest.html.erb b/app/views/contests/show_attendingcontest.html.erb index 5aff8d1e0..c556a6e59 100644 --- a/app/views/contests/show_attendingcontest.html.erb +++ b/app/views/contests/show_attendingcontest.html.erb @@ -193,6 +193,61 @@ +
+ + + + + <% if get_prize(c_project).nil? or get_prize(c_project) == "" %> + <% if @contest.deadline < Date.today %> + <%= l(:label_noawards)%> + <% end %> + <% else %> + <% case get_prize(c_project) %> + <% when '-1' %> + <%= image_tag("/images/bid/special_reward.png")%> + <% when '0' %> + <%= image_tag("/images/bid/first_reward.png")%> + <% when '1' %> + <%= image_tag("/images/bid/second_reward.png")%> + <% when '2' %> + <%= image_tag("/images/bid/third_reward.png")%> + <% when '3' %> + <%= image_tag("/images/bid/forth_reward.png")%> + <% when '4' %> + <%= image_tag("/images/bid/fifth_reward.png")%> + <% when '5' %> + <%= image_tag("/images/bid/qualified.png")%> + <% end %> + <% end %> + + + + + + <% if ((User.current.id == @contest.author_id) && (@contest.deadline > Date.today))||User.current.admin %> + + <%= toggle_link '评价', c_project.id.to_s %> + + + + <% end %> + + + +
<% end %>
@@ -219,6 +274,62 @@ + +
+ + + + + <% if get_prize(c_softapplication).nil? or get_prize(c_softapplication) == "" %> + <% if @contest.deadline < Date.today %> + <%= l(:label_noawards)%> + <% end %> + <% else %> + <% case get_prize(c_softapplication) %> + <% when '-1' %> + <%= image_tag("/images/bid/special_reward.png")%> + <% when '0' %> + <%= image_tag("/images/bid/first_reward.png")%> + <% when '1' %> + <%= image_tag("/images/bid/second_reward.png")%> + <% when '2' %> + <%= image_tag("/images/bid/third_reward.png")%> + <% when '3' %> + <%= image_tag("/images/bid/forth_reward.png")%> + <% when '4' %> + <%= image_tag("/images/bid/fifth_reward.png")%> + <% when '5' %> + <%= image_tag("/images/bid/qualified.png")%> + <% end %> + <% end %> + + + + + + <% if ((User.current.id == @contest.author_id) && (@contest.deadline > Date.today))||User.current.admin %> + + <%= toggle_link '评价', c_softapplication.id.to_s %> + + + + <% end %> + + + +
<% end %>
diff --git a/config/routes.rb b/config/routes.rb index 62d773077..a858b204a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -67,16 +67,18 @@ RedmineApp::Application.routes.draw do end member do match 'add_softapplication' - match 'update_contest' , via: [:put] - match 'show_contest' , via: :get - match 'show_project' , via: :get - match 'show_softapplication' , via: :get - match 'show_attendingcontest' , via: :get - match 'show_participator' , via: :get - match 'add' , via: [:get, :post] - match 'add_softapplication' , via: [:get, :post] - match 'create' , via: :post - match 'settings' , via: [:get, :post] + match 'update_contest' , via: [:put] + match 'show_contest' , via: :get + match 'show_project' , via: :get + match 'show_softapplication' , via: :get + match 'show_attendingcontest' , via: :get + match 'show_participator' , via: :get + match 'set_reward_project' , via: [:get, :post] + match 'set_reward_softapplication' , via: [:get, :post] + match 'add' , via: [:get, :post] + match 'add_softapplication' , via: [:get, :post] + match 'create' , via: :post + match 'settings' , via: [:get, :post] end end