From 52e0d9ad7185ceff0a5af033bdd464b7843647ed Mon Sep 17 00:00:00 2001 From: Absurdon Date: Sat, 7 Oct 2017 14:02:14 +0200 Subject: [PATCH] Improving and fixing status updating via ajax request, prevent creation of new proposals when there is a confirmed one (not tested yet) --- app/controllers/match_proposals_controller.rb | 7 ++++++- app/views/match_proposals/index.html.erb | 7 +++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/controllers/match_proposals_controller.rb b/app/controllers/match_proposals_controller.rb index ae042db..6e8f9cf 100644 --- a/app/controllers/match_proposals_controller.rb +++ b/app/controllers/match_proposals_controller.rb @@ -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, diff --git a/app/views/match_proposals/index.html.erb b/app/views/match_proposals/index.html.erb index d000b2f..6adadad 100644 --- a/app/views/match_proposals/index.html.erb +++ b/app/views/match_proposals/index.html.erb @@ -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);