Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow name,capacity ticket edit when there are registrations #699

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/controllers/access_levels_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ def update
authorize! :update, @event
@access_level = @event.access_levels.find(params.require(:id))

flash.now[:error] = "Something went wrong updating the ticket" unless @access_level.update(access_level_params)
flash.now[:error] = "Something went wrong updating the ticket" unless @access_level.update(
@access_level.registrations.any? ? access_level_params_strict : access_level_params
)

respond_with @access_level
end
Expand Down Expand Up @@ -68,4 +70,8 @@ def toggle_visibility
def access_level_params
params.require(:access_level).permit(:name, :capacity, :price, :has_comment, :hidden, :permit)
end

def access_level_params_strict
params.require(:access_level).permit(:name, :capacity)
end
end
6 changes: 6 additions & 0 deletions app/models/access_level.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ class AccessLevel < ApplicationRecord
validates :price, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates :capacity, numericality: { allow_nil: true, only_integer: true, greater_than: 0 }

validate do |access_level|
if access_level.capacity && access_level.registrations.size > access_level.capacity
access_level.errors.add "Registration", "count exceeds capacity."
end
end

validate do |access_level|
access_level.errors.add :event_id, "has no bank number." if access_level.price.positive? && access_level.event.bank_number.blank?
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/access_levels/_access_level.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<td>
<div class="nowrap">
<%= link_to raw(visibility_icon(access_level)), toggle_visibility_event_access_level_path(access_level.event, access_level), class: 'btn btn-xs btn-default', remote: true %>
<%= link_to raw('<i class="glyphicon glyphicon-edit"></i> Edit'), edit_event_access_level_path(access_level.event, access_level), class: 'btn btn-xs btn-default', remote: true %>
<% unless access_level.registrations.any? or access_level.partners.any? %>
<%= link_to raw('<i class="glyphicon glyphicon-edit"></i> Edit'), edit_event_access_level_path(access_level.event, access_level), class: 'btn btn-xs btn-default', remote: true %>
<%= link_to raw('<i class="glyphicon glyphicon-trash"></i> Delete'), event_access_level_path(access_level.event, access_level), class: 'btn btn-xs btn-danger', data: {confirm: 'Are you sure?'}, remote: true, method: :delete %>
<% end %>
</div>
Expand Down
8 changes: 4 additions & 4 deletions app/views/access_levels/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<%= form_for [object.event, object], remote: true do |f| %>
<td><%= f.text_field :name, class: 'form-control' %></td>
<td><%= f.number_field :capacity, class: 'form-control', placeholder: 0 %></td>
<td><%= f.text_field :price, value: nice_amount(f.object.price), class: 'form-control', placeholder: "0.00" %></td>
<td><%= f.text_field :price, value: nice_amount(f.object.price), class: 'form-control', placeholder: "0.00", disabled: f.object.registrations.any? %></td>
<td width="130px">
<%= f.collection_select :permit, AccessLevel.permits.keys, :itself, lambda {|k| translate(k)}, {}, class: 'form-control' %>
<%= f.collection_select :permit, AccessLevel.permits.keys, :itself, lambda {|k| translate(k)}, {}, class: 'form-control', disabled: f.object.registrations.any? %>
</td>
<td><div class="checkbox"><%= f.check_box :has_comment %></div></td>
<td><div class="checkbox"><%= f.check_box :hidden %></div></td>
<td><div class="checkbox"><%= f.check_box :has_comment, disabled: f.object.registrations.any? %></div></td>
<td><div class="checkbox"><%= f.check_box :hidden, disabled: f.object.registrations.any? %></div></td>
<td><%= f.button button_name, class: 'btn btn-sm btn-primary' %></td>
<%= javascript_tag do %>
var id = "#<% if button_name == 'Save' %>edit_<% end %><%= dom_id(f.object) %>";
Expand Down
Loading