Merge 4c60baf7c1 into 33aee342b4
This commit is contained in:
commit
0ef6aa0644
8 changed files with 74 additions and 12 deletions
|
|
@ -57,3 +57,5 @@ $(document).ready(function() {
|
|||
delegateSelector: 'a.smoothscroll'
|
||||
});
|
||||
});
|
||||
|
||||
UnobtrusiveFlash.flashOptions['timeout'] = 3000;
|
||||
|
|
|
|||
|
|
@ -94,3 +94,8 @@ p.comment-body {
|
|||
.box{
|
||||
height: 230px;
|
||||
}
|
||||
|
||||
.quantity_left{
|
||||
height: 3em;
|
||||
width: 9em;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ module Admin
|
|||
class ResourcesController < Admin::BaseController
|
||||
load_and_authorize_resource :conference, find_by: :short_title
|
||||
load_and_authorize_resource :resource, only: [:show, :edit, :update, :destroy]
|
||||
after_action :prepare_unobtrusive_flash, only: [:update]
|
||||
|
||||
def index; end
|
||||
|
||||
|
|
@ -23,12 +24,23 @@ module Admin
|
|||
end
|
||||
|
||||
def update
|
||||
if @resource.update_attributes(resource_params)
|
||||
redirect_to admin_conference_resources_path(conference_id: @conference.short_title),
|
||||
notice: 'Resource successfully updated.'
|
||||
else
|
||||
flash.now[:error] = "Resource update failed: #{@resource.errors.full_messages.join('. ')}."
|
||||
render :edit
|
||||
successful_update = check_successful_update params[:increment_used_resource_flag]
|
||||
respond_to do |format|
|
||||
if successful_update
|
||||
format.html do
|
||||
redirect_to admin_conference_resources_path(conference_id: @conference.short_title),
|
||||
notice: 'Resource successfully updated.'
|
||||
end
|
||||
flash.now[:notice] = if params[:increment_used_resource_flag].to_i.zero?
|
||||
"One #{@resource.name} freed."
|
||||
else
|
||||
"One more #{@resource.name} used."
|
||||
end
|
||||
else
|
||||
flash.now[:error] = "Resource #{@resource.name}'s update failed: #{@resource.errors.full_messages.join('. ')}."
|
||||
format.html{ render :edit }
|
||||
end
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -48,5 +60,16 @@ module Admin
|
|||
def resource_params
|
||||
params.require(:resource).permit(:name, :description, :quantity, :used, :conference_id)
|
||||
end
|
||||
|
||||
def check_successful_update(increment_used_resource_flag)
|
||||
if increment_used_resource_flag.present?
|
||||
# Increment/Decrement of Resource via Index Page
|
||||
@resource.used = params[:increment_used_resource_flag].to_i == 1 ? (@resource.used + 1) : (@resource.used - 1)
|
||||
@resource.save
|
||||
else
|
||||
# Update via Edit Page
|
||||
@resource.update_attributes(resource_params)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
17
app/views/admin/resources/_update_links.html.haml
Normal file
17
app/views/admin/resources/_update_links.html.haml
Normal 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
|
||||
|
||||
|
||||
|
|
@ -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))
|
||||
|
||||
|
||||
|
|
|
|||
5
app/views/admin/resources/update.js.erb
Normal file
5
app/views/admin/resources/update.js.erb
Normal 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();
|
||||
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
-# Index admin sidebar
|
||||
= render 'layouts/admin_sidebar_index'
|
||||
.col-md-10
|
||||
#messages
|
||||
.unobtrusive-flash-container#messages
|
||||
=render 'layouts/messages'
|
||||
#content
|
||||
= yield
|
||||
= yield
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue