Module | CalendarHelper |
In: |
app/helpers/calendar_helper.rb
|
カレンダーを返す。
# File app/helpers/calendar_helper.rb, line 5 5: def calendar(id, options = {}, &block) 6: raise(ArgumentError, "No year given") unless options.has_key?(:year) 7: raise(ArgumentError, "No month given") unless options.has_key?(:month) 8: 9: block = Proc.new {|d| nil} unless block 10: 11: defaults = { 12: :table_class => 'calendar', 13: :day_name_class => 'dayName', 14: :normal_day_class => 'normalDay', 15: :holiday_class => 'holiday', 16: :empty_day_class => 'emptyDay' 17: } 18: options = defaults.merge options 19: 20: day_names = [s_("Calendar|Sun"), s_("Calendar|Mon"), s_("Calendar|Tue"), s_("Calendar|Wed"), s_("Calendar|Thu"), s_("Calendar|Fri"), s_("Calendar|Sat")] 21: 22: cal = "<table id=\"#{id}\" class=\"#{options[:table_class]}\" border=\"0\">\n" 23: 24: # week names 25: cal << "<thead>\n" 26: cal << "<tr>\n" 27: day_names.each{ |day_name| 28: cal << "<th class=\"#{options[:day_name_class]}\">#{day_name}</th>\n" 29: } 30: cal << "</tr>\n" 31: cal << "</thead>\n" 32: 33: # days 34: cal << "<tbody>\n" 35: day = Date.civil(@year, @month, 1) 36: 37: cal << "<tr>\n" 38: day.wday.times{ 39: cal << "<td class=\"#{options[:empty_day_class]}\"></td>\n" 40: } 41: 42: while day.month == @month 43: if day.wday == 0 && day.mday != 1 44: cal << "<tr>\n" 45: end 46: 47: if block_given? 48: cell_text, cell_attrs = block.call(day) 49: day_class = 50: cell_attrs.kind_of?(Hash) && cell_attrs[:class] ? cell_attrs[:class] : options[:normal_day_class] 51: day_text = cell_text ? cell_text : day.mday.to_s 52: else 53: day_class = options[:normal_day_class] 54: day_class = options[:holiday_class] if day.wday == 0 || day.wday == 6 55: day_text = day.mday.to_s 56: end 57: cal << "<td class=\"#{day_class}\">#{day_text}</td>\n" 58: 59: if day.wday == 6 60: cal << "</tr>\n" 61: end 62: 63: day += 1 64: end 65: 66: if day.wday != 0 67: (7 - day.wday).times{ 68: cal << "<td class=\"#{options[:empty_day_class]}\"></td>\n" 69: } 70: cal << "</tr>\n" 71: end 72: 73: cal << "</tbody>\n" 74: 75: cal << "</table>\n" 76: end
カレンダーに配置する button box を返す。
# File app/helpers/calendar_helper.rb, line 116 116: def calendar_button_box 117: @calendar_button_box ||= lcr_button_box({ 118: :left => link_to_close({"_" => "&suffix;"}, @return_to_url, :class => "button"), 119: }) 120: return @calendar_button_box 121: end
日付を選択するためのリンクを返す。
# File app/helpers/calendar_helper.rb, line 79 79: def date_link(date, return_format, current_view, options, html_options = {}) 80: link_to_view_motion(date.mday.to_s, 81: current_view, 82: "calendar_#{date.mday.to_s}", 83: {}, 84: options.merge(:action => "pick", 85: :return_value => CustomFormatTranslator::format_date(date, return_format)), 86: html_options) 87: end
月の選択するための select box を返す。
# File app/helpers/calendar_helper.rb, line 103 103: def month_selector(id, current_month) 104: options = Array.new 105: (1..12).each{ |month| 106: options << [month.to_s, month.to_s] 107: } 108: select_tag(id, 109: options_for_select(options, current_month.to_s), 110: :id => nil, 111: :class => "calendar_month", 112: :onchange => "this.form.onsubmit()") 113: end
年を選択するための select box を返す。
# File app/helpers/calendar_helper.rb, line 90 90: def year_selector(id, current_year) 91: options = Array.new 92: ((current_year-2)..(current_year+2)).each{ |year| 93: options << [year.to_s, year.to_s] 94: } 95: select_tag(id, 96: options_for_select(options, current_year.to_s), 97: :id => nil, 98: :class => "calendar_year", 99: :onchange => "this.form.onsubmit()") 100: end