class Panel::CalendarNew::FrontEnd::EventsController < OrbitWidgetController
  # GET /events
  # GET /events.json
  def initialize
    super
    @app_title = 'calendar'
  end

  def index
   @item = Page.find(params[:page_id])
   @title = @item.title
    if !@item.frontend_data_count.blank?
      @page_num = @item.frontend_data_count
    else
      @page_num = 10
    end

    if params[:start].present? && params[:end].present?
      sdt = Time.at(params[:start].to_i)
      edt = Time.at(params[:end].to_i)
      @monthly_events = Event.monthly_event(sdt,edt)
      @re = Event.recurring_event(sdt,edt)
      @events = @monthly_events.inject(@re, :<<)    
    end
    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @events }
    end
  end
  def show
    @event = Event.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @event }
    end
  end

  def agenda
    agenda_start = Date.parse(params[:agenda_start])
    agenda_end = Date.parse(params[:agenda_end])
    @events = Event.agenda_events(agenda_start,agenda_end)
    render :json=>@events.to_json
  end
end