mirror of
https://github.com/ENSL/ensl.org.git
synced 2025-01-13 21:31:28 +00:00
Improving and fixing status updating via ajax request, prevent creation of new proposals when there is a confirmed one (not tested yet)
This commit is contained in:
parent
62bc78274a
commit
52e0d9ad71
2 changed files with 9 additions and 5 deletions
|
@ -5,6 +5,11 @@ class MatchProposalsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
mp = MatchProposal.confirmed_for_match(@match).first
|
||||||
|
if mp
|
||||||
|
flash[:danger] = 'Cannot create a new proposal aslong as there already is a confirmed one'
|
||||||
|
redirect_to(match_proposals_path(@match)) && return
|
||||||
|
end
|
||||||
@proposal = MatchProposal.new
|
@proposal = MatchProposal.new
|
||||||
@proposal.match = @match
|
@proposal.match = @match
|
||||||
raise AccessError unless @proposal.can_create? cuser
|
raise AccessError unless @proposal.can_create? cuser
|
||||||
|
@ -47,7 +52,7 @@ class MatchProposalsController < ApplicationController
|
||||||
if proposal.save
|
if proposal.save
|
||||||
rjson[:status] = MatchProposal.status_strings[proposal.status]
|
rjson[:status] = MatchProposal.status_strings[proposal.status]
|
||||||
rjson[:message] = "Successfully updated status to #{MatchProposal.status_strings[proposal.status]}"
|
rjson[:message] = "Successfully updated status to #{MatchProposal.status_strings[proposal.status]}"
|
||||||
render(json: rjson, status: :success)
|
render(json: rjson, status: :accepted)
|
||||||
else
|
else
|
||||||
rjson[:error] = {
|
rjson[:error] = {
|
||||||
code: 500,
|
code: 500,
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
<%= f.hidden_field :status, value: 0 %>
|
<%= f.hidden_field :status, value: 0 %>
|
||||||
<%= link_to_function icon('check'), "proposalStateSubmit(#{MatchProposal::STATUS_CONFIRMED},#{proposal.id})", title: 'Confirm' %>
|
<%= link_to_function icon('check'), "proposalStateSubmit(#{MatchProposal::STATUS_CONFIRMED},#{proposal.id})", title: 'Confirm' %>
|
||||||
<%= link_to_function icon('times'), "proposalStateSubmit(#{MatchProposal::STATUS_REJECTED},#{proposal.id})", title: 'Reject' %>
|
<%= link_to_function icon('times'), "proposalStateSubmit(#{MatchProposal::STATUS_REJECTED},#{proposal.id})", title: 'Reject' %>
|
||||||
<%= link_to_function icon('eraser'), "proposalStateSubmit(#{MatchProposal::STATUS_REVOKED},#{proposal.id})", title: 'Revoke' %>
|
<%= link_to_function icon('undo'), "proposalStateSubmit(#{MatchProposal::STATUS_REVOKED},#{proposal.id})", title: 'Revoke' %>
|
||||||
<% if proposal.status_change_allowed?(cuser, MatchProposal::STATUS_DELAYED) %>
|
<% if proposal.status_change_allowed?(cuser, MatchProposal::STATUS_DELAYED) %>
|
||||||
<%= link_to_function icon('hourglass'), "proposalStateSubmit(#{MatchProposal::STATUS_DELAYED},#{proposal.id})", title: 'Delay' %>
|
<%= link_to_function icon('hourglass'), "proposalStateSubmit(#{MatchProposal::STATUS_DELAYED},#{proposal.id})", title: 'Delay' %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -41,10 +41,9 @@
|
||||||
var form = $('#edit_match_proposal_' + formID);
|
var form = $('#edit_match_proposal_' + formID);
|
||||||
form.children("input[type='hidden']").val(newState);
|
form.children("input[type='hidden']").val(newState);
|
||||||
$.post(form.attr('action'),form.serialize(), function(data) {
|
$.post(form.attr('action'),form.serialize(), function(data) {
|
||||||
datajson = data.responseText;
|
|
||||||
tr = form.closest('tr');
|
tr = form.closest('tr');
|
||||||
tr.children('td').eq(1).html(datajson.status);
|
tr.children('td').eq(2).text(data.status);
|
||||||
alert(datajson.message);
|
if(data.status === 'Revoked' || data.status === 'Rejected') tr.children('td').eq(3).empty();
|
||||||
}, 'json')
|
}, 'json')
|
||||||
.error(function (err) {
|
.error(function (err) {
|
||||||
errjson = JSON.parse(err.responseText);
|
errjson = JSON.parse(err.responseText);
|
||||||
|
|
Loading…
Reference in a new issue