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:
Absurdon 2017-10-07 14:02:14 +02:00
parent 62bc78274a
commit 52e0d9ad71
2 changed files with 9 additions and 5 deletions

View file

@ -5,6 +5,11 @@ class MatchProposalsController < ApplicationController
end
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.match = @match
raise AccessError unless @proposal.can_create? cuser
@ -47,7 +52,7 @@ class MatchProposalsController < ApplicationController
if proposal.save
rjson[:status] = 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
rjson[:error] = {
code: 500,

View file

@ -25,7 +25,7 @@
<%= f.hidden_field :status, value: 0 %>
<%= 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('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) %>
<%= link_to_function icon('hourglass'), "proposalStateSubmit(#{MatchProposal::STATUS_DELAYED},#{proposal.id})", title: 'Delay' %>
<% end %>
@ -41,10 +41,9 @@
var form = $('#edit_match_proposal_' + formID);
form.children("input[type='hidden']").val(newState);
$.post(form.attr('action'),form.serialize(), function(data) {
datajson = data.responseText;
tr = form.closest('tr');
tr.children('td').eq(1).html(datajson.status);
alert(datajson.message);
tr.children('td').eq(2).text(data.status);
if(data.status === 'Revoked' || data.status === 'Rejected') tr.children('td').eq(3).empty();
}, 'json')
.error(function (err) {
errjson = JSON.parse(err.responseText);