Fix match proposals

This commit is contained in:
Ari Timonen 2020-03-27 03:00:29 +02:00
parent 6c3648cafe
commit f37dc8cdaa
3 changed files with 27 additions and 21 deletions

View file

@ -49,6 +49,20 @@ $(function() {
}); });
// Submit TODO // Submit TODO
$("form.edit_match_proposal a").on('click', function() {
var form = $(this).closest('form.edit_match_proposal');
form.children("input#match_proposal_status").val($(this).dataset.id);
$.post(form.attr('action'),form.serialize(), function(data) {
tr = form.closest('tr');
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);
alert(errjson.error.message);
});
}
);
$("a.submit").on('click', function() { $("a.submit").on('click', function() {
$(this).closest('form').submit() $(this).closest('form').submit()
@ -122,6 +136,10 @@ function QuoteText(id, type) {
}); });
} }
// Match proposal
// Fields removing and adding dynamically // Fields removing and adding dynamically
function remove_fields(link) { function remove_fields(link) {

View file

@ -1,5 +1,6 @@
module PollsHelper module PollsHelper
def add_option_link(name, form) def add_option_link(name, form)
# FIXME: not used atm.
link_to_function name do |page| link_to_function name do |page|
option = render :partial => 'option', :locals => { :pf => form, :options => Option.new } option = render :partial => 'option', :locals => { :pf => form, :options => Option.new }
page << %{ page << %{

View file

@ -14,7 +14,7 @@
<% end %> <% end %>
</tr> </tr>
<% @match.match_proposals.each do |proposal| %> <% @match.match_proposals.each do |proposal| %>
<tr class="<%=cycle('even', 'odd') %>"> <tr class="<%=cycle('even', 'odd') %>">-
<td><%= proposal.team.name %></td> <td><%= proposal.team.name %></td>
<td><%= longtime proposal.proposed_time %> </td> <td><%= longtime proposal.proposed_time %> </td>
<td><%= MatchProposal.status_strings[proposal.status] %></td> <td><%= MatchProposal.status_strings[proposal.status] %></td>
@ -22,18 +22,19 @@
<td class="actions"> <td class="actions">
<% unless proposal.state_immutable? %> <% unless proposal.state_immutable? %>
<%= form_for proposal, url: match_proposal_path(@match, proposal) do |f| %> <%= form_for proposal, url: match_proposal_path(@match, proposal) do |f| %>
<%= f.hidden_field :id, value: 0 %>
<%= f.hidden_field :status, value: 0 %> <%= f.hidden_field :status, value: 0 %>
<% if proposal.status_change_allowed?(cuser, MatchProposal::STATUS_CONFIRMED) %> <% if proposal.status_change_allowed?(cuser, MatchProposal::STATUS_CONFIRMED) %>
<%= link_to_function icon('check'), "proposalStateSubmit(#{MatchProposal::STATUS_CONFIRMED},#{proposal.id})", title: 'Confirm' %> <%= link_to icon('check'), "#", 'data-id': "#{MatchProposal::STATUS_CONFIRMED}", title: 'Confirm' %>
<% end %> <% end %>
<% if proposal.status_change_allowed?(cuser, MatchProposal::STATUS_REJECTED) %> <% if proposal.status_change_allowed?(cuser, MatchProposal::STATUS_REJECTED) %>
<%= link_to_function icon('times'), "proposalStateSubmit(#{MatchProposal::STATUS_REJECTED},#{proposal.id})", title: 'Reject' %> <%= link_to icon('times'), "#", 'data-id': "#{MatchProposal::STATUS_REJECTED}", title: 'Reject' %>
<% end %> <% end %>
<% if proposal.status_change_allowed?(cuser, MatchProposal::STATUS_REVOKED) %> <% if proposal.status_change_allowed?(cuser, MatchProposal::STATUS_REVOKED) %>
<%= link_to_function icon('undo'), "proposalStateSubmit(#{MatchProposal::STATUS_REVOKED},#{proposal.id})", title: 'Revoke' %> <%= link_to icon('undo'), "#", 'data-id': "#{MatchProposal::STATUS_REVOKED}", title: 'Revoke' %>
<% end %> <% end %>
<% 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 icon('hourglass'), "#", 'data-id': "#{MatchProposal::STATUS_DELAYED}", title: 'Delay' %>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>
@ -42,20 +43,6 @@
</tr> </tr>
<% end %> <% end %>
</table> </table>
<script type="text/javascript">
function proposalStateSubmit(newState, formID) {
var form = $('#edit_match_proposal_' + formID);
form.children("input[type='hidden']").val(newState);
$.post(form.attr('action'),form.serialize(), function(data) {
tr = form.closest('tr');
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);
alert(errjson.error.message);
});
}
</script>
<% end %> <% end %>
<%= link_to 'Back', match_path(@match), class: 'button' %><%= link_to 'Propose match time', new_match_proposal_path(@match), class: 'button' %> <%= link_to 'Back', match_path(@match), class: 'button' %><%= link_to 'Propose match time', new_match_proposal_path(@match), class: 'button' %>