Class: FullcalendarEngine::EventsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/fullcalendar_engine/events_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject


11
12
13
14
15
16
17
# File 'app/controllers/fullcalendar_engine/events_controller.rb', line 11

def create
  if @event.save
    render nothing: true
  else
    render text: @event.errors.full_messages.to_sentence, status: 422
  end
end

#destroyObject


86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/controllers/fullcalendar_engine/events_controller.rb', line 86

def destroy
  case params[:delete_all]
  when 'true'
    @event.event_series.destroy
  when 'future'
    @events = @event.event_series.events.where('starttime > :start_time',
                                               start_time: @event.starttime.to_formatted_s(:db)).to_a
    @event.event_series.events.delete(@events)
  else
    @event.destroy
  end
  render nothing: true
end

#editObject


66
67
68
# File 'app/controllers/fullcalendar_engine/events_controller.rb', line 66

def edit
  render json: { form: render_to_string(partial: 'edit_form') } 
end

#get_eventsObject


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/fullcalendar_engine/events_controller.rb', line 25

def get_events
  start_time = Time.at(params[:start].to_i).to_formatted_s(:db)
  end_time   = Time.at(params[:end].to_i).to_formatted_s(:db)

  @events = Event.where('
              (starttime >= :start_time and endtime <= :end_time) or
              (starttime >= :start_time and endtime > :end_time and starttime <= :end_time) or
              (starttime <= :start_time and endtime >= :start_time and endtime <= :end_time) or
              (starttime <= :start_time and endtime > :end_time)',
              start_time: start_time, end_time: end_time)
  events = []
  @events.each do |event|
    events << { id: event.id,
                title: event.title,
                description: event.description || '', 
                start: event.starttime.iso8601,
                end: event.endtime.iso8601,
                allDay: event.all_day,
                recurring: (event.event_series_id) ? true : false }
  end
  render json: events.to_json
end

#moveObject


48
49
50
51
52
53
54
55
56
# File 'app/controllers/fullcalendar_engine/events_controller.rb', line 48

def move
  if @event
    @event.starttime = make_time_from_minute_and_day_delta(@event.starttime)
    @event.endtime   = make_time_from_minute_and_day_delta(@event.endtime)
    @event.all_day   = params[:all_day]
    @event.save
  end
  render nothing: true
end

#newObject


19
20
21
22
23
# File 'app/controllers/fullcalendar_engine/events_controller.rb', line 19

def new
  respond_to do |format|
    format.js
  end
end

#resizeObject


58
59
60
61
62
63
64
# File 'app/controllers/fullcalendar_engine/events_controller.rb', line 58

def resize
  if @event
    @event.endtime = make_time_from_minute_and_day_delta(@event.endtime)
    @event.save
  end    
  render nothing: true
end

#updateObject


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/controllers/fullcalendar_engine/events_controller.rb', line 70

def update
  case params[:event][:commit_button]
  when 'Update All Occurrence'
    @events = @event.event_series.events
    @event.update_events(@events, event_params)
  when 'Update All Following Occurrence'
    @events = @event.event_series.events.where('starttime > :start_time', 
                                               start_time: @event.starttime.to_formatted_s(:db)).to_a
    @event.update_events(@events, event_params)
  else
    @event.attributes = event_params
    @event.save
  end
  render nothing: true
end