recurring_select 3.0.1 → 4.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -13
- data/app/assets/javascripts/defaults.js +31 -0
- data/app/assets/javascripts/jquery-mobile-rs.js +20 -0
- data/app/assets/javascripts/recurring_select/{fr.js.coffee → fr.js} +2 -2
- data/app/assets/javascripts/recurring_select.js +96 -0
- data/app/assets/javascripts/recurring_select_dialog.js.erb +447 -0
- data/app/assets/javascripts/utils.js +70 -0
- data/app/assets/stylesheets/recurring_select.scss +37 -9
- data/lib/helpers/recurring_select_helper.rb +11 -10
- data/lib/recurring_select/engine.rb +1 -0
- data/lib/recurring_select/version.rb +1 -1
- data/lib/recurring_select.rb +1 -1
- metadata +16 -42
- data/app/assets/javascripts/jquery-mobile-rs.js.coffee +0 -15
- data/app/assets/javascripts/recurring_select.js.coffee +0 -105
- data/app/assets/javascripts/recurring_select_dialog.js.coffee.erb +0 -372
@@ -1,372 +0,0 @@
|
|
1
|
-
window.RecurringSelectDialog =
|
2
|
-
class RecurringSelectDialog
|
3
|
-
constructor: (@recurring_selector) ->
|
4
|
-
@current_rule = @recurring_selector.recurring_select('current_rule')
|
5
|
-
@initDialogBox()
|
6
|
-
if not @current_rule.hash? or not @current_rule.hash.rule_type?
|
7
|
-
@freqChanged()
|
8
|
-
else
|
9
|
-
setTimeout @positionDialogVert, 10 # allow initial render
|
10
|
-
|
11
|
-
initDialogBox: ->
|
12
|
-
$(".rs_dialog_holder").remove()
|
13
|
-
|
14
|
-
open_in = $("body")
|
15
|
-
open_in = $(".ui-page-active") if $(".ui-page-active").length
|
16
|
-
open_in.append @template()
|
17
|
-
@outer_holder = $(".rs_dialog_holder")
|
18
|
-
@inner_holder = @outer_holder.find ".rs_dialog"
|
19
|
-
@content = @outer_holder.find ".rs_dialog_content"
|
20
|
-
@positionDialogVert(true)
|
21
|
-
@mainEventInit()
|
22
|
-
@freqInit()
|
23
|
-
@summaryInit()
|
24
|
-
@outer_holder.trigger "recurring_select:dialog_opened"
|
25
|
-
@freq_select.focus()
|
26
|
-
|
27
|
-
positionDialogVert: (initial_positioning) =>
|
28
|
-
window_height = $(window).height()
|
29
|
-
window_width = $(window).width()
|
30
|
-
dialog_height = @content.outerHeight()
|
31
|
-
if dialog_height < 80
|
32
|
-
dialog_height = 80
|
33
|
-
margin_top = (window_height - dialog_height)/2 - 30
|
34
|
-
margin_top = 10 if margin_top < 10
|
35
|
-
# if dialog_height > window_height - 20
|
36
|
-
# dialog_height = window_height - 20
|
37
|
-
|
38
|
-
new_style_hash =
|
39
|
-
"margin-top" : margin_top+"px"
|
40
|
-
"min-height" : dialog_height+"px"
|
41
|
-
|
42
|
-
if initial_positioning?
|
43
|
-
@inner_holder.css new_style_hash
|
44
|
-
@inner_holder.trigger "recurring_select:dialog_positioned"
|
45
|
-
else
|
46
|
-
@inner_holder.addClass "animated"
|
47
|
-
@inner_holder.animate new_style_hash, 200, =>
|
48
|
-
@inner_holder.removeClass "animated"
|
49
|
-
@content.css {"width": "auto"}
|
50
|
-
@inner_holder.trigger "recurring_select:dialog_positioned"
|
51
|
-
|
52
|
-
cancel: =>
|
53
|
-
@outer_holder.remove()
|
54
|
-
@recurring_selector.recurring_select('cancel')
|
55
|
-
|
56
|
-
outerCancel: (event) =>
|
57
|
-
if $(event.target).hasClass("rs_dialog_holder")
|
58
|
-
@cancel()
|
59
|
-
|
60
|
-
save: =>
|
61
|
-
return if !@current_rule.str?
|
62
|
-
@outer_holder.remove()
|
63
|
-
@recurring_selector.recurring_select('save', @current_rule)
|
64
|
-
|
65
|
-
# ========================= Init Methods ===============================
|
66
|
-
|
67
|
-
mainEventInit: ->
|
68
|
-
# Tap hooks are for jQueryMobile
|
69
|
-
@outer_holder.on 'click tap', @outerCancel
|
70
|
-
@content.on 'click tap', 'h1 a', @cancel
|
71
|
-
@save_button = @content.find('input.rs_save').on "click tap", @save
|
72
|
-
@content.find('input.rs_cancel').on "click tap", @cancel
|
73
|
-
|
74
|
-
freqInit: ->
|
75
|
-
@freq_select = @outer_holder.find ".rs_frequency"
|
76
|
-
if @current_rule.hash? && (rule_type = @current_rule.hash.rule_type)?
|
77
|
-
if rule_type.search(/Weekly/) != -1
|
78
|
-
@freq_select.prop('selectedIndex', 1)
|
79
|
-
@initWeeklyOptions()
|
80
|
-
else if rule_type.search(/Monthly/) != -1
|
81
|
-
@freq_select.prop('selectedIndex', 2)
|
82
|
-
@initMonthlyOptions()
|
83
|
-
else if rule_type.search(/Yearly/) != -1
|
84
|
-
@freq_select.prop('selectedIndex', 3)
|
85
|
-
@initYearlyOptions()
|
86
|
-
else
|
87
|
-
@initDailyOptions()
|
88
|
-
@freq_select.on "change", @freqChanged
|
89
|
-
|
90
|
-
initDailyOptions: ->
|
91
|
-
section = @content.find('.daily_options')
|
92
|
-
interval_input = section.find('.rs_daily_interval')
|
93
|
-
interval_input.val(@current_rule.hash.interval)
|
94
|
-
interval_input.on "change keyup", @intervalChanged
|
95
|
-
section.show()
|
96
|
-
|
97
|
-
initWeeklyOptions: ->
|
98
|
-
section = @content.find('.weekly_options')
|
99
|
-
|
100
|
-
# connect the interval field
|
101
|
-
interval_input = section.find('.rs_weekly_interval')
|
102
|
-
interval_input.val(@current_rule.hash.interval)
|
103
|
-
interval_input.on "change keyup", @intervalChanged
|
104
|
-
|
105
|
-
# clear selected days
|
106
|
-
section.find(".day_holder a").each (index, element) ->
|
107
|
-
$(element).removeClass("selected")
|
108
|
-
|
109
|
-
# connect the day fields
|
110
|
-
if @current_rule.hash.validations? && @current_rule.hash.validations.day?
|
111
|
-
$(@current_rule.hash.validations.day).each (index, val) ->
|
112
|
-
section.find(".day_holder a[data-value='"+val+"']").addClass("selected")
|
113
|
-
|
114
|
-
section.off('click', '.day_holder a').on "click", ".day_holder a", @daysChanged
|
115
|
-
|
116
|
-
section.show()
|
117
|
-
|
118
|
-
initMonthlyOptions: ->
|
119
|
-
section = @content.find('.monthly_options')
|
120
|
-
interval_input = section.find('.rs_monthly_interval')
|
121
|
-
interval_input.val(@current_rule.hash.interval)
|
122
|
-
interval_input.on "change keyup", @intervalChanged
|
123
|
-
|
124
|
-
@current_rule.hash.validations ||= {}
|
125
|
-
@current_rule.hash.validations.day_of_month ||= []
|
126
|
-
@current_rule.hash.validations.day_of_week ||= {}
|
127
|
-
@init_calendar_days(section)
|
128
|
-
@init_calendar_weeks(section)
|
129
|
-
|
130
|
-
in_week_mode = Object.keys(@current_rule.hash.validations.day_of_week).length > 0
|
131
|
-
section.find(".monthly_rule_type_week").prop("checked", in_week_mode)
|
132
|
-
section.find(".monthly_rule_type_day").prop("checked", !in_week_mode)
|
133
|
-
@toggle_month_view()
|
134
|
-
section.find("input[name=monthly_rule_type]").on "change", @toggle_month_view
|
135
|
-
section.show()
|
136
|
-
|
137
|
-
initYearlyOptions: ->
|
138
|
-
section = @content.find('.yearly_options')
|
139
|
-
interval_input = section.find('.rs_yearly_interval')
|
140
|
-
interval_input.val(@current_rule.hash.interval)
|
141
|
-
interval_input.on "change keyup", @intervalChanged
|
142
|
-
section.show()
|
143
|
-
|
144
|
-
|
145
|
-
summaryInit: ->
|
146
|
-
@summary = @outer_holder.find(".rs_summary")
|
147
|
-
@summaryUpdate()
|
148
|
-
|
149
|
-
# ========================= render methods ===============================
|
150
|
-
|
151
|
-
summaryUpdate: (new_string) =>
|
152
|
-
@summary.width @content.width()
|
153
|
-
if @current_rule.hash? && @current_rule.str?
|
154
|
-
@summary.removeClass "fetching"
|
155
|
-
@save_button.removeClass("disabled")
|
156
|
-
rule_str = @current_rule.str.replace("*", "")
|
157
|
-
if rule_str.length < 20
|
158
|
-
rule_str = "#{$.fn.recurring_select.texts["summary"]}: "+rule_str
|
159
|
-
@summary.find("span").html rule_str
|
160
|
-
else
|
161
|
-
@summary.addClass "fetching"
|
162
|
-
@save_button.addClass("disabled")
|
163
|
-
@summary.find("span").html ""
|
164
|
-
@summaryFetch()
|
165
|
-
|
166
|
-
summaryFetch: ->
|
167
|
-
return if !(@current_rule.hash? && (rule_type = @current_rule.hash.rule_type)?)
|
168
|
-
@current_rule.hash['week_start'] = $.fn.recurring_select.texts["first_day_of_week"]
|
169
|
-
$.ajax
|
170
|
-
url: "<%= Rails.application.config.action_controller.relative_url_root %>/recurring_select/translate/#{$.fn.recurring_select.texts["locale_iso_code"]}",
|
171
|
-
type: "POST",
|
172
|
-
data: @current_rule.hash
|
173
|
-
success: @summaryFetchSuccess
|
174
|
-
|
175
|
-
summaryFetchSuccess: (data) =>
|
176
|
-
@current_rule.str = data
|
177
|
-
@summaryUpdate()
|
178
|
-
@content.css {"width": "auto"}
|
179
|
-
|
180
|
-
init_calendar_days: (section) =>
|
181
|
-
monthly_calendar = section.find(".rs_calendar_day")
|
182
|
-
monthly_calendar.html ""
|
183
|
-
for num in [1..31]
|
184
|
-
monthly_calendar.append (day_link = $(document.createElement("a")).text(num))
|
185
|
-
if $.inArray(num, @current_rule.hash.validations.day_of_month) != -1
|
186
|
-
day_link.addClass("selected")
|
187
|
-
|
188
|
-
# add last day of month button
|
189
|
-
monthly_calendar.append (end_of_month_link = $(document.createElement("a")).text($.fn.recurring_select.texts["last_day"]))
|
190
|
-
end_of_month_link.addClass("end_of_month")
|
191
|
-
if $.inArray(-1, @current_rule.hash.validations.day_of_month) != -1
|
192
|
-
end_of_month_link.addClass("selected")
|
193
|
-
|
194
|
-
monthly_calendar.find("a").on "click tap", @dateOfMonthChanged
|
195
|
-
|
196
|
-
init_calendar_weeks: (section) =>
|
197
|
-
monthly_calendar = section.find(".rs_calendar_week")
|
198
|
-
monthly_calendar.html ""
|
199
|
-
row_labels = $.fn.recurring_select.texts["order"]
|
200
|
-
show_row = $.fn.recurring_select.options["monthly"]["show_week"]
|
201
|
-
cell_str = $.fn.recurring_select.texts["days_first_letter"]
|
202
|
-
|
203
|
-
for num, index in [1, 2, 3, 4, 5, -1]
|
204
|
-
if show_row[index]
|
205
|
-
monthly_calendar.append "<span>#{row_labels[num - 1]}</span>"
|
206
|
-
for day_of_week in [$.fn.recurring_select.texts["first_day_of_week"]...(7 + $.fn.recurring_select.texts["first_day_of_week"])]
|
207
|
-
day_of_week = day_of_week % 7
|
208
|
-
day_link = $("<a>", {text: cell_str[day_of_week] })
|
209
|
-
day_link.attr("day", day_of_week)
|
210
|
-
day_link.attr("instance", num)
|
211
|
-
monthly_calendar.append day_link
|
212
|
-
|
213
|
-
$.each @current_rule.hash.validations.day_of_week, (key, value) ->
|
214
|
-
$.each value, (index, instance) ->
|
215
|
-
section.find("a[day='#{key}'][instance='#{instance}']").addClass("selected")
|
216
|
-
monthly_calendar.find("a").on "click tap", @weekOfMonthChanged
|
217
|
-
|
218
|
-
toggle_month_view: =>
|
219
|
-
week_mode = @content.find(".monthly_rule_type_week").prop("checked")
|
220
|
-
@content.find(".rs_calendar_week").toggle(week_mode)
|
221
|
-
@content.find(".rs_calendar_day").toggle(!week_mode)
|
222
|
-
|
223
|
-
# ========================= Change callbacks ===============================
|
224
|
-
|
225
|
-
freqChanged: =>
|
226
|
-
@current_rule.hash = null unless $.isPlainObject(@current_rule.hash) # for custom values
|
227
|
-
|
228
|
-
@current_rule.hash ||= {}
|
229
|
-
@current_rule.hash.interval = 1
|
230
|
-
@current_rule.hash.until = null
|
231
|
-
@current_rule.hash.count = null
|
232
|
-
@current_rule.hash.validations = null
|
233
|
-
@content.find(".freq_option_section").hide();
|
234
|
-
@content.find("input[type=radio], input[type=checkbox]").prop("checked", false)
|
235
|
-
switch @freq_select.val()
|
236
|
-
when "Weekly"
|
237
|
-
@current_rule.hash.rule_type = "IceCube::WeeklyRule"
|
238
|
-
@current_rule.str = $.fn.recurring_select.texts["weekly"]
|
239
|
-
@initWeeklyOptions()
|
240
|
-
when "Monthly"
|
241
|
-
@current_rule.hash.rule_type = "IceCube::MonthlyRule"
|
242
|
-
@current_rule.str = $.fn.recurring_select.texts["monthly"]
|
243
|
-
@initMonthlyOptions()
|
244
|
-
when "Yearly"
|
245
|
-
@current_rule.hash.rule_type = "IceCube::YearlyRule"
|
246
|
-
@current_rule.str = $.fn.recurring_select.texts["yearly"]
|
247
|
-
@initYearlyOptions()
|
248
|
-
else
|
249
|
-
@current_rule.hash.rule_type = "IceCube::DailyRule"
|
250
|
-
@current_rule.str = $.fn.recurring_select.texts["daily"]
|
251
|
-
@initDailyOptions()
|
252
|
-
@summaryUpdate()
|
253
|
-
@positionDialogVert()
|
254
|
-
|
255
|
-
intervalChanged: (event) =>
|
256
|
-
@current_rule.str = null
|
257
|
-
@current_rule.hash ||= {}
|
258
|
-
@current_rule.hash.interval = parseInt($(event.currentTarget).val())
|
259
|
-
if @current_rule.hash.interval < 1 || isNaN(@current_rule.hash.interval)
|
260
|
-
@current_rule.hash.interval = 1
|
261
|
-
@summaryUpdate()
|
262
|
-
|
263
|
-
daysChanged: (event) =>
|
264
|
-
$(event.currentTarget).toggleClass("selected")
|
265
|
-
@current_rule.str = null
|
266
|
-
@current_rule.hash ||= {}
|
267
|
-
@current_rule.hash.validations = {}
|
268
|
-
raw_days = @content.find(".day_holder a.selected").map -> parseInt($(this).data("value"))
|
269
|
-
@current_rule.hash.validations.day = raw_days.get()
|
270
|
-
@summaryUpdate()
|
271
|
-
false # this prevents default and propogation
|
272
|
-
|
273
|
-
dateOfMonthChanged: (event) =>
|
274
|
-
$(event.currentTarget).toggleClass("selected")
|
275
|
-
@current_rule.str = null
|
276
|
-
@current_rule.hash ||= {}
|
277
|
-
@current_rule.hash.validations = {}
|
278
|
-
raw_days = @content.find(".monthly_options .rs_calendar_day a.selected").map ->
|
279
|
-
res = if $(this).text() == $.fn.recurring_select.texts["last_day"] then -1 else parseInt($(this).text())
|
280
|
-
res
|
281
|
-
@current_rule.hash.validations.day_of_week = {}
|
282
|
-
@current_rule.hash.validations.day_of_month = raw_days.get()
|
283
|
-
@summaryUpdate()
|
284
|
-
false
|
285
|
-
|
286
|
-
weekOfMonthChanged: (event) =>
|
287
|
-
$(event.currentTarget).toggleClass("selected")
|
288
|
-
@current_rule.str = null
|
289
|
-
@current_rule.hash ||= {}
|
290
|
-
@current_rule.hash.validations = {}
|
291
|
-
@current_rule.hash.validations.day_of_month = []
|
292
|
-
@current_rule.hash.validations.day_of_week = {}
|
293
|
-
@content.find(".monthly_options .rs_calendar_week a.selected").each (index, elm) =>
|
294
|
-
day = parseInt($(elm).attr("day"))
|
295
|
-
instance = parseInt($(elm).attr("instance"))
|
296
|
-
@current_rule.hash.validations.day_of_week[day] ||= []
|
297
|
-
@current_rule.hash.validations.day_of_week[day].push instance
|
298
|
-
@summaryUpdate()
|
299
|
-
false
|
300
|
-
|
301
|
-
# ========================= Change callbacks ===============================
|
302
|
-
|
303
|
-
template: () ->
|
304
|
-
str = "
|
305
|
-
<div class='rs_dialog_holder'>
|
306
|
-
<div class='rs_dialog'>
|
307
|
-
<div class='rs_dialog_content'>
|
308
|
-
<h1>#{$.fn.recurring_select.texts["repeat"]} <a href='#' title='#{$.fn.recurring_select.texts["cancel"]}' Alt='#{$.fn.recurring_select.texts["cancel"]}'></a> </h1>
|
309
|
-
<p class='frequency-select-wrapper'>
|
310
|
-
<label for='rs_frequency'>#{$.fn.recurring_select.texts["frequency"]}:</label>
|
311
|
-
<select data-wrapper-class='ui-recurring-select' id='rs_frequency' class='rs_frequency' name='rs_frequency'>
|
312
|
-
<option value='Daily'>#{$.fn.recurring_select.texts["daily"]}</option>
|
313
|
-
<option value='Weekly'>#{$.fn.recurring_select.texts["weekly"]}</option>
|
314
|
-
<option value='Monthly'>#{$.fn.recurring_select.texts["monthly"]}</option>
|
315
|
-
<option value='Yearly'>#{$.fn.recurring_select.texts["yearly"]}</option>
|
316
|
-
</select>
|
317
|
-
</p>
|
318
|
-
|
319
|
-
<div class='daily_options freq_option_section'>
|
320
|
-
<p>
|
321
|
-
#{$.fn.recurring_select.texts["every"]}
|
322
|
-
<input type='text' data-wrapper-class='ui-recurring-select' name='rs_daily_interval' class='rs_daily_interval rs_interval' value='1' size='2' />
|
323
|
-
#{$.fn.recurring_select.texts["days"]}
|
324
|
-
</p>
|
325
|
-
</div>
|
326
|
-
<div class='weekly_options freq_option_section'>
|
327
|
-
<p>
|
328
|
-
#{$.fn.recurring_select.texts["every"]}
|
329
|
-
<input type='text' data-wrapper-class='ui-recurring-select' name='rs_weekly_interval' class='rs_weekly_interval rs_interval' value='1' size='2' />
|
330
|
-
#{$.fn.recurring_select.texts["weeks_on"]}:
|
331
|
-
</p>
|
332
|
-
<div class='day_holder'>
|
333
|
-
"
|
334
|
-
for day_of_week in [$.fn.recurring_select.texts["first_day_of_week"]...(7 + $.fn.recurring_select.texts["first_day_of_week"])]
|
335
|
-
day_of_week = day_of_week % 7
|
336
|
-
str += "<a href='#' data-value='#{day_of_week}'>#{$.fn.recurring_select.texts["days_first_letter"][day_of_week]}</a>"
|
337
|
-
|
338
|
-
str += "
|
339
|
-
</div>
|
340
|
-
<span style='clear:both; visibility:hidden; height:1px;'>.</span>
|
341
|
-
</div>
|
342
|
-
<div class='monthly_options freq_option_section'>
|
343
|
-
<p>
|
344
|
-
#{$.fn.recurring_select.texts["every"]}
|
345
|
-
<input type='text' data-wrapper-class='ui-recurring-select' name='rs_monthly_interval' class='rs_monthly_interval rs_interval' value='1' size='2' />
|
346
|
-
#{$.fn.recurring_select.texts["months"]}:
|
347
|
-
</p>
|
348
|
-
<p class='monthly_rule_type'>
|
349
|
-
<span><label for='monthly_rule_type_day'>#{$.fn.recurring_select.texts["day_of_month"]}</label><input type='radio' class='monthly_rule_type_day' name='monthly_rule_type' id='monthly_rule_type_day' value='true' /></span>
|
350
|
-
<span><label for='monthly_rule_type_week'>#{$.fn.recurring_select.texts["day_of_week"]}</label><input type='radio' class='monthly_rule_type_week' name='monthly_rule_type' id='monthly_rule_type_week' value='true' /></span>
|
351
|
-
</p>
|
352
|
-
<p class='rs_calendar_day'></p>
|
353
|
-
<p class='rs_calendar_week'></p>
|
354
|
-
</div>
|
355
|
-
<div class='yearly_options freq_option_section'>
|
356
|
-
<p>
|
357
|
-
#{$.fn.recurring_select.texts["every"]}
|
358
|
-
<input type='text' data-wrapper-class='ui-recurring-select' name='rs_yearly_interval' class='rs_yearly_interval rs_interval' value='1' size='2' />
|
359
|
-
#{$.fn.recurring_select.texts["years"]}
|
360
|
-
</p>
|
361
|
-
</div>
|
362
|
-
<p class='rs_summary'>
|
363
|
-
<span></span>
|
364
|
-
</p>
|
365
|
-
<div class='controls'>
|
366
|
-
<input type='button' data-wrapper-class='ui-recurring-select' class='rs_save' value='#{$.fn.recurring_select.texts["ok"]}' />
|
367
|
-
<input type='button' data-wrapper-class='ui-recurring-select' class='rs_cancel' value='#{$.fn.recurring_select.texts["cancel"]}' />
|
368
|
-
</div>
|
369
|
-
</div>
|
370
|
-
</div>
|
371
|
-
</div>
|
372
|
-
"
|