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'
|
delegateSelector: 'a.smoothscroll'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
UnobtrusiveFlash.flashOptions['timeout'] = 3000;
|
||||||
|
|
|
||||||
|
|
@ -94,3 +94,8 @@ p.comment-body {
|
||||||
.box{
|
.box{
|
||||||
height: 230px;
|
height: 230px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.quantity_left{
|
||||||
|
height: 3em;
|
||||||
|
width: 9em;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ module Admin
|
||||||
class ResourcesController < Admin::BaseController
|
class ResourcesController < Admin::BaseController
|
||||||
load_and_authorize_resource :conference, find_by: :short_title
|
load_and_authorize_resource :conference, find_by: :short_title
|
||||||
load_and_authorize_resource :resource, only: [:show, :edit, :update, :destroy]
|
load_and_authorize_resource :resource, only: [:show, :edit, :update, :destroy]
|
||||||
|
after_action :prepare_unobtrusive_flash, only: [:update]
|
||||||
|
|
||||||
def index; end
|
def index; end
|
||||||
|
|
||||||
|
|
@ -23,12 +24,23 @@ module Admin
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
if @resource.update_attributes(resource_params)
|
successful_update = check_successful_update params[:increment_used_resource_flag]
|
||||||
redirect_to admin_conference_resources_path(conference_id: @conference.short_title),
|
respond_to do |format|
|
||||||
notice: 'Resource successfully updated.'
|
if successful_update
|
||||||
else
|
format.html do
|
||||||
flash.now[:error] = "Resource update failed: #{@resource.errors.full_messages.join('. ')}."
|
redirect_to admin_conference_resources_path(conference_id: @conference.short_title),
|
||||||
render :edit
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -48,5 +60,16 @@ module Admin
|
||||||
def resource_params
|
def resource_params
|
||||||
params.require(:resource).permit(:name, :description, :quantity, :used, :conference_id)
|
params.require(:resource).permit(:name, :description, :quantity, :used, :conference_id)
|
||||||
end
|
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
|
||||||
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
|
%table.table.table-hover.datatable
|
||||||
%thead
|
%thead
|
||||||
%th Name
|
%th Name
|
||||||
%th Left( Left/Total )
|
%th Remaining / Total
|
||||||
%th Used
|
%th Used
|
||||||
%th Actions
|
%th Actions
|
||||||
%tbody
|
%tbody
|
||||||
|
|
@ -20,9 +20,18 @@
|
||||||
= link_to(admin_conference_resource_path(@conference.short_title, resource.id)) do
|
= link_to(admin_conference_resource_path(@conference.short_title, resource.id)) do
|
||||||
= resource.name
|
= resource.name
|
||||||
%td
|
%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
|
%td
|
||||||
= resource.used
|
%span{ id: "resource_used_#{resource.id}" }
|
||||||
|
= resource.used
|
||||||
%td
|
%td
|
||||||
.btn-group
|
.btn-group
|
||||||
= link_to 'Edit', edit_admin_conference_resource_path(@conference.short_title, resource.id),
|
= link_to 'Edit', edit_admin_conference_resource_path(@conference.short_title, resource.id),
|
||||||
|
|
@ -34,3 +43,4 @@
|
||||||
.col-md-12
|
.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))
|
= 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
|
-# Index admin sidebar
|
||||||
= render 'layouts/admin_sidebar_index'
|
= render 'layouts/admin_sidebar_index'
|
||||||
.col-md-10
|
.col-md-10
|
||||||
#messages
|
.unobtrusive-flash-container#messages
|
||||||
=render 'layouts/messages'
|
=render 'layouts/messages'
|
||||||
#content
|
#content
|
||||||
= yield
|
= yield
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ feature Resource do
|
||||||
click_button 'Update Resource'
|
click_button 'Update Resource'
|
||||||
resource.reload
|
resource.reload
|
||||||
|
|
||||||
expect(flash).to eq('Resource successfully updated.')
|
expect(page).to have_css('#messages'), text('Resource successfully updated.')
|
||||||
expect(resource.name).to eq('changed_name')
|
expect(resource.name).to eq('changed_name')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue