Added submit function and processing

This commit is contained in:
Absurdon 2017-06-11 16:36:10 +02:00
parent c4fa4bd188
commit 29a6a83887
2 changed files with 22 additions and 3 deletions

View file

@ -16,15 +16,32 @@ class MatchProposalsController < ApplicationController
@proposal.team = cuser.team
@proposal.status = MatchProposal::STATUS_PENDING
if @proposal.save!
if @proposal.save
flash[:notice] = 'Created new proposal'
redirect_to(@match)
redirect_to(match_proposals_path(@match))
else
render :new
end
end
def update
raise AccessError unless @match.can_make_proposal?(cuser)
@proposal = MatchProposal.find(params[:id])
@proposal.status = params[:match_proposal][:status]
if @proposal.save
action = case @proposal.status
when MatchProposal::STATUS_CONFIRMED
"Confirmed Proposal for #{Time.use_zone(view_context.timezone_offset) { @proposal.proposed_time.strftime('%d %B %y %H:%M %Z') }}"
when MatchProposal::STATUS_REJECTED
"Rejected Proposal for #{Time.use_zone(view_context.timezone_offset) { @proposal.proposed_time.strftime('%d %B %y %H:%M %Z') }}"
else
"Smthn went wrong"
end
flash[:notice] = action
else
flash[:notice] = "Error"
end
redirect_to(match_proposals_path(@match))
end
private

View file

@ -31,7 +31,9 @@
</table>
<script type="text/javascript">
function proposalStateSubmit(newState, formID) {
var form = $('#edit_match_proposal_' + formID);
form.children("input[type='hidden']").val(newState);
form.submit();
}
</script>
<% end %>