Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update form_helper syntax for Rails 4 compatibility. #4

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions README.mkd
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# CalendarDateSelect

http://code.google.com/p/calendardateselect/

This project is looking for a new maintainer. Please contact me if you have sufficient interest in this project to move it forward.

## Examples

"See a demo here":http://electronicholas.com/calendar

## Assets in Rails 3.1 or greater (with asset pipeline *enabled*)

The asset files will be added to the asset pipeline and available for you to use. Add these lines in `app/assets/javascripts/application.js`:

```js
//= require calendar_date_select
```
*Optional*: Include your locale:
```js
//= require calendar_date_select/locale/fr
```

And add in your `app/assets/stylesheets/application.css`:
```css
/*
*= require calendar_date_select/default
*/
```

## Submitting patches

Please take care to do the following:

* Clean up your patch (don't send a patch bomb with a hundred features in one)
* Write test cases!
* As a general rule of thumb, think of ways to make things more general purpose than specific.
17 changes: 0 additions & 17 deletions README.txt

This file was deleted.

2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.16.2
1.16.3
1 change: 1 addition & 0 deletions calendar_date_select.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Gem::Specification.new do |s|
"spec/calendar_date_select/includes_helper_spec.rb",
"spec/spec_helper.rb"
]
s.add_dependency 'prototype-rails'

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Date.padded2 = function(hour) { var padded2 = parseInt(hour, 10); if (hour < 10)
Date.prototype.getPaddedMinutes = function() { return Date.padded2(this.getMinutes()); }
Date.prototype.getAMPMHour = function() { var hour = this.getHours(); return (hour == 0) ? 12 : (hour > 12 ? hour - 12 : hour ) }
Date.prototype.getAMPM = function() { return (this.getHours() < 12) ? "AM" : "PM"; }
Date.prototype.getHourForDropdown = function() { return this.getAMPMHour()+ " " + this.getAMPM(); }
Date.prototype.stripTime = function() { return new Date(this.getFullYear(), this.getMonth(), this.getDate());};
Date.prototype.daysDistance = function(compare_date) { return Math.round((compare_date - this) / Date.one_day); };
Date.prototype.toFormattedString = function(include_time){
Expand Down Expand Up @@ -209,7 +210,7 @@ CalendarDateSelect.prototype = {

var t = new Date();
this.hour_select = new SelectBox(buttons_div,
blank_time.concat($R(0,23).map(function(x) {t.setHours(x); return $A([t.getAMPMHour()+ " " + t.getAMPM(),x])} )),
blank_time.concat($R(0,23).map(function(x) {t.setHours(x); return $A([t.getHourForDropdown(),x])} )),
{
calendar_date_select: this,
onchange: function() { this.calendar_date_select.updateSelectedDate( { hour: this.value });},
Expand Down Expand Up @@ -380,8 +381,16 @@ CalendarDateSelect.prototype = {
this.selection_made = true;
}

if (!isNaN(parts.get("hour"))) this.selected_date.setHours(parts.get("hour"));
if (!isNaN(parts.get("minute"))) this.selected_date.setMinutes( Math.floor_to_interval(parts.get("minute"), this.options.get("minute_interval")) );
if (!isNaN(parts.get("hour"))){
this.selected_date.setHours(parts.get("hour"));
this.selection_made = true;
}

if (!isNaN(parts.get("minute"))){
this.selected_date.setMinutes( Math.floor_to_interval(parts.get("minute"), this.options.get("minute_interval")) );
this.selection_made = true;
}

if (parts.get("hour") === "" || parts.get("minute") === "")
this.setUseTime(false);
else if (!isNaN(parts.get("hour")) || !isNaN(parts.get("minute")))
Expand Down Expand Up @@ -456,4 +465,4 @@ CalendarDateSelect.prototype = {
if (e.keyCode==Event.KEY_ESC) this.close();
},
callback: function(name, param) { if (this.options.get(name)) { this.options.get(name).bind(this.target_element)(param); } }
}
}
17 changes: 11 additions & 6 deletions lib/calendar_date_select.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,25 @@
module CalendarDateSelect

Files = [
'/public',
'/public/javascripts/calendar_date_select',
'/public/stylesheets/calendar_date_select',
'/public/images/calendar_date_select',
'/public/javascripts/calendar_date_select/locale'
'/lib/assets',
'/lib/assets/javascripts/calendar_date_select',
'/lib/assets/stylesheets/calendar_date_select',
'/lib/assets/images/calendar_date_select',
'/lib/assets/javascripts/calendar_date_select/locale'
]

module Rails
class Engine < ::Rails::Engine
end
end

class Railtie < ::Rails::Railtie

initializer 'calendardateselect.initialize', :after => :action_view do
ActionView::Helpers::FormHelper.send(:include, CalendarDateSelect::FormHelpers)
ActionView::Base.send(:include, CalendarDateSelect::FormHelpers)
ActionView::Base.send(:include, CalendarDateSelect::IncludesHelper)

ActionView::Helpers::InstanceTag.class_eval do
class << self; alias new_with_backwards_compatibility new; end #TODO: singleton_class.class_eval
end
Expand Down
2 changes: 1 addition & 1 deletion lib/calendar_date_select/calendar_date_select.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module CalendarDateSelect
VERSION = '1.16.2'
VERSION = '1.16.3'

FORMATS = {
:natural => {
Expand Down
15 changes: 11 additions & 4 deletions lib/calendar_date_select/form_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def calendar_date_select_tag( name, value = nil, options = {})
javascript_options.delete(:format)

options[:id] ||= name
options.merge!(:onclick => "new CalendarDateSelect( $(this), #{"{#{javascript_options.keys.map { |k| "#{k}:#{javascript_options[k]}" }.sort.join(', ')}}"} );")
tag = javascript_options[:hidden] || javascript_options[:embedded] ?
hidden_field_tag(name, value, options) :
text_field_tag(name, value, options)
Expand Down Expand Up @@ -143,9 +144,14 @@ def calendar_date_select(object, method, options={})
end
end

tag = ActionView::Helpers::InstanceTag.new_with_backwards_compatibility(object, method, self, options.delete(:object))

options.delete(:object)
options.merge!(:type => (javascript_options[:hidden] || javascript_options[:embedded]) ? "hidden" : "text")
options.merge!(:onclick => "new CalendarDateSelect( $(this), #{"{#{javascript_options.keys.map { |k| "#{k}:#{javascript_options[k]}" }.sort.join(', ')}}"} );")
tag = ActionView::Helpers::Tags::TextField.new(object, method, self, options).render

calendar_date_select_output(
tag.to_input_field_tag( (javascript_options[:hidden] || javascript_options[:embedded]) ? "hidden" : "text", options),
tag,
image,
options,
javascript_options
Expand Down Expand Up @@ -203,15 +209,16 @@ def calendar_date_select_process_options(options)

def calendar_date_select_output(input, image, options = {}, javascript_options = {})
out = input

if javascript_options[: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(), #{options_for_javascript(javascript_options)} ); ")
out << javascript_tag("new CalendarDateSelect( $('#{uniq_id}').previous(), #{"{#{javascript_options.keys.map { |k| "#{k}:#{javascript_options[k]}" }.sort.join(', ')}}"} ); ")
else
out << " "
out << image_tag(image,
:onclick => "new CalendarDateSelect( $(this).previous(), #{options_for_javascript(javascript_options)} );",
:onclick => "new CalendarDateSelect( $(this).previous(), #{"{#{javascript_options.keys.map { |k| "#{k}:#{javascript_options[k]}" }.sort.join(', ')}}"} );",
:style => 'border:0px; cursor:pointer;',
:class=>'calendar_date_select_popup_icon')
end
Expand Down
5 changes: 5 additions & 0 deletions lib/calendar_date_select/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module CalendarDateSelect
module Rails
VERSION = "1.2.0"
end
end