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

Add option to end after a number of occurrances or on a date #117

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
583d038
Update recurring_select_helper.rb
sahild Oct 31, 2016
08d08c0
Rails 5 Fix refactor
sahild Oct 31, 2016
2c16c4d
read 'until' and 'count' from model. add initial UI to select until/c…
Aug 1, 2017
49a8c7a
work on the formatting of the end options
Aug 1, 2017
a985749
css for "ends" section
Aug 1, 2017
a27aaf7
init and change events for never/count options
Aug 1, 2017
7f71cd4
fix typo. default to 'never'
Aug 1, 2017
799dd18
update rule when occurrence count changes
Aug 1, 2017
426bb53
bug fix
Aug 1, 2017
b6041d3
don't unset "ends" radio on freq change
Aug 1, 2017
2ca2141
don't remove termination options from summary when changing freq
Aug 1, 2017
78c1003
unset str on freq change to force api call for summary
Aug 1, 2017
132a635
add datepicker
Aug 1, 2017
64a722e
use ruby-friendly date format
Aug 1, 2017
74004ca
parse date from {:time, :zone} hash
Aug 1, 2017
1816962
new Date() instead of Date.parse()
Aug 1, 2017
bedcdba
potential bug fixes
Aug 1, 2017
c5b0c25
refactor date parsing
Aug 1, 2017
fa04ba5
style the datepicker input
Aug 1, 2017
d6469c1
require jquery-ui-rails for "ends on" date picker
Aug 1, 2017
080bd56
working dummy app with jQuery UI date picker
Aug 1, 2017
1e7150f
update min jquery-ui-rails version
Aug 1, 2017
ed2c2cc
set min date
Aug 1, 2017
56560c0
down to jquery-ui-rails 5.0 for active admin support
Aug 1, 2017
21e01d2
Merge pull request #1 from Skookum/add-end-count-or-date
Aug 1, 2017
322845f
update to jquery-ui-rails 6
Aug 8, 2017
47acf92
Merge pull request #2 from Skookum/jquery-ui-rails-6
Aug 8, 2017
fdc241b
Merge pull request #3 from sahild/master
Jan 22, 2018
0c14257
Merge remote-tracking branch 'upstream/master'
May 14, 2019
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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ gem 'pg', platform: :ruby
gem 'activerecord-jdbcpostgresql-adapter', platform: :jruby

gem 'jquery-rails'
gem 'jquery-ui-rails', '>= 6.0'

gem 'rails', '~> 4.0.12'
gem 'sass-rails', '~> 4.0.5'
16 changes: 10 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ PATH
coffee-rails (>= 3.1)
ice_cube (>= 0.11)
jquery-rails (>= 3.0)
jquery-ui-rails (>= 6.0)
rails (>= 3.2)
sass-rails (>= 4.0)

Expand Down Expand Up @@ -48,16 +49,18 @@ GEM
erubis (2.7.0)
execjs (2.7.0)
hike (1.2.3)
i18n (0.7.0)
i18n (0.8.6)
ice_cube (0.16.2)
jquery-rails (3.1.2)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
jquery-ui-rails (6.0.1)
railties (>= 3.2.16)
mail (2.6.3)
mime-types (>= 1.16, < 3)
mime-types (2.6.2)
minitest (4.7.5)
multi_json (1.11.2)
multi_json (1.12.1)
pg (0.17.1)
rack (1.5.5)
rack-test (0.6.3)
Expand All @@ -75,7 +78,7 @@ GEM
activesupport (= 4.0.13)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.4.2)
rake (12.0.0)
rspec (3.1.0)
rspec-core (~> 3.1.0)
rspec-expectations (~> 3.1.0)
Expand Down Expand Up @@ -111,10 +114,10 @@ GEM
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
thor (0.19.1)
thread_safe (0.3.5)
thor (0.19.4)
thread_safe (0.3.6)
tilt (1.4.1)
tzinfo (0.3.44)
tzinfo (0.3.53)

PLATFORMS
ruby
Expand All @@ -123,6 +126,7 @@ DEPENDENCIES
activerecord-jdbcpostgresql-adapter
bundler (>= 1.3.5)
jquery-rails
jquery-ui-rails (>= 6.0)
pg
rails (~> 4.0.12)
rake (>= 0.9.6)
Expand Down
6 changes: 6 additions & 0 deletions app/assets/javascripts/recurring_select.js.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//= require jquery-ui/widgets/datepicker
//= require recurring_select_dialog
//= require_self

Expand Down Expand Up @@ -95,6 +96,11 @@ $.fn.recurring_select.texts = {
years: "year(s)"
day_of_month: "Day of month"
day_of_week: "Day of week"
ends: "Ends"
never: "Never"
after: "After"
occurrences: "occurrences"
on: "On"
cancel: "Cancel"
ok: "OK"
summary: "Summary"
Expand Down
80 changes: 73 additions & 7 deletions app/assets/javascripts/recurring_select_dialog.js.coffee.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ window.RecurringSelectDialog =
@positionDialogVert(true)
@mainEventInit()
@freqInit()
@terminationInit()
@summaryInit()
@outer_holder.trigger "recurring_select:dialog_opened"
@freq_select.focus()
Expand Down Expand Up @@ -141,6 +142,31 @@ window.RecurringSelectDialog =
interval_input.on "change keyup", @intervalChanged
section.show()

terminationInit: ->
@until_date = @outer_holder.find '#rs_until_date'
@until_date.datepicker({ dateFormat: 'yy-mm-dd', minDate: 0 })
if @current_rule.hash? && @current_rule.hash.count?
@count_option = @outer_holder.find "input[name='rs_termination'][value='count']"
@count_option.prop('checked', true)
@occurrence_count = @outer_holder.find '#rs_occurrence_count'
@occurrence_count.val(@current_rule.hash.count)
else if @current_rule.hash? && @current_rule.hash.until?
@until_option = @outer_holder.find "input[name='rs_termination'][value='until']"
@until_option.prop('checked', true)
# IceCube::TimeUtil will serialize a TimeWithZone into a hash, such as:
# {time: Thu, 04 Sep 2014 06:59:59 +0000, zone: "Pacific Time (US & Canada)"}
# If we're initializing from an unsaved rule, until will be a string
if @current_rule.hash.until.time?
@until_val = new Date(@current_rule.hash.until.time)
@until_date.val(@until_val.getFullYear() + '-' + (@until_val.getMonth() + 1) + '-' + @until_val.getDate())
else
@until_date.val(@current_rule.hash.until)
else
@never_option = @outer_holder.find "input[name='rs_termination'][value='never']"
@never_option.prop('checked', true)

@all_termination_options = @outer_holder.find ".rs_termination_section input[type='radio'], #rs_occurrence_count, #rs_until_date"
@all_termination_options.on "change", @terminationChanged

summaryInit: ->
@summary = @outer_holder.find(".rs_summary")
Expand Down Expand Up @@ -225,29 +251,24 @@ window.RecurringSelectDialog =
freqChanged: =>
@current_rule.hash = null unless $.isPlainObject(@current_rule.hash) # for custom values

@current_rule.str = null
@current_rule.hash ||= {}
@current_rule.hash.interval = 1
@current_rule.hash.until = null
@current_rule.hash.count = null
@current_rule.hash.validations = null
@content.find(".freq_option_section").hide();
@content.find("input[type=radio], input[type=checkbox]").prop("checked", false)
@content.find(".freq_option_section input[type=radio], input[type=checkbox]").prop("checked", false)
switch @freq_select.val()
when "Weekly"
@current_rule.hash.rule_type = "IceCube::WeeklyRule"
@current_rule.str = $.fn.recurring_select.texts["weekly"]
@initWeeklyOptions()
when "Monthly"
@current_rule.hash.rule_type = "IceCube::MonthlyRule"
@current_rule.str = $.fn.recurring_select.texts["monthly"]
@initMonthlyOptions()
when "Yearly"
@current_rule.hash.rule_type = "IceCube::YearlyRule"
@current_rule.str = $.fn.recurring_select.texts["yearly"]
@initYearlyOptions()
else
@current_rule.hash.rule_type = "IceCube::DailyRule"
@current_rule.str = $.fn.recurring_select.texts["daily"]
@initDailyOptions()
@summaryUpdate()
@positionDialogVert()
Expand Down Expand Up @@ -298,6 +319,26 @@ window.RecurringSelectDialog =
@summaryUpdate()
false

terminationChanged: (event) =>
@selected_termination_type = @outer_holder.find ".rs_termination_section input[type='radio']:checked"
if !@selected_termination_type?
return
@current_rule.str = null
@current_rule.hash ||= {}
switch @selected_termination_type.val()
when 'count'
@current_rule.hash.count = parseInt($('#rs_occurrence_count').val())
if @current_rule.hash.count < 1 || isNaN(@current_rule.hash.count)
@current_rule.hash.count = 1
@current_rule.hash.until = null
when 'until'
@current_rule.hash.until = $('#rs_until_date').val()
@current_rule.hash.count = null
else
@current_rule.hash.until = null
@current_rule.hash.count = null
@summaryUpdate()

# ========================= Change callbacks ===============================

template: () ->
Expand Down Expand Up @@ -359,6 +400,31 @@ window.RecurringSelectDialog =
#{$.fn.recurring_select.texts["years"]}
</p>
</div>
<div class='rs_termination_section'>
<table>
<tr>
<td>
<label class='rs_termination_label'>#{$.fn.recurring_select.texts["ends"]}:</label>
</td>
<td>
<label>
<input type='radio' name='rs_termination' value='never' />
#{$.fn.recurring_select.texts["never"]}
</label><br>
<label>
<input type='radio' name='rs_termination' value='count' />
#{$.fn.recurring_select.texts["after"]}
<input type='text' data-wrapper-class='ui-recurring-select' id='rs_occurrence_count' class='rs_count' value='10' size='2' />
#{$.fn.recurring_select.texts["occurrences"]}
</label><br>
<label>
<input type='radio' name='rs_termination' value='until' />
#{$.fn.recurring_select.texts["on"]}
<input type='text' data-wrapper-class='ui-recurring-select' class='rs_datepicker' id='rs_until_date' />
</label>
</td>
</table>
</div>
<p class='rs_summary'>
<span></span>
</p>
Expand Down
20 changes: 20 additions & 0 deletions app/assets/stylesheets/recurring_select.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/*
*= require jquery-ui/datepicker
*/
@import "utilities.scss";

/* -------- resets ---------------*/
Expand Down Expand Up @@ -76,6 +79,23 @@ select {
}
}

.rs_termination_section {
table {
margin: 0;
padding-top: 5px;
td {
padding: 0;
vertical-align: top;
}
}
.rs_termination_label {margin-right:10px;}
.rs_count {width:30px; text-align:center; display: inline-block;}
}

.rs_datepicker {
width: 80px;
text-align: center;
}

.rs_summary { padding:0px; margin-top:15px; border-top:1px solid #ccc;
span {font-weight:bold; border-top:1px solid #fff; display:block; padding:10px 0 5px 0;}
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/recurring_select_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def select_recurring(object, method, default_schedules = nil, options = {}, html
end
end
end

module FormBuilder
def select_recurring(method, default_schedules = nil, options = {}, html_options = {})
if [email protected]_to?(:select_recurring)
Expand Down
18 changes: 18 additions & 0 deletions lib/recurring_select.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def self.filter_params(params)

params[:interval] = params[:interval].to_i if params[:interval]
params[:week_start] = params[:week_start].to_i if params[:week_start]
params[:count] = params[:count].to_i if params[:count]

params[:validations] ||= {}
params[:validations].symbolize_keys!
Expand Down Expand Up @@ -78,6 +79,23 @@ def self.filter_params(params)
params[:validations][:day_of_year] = params[:validations][:day_of_year].collect(&:to_i)
end

begin
# IceCube::TimeUtil will serialize a TimeWithZone into a hash, such as:
# {time: Thu, 04 Sep 2014 06:59:59 +0000, zone: "Pacific Time (US & Canada)"}
# So don't try to DateTime.parse the hash. IceCube::TimeUtil will deserialize this for us.
if (until_param = params[:until])
if until_param.is_a?(String)
# Set to 23:59:59 (in current TZ) to encompass all events on until day
params[:until] = Time.zone.parse(until_param).change(hour: 23, min: 59, sec: 59)
elsif until_param.is_a?(Hash) # ex: {time: Thu, 28 Aug 2014 06:59:590000, zone: "Pacific Time (US & Canada)"}
until_param = until_param.symbolize_keys
params[:until] = until_param[:time].in_time_zone(until_param[:zone])
end
end
rescue ArgumentError
# Invalid date given, attempt to assign :until will fail silently
end

params
end
end
1 change: 1 addition & 0 deletions recurring_select.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Gem::Specification.new do |s|

s.add_dependency "rails", ">= 3.2"
s.add_dependency "jquery-rails", ">= 3.0"
s.add_dependency "jquery-ui-rails", ">= 6.0"
s.add_dependency "ice_cube", ">= 0.11"
s.add_dependency "sass-rails", ">= 4.0"
s.add_dependency "coffee-rails", ">= 3.1"
Expand Down