Module: CalendarDateSelect::FormHelper
- Defined in:
- lib/calendar_date_select.rb
Instance Method Summary collapse
- #calendar_date_select(object, method, options = {}) ⇒ Object
- #calendar_date_select_output(input, calendar_options = {}) ⇒ Object
-
#calendar_date_select_process_options(options) ⇒ Object
extracts any options passed into calendar date select, appropriating them to either the Javascript call or the html tag.
- #calendar_date_select_tag(name, value = nil, options = {}) ⇒ Object
- #format_time(value, options = {}) ⇒ Object
Instance Method Details
#calendar_date_select(object, method, options = {}) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/calendar_date_select.rb', line 151 def calendar_date_select(object, method, ={}) obj = [:object] || instance_variable_get("@#{object}") if !.include?(:time) && obj.class.respond_to?("columns_hash") column_type = (obj.class.columns_hash[method.to_s].type rescue nil) [:time] = true if column_type == :datetime end use_time = [:time] if [:time].to_s=="mixed" use_time = false if Date===(obj.respond_to?(method) && obj.send(method)) end = () [:value] ||= if(obj.respond_to?(method) && obj.send(method).respond_to?(:strftime)) obj.send(method).strftime(CalendarDateSelect.date_format_string(use_time)) elsif obj.respond_to?("#{method}_before_type_cast") obj.send("#{method}_before_type_cast") elsif obj.respond_to?(method) obj.send(method).to_s else nil end tag = ActionView::Helpers::InstanceTag.new(object, method, self, nil, .delete(:object)) calendar_date_select_output( tag.to_input_field_tag( ([:hidden] || [:embedded]) ? "hidden" : "text", ), ) end |
#calendar_date_select_output(input, calendar_options = {}) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/calendar_date_select.rb', line 185 def calendar_date_select_output(input, = {}) out = input if [:embedded] uniq_id = "cds_placeholder_#{(rand*100000).to_i}" # we need to be able to locate the target input element, so lets stick an invisible span tag here we can easily locate out << content_tag(:span, nil, :style => "display: none; position: absolute;", :id => uniq_id) out << javascript_tag("new CalendarDateSelect( $('#{uniq_id}').previous(), #{()} ); ") else out << " " out << image_tag(CalendarDateSelect.image, :onclick => "new CalendarDateSelect( $(this).previous(), #{()} );", :style => 'border:0px; cursor:pointer;') end out end |
#calendar_date_select_process_options(options) ⇒ Object
extracts any options passed into calendar date select, appropriating them to either the Javascript call or the html tag.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/calendar_date_select.rb', line 113 def () = {} callbacks = [:before_show, :before_close, :after_show, :after_close, :after_navigate] for key in [:time, :valid_date_check, :embedded, :buttons, :format, :year_range, :month_year, :popup, :hidden, :minute_interval] + callbacks [key] = .delete(key) if .has_key?(key) end # if passing in mixed, pad it with single quotes [:time] = "'mixed'" if [:time].to_s=="mixed" [:month_year] = "'#{[:month_year]}'" if [:month_year] # if we are forcing the popup, automatically set the readonly property on the input control. if [:popup].to_s == "force" [:popup] = "'force'" [:readonly] = true end if (vdc=.delete(:valid_date_check)) if vdc.include?(";") || vdc.include?("function") throw ":valid_date_check function is missing a 'return' statement. Try something like: :valid_date_check => 'if (date > new(Date)) return true; else return false;'" unless vdc.include?("return"); end vdc = "return(#{vdc})" unless vdc.include?("return") vdc = "function(date) { #{vdc} }" unless vdc.include?("function") [:valid_date_check] = vdc end [:popup_by] ||= "this" if [:hidden] # surround any callbacks with a function, if not already done so for key in callbacks [key] = "function(param) { #{[key]} }" unless [key].include?("function") if [key] end [:year_range] = format_year_range([:year_range] || 10) end |
#calendar_date_select_tag(name, value = nil, options = {}) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/calendar_date_select.rb', line 83 def calendar_date_select_tag( name, value = nil, = {}) = () value = format_time(value, ) .delete(:format) [:id] ||= name tag = [:hidden] || [:embedded] ? hidden_field_tag(name, value, ) : text_field_tag(name, value, ) calendar_date_select_output(tag, ) end |
#format_time(value, options = {}) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/calendar_date_select.rb', line 97 def format_time(value, = {}) if value.respond_to?("strftime") if [:format] value = value.strftime([:format]) else if .has_key? :time value = value.strftime(CalendarDateSelect.date_format_string([:time])) else value = CalendarDateSelect.format_date(value) end end end value end |