rrule_form 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +59 -0
- data/Rakefile +6 -0
- data/app/helpers/rrule_form/application_helper.rb +10 -0
- data/app/views/rrule/_rrule_form.html.erb +143 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rrule_form.rb +17 -0
- data/lib/rrule_form/version.rb +3 -0
- data/rrule_form.gemspec +29 -0
- data/vendor/assets/javascripts/rrule-gui.js +849 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 46c950517d003d7d7362478d9722259a019bc09b555b331fc8a2d7cc89a8fb2f
|
4
|
+
data.tar.gz: d17e280fe95f05169df20e0b2143e786b5e4aac53c350ace5e99efd9683d983a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 486569f6cd45c337a5d99408d9d5b9406a56344cec9783a7a373d86ab95b3e5c6e6105aa80ddc938d16754f42b7b76b0344650037032547f2b800c87f5a13526
|
7
|
+
data.tar.gz: 84550791f37a928570ae3f0d4ce016fe2814fefccbd5c381797c1a97eae3e91e3909934596a9d43121d47c1909287aadec77e6251390c96dc41a6cd43935ca51
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 ravi-bebble
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# RruleForm
|
2
|
+
This is a gem wrapping up the javascript and html required for collecting rrule string.
|
3
|
+
|
4
|
+
The gem inspired from https://github.com/superherogeek/rrule-generator-form
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rrule_form'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rrule_form
|
22
|
+
|
23
|
+
Add following to application.js
|
24
|
+
|
25
|
+
```javascript
|
26
|
+
//= require rrule-gui.js
|
27
|
+
```
|
28
|
+
|
29
|
+
The javascript under this gem needs some dependencies required:
|
30
|
+
|
31
|
+
1. jquery
|
32
|
+
1. jquery-ui/widgets/datepicker
|
33
|
+
1. bootstrap css for stylesheets
|
34
|
+
1. bootstrap js for modal usage
|
35
|
+
|
36
|
+
The javascript part of this gem handles the form manipulation of the form
|
37
|
+
|
38
|
+
|
39
|
+
## Usage
|
40
|
+
|
41
|
+
This gem will provide with a helper which will.
|
42
|
+
```ruby
|
43
|
+
rrule_form_for(selector, callback=nil)
|
44
|
+
```
|
45
|
+
|
46
|
+
selector would be jquery selector for the field to be assigned with rrule field.
|
47
|
+
|
48
|
+
## Development
|
49
|
+
|
50
|
+
This gem is in draft state to provide the basic working of a form that handles all types of recurrence.
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ravi-ture/rrule_form.
|
55
|
+
|
56
|
+
|
57
|
+
## License
|
58
|
+
|
59
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
|
2
|
+
<div class="modal" tabindex="-1" role="dialog" id='rrule_form_modal-<%= selector.gsub(/[^\w\s]/, '_') %>'>
|
3
|
+
<div class="modal-dialog" role="document">
|
4
|
+
<div class="modal-content">
|
5
|
+
<div class="modal-header">
|
6
|
+
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
7
|
+
<span aria-hidden="true">×</span>
|
8
|
+
</button>
|
9
|
+
<h3 class="modal-title">Set Recurrence Rule</h3>
|
10
|
+
</div>
|
11
|
+
<div class="modal-body">
|
12
|
+
<form name="rrule[<%= selector.gsub(/[^\w\s]/, '_') %>]" id="rrule-<%= selector.gsub(/[^\w\s]/, '_') %>" class='rrule-form' action='javascript:void(0);'>
|
13
|
+
<p>Start Date: <input type="text" class="datepicker" id="start-date-rrule" /></p>
|
14
|
+
<input type="hidden" name="start-date-formatted" id="start-date-hidden" value="" />
|
15
|
+
<!-- <p> End Date: <input type="text" class="datepicker" id="start-date" /></p> -->
|
16
|
+
<p>Recurring Event?
|
17
|
+
<input type="radio" name="event-recurring" value="no" checked="checked" /> No
|
18
|
+
<input type="radio" name="event-recurring" value="yes" /> Yes
|
19
|
+
</p>
|
20
|
+
<div id="recurring-rules" style="display:none;">
|
21
|
+
<!-- FREQ -->
|
22
|
+
<p>
|
23
|
+
Frequency
|
24
|
+
<select name="freq">
|
25
|
+
<option value="daily" class="days">Daily</option>
|
26
|
+
<option value="weekly" class="weeks">Weekly</option>
|
27
|
+
<option value="monthly" class="months">Monthly</option>
|
28
|
+
<option value="yearly" class="years">Yearly</option>
|
29
|
+
</select>
|
30
|
+
</p>
|
31
|
+
<p>Every <input type="text" name="interval" value="1" size="2" /> <span class="freq-selection">day(s)</span>
|
32
|
+
</p>
|
33
|
+
<!-- BYWEEKDAY -->
|
34
|
+
<div id="weekday-select" class="btn-toolbar weeks-choice" role="toolbar" style="display:none;">
|
35
|
+
<b>Which day(s) of the week does this repeat on:</b>
|
36
|
+
<div class="btn-group">
|
37
|
+
<% %w{SUN MON TUE WED THU FRI SAT}.each do |wday| %>
|
38
|
+
<button class="btn btn-default" id="<%= wday.first(2) %>"><%= wday.titleize %></button>
|
39
|
+
<% end %>
|
40
|
+
</div>
|
41
|
+
</div>
|
42
|
+
<!-- BYMONTH -->
|
43
|
+
<div id="bymonth-select" class="btn-toolbar years-choice" role="toolbar" style="display:none;">
|
44
|
+
<span>Which month(s) of the year does this repeat on</span>
|
45
|
+
<p><input type="radio" name="yearly-options" id="yearly-one-month" checked="checked" /> One Month Out of the Year</p>
|
46
|
+
on
|
47
|
+
<select name="yearly-bymonth" id="yearly-bymonth" class="yearly-one-month">
|
48
|
+
<% I18n.t("date.month_names").compact.each_with_index do |month, index| %>
|
49
|
+
<option value="<%= index + 1 %>"><%= month %></option>
|
50
|
+
<% end %>
|
51
|
+
</select>
|
52
|
+
<select name="yearly-bymonthday" id="yearly-bymonthday" class="yearly-one-month">
|
53
|
+
<% (1..31).each do |index| %>
|
54
|
+
<option value="<%= index %>"><%= index %></option>
|
55
|
+
<% end %>
|
56
|
+
</select>
|
57
|
+
<p><input type="radio" name="yearly-options" id="yearly-multiple-months" /> Multiple Months</p>
|
58
|
+
<% I18n.t("date.abbr_month_names").compact.in_groups_of(6).each do |month_grp| %>
|
59
|
+
<div style="display:block;float:none;" class="btn-group yearly-multiple-months">
|
60
|
+
<% month_grp.each do |month| %>
|
61
|
+
<button class="btn btn-default" style="width:16.66666666666667%" data-month-num="<%= I18n.t("date.abbr_month_names").compact.index(month) + 1%>" disabled="disabled"><%= month %></button>
|
62
|
+
<% end %>
|
63
|
+
</div>
|
64
|
+
<% end %>
|
65
|
+
<p><input type="radio" name="yearly-options" id="yearly-precise" /> Or be precise</p>
|
66
|
+
on the
|
67
|
+
<select name="yearly-bysetpos" class="yearly-precise" disabled="disabled">
|
68
|
+
<option value="1" selected="selected">First</option>
|
69
|
+
<option value="2">Second</option>
|
70
|
+
<option value="3">Third</option>
|
71
|
+
<option value="4">Fourth</option>
|
72
|
+
<option value="-1">Last</option>
|
73
|
+
</select>
|
74
|
+
<select name="yearly-byday" class="yearly-precise" disabled="disabled">
|
75
|
+
<% Date::DAYNAMES.each do |day| %>
|
76
|
+
<option value="<%= day.first(2).upcase %>"><%= day %></option>
|
77
|
+
<% end %>
|
78
|
+
<option value="SU,MO,TU,WE,TH,FR,SA" selected="selected">Day</option>
|
79
|
+
<option value="MO,TU,WE,TH,FR">Weekday</option>
|
80
|
+
<option value="SU,SA">Weekend day</option>
|
81
|
+
</select>
|
82
|
+
in
|
83
|
+
<select name="yearly-bymonth-with-bysetpos-byday" id="yearly-bymonth-with-bysetpos-byday" class="yearly-precise" disabled="disabled">
|
84
|
+
<% I18n.t("date.month_names").compact.each_with_index do |month, index| %>
|
85
|
+
<option value="<%= index + 1 %>"><%= month %></option>
|
86
|
+
<% end %>
|
87
|
+
</select>
|
88
|
+
</div>
|
89
|
+
<!-- BYMONTHDAY -->
|
90
|
+
<div id="monthday-select" class="btn-toolbar months-choice" role="toolbar" style="display:none;">
|
91
|
+
<input type="radio" name="monthday-pos-select" value="monthday-selected" id="monthday-selected" checked="checked" />
|
92
|
+
<b>Which day(s) of the month does this repeat on</b>
|
93
|
+
<% (1..31).to_a.in_groups_of(7).each do |date_grp| %>
|
94
|
+
<div class="btn-group" style="display:block;float:none;">
|
95
|
+
<% date_grp.compact.each do |date| %>
|
96
|
+
<button class="btn btn-default" style="width:14.28571428571429%;" data-day-num="<%= date %>"><%= date %></button>
|
97
|
+
<% end %>
|
98
|
+
</div>
|
99
|
+
<% end %>
|
100
|
+
<!-- BYDAY -->
|
101
|
+
<div>
|
102
|
+
<input type="radio" name="monthday-pos-select" value="month-byday-pos-selected" id="month-byday-pos-selected" /> Or
|
103
|
+
<select name="month-byday-pos" disabled="yes">
|
104
|
+
<option value="1" selected="selected">First</option>
|
105
|
+
<option value="2">Second</option>
|
106
|
+
<option value="3">Third</option>
|
107
|
+
<option value="4">Fourth</option>
|
108
|
+
<option value="-1">Last</option>
|
109
|
+
</select>
|
110
|
+
<select name="month-byday-pos-name" disabled="yes">
|
111
|
+
<% Date::DAYNAMES.each do |day| %>
|
112
|
+
<option value="<%= day.first(2).upcase %>"><%= day %></option>
|
113
|
+
<% end %>
|
114
|
+
<option value="SU,MO,TU,WE,TH,FR,SA" selected="selected">Day</option>
|
115
|
+
<option value="MO,TU,WE,TH,FR">Weekday</option>
|
116
|
+
<option value="SU,SA">Weekend day</option>
|
117
|
+
</select>
|
118
|
+
</div>
|
119
|
+
</div>
|
120
|
+
<div id="until-rules" style="display:none;">
|
121
|
+
<p>Until</p>
|
122
|
+
<p> <label for="count-select"><input type="radio" name="end-select" value="count" id="count-select" checked="checked"/> How many times does this transaction occur?
|
123
|
+
<input autocomplete="off" type="number" name="count" min="1" max="50" value="1" step="1"/> Time(s)</label>
|
124
|
+
</p>
|
125
|
+
<p><label for="until-select"><input type="radio" name="end-select" value="until" id="until-select" /> Specific Date (aka until)
|
126
|
+
<input type="text" name="until" id="end-date-rrule" disabled="yes" />
|
127
|
+
<input type="hidden" name="end-date-formatted" id="end-date-hidden" value="" /></label>
|
128
|
+
</p>
|
129
|
+
</div>
|
130
|
+
<input type="submit" name="submit" value="submit" />
|
131
|
+
</div>
|
132
|
+
<div class="show-dates"></div>
|
133
|
+
<div class="readout"></div>
|
134
|
+
<!-- End Recurrence Form -->
|
135
|
+
</form>
|
136
|
+
</div>
|
137
|
+
</div>
|
138
|
+
</div>
|
139
|
+
</div>
|
140
|
+
|
141
|
+
<script type="text/javascript">
|
142
|
+
RruleForm.initialize('<%= selector %>', '<%= callback %>');
|
143
|
+
</script>
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rrule_form"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/rrule_form.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "rrule_form/version"
|
2
|
+
|
3
|
+
module RruleForm
|
4
|
+
class Error < StandardError; end
|
5
|
+
|
6
|
+
module Rails
|
7
|
+
class Engine < ::Rails::Engine
|
8
|
+
|
9
|
+
isolate_namespace RruleForm
|
10
|
+
initializer 'local_helper.action_controller' do
|
11
|
+
ActiveSupport.on_load :action_controller do
|
12
|
+
helper RruleForm::ApplicationHelper
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/rrule_form.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'lib/rrule_form/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "rrule_form"
|
5
|
+
spec.version = RruleForm::VERSION
|
6
|
+
spec.authors = ["ravi-ture"]
|
7
|
+
spec.email = ["raviture@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{Wrapper for rrule-generater-form}
|
10
|
+
spec.description = %q{This is a rails wrapper for rrule-generater-form jquery plugin}
|
11
|
+
spec.homepage = "https://github.com/ravi-ture/rrule_form"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = "https://github.com/ravi-ture/rrule_form"
|
17
|
+
spec.metadata["changelog_uri"] = "https://github.com/ravi-ture/rrule_form"
|
18
|
+
spec.add_dependency "rails"
|
19
|
+
spec.add_dependency "sass"
|
20
|
+
spec.add_dependency "sass-rails"
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
end
|
@@ -0,0 +1,849 @@
|
|
1
|
+
/*
|
2
|
+
|
3
|
+
RRULE GENERATOR FORM aka RRULE GUI
|
4
|
+
|
5
|
+
MIT License
|
6
|
+
|
7
|
+
Copyright (c) 2016 Jordan Roberts
|
8
|
+
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
11
|
+
in the Software without restriction, including without limitation the rights
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
14
|
+
furnished to do so, subject to the following conditions:
|
15
|
+
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
17
|
+
copies or substantial portions of the Software.
|
18
|
+
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
25
|
+
SOFTWARE.
|
26
|
+
|
27
|
+
|
28
|
+
*/
|
29
|
+
RruleForm = {
|
30
|
+
readRule: function(rrule) {
|
31
|
+
|
32
|
+
rrule = typeof rrule !== 'undefined' ? rrule : '';
|
33
|
+
|
34
|
+
if (rrule != '') {
|
35
|
+
// Break down the rule by semi-colons first
|
36
|
+
var items = rrule.split(';');
|
37
|
+
var recur = [];
|
38
|
+
for (i = 0; i < items.length; i++) {
|
39
|
+
if (items[i] !== '') {
|
40
|
+
temp = items[i].split('=');
|
41
|
+
}
|
42
|
+
recur[temp[0]] = temp[1];
|
43
|
+
}
|
44
|
+
console.log(recur);
|
45
|
+
|
46
|
+
// See if the recurring rule has enough valid parts
|
47
|
+
if (recur.FREQ && recur.DTSTART && (recur.COUNT || recur.UNTIL)) {
|
48
|
+
recurringRule = {
|
49
|
+
freq: recur.FREQ,
|
50
|
+
dtstart: recur.DTSTART,
|
51
|
+
interval: recur.INTERVAL,
|
52
|
+
byday: "",
|
53
|
+
bysetpos: "",
|
54
|
+
bymonthday: "",
|
55
|
+
bymonth: "",
|
56
|
+
count: "",
|
57
|
+
until: ""
|
58
|
+
|
59
|
+
};
|
60
|
+
|
61
|
+
// Set either COUNT or UNTIL
|
62
|
+
if (typeof recur.COUNT == 'undefined' && recur.UNTIL) {
|
63
|
+
recurringRule.until = recur.UNTIL;
|
64
|
+
|
65
|
+
} else if (typeof recur.UNTIL == 'undefined' && recur.COUNT) {
|
66
|
+
recurringRule.count = recur.COUNT;
|
67
|
+
}
|
68
|
+
|
69
|
+
// Set INTERVAL
|
70
|
+
$('input[name="interval"]').val(recur.INTERVAL);
|
71
|
+
|
72
|
+
|
73
|
+
// Setup start-date picker
|
74
|
+
startYear = recur.DTSTART.substring(0, 4);
|
75
|
+
startMonth = recur.DTSTART.substring(4, 6);
|
76
|
+
startDay = recur.DTSTART.substring(6, 8);
|
77
|
+
//alert(startYear + startMonth + startDay);
|
78
|
+
$('#start-date-rrule').val(startYear + '-' + startMonth + '-' + startDay);
|
79
|
+
$('#start-date-hidden').val(startYear + startMonth + startDay + 'T040000z');
|
80
|
+
|
81
|
+
// Setup start-date picker
|
82
|
+
$('#start-date-rrule').datepicker({
|
83
|
+
showOtherMonths: true,
|
84
|
+
selectOtherMonths: true,
|
85
|
+
dateFormat: 'yy-mm-dd',
|
86
|
+
onSelect: function(value) {
|
87
|
+
|
88
|
+
dateSelected = new Date(value + ' 00:00:00');
|
89
|
+
dtstartString = dateSelected.getFullYear() + ('0' + (dateSelected.getMonth() + 1)).slice(-2) + ('0' + dateSelected.getDate()).slice(-2);
|
90
|
+
$('#start-date-hidden').val(dtstartString + 'T040000z');
|
91
|
+
recurringRule.dtstart = dtstartString + 'T040000z';
|
92
|
+
|
93
|
+
// Set minimum selected date on end-datepicker
|
94
|
+
minEndDate = dateSelected.getFullYear() + '-' + ('0' + (dateSelected.getMonth() + 1)).slice(-2) + '-' + ('0' + dateSelected.getDate()).slice(-2);
|
95
|
+
$('#end-date-rrule').datepicker('option', 'minDate', minEndDate);
|
96
|
+
// Reset the selected enddate
|
97
|
+
$('#end-date-hidden').val(dtstartString + 'T040000z');
|
98
|
+
|
99
|
+
}
|
100
|
+
}).datepicker('setDate', 'today');
|
101
|
+
|
102
|
+
|
103
|
+
// Setup the end-date picker
|
104
|
+
$('#end-date-rrule').datepicker({
|
105
|
+
showOtherMonths: true,
|
106
|
+
selectOtherMonths: true,
|
107
|
+
dateFormat: 'yy-mm-dd',
|
108
|
+
onSelect: function(value) {
|
109
|
+
dateSelected = new Date(value + ' 00:00:00');
|
110
|
+
untilString = dateSelected.getFullYear() + ('0' + (dateSelected.getMonth() + 1)).slice(-2) + ('0' + dateSelected.getDate()).slice(-2);
|
111
|
+
$('#end-date-hidden').val(untilString + 'T040000z');
|
112
|
+
// Remove the count variable
|
113
|
+
recurringRule.count = '';
|
114
|
+
// Set until variable
|
115
|
+
recurringRule.until = untilString + 'T040000z';
|
116
|
+
}
|
117
|
+
}).datepicker('setDate', 'today');
|
118
|
+
|
119
|
+
if (recur.UNTIL) {
|
120
|
+
// Setup end date picker
|
121
|
+
endYear = recur.UNTIL.substring(0, 4);
|
122
|
+
endMonth = recur.UNTIL.substring(4, 6);
|
123
|
+
endDay = recur.UNTIL.substring(6, 8);
|
124
|
+
|
125
|
+
$('#end-date-rrule').val(endYear + '-' + endMonth + '-' + endDay);
|
126
|
+
$('#end-date-hidden').val(endYear + endMonth + endDay + 'T040000z');
|
127
|
+
|
128
|
+
// Set ENDDATE radio to yes
|
129
|
+
$('input[name="end-select"]').prop('checked', true);
|
130
|
+
}
|
131
|
+
|
132
|
+
// Set Recurring event radio to yes
|
133
|
+
$('input[name="event-recurring"]').prop('checked', true);
|
134
|
+
|
135
|
+
// Show Recurring rules
|
136
|
+
$('#recurring-rules').slideDown();
|
137
|
+
|
138
|
+
// Show Until Rules
|
139
|
+
$('#until-rules').show();
|
140
|
+
|
141
|
+
|
142
|
+
switch (recur.FREQ) {
|
143
|
+
|
144
|
+
case ("DAILY"):
|
145
|
+
|
146
|
+
break;
|
147
|
+
|
148
|
+
case ("WEEKLY"):
|
149
|
+
// Selectbox FREQ = monthly
|
150
|
+
$('select[name="freq"]').val('weekly');
|
151
|
+
|
152
|
+
// Hide all DIVS
|
153
|
+
$('#recurring-rules > div').hide();
|
154
|
+
|
155
|
+
// Show selected DIV
|
156
|
+
$('div.' + 'weeks-choice').show();
|
157
|
+
$('span.freq-selection').text('week(s)');
|
158
|
+
|
159
|
+
// Show Until / Count Rules
|
160
|
+
$('#until-rules').show();
|
161
|
+
|
162
|
+
if (typeof recur.BYDAY !== 'undefined') {
|
163
|
+
|
164
|
+
// Split up the individual bymonthdays
|
165
|
+
bydays = recur.BYDAY.split(',');
|
166
|
+
|
167
|
+
// Loop through the BYDAYs
|
168
|
+
for (v = 0; v < bydays.length; v++) {
|
169
|
+
console.log(bydays[v]);
|
170
|
+
// Set select monthday buttons to active
|
171
|
+
$('#weekday-select button[id="' + bydays[v] + '"]').addClass('active')
|
172
|
+
}
|
173
|
+
recurringRule.byday = recur.BYDAY;
|
174
|
+
|
175
|
+
return true;
|
176
|
+
}
|
177
|
+
|
178
|
+
break;
|
179
|
+
|
180
|
+
case ("MONTHLY"):
|
181
|
+
// Selectbox FREQ = monthly
|
182
|
+
$('select[name="freq"]').val('monthly');
|
183
|
+
|
184
|
+
// Hide all DIVS
|
185
|
+
$('#recurring-rules > div').hide();
|
186
|
+
|
187
|
+
// Show selected DIV
|
188
|
+
$('div.' + 'months-choice').show();
|
189
|
+
$('span.freq-selection').text('month(s)');
|
190
|
+
|
191
|
+
// Show Until / Count Rules
|
192
|
+
$('#until-rules').show();
|
193
|
+
|
194
|
+
if (typeof recur.BYMONTHDAY !== 'undefined') {
|
195
|
+
|
196
|
+
// Split up the individual bymonthdays
|
197
|
+
bymonthdays = recur.BYMONTHDAY.split(',');
|
198
|
+
|
199
|
+
// Loop through the BYMONTHDAYs
|
200
|
+
for (v = 0; v < bymonthdays.length; v++) {
|
201
|
+
console.log(bymonthdays[v]);
|
202
|
+
// Set select monthday buttons to active
|
203
|
+
$('#monthday-select button[data-day-num="' + bymonthdays[v] + '"]').addClass('active')
|
204
|
+
}
|
205
|
+
recurringRule.bymonthday = recur.BYMONTHDAY;
|
206
|
+
|
207
|
+
return true;
|
208
|
+
}
|
209
|
+
|
210
|
+
if (typeof recur.BYSETPOS !== 'undefined' && typeof recur.BYDAY !== 'undefined') {
|
211
|
+
|
212
|
+
// Set Radio Button
|
213
|
+
$('input#month-byday-pos-selected').prop('checked', true);
|
214
|
+
|
215
|
+
// alert(recur.BYDAY);
|
216
|
+
$('select[name^="month-byday"]').removeAttr('disabled');
|
217
|
+
|
218
|
+
// Set values
|
219
|
+
$('select[name="month-byday-pos"]').val(recur.BYSETPOS);
|
220
|
+
$('select[name="month-byday-pos-name"]').val(recur.BYDAY);
|
221
|
+
|
222
|
+
|
223
|
+
//Disable day buttons
|
224
|
+
$('#monthday-select button').attr('disabled', 'disabled');
|
225
|
+
|
226
|
+
recurringRule.bysetpos = recur.BYSETPOS;
|
227
|
+
recurringRule.byday = recur.BYDAY;
|
228
|
+
|
229
|
+
return true;
|
230
|
+
}
|
231
|
+
|
232
|
+
|
233
|
+
|
234
|
+
break;
|
235
|
+
|
236
|
+
case ("YEARLY"):
|
237
|
+
// Selectbox FREQ = monthly
|
238
|
+
$('select[name="freq"]').val('yearly');
|
239
|
+
|
240
|
+
// Hide all DIVS
|
241
|
+
$('#recurring-rules > div').hide();
|
242
|
+
|
243
|
+
// Show selected DIV
|
244
|
+
$('div.' + 'years-choice').show();
|
245
|
+
$('span.freq-selection').text('year(s)');
|
246
|
+
|
247
|
+
// Show Until / Count Rules
|
248
|
+
$('#until-rules').show();
|
249
|
+
|
250
|
+
// BYMONTH and BYMONTHDAY attributes are going to be set
|
251
|
+
if (typeof recur.BYMONTHDAY !== 'undefined' && typeof recur.BYMONTH !== 'undefined') {
|
252
|
+
|
253
|
+
// Set Radio Button
|
254
|
+
$('input#yearly-one-month').prop('checked', true);
|
255
|
+
|
256
|
+
// alert(recur.BYDAY);
|
257
|
+
$('select[name="yearly-bymonth"]').removeAttr('disabled');
|
258
|
+
$('select[name="yearly-bymonthday"]').removeAttr('disabled');
|
259
|
+
|
260
|
+
// Set values
|
261
|
+
$('select[name="yearly-bymonth"]').val(recur.BYMONTH);
|
262
|
+
$('select[name="yearly-bymonthday"]').val(recur.BYMONTHDAY);
|
263
|
+
|
264
|
+
|
265
|
+
recurringRule.bymonth = recur.BYMONTH;
|
266
|
+
recurringRule.bymonthday = recur.BYMONTHDAY;
|
267
|
+
|
268
|
+
return true;
|
269
|
+
}
|
270
|
+
|
271
|
+
// Multiple Month Selection
|
272
|
+
if (typeof recur.BYMONTH !== 'undefined' && typeof recur.BYMONTHDAY == 'undefined') {
|
273
|
+
// Disable yearly select boxes
|
274
|
+
$('select[name^=yearly-').attr('disabled', 'disabled');
|
275
|
+
// Set Radio Button
|
276
|
+
$('input#yearly-multiple-months').prop('checked', true);
|
277
|
+
|
278
|
+
// Make buttons active
|
279
|
+
$('.yearly-multiple-months button').removeAttr('disabled');
|
280
|
+
// Split up the individual bymonthdays
|
281
|
+
bymonth = recur.BYMONTH.split(',');
|
282
|
+
|
283
|
+
// Loop through the BYMONTHDAYs
|
284
|
+
for (v = 0; v < bymonth.length; v++) {
|
285
|
+
console.log(bymonth[v]);
|
286
|
+
// Set select monthday buttons to active
|
287
|
+
$('.yearly-multiple-months button[data-month-num="' + bymonth[v] + '"]').addClass('active')
|
288
|
+
}
|
289
|
+
recurringRule.bymonth = recur.BYMONTH;
|
290
|
+
|
291
|
+
return true;
|
292
|
+
}
|
293
|
+
|
294
|
+
// Precise Yearly Selection
|
295
|
+
if (typeof recur.BYMONTH !== 'undefined' && typeof recur.BYDAY !== 'undefined' && typeof recur.BYSETPOS !== 'undefined') {
|
296
|
+
// Disable yearly select boxes
|
297
|
+
$('select[name^=yearly-').attr('disabled', 'disabled');
|
298
|
+
|
299
|
+
// Enable the right select
|
300
|
+
$('select[class=yearly-precise').removeAttr('disabled');
|
301
|
+
|
302
|
+
// Set Radio Button
|
303
|
+
$('input#yearly-precise').prop('checked', true);
|
304
|
+
|
305
|
+
// Set select values
|
306
|
+
$('select[name="yearly-byday"]').val(recur.BYDAY);
|
307
|
+
$('select[name="yearly-bysetpos"]').val(recur.BYSETPOS);
|
308
|
+
|
309
|
+
recurringRule.bymonth = recur.BYMONTH;
|
310
|
+
recurringRule.byday = recur.BYDAY;
|
311
|
+
recurringRule.bysetpos = recur.BYSETPOS;
|
312
|
+
|
313
|
+
return true;
|
314
|
+
}
|
315
|
+
|
316
|
+
|
317
|
+
break;
|
318
|
+
|
319
|
+
}
|
320
|
+
|
321
|
+
}
|
322
|
+
}
|
323
|
+
|
324
|
+
return false;
|
325
|
+
|
326
|
+
},
|
327
|
+
|
328
|
+
readRuleState: false,
|
329
|
+
resetOptions: function() {
|
330
|
+
|
331
|
+
// Format the date (http://stackoverflow.com/questions/3605214/javascript-add-leading-zeroes-to-date)
|
332
|
+
today = new Date();
|
333
|
+
MyDateString = today.getFullYear() + ('0' + (today.getMonth() + 1)).slice(-2) + ('0' + today.getDate()).slice(-2);
|
334
|
+
|
335
|
+
// Reset all the selected rules
|
336
|
+
recurringRule = {
|
337
|
+
freq: "daily",
|
338
|
+
dtstart: MyDateString + 'T040000z',
|
339
|
+
interval: "1",
|
340
|
+
byday: "",
|
341
|
+
bysetpos: "",
|
342
|
+
bymonthday: "",
|
343
|
+
bymonth: "",
|
344
|
+
count: "",
|
345
|
+
until: MyDateString + 'T040000z'
|
346
|
+
|
347
|
+
};
|
348
|
+
|
349
|
+
// Reset all button states and input values
|
350
|
+
$('button').removeClass('active');
|
351
|
+
|
352
|
+
// Reset back interval label to 'days'
|
353
|
+
$('span.freq-selection').text('days');
|
354
|
+
|
355
|
+
// Hide all but the daily options
|
356
|
+
|
357
|
+
$('#monthday-select,#bymonth-select,#weekday-select').hide();
|
358
|
+
|
359
|
+
// Reset Interval back to 1
|
360
|
+
$('input[name="interval"]').val("1");
|
361
|
+
|
362
|
+
// Reset Count back to 1
|
363
|
+
$('input[name="count"]').val("1");
|
364
|
+
|
365
|
+
|
366
|
+
// Change back Daily
|
367
|
+
$('select[name="freq"]').val('daily');
|
368
|
+
|
369
|
+
// Reset Until / Count radio buttons
|
370
|
+
$('input[id="until-select"]').prop('checked', false);
|
371
|
+
$('input[id="count-select"]').prop('checked', true).change();
|
372
|
+
// $('#count').reset();
|
373
|
+
},
|
374
|
+
rruleGenerate: function() {
|
375
|
+
// Produce RRULE state to feed to rrule.js
|
376
|
+
rrule = "";
|
377
|
+
|
378
|
+
// Check to be sure there is a count value or until date selected
|
379
|
+
if (recurringRule.count == "" && recurringRule.until == "") {
|
380
|
+
// No end in sight, make it default to 1 occurence
|
381
|
+
recurringRule.count = "1";
|
382
|
+
}
|
383
|
+
for (var key in recurringRule) {
|
384
|
+
if (recurringRule.hasOwnProperty(key)) {
|
385
|
+
if (recurringRule[key] != '') {
|
386
|
+
rrule += key + '=' + recurringRule[key] + ';';
|
387
|
+
}
|
388
|
+
}
|
389
|
+
}
|
390
|
+
// Remove the last semicolon from the end of RRULE
|
391
|
+
rrule = rrule.replace(/;\s*$/, "");
|
392
|
+
|
393
|
+
// Convert to Uppercase and return
|
394
|
+
return rrule.toUpperCase();
|
395
|
+
},
|
396
|
+
initialize: function(selector, callback) {
|
397
|
+
if (!$(selector).length) return;
|
398
|
+
|
399
|
+
$('<a class="btn btn-small btn-default" data-toggle="modal" data-target="#rrule_form_modal-' + selector.replace(/[^\w\s]/g, '_') + '" href="#">change</a>').insertAfter($(selector)[0])
|
400
|
+
if ($(selector).val() != '') {
|
401
|
+
RruleForm.readRule($(selector).val())
|
402
|
+
} else {
|
403
|
+
RruleForm.resetOptions();
|
404
|
+
// Setup start-date picker
|
405
|
+
$('#start-date-rrule').datepicker({
|
406
|
+
showOtherMonths: true,
|
407
|
+
selectOtherMonths: true,
|
408
|
+
dateFormat: 'dd/mm/yy',
|
409
|
+
onSelect: function(value) {
|
410
|
+
|
411
|
+
dateSelected = new Date(value.replace(/-/g, "/") + ' 00:00:00'); // REGEX used to please SAFARI browser!
|
412
|
+
dtstartString = dateSelected.getFullYear() + ('0' + (dateSelected.getMonth() + 1)).slice(-2) + ('0' + dateSelected.getDate()).slice(-2);
|
413
|
+
$('#start-date-hidden').val(dtstartString + 'T040000z');
|
414
|
+
recurringRule.dtstart = dtstartString + 'T040000z';
|
415
|
+
|
416
|
+
// Set minimum selected date on end-datepicker
|
417
|
+
minEndDate = dateSelected.getFullYear() + '-' + ('0' + (dateSelected.getMonth() + 1)).slice(-2) + '-' + ('0' + dateSelected.getDate()).slice(-2);
|
418
|
+
$('#end-date-rrule').datepicker('option', 'minDate', minEndDate);
|
419
|
+
// Reset the selected enddate
|
420
|
+
$('#end-date-hidden').val(dtstartString + 'T040000z');
|
421
|
+
//alert(dateSelected);
|
422
|
+
}
|
423
|
+
}).datepicker('setDate', 'today');
|
424
|
+
|
425
|
+
$('#start-date-hidden').val(MyDateString + 'T000000z');
|
426
|
+
|
427
|
+
// Setup the end-date picker
|
428
|
+
$('#end-date-rrule').datepicker({
|
429
|
+
showOtherMonths: true,
|
430
|
+
selectOtherMonths: true,
|
431
|
+
dateFormat: 'dd/mm/yy',
|
432
|
+
onSelect: function(value) {
|
433
|
+
//dateSelected = Date.parseExact(value, "yyyy-MM-dd");
|
434
|
+
dateSelected = new Date(value.replace(/-/g, "/") + ' 00:00:00'); // REGEX used to please SAFARI browser!
|
435
|
+
untilString = dateSelected.getFullYear() + ('0' + (dateSelected.getMonth() + 1)).slice(-2) + ('0' + dateSelected.getDate()).slice(-2);
|
436
|
+
$('#end-date-hidden').val(untilString + 'T040000z');
|
437
|
+
// Remove the count variable
|
438
|
+
recurringRule.count = '';
|
439
|
+
// Set until variable
|
440
|
+
recurringRule.until = untilString + 'T040000z';
|
441
|
+
|
442
|
+
//alert(dateSelected);
|
443
|
+
}
|
444
|
+
}).datepicker('setDate', 'today');
|
445
|
+
|
446
|
+
|
447
|
+
$('#end-date-hidden').val(MyDateString + 'T040000z');
|
448
|
+
|
449
|
+
}
|
450
|
+
|
451
|
+
|
452
|
+
// Setup buttons Don't allow any buttons to submit the form
|
453
|
+
$('button').click(function(e) {
|
454
|
+
e.preventDefault;
|
455
|
+
return false;
|
456
|
+
});
|
457
|
+
|
458
|
+
|
459
|
+
|
460
|
+
// Recurring Event Calculator: Show/Hide. Grab all the radio buttons to see which one.
|
461
|
+
$('input[name="event-recurring"]').change(function() {
|
462
|
+
|
463
|
+
// Resets all the recurring options
|
464
|
+
RruleForm.resetOptions();
|
465
|
+
// enable the input next to the selected radio button
|
466
|
+
if ($(this).val() == "yes") {
|
467
|
+
$('#recurring-rules').slideDown();
|
468
|
+
|
469
|
+
// Show Until Rules
|
470
|
+
$('#until-rules').show();
|
471
|
+
|
472
|
+
} else {
|
473
|
+
//disable the inputs not selected.
|
474
|
+
$('#recurring-rules').hide();
|
475
|
+
}
|
476
|
+
|
477
|
+
});
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
// FREQ Selection
|
482
|
+
$(document).on('change', 'select[name="freq"]', function() {
|
483
|
+
|
484
|
+
selectedFrequency = $('select[name="freq"] option:selected').attr('class');
|
485
|
+
|
486
|
+
// Hide all DIVS
|
487
|
+
$('#recurring-rules > div').hide();
|
488
|
+
|
489
|
+
// Show selected DIV
|
490
|
+
$('div.' + selectedFrequency + '-choice').show();
|
491
|
+
$('span.freq-selection').text(selectedFrequency);
|
492
|
+
|
493
|
+
// Show Until / Count Rules
|
494
|
+
$('#until-rules').show();
|
495
|
+
|
496
|
+
|
497
|
+
// Reset all the selected rules
|
498
|
+
recurringRule = {
|
499
|
+
freq: "",
|
500
|
+
dtstart: $('#start-date-hidden').val(),
|
501
|
+
interval: "1",
|
502
|
+
byday: "",
|
503
|
+
bysetpos: "",
|
504
|
+
bymonthday: "",
|
505
|
+
bymonth: "",
|
506
|
+
count: "1",
|
507
|
+
until: ""
|
508
|
+
|
509
|
+
};
|
510
|
+
|
511
|
+
// Set frequency
|
512
|
+
recurringRule.freq = $('select[name="freq"] option:selected').val();
|
513
|
+
|
514
|
+
// If it is yearly, fire a change to setup the default values
|
515
|
+
if (recurringRule.freq == "yearly") {
|
516
|
+
$('select[name="yearly-bymonth"]').change();
|
517
|
+
}
|
518
|
+
|
519
|
+
});
|
520
|
+
|
521
|
+
// Interval Selection
|
522
|
+
$(document).on('change blur keyup', 'input[name="interval"]', function() {
|
523
|
+
recurringRule.interval = $(this).val();
|
524
|
+
|
525
|
+
});
|
526
|
+
|
527
|
+
// BYDAY - FREQ: WEEKLY Selection
|
528
|
+
$('#weekday-select button').on('click', function() {
|
529
|
+
$(this).toggleClass('active');
|
530
|
+
var byday = []; // Array to Store 'byday' in. Reset it to '' to store new days in below
|
531
|
+
|
532
|
+
// Store Selected Days in the BYDAY rule
|
533
|
+
$('#weekday-select button').each(function() {
|
534
|
+
|
535
|
+
// Active class is the selected day, store the ID of active days which contains the short day name for the rrule (ex. MO, TU, WE, etc)
|
536
|
+
if ($(this).hasClass('active')) {
|
537
|
+
byday.push($(this).attr('id'));
|
538
|
+
}
|
539
|
+
|
540
|
+
});
|
541
|
+
recurringRule.byday = byday;
|
542
|
+
|
543
|
+
});
|
544
|
+
|
545
|
+
// BYMONTHDAY Selection
|
546
|
+
$('#monthday-select button').on('click', function() {
|
547
|
+
$(this).toggleClass('active');
|
548
|
+
var bymonthday = []; // Array to Store 'bymonthday' in. Reset it to '' to store new days in below
|
549
|
+
|
550
|
+
// Store Selected Days in the BYDAY rule
|
551
|
+
$('#monthday-select button').each(function() {
|
552
|
+
|
553
|
+
// Active class is the selected day, store the ID of active days which contains the short day name for the rrule (ex. MO, TU, WE, etc)
|
554
|
+
if ($(this).hasClass('active')) {
|
555
|
+
bymonthday.push($(this).attr('data-day-num'));
|
556
|
+
}
|
557
|
+
|
558
|
+
});
|
559
|
+
recurringRule.bymonthday = bymonthday;
|
560
|
+
|
561
|
+
// Reset BYDAY Option
|
562
|
+
recurringRule.byday = "";
|
563
|
+
|
564
|
+
// Reset BySetPos
|
565
|
+
recurringRule.bysetpos = "";
|
566
|
+
});
|
567
|
+
|
568
|
+
// BYMONTH Selection
|
569
|
+
$('#bymonth-select button').on('click', function() {
|
570
|
+
$(this).toggleClass('active');
|
571
|
+
var bymonth = []; // Array to Store 'byday' in. Reset it to '' to store new days in below
|
572
|
+
|
573
|
+
// Store Selected Days in the BYDAY rule
|
574
|
+
$('#bymonth-select button').each(function() {
|
575
|
+
|
576
|
+
// Active class is the selected day, store the ID of active days which contains the short day name for the rrule (ex. MO, TU, WE, etc)
|
577
|
+
if ($(this).hasClass('active')) {
|
578
|
+
bymonth.push($(this).attr('data-month-num'));
|
579
|
+
}
|
580
|
+
|
581
|
+
});
|
582
|
+
recurringRule.bymonth = bymonth;
|
583
|
+
});
|
584
|
+
|
585
|
+
|
586
|
+
// FREQ=MONTHLY - RADIO BUTTONS
|
587
|
+
$('input[name="monthday-pos-select"]').change(function() {
|
588
|
+
|
589
|
+
// Selected Radio Button
|
590
|
+
var selectedRadio = $(this).val();
|
591
|
+
|
592
|
+
// A Radio was changed. Grab all the radio buttons to see which one.
|
593
|
+
$('input[name="monthday-pos-select"]').each(function() {
|
594
|
+
|
595
|
+
if ($(this).val() == selectedRadio) {
|
596
|
+
|
597
|
+
switch ($(this).val()) {
|
598
|
+
case "month-byday-pos-selected":
|
599
|
+
// ByDay Select Boxes are being used instead of the Month Day
|
600
|
+
|
601
|
+
// Disable all the monthday buttons
|
602
|
+
$('#monthday-select button').attr('disabled', 'disabled');
|
603
|
+
$('select[name^="month-byday"]').removeAttr('disabled');
|
604
|
+
|
605
|
+
// Generate the BYDAY variable from selected dropdowns by firing 'change' event
|
606
|
+
$('select[name^="month-byday"]').change();
|
607
|
+
// Mark recurring object bymonthday back to nothing
|
608
|
+
recurringRule.bymonthday = "";
|
609
|
+
|
610
|
+
break;
|
611
|
+
|
612
|
+
case "monthday-selected":
|
613
|
+
|
614
|
+
// Month Day Buttons are being used instead of the ByDay select boxes
|
615
|
+
$('#monthday-select button').removeAttr('disabled');
|
616
|
+
$('#monthday-select button').removeClass('active');
|
617
|
+
|
618
|
+
$('select[name^="month-byday"]').attr('disabled', 'disabled');
|
619
|
+
recurringRule.byday = "";
|
620
|
+
recurringRule.bysetpos = "";
|
621
|
+
|
622
|
+
|
623
|
+
break;
|
624
|
+
|
625
|
+
}
|
626
|
+
}
|
627
|
+
|
628
|
+
});
|
629
|
+
});
|
630
|
+
|
631
|
+
// FREQ=YEARLY - RADIO BUTTONS
|
632
|
+
$('input[name="yearly-options"]').change(function() {
|
633
|
+
|
634
|
+
// Selected Radio Button ID
|
635
|
+
var selectedRadio = $(this).attr('id');
|
636
|
+
|
637
|
+
// A Radio was changed. Check all the radio buttons' ids to see which one.
|
638
|
+
$('input[name="yearly-options"]').each(function() {
|
639
|
+
|
640
|
+
if ($(this).attr('id') == selectedRadio) {
|
641
|
+
|
642
|
+
switch ($(this).attr('id')) {
|
643
|
+
case "yearly-one-month":
|
644
|
+
// Example Pattern
|
645
|
+
// FREQ=YEARLY;BYMONTH=1;BYMONTHDAY=1;UNTIL=20150818;
|
646
|
+
|
647
|
+
// BYMONTH and BYMONTHDAY attributes are going to be set
|
648
|
+
// Reset BYSETPOS, BYDAY,
|
649
|
+
recurringRule.bysetpos = "";
|
650
|
+
recurringRule.byday = "";
|
651
|
+
|
652
|
+
// Disable all the yearly select boxes
|
653
|
+
$('select[class^="yearly"]').attr('disabled', 'disabled');
|
654
|
+
|
655
|
+
// Disable all the yearly multiple month buttons
|
656
|
+
$('.yearly-multiple-months button').attr('disabled', 'disabled');
|
657
|
+
$('.yearly-multiple-months button').removeClass('active');
|
658
|
+
|
659
|
+
// Enable Yearly One Month Options
|
660
|
+
$('select[class="yearly-one-month"]').removeAttr('disabled');
|
661
|
+
|
662
|
+
// Fire change to select default values
|
663
|
+
$('select[name="yearly-bymonth"]').change();
|
664
|
+
|
665
|
+
break;
|
666
|
+
|
667
|
+
case "yearly-multiple-months":
|
668
|
+
// Example Pattern
|
669
|
+
// FREQ=YEARLY;INTERVAL=1;BYMONTH=1,3,4,10;COUNT=1
|
670
|
+
|
671
|
+
// BYMONTH attribute is going to be set
|
672
|
+
// Reset BYMONTHDAY, BYDAY, BYSETPOS
|
673
|
+
recurringRule.bymonthday = "";
|
674
|
+
recurringRule.byday = "";
|
675
|
+
recurringRule.bysetpos = "";
|
676
|
+
|
677
|
+
// Disable all the monthday buttons
|
678
|
+
$('select[class^="yearly"]').attr('disabled', 'disabled');
|
679
|
+
|
680
|
+
// Enable the buttons
|
681
|
+
$('.yearly-multiple-months button').removeAttr('disabled');
|
682
|
+
|
683
|
+
|
684
|
+
break;
|
685
|
+
|
686
|
+
case "yearly-precise":
|
687
|
+
// Example Pattern
|
688
|
+
// FREQ=YEARLY;BYDAY=SU;BYSETPOS=1;BYMONTH=1;UNTIL=20150818;
|
689
|
+
|
690
|
+
// BYDAY, BYSETPOS, and BYMONTH are going to be set
|
691
|
+
// Reset BYMONTHDAY
|
692
|
+
recurringRule.bymonthday = "";
|
693
|
+
|
694
|
+
// Disable all the yearly select boxes
|
695
|
+
$('select[class^="yearly"]').attr('disabled', 'disabled');
|
696
|
+
|
697
|
+
// Disable all the yearly multiple month buttons
|
698
|
+
$('.yearly-multiple-months button').attr('disabled', 'disabled');
|
699
|
+
$('.yearly-multiple-months button').removeClass('active');
|
700
|
+
|
701
|
+
// Enable Yearly One Month Options
|
702
|
+
$('select[class="yearly-precise"]').removeAttr('disabled');
|
703
|
+
|
704
|
+
// Fire change to select default values
|
705
|
+
$('select[name="yearly-bysetpos"]').change();
|
706
|
+
break;
|
707
|
+
}
|
708
|
+
}
|
709
|
+
|
710
|
+
});
|
711
|
+
});
|
712
|
+
|
713
|
+
// FREQ=YEARLY - Yearly One Month selection
|
714
|
+
// Example Pattern
|
715
|
+
// FREQ=YEARLY;BYMONTH=1;BYMONTHDAY=1;UNTIL=20150818;
|
716
|
+
|
717
|
+
// BYMONTH and BYMONTHDAY attributes are going to be set
|
718
|
+
|
719
|
+
$(document).on('change', 'select[name^="yearly-bymonth"]', function() {
|
720
|
+
// Example Pattern
|
721
|
+
// FREQ=MONTHLY;INTERVAL=1;BYDAY=SU,SA;BYSETPOS=1;COUNT=1
|
722
|
+
|
723
|
+
// First, Second, Third, Fourth or Last Days
|
724
|
+
var bymonth = $('select[name="yearly-bymonth"]').val();
|
725
|
+
|
726
|
+
// Make array of selected days.
|
727
|
+
var bymonthday = $('select[name="yearly-bymonthday"]').val();
|
728
|
+
|
729
|
+
recurringRule.bymonth = bymonth;
|
730
|
+
recurringRule.bymonthday = bymonthday;
|
731
|
+
});
|
732
|
+
|
733
|
+
// FREQ=YEARLY - Yearly Multiple Month selection
|
734
|
+
// Example Pattern
|
735
|
+
// FREQ=YEARLY;INTERVAL=1;BYMONTH=1,3,4,10;COUNT=1
|
736
|
+
$(document).on('click', '.yearly-multiple-months button', function() {
|
737
|
+
$(this).toggleClass('active');
|
738
|
+
var bymonth = []; // Array to Store 'bymonth' in. Reset it to '' to store new days in below
|
739
|
+
|
740
|
+
// Store Selected Days in the BYDAY rule
|
741
|
+
$('.yearly-multiple-months button').each(function() {
|
742
|
+
|
743
|
+
// Active class is the selected day, store the ID of active days which contains the short day name for the rrule (ex. MO, TU, WE, etc)
|
744
|
+
if ($(this).hasClass('active')) {
|
745
|
+
bymonth.push($(this).attr('data-month-num'));
|
746
|
+
}
|
747
|
+
|
748
|
+
});
|
749
|
+
recurringRule.bymonth = bymonth;
|
750
|
+
});
|
751
|
+
|
752
|
+
// FREQ=YEARLY - Yearly Precise Selection
|
753
|
+
// Example PAttern
|
754
|
+
// FREQ=YEARLY;BYDAY=SU;BYSETPOS=1;BYMONTH=1;UNTIL=20150818;
|
755
|
+
|
756
|
+
// BYDAY, BYSETPOS, and BYMONTH are going to be set
|
757
|
+
|
758
|
+
$(document).on('change', 'select[name="yearly-bysetpos"], select[name="yearly-byday"], select[name="yearly-bymonth-with-bysetpos-byday"]', function() {
|
759
|
+
// Example Pattern
|
760
|
+
// FREQ=MONTHLY;INTERVAL=1;BYDAY=SU,SA;BYSETPOS=1;COUNT=1
|
761
|
+
|
762
|
+
// First, Second, Third, Fourth or Last Days
|
763
|
+
var bysetpos = $('select[name="yearly-bysetpos"]').val();
|
764
|
+
|
765
|
+
// Make array of selected days.
|
766
|
+
var byday = $('select[name="yearly-byday"]').val().split(',');
|
767
|
+
|
768
|
+
// First, Second, Third, Fourth or Last Days
|
769
|
+
var bymonth = $('select[name="yearly-bymonth-with-bysetpos-byday"]').val();
|
770
|
+
//alert($('select[name="yearly-bymonth-with-bysetpos-byday"]').val());
|
771
|
+
|
772
|
+
recurringRule.bymonthday = "";
|
773
|
+
|
774
|
+
recurringRule.bymonth = bymonth;
|
775
|
+
recurringRule.byday = byday;
|
776
|
+
recurringRule.bysetpos = bysetpos;
|
777
|
+
});
|
778
|
+
|
779
|
+
|
780
|
+
// FREQ=MONTHLY
|
781
|
+
// BYDAY and BYSETPOS MONTHLY Setting
|
782
|
+
|
783
|
+
$(document).on('change', 'select[name^="month-byday"]', function() {
|
784
|
+
// Example Pattern
|
785
|
+
// FREQ=MONTHLY;INTERVAL=1;BYDAY=SU,SA;BYSETPOS=1;COUNT=1
|
786
|
+
|
787
|
+
// First, Second, Third, Fourth or Last Days
|
788
|
+
var bySetPos = $('select[name="month-byday-pos"]').val();
|
789
|
+
|
790
|
+
// Make array of selected days.
|
791
|
+
var daysSelected = $('select[name="month-byday-pos-name"]').val().split(',');
|
792
|
+
|
793
|
+
recurringRule.bysetpos = bySetPos;
|
794
|
+
recurringRule.byday = daysSelected;
|
795
|
+
});
|
796
|
+
|
797
|
+
// Set the count variable
|
798
|
+
$(document).on('input change', 'input[name="count"]', function() {
|
799
|
+
|
800
|
+
recurringRule.count = $(this).val();
|
801
|
+
});
|
802
|
+
|
803
|
+
|
804
|
+
|
805
|
+
// Handle Until / Count Radio Buttons
|
806
|
+
$('input[name="end-select"]').change(function() {
|
807
|
+
|
808
|
+
// Selected Radio Button
|
809
|
+
var selectedRadio = $(this).val();
|
810
|
+
|
811
|
+
// A Radio was changed. Grab all the radio buttons to see which one.
|
812
|
+
$('input[name="end-select"]').each(function() {
|
813
|
+
// enable the input next to the selected radio button
|
814
|
+
if ($(this).val() == selectedRadio) {
|
815
|
+
$('input[name="' + selectedRadio + '"]').removeAttr('disabled');
|
816
|
+
if ($(this).val() == 'until') {
|
817
|
+
// Set the date in the until textbox as the until date
|
818
|
+
|
819
|
+
// Remove the count variable
|
820
|
+
recurringRule.count = '';
|
821
|
+
// Set until variable
|
822
|
+
recurringRule.until = $('#end-date-hidden').val();
|
823
|
+
}
|
824
|
+
} else {
|
825
|
+
//disable the inputs not selected.
|
826
|
+
$(this).next('input').attr('disabled', 'disabled').val('');
|
827
|
+
|
828
|
+
//reset the stored value in the recurringRule object
|
829
|
+
var not_selected = $(this).next('input').attr('name');
|
830
|
+
|
831
|
+
recurringRule[not_selected] = '';
|
832
|
+
|
833
|
+
}
|
834
|
+
|
835
|
+
});
|
836
|
+
});
|
837
|
+
|
838
|
+
// Handle Form Submission
|
839
|
+
$('#rrule-' + selector.replace(/[^\w\s]/g, '_')).submit(function(e) {
|
840
|
+
e.preventDefault();
|
841
|
+
if (callback === '') {
|
842
|
+
$(selector).val(RruleForm.rruleGenerate());
|
843
|
+
} else {
|
844
|
+
callback(RruleForm.rruleGenerate())
|
845
|
+
}
|
846
|
+
$('.modal.in').modal('hide');
|
847
|
+
});
|
848
|
+
}
|
849
|
+
}
|