app/controllers/events_controller.rb in artfully_ose-1.1.0 vs app/controllers/events_controller.rb in artfully_ose-1.2.0.alpha.1
- old
+ new
@@ -1,10 +1,11 @@
class EventsController < ArtfullyOseController
- respond_to :html, :json
+ respond_to :html, :json, :js
- before_filter :find_event, :only => [ :show, :edit, :update, :destroy, :widget, :image, :storefront_link, :prices, :messages, :resell, :wp_plugin ]
+ before_filter :find_event, :only => [ :show, :edit, :update, :destroy, :widget, :image, :storefront_link, :prices, :messages, :resell, :wp_plugin, :passes ]
before_filter :upcoming_shows, :only => :show
+ before_filter { authorize! :view, @event if @event }
def create
@event = Event.new(params[:event])
@templates = current_organization.charts.template
@event.organization_id = current_organization.id
@@ -20,11 +21,20 @@
end
end
def index
authorize! :view, Event
- @events = current_organization.events.includes(:shows, :venue).order('updated_at DESC')
+
+ scope = Event.unscoped.where(:deleted_at => nil).where(:organization_id => current_organization.id).includes(:shows).order('name ASC')
+ scope = if params[:range].present? && params[:range] == 'all'
+ @all = scope
+ else
+ @upcoming = scope.where :id => current_organization.shows.unplayed.pluck(:event_id).uniq
+ end
+
+ scope = scope.where('LOWER(name) LIKE ?', "%#{params[:query].downcase}%") unless params[:query].blank?
+ @events = scope
end
def show
authorize! :view, @event
@shows = @event.shows.paginate(:page => params[:page], :per_page => 25)
@@ -49,11 +59,11 @@
end
def edit
authorize! :edit, @event
end
-
+
def image
authorize! :edit, @event
end
def assign
@@ -68,22 +78,12 @@
def update
authorize! :edit, @event
if @event.update_attributes(params[:event])
- if user_requesting_next_step?
- if user_just_uploaded_an_image?
- redirect_to messages_event_path(@event)
- elsif user_set_special_instructions?
- redirect_to event_shows_path(@event)
- else
- redirect_to edit_event_venue_path(@event)
- end
- else
- flash[:notice] = "Your event has been updated."
- redirect_to event_url(@event)
- end
+ build_flash_message
+ redirect_to redirect_path and return
else
render :edit
end
end
@@ -93,47 +93,56 @@
flash[:notice] = "Your event has been deleted"
redirect_to events_url
end
def widget
+ @donation_kit = current_user.current_organization.kit(:regular_donation)
end
def storefront_link
end
def wp_plugin
end
-
+
def prices
end
- def temp_discounts_index
- find_event
+ def passes
end
- def temp_discount_form
- find_event
-
- @discount = TempDiscount.new
- @discount.promotion_type = 'two-for-one'
-
- @event.charts.collect(&:sections).flatten.each do |section|
- @discount.discount_sections.new(
- :section => section,
- :price => section.price
- )
- end
- end
-
def messages
end
def resell
@organization = current_organization
@reseller_profiles = ResellerProfile.includes(:organization).order("organizations.name").all
end
private
+
+ def redirect_path
+ if user_requesting_next_step?
+ if user_just_uploaded_an_image?
+ messages_event_path(@event)
+ elsif user_set_special_instructions?
+ new_event_show_path(@event)
+ else
+ edit_event_venue_path(@event)
+ end
+ else
+ event_url(@event)
+ end
+ end
+
+ def build_flash_message
+ if user_just_uploaded_an_image?
+ flash[:notice] = "We're processing your image and will have the new image up in a few minutes."
+ else
+ flash[:notice] = "Your event has been updated."
+ end
+ end
+
def find_event
@event = Event.find(params[:id])
end
def user_set_special_instructions?