Add increment and decrement functionality to left resource

This commit is contained in:
Chaitanya 2017-04-05 01:36:22 +05:30
parent 033dbe4c40
commit 4c60baf7c1
8 changed files with 74 additions and 12 deletions

View file

@ -0,0 +1,17 @@
= link_to admin_conference_resource_path(conference.short_title,
resource, increment_used_resource_flag: 0), method: :put,
title: "Free 1 #{resource.name}",
class: "btn btn-primary #{'disabled' if resource.used <= 0}",
remote: true do
%span.fa.fa-minus.fa-2x.update_action
%button.btn.btn-default.quantity_left.disabled.action-btn
%span{ id: "resource_left_#{resource.id}" }
= quantity_left_of(resource)
= link_to admin_conference_resource_path(conference.short_title,
resource, increment_used_resource_flag: 1), method: :put,
title: "Use 1 #{resource.name}",
class: "btn btn-primary #{'disabled' if resource.used >= resource.quantity}",
remote: true do
%span.fa.fa-plus.fa-2x.update_action

View file

@ -10,7 +10,7 @@
%table.table.table-hover.datatable
%thead
%th Name
%th Left( Left/Total )
%th Remaining / Total
%th Used
%th Actions
%tbody
@ -20,9 +20,18 @@
= link_to(admin_conference_resource_path(@conference.short_title, resource.id)) do
= resource.name
%td
= quantity_left_of(resource)
.btn-group.hidden-sm.hidden-xs
%span{ id: "group_large_update_actions_#{resource.id}" }
= render partial: 'update_links',
locals: { conference: @conference, resource: resource }
.btn-group-vertical.visible-sm.visible-xs
%span{ id: "group_small_update_actions_#{resource.id}" }
= render partial: 'update_links',
locals: { conference: @conference, resource: resource}
%td
= resource.used
%span{ id: "resource_used_#{resource.id}" }
= resource.used
%td
.btn-group
= link_to 'Edit', edit_admin_conference_resource_path(@conference.short_title, resource.id),
@ -34,3 +43,4 @@
.col-md-12
= link_to 'Add Resource', new_admin_conference_resource_path, class: 'btn btn-success pull-right', disabled: !(can? :create, Resource.new(conference_id: @conference_id))

View file

@ -0,0 +1,5 @@
$('<%= "#group_large_update_actions_#{@resource.id.to_s}" %>').html('<%= j render partial: "update_links", locals: { conference: @conference, resource: @resource} %>');
$('<%= "#group_small_update_actions_#{@resource.id.to_s}" %>').html('<%= j render partial: "update_links", locals: { conference: @conference, resource: @resource} %>');
$('<%= "#resource_left_#{@resource.id.to_s}" %>').text('<%= "#{@resource.quantity - @resource.used }/#{@resource.quantity}"%>').fadeIn();
$('<%= "#resource_used_#{@resource.id.to_s}" %>').text(<%=@resource.used%>).fadeIn();