Class | CalendarController
In: | app/controllers/calendar_controller.rb
Parent: | ApplicationController

カレンダーで日付を選択する。

### Methods

calendar index pick test

### Constants

CALENDAR_RETURN_TO | = | { :calendar_test => {:controller => "calendar", :action => "test"}, }.with_indifferent_access |  | allow registered return_to only because do not redirect to any url
CALENDAR_ERROR_RETURN_TO | = | "/"

### Public Instance methods

calendar()

カレンダーを表示する。

[Source]

        # File app/controllers/calendar_controller.rb, line 19
    19:   def calendar
    20:     @year = (params[:year] || flash[:year] || Time.now.year).to_i
    21:     @month = (params[:month] || flash[:month] || Time.now.month).to_i
    22:     unless Date.valid_date?(@year, @month, 1)
    23:       @year = Time.now.year
    24:       @month = Time.now.month
    25:     end
    26:     @this = Date.new(@year, @month, 1)
    27:
    28:     if params[:previous_year]
    29:       @this = (@this << 12) unless params[:previous_month]
    30:     elsif params[:previous_month]
    31:       @this = (@this << 1)
    32:     elsif params[:next_month]
    33:       @this = (@this >> 1)
    34:     elsif params[:next_year]
    35:       @this = (@this >> 12)
    36:     end
    37:
    38:     @year = @this.year
    39:     @month = @this.month
    40:
    41:     @prev_month = (@this << 1)
    42:     @next_month = (@this >> 1)
    43:     @prev_year = (@this << 12)
    44:     @next_year = (@this >> 12)
    45:
    46:     @holidays = Hash.new(nil)
    47:
    48:     # ToDo: select only the holidays during the specified month
    49:     Holiday.find(:all, :select => "day", :conditions => ["year = ? AND month = ?", @year, @month]).each do |holiday|
    50:       @holidays[holiday.day] = true
    51:     end
    52:
    53:     @return_format = params[:return_format] ? params[:return_format] : "yyyy/mm/dd"
    54:     @alert_holiday = params[:alert_holiday]
    55:
    56:     pass_params
    57:   end

index()

`test` へリダイレクトする。

[Source]

        # File app/controllers/calendar_controller.rb, line 14
    14:   def index
    15:     redirect_to :action => :test
    16:   end

pick()

カレンダーから選択する。

[Source]

        # File app/controllers/calendar_controller.rb, line 60
    60:   def pick
    61:     flash[:pick] = {
    62:       :field => params[:return_field],
    63:       :return_value => params[:return_value]
    64:     }
    65:     x_close_or_redirect_to return_to_url
    66:   end

test()

(試験用)

[Source]

        # File app/controllers/calendar_controller.rb, line 69
    69:   def test
    70:     @current_view = "view_main"
    71:     @sub_view = "view_calendar"
    72:
    73:     if flash[:pick] && flash[:pick][:return_value]
    74:       @formatted_date = flash[:pick][:return_value]
    75:     end
    76:   end

[Validate]