Class: ShowsController

Inherits:
ArtfullyOseController show all
Defined in:
app/controllers/shows_controller.rb

Instance Method Summary collapse

Instance Method Details

#builtObject



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'app/controllers/shows_controller.rb', line 155

def built
  @show = Show.find(params[:show_id])
  authorize! :edit, @show

  @event = @show.event
  # TODO: The ability to create tickets is business logic, not authorization logic.
  authorize! :create_tickets, @show.chart.sections

  @show.build!

  respond_to do |format|
    format.html { redirect_to event_show_url(@event, @show) }
    format.json { render :json => @show.as_json.merge('glance' => @show.glance.as_json) }
  end
end

#createObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/shows_controller.rb', line 29

def create
  @event = Event.find(params[:event_id])
  @show = @event.next_show
  (render :new and return) unless valid_datetime?
  ActiveRecord::Base.transaction do
    chart_params = params[:show].delete(:chart) 
    if(chart_params.nil? || chart_params.empty?)
      flash[:error] = "Please specify at least one ticket type for your show."
      render :new and return
    end
    
    #clear the sections and replace them with whatever they entered
    @show.chart.sections = []
    @show.chart.update_attributes_from_params(chart_params)
    @show.update_attributes(params[:show])
    @show.organization = current_organization
    @show.chart_id = @show.chart.id
    @show.datetime = ActiveSupport::TimeZone.create(@event.time_zone).parse(params[:show][:datetime])

    if @show.go!(publishing_show?)      
      flash[:notice] = "Show created on #{l @show.datetime_local_to_event, :format => :date_at_time}"
      redirect_to event_show_path(@event, @show)
    else      
      flash[:error] = "There was a problem creating your show: #{@show.errors.full_messages.reject{|e| e.end_with? "be blank"}.to_sentence}"
      render :new
      raise ActiveRecord::Rollback
    end
  end
end

#destroyObject



100
101
102
103
104
105
106
107
108
109
# File 'app/controllers/shows_controller.rb', line 100

def destroy
  @show = Show.find(params[:id])
  authorize! :destroy, @show

  if @show.destroy
    render :nothing => true, :status => 204 and return  
  else
    render :status => :forbidden and return
  end
end

#door_listObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'app/controllers/shows_controller.rb', line 111

def door_list
  @show = Show.find(params[:id])
  @event = @show.event
  authorize! :view, @show
  @current_time = DateTime.now.in_time_zone(@show.event.time_zone)
  @door_list = DoorList.new(@show)

  respond_to do |format|
    format.html

    format.csv do
      @filename = [ @event.name, @show.datetime_local_to_event.to_s(:db_date), "door-list.csv" ].join("-")
      @csv_string = @door_list.items.to_comma
      send_data @csv_string, :filename => @filename, :type => "text/csv", :disposition => "attachment"
    end
  end
end

#duplicateObject



16
17
18
19
20
21
22
23
# File 'app/controllers/shows_controller.rb', line 16

def duplicate
  @show = Show.find(params[:id])
  authorize! :duplicate, @show

  @new_show = @show.dup!
  @new_show.save
  redirect_to event_path(@show.event)
end

#editObject



77
78
79
80
# File 'app/controllers/shows_controller.rb', line 77

def edit
  @show = Show.find(params[:id])
  authorize! :edit, @show
end

#indexObject



11
12
13
14
# File 'app/controllers/shows_controller.rb', line 11

def index
  authorize! :manage, @event
  @shows = Show.where(:event_id => @event.id).includes(:tickets, :chart, :event => :venue).order('datetime ASC')
end

#newObject



25
26
27
# File 'app/controllers/shows_controller.rb', line 25

def new
  @show = @event.next_show
end

#on_saleObject



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'app/controllers/shows_controller.rb', line 171

def on_sale
  authorize! :bulk_edit, Ticket
  with_confirmation do
    @show = Show.find(params[:show_id])

    if @show.bulk_on_sale(:all)
      @show.publish!
      notice = "Put all tickets on sale."
    else
      error = "Tickets that have been sold or comped can't be put on or taken off sale. A ticket that is already on sale or off sale can't be put on or off sale again."
    end

    respond_to do |format|
      format.html do
        flash[:notice] = notice
        flash[:error] = error
        redirect_to event_show_url(@show.event, @show)
      end

      format.json do
        if error.blank?
          render :json => @show.as_json.merge('glance' => @show.glance.as_json)
        else
          render :json => { :errors => [ error ] }, :status => 409
        end
      end

    end
  end
end

#publishedObject



129
130
131
132
133
134
135
136
137
138
139
140
# File 'app/controllers/shows_controller.rb', line 129

def published
  @show = Show.find(params[:show_id])
  authorize! :show, @show

  with_confirmation do
    @show.publish!
    respond_to do |format|
      format.html { redirect_to event_show_url(@show.event, @show), :notice => 'Your show is now published.' }
      format.json { render :json => @show.as_json }
    end
  end
end

#publishing_show?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/controllers/shows_controller.rb', line 67

def publishing_show?
  ("Save and Publish" == params[:commit])
end

#showObject



71
72
73
74
75
# File 'app/controllers/shows_controller.rb', line 71

def show
  @show = Show.includes(:event => :venue, :tickets => :section).find(params[:id])
  authorize! :view, @show
  @tickets = @show.tickets
end

#unpublishedObject



142
143
144
145
146
147
148
149
150
151
152
153
# File 'app/controllers/shows_controller.rb', line 142

def unpublished
  @show = Show.find(params[:show_id])
  authorize! :hide, @show

  with_confirmation do
    @show.unpublish!
    respond_to do |format|
      format.html { redirect_to event_show_url(@show.event, @show), :notice => 'Your show is now unpublished.' }
      format.json { render :json => @show.as_json }
    end
  end
end

#updateObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/controllers/shows_controller.rb', line 82

def update
  @show = Show.find(params[:id])
  authorize! :edit, @show
  if @show.live?
    flash[:alert] = 'Tickets have already been created for this performance'
    redirect_to event_url(@performance.event) and return
  else
    @show.datetime = ActiveSupport::TimeZone.create(@show.event.time_zone).parse(params[:show][:datetime])
    @show.chart_id = params[:show][:chart_id]
    if @show.save
      redirect_to event_path(@show.event)
    else
      flash[:alert] = 'This performance cannot be edited'
      render :edit
    end
  end
end

#valid_datetime?Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
65
# File 'app/controllers/shows_controller.rb', line 59

def valid_datetime?
  if ActiveSupport::TimeZone.create(@event.time_zone).parse(params[:show][:datetime]) < Time.now
    flash[:error] = "Please pick a date and time that is in the future."
    return false
  end
  true
end