diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index fa73e42..63237c4 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -31,4 +31,7 @@ $ -> $(this).closest('form').submit() return false + $('select.autosubmit').change -> + $(this).closest('form').submit() + $('#notification').delay(3000).fadeOut() \ No newline at end of file diff --git a/app/models/match.rb b/app/models/match.rb index 8e453d3..93c3c59 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -294,8 +294,12 @@ class Match < ActiveRecord::Base def can_update? cuser, params = {} return false unless cuser return true if cuser.admin? - return true if cuser.caster? and Verification.contain params, [:caster_id] - return true if cuser.ref? and !referee and Verification.contain params, [:referee_id] + return true if cuser.caster? and Verification.contain params, [:caster_id] \ + and (params[:caster_id] && params[:caster_id].to_i == cuser.id && caster_id.blank?) \ + or (params[:caster_id].blank? && caster_id == cuser.id) + return true if cuser.ref? and Verification.contain params, [:referee_id] \ + and (params[:referee_id] && params[:referee_id].to_i == cuser.id && referee_id.blank?) \ + or (params[:referee_id].blank? && referee_id == cuser.id) return true if cuser.ref? and referee == cuser \ and Verification.contain params, [:score1, :score2, :forfeit, :report, :demo_id, :motm_name, :matchers_attributes, :server_id] return true if match_time.past? and !score1 and !score2 and !forfeit \ diff --git a/app/models/user.rb b/app/models/user.rb index 1f06540..bd284d8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -194,7 +194,7 @@ class User < ActiveRecord::Base end def caster? - group.exists? :id => Group::CASTERS + groups.exists? :id => Group::CASTERS end def verified? @@ -286,4 +286,12 @@ class User < ActiveRecord::Base def self.search(search) search ? where("LOWER(username) LIKE LOWER(?) OR steamid LIKE ?", "%#{search}%", "%#{search}%") : scoped end + + def self.refadmins + Group.find(Group::REFEREES).users.order(:username) + Group.find(Group::ADMINS).users.order(:username) + end + + def self.casters + Group.find(Group::CASTERS).users.order(:username) + end end diff --git a/app/views/matches/admin.html.haml b/app/views/matches/admin.html.haml index 66dfd63..a0e589e 100644 --- a/app/views/matches/admin.html.haml +++ b/app/views/matches/admin.html.haml @@ -25,18 +25,34 @@ \- #{h match.score2} %td - if match.caster - = namelink match.caster - - elsif match.can_update?(cuser, {:caster_id => 1}) = form_for match do |f| - = f.hidden_field :caster_id, {:value => cuser.id} - = link_to "Take!", "#form_submit" + = f.hidden_field :caster_id, {:value => nil} + = namelink match.caster + - if match.can_update?(cuser, {:caster_id => nil}) + = link_to "#form_submit" do + %i.fa.fa-times + - elsif match.can_update?(cuser, {:caster_id => cuser.id}) + = form_for match do |f| + - if cuser.admin? + = f.collection_select :caster_id, Group.casters, :id, :username, {:include_blank => true}, {:class => "autosubmit"} + - else + = f.hidden_field :caster_id, {:value => cuser.id} + = link_to "Take!", "#form_submit" %td - if match.referee - = namelink match.referee - - elsif match.can_update?(cuser, {:referee_id => 1}) = form_for match do |f| - = f.hidden_field :referee_id, {:value => cuser.id} - = link_to "Take!", "#form_submit" + = f.hidden_field :referee_id, {:value => nil} + = namelink match.referee + - if match.can_update?(cuser, {:referee_id => nil}) + = link_to "#form_submit" do + %i.fa.fa-times + - elsif match.can_update?(cuser, {:referee_id => cuser.id}) + = form_for match do |f| + - if cuser.admin? + = f.collection_select :referee_id, User.refadmins, :id, :username, {:include_blank => true}, {:class => "autosubmit"} + - else + = f.hidden_field :referee_id, {:value => cuser.id} + = link_to "Take!", "#form_submit" %td.actions - if cuser.ref? || cuser.admin? - = link_to "Admin", match_ref_path(match) \ No newline at end of file + = link_to "Admin", "/matches/ref/#{match.id}" \ No newline at end of file