-
Notifications
You must be signed in to change notification settings - Fork 237
Expand file tree
/
Copy pathrecurring_select.js.coffee
More file actions
122 lines (101 loc) · 3.23 KB
/
recurring_select.js.coffee
File metadata and controls
122 lines (101 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//= require recurring_select_dialog
//= require_self
$ = jQuery
$ ->
$(document).on "focus", ".recurring_select", ->
$(this).recurring_select('set_initial_values')
$(document).on "change", ".recurring_select", ->
$(this).recurring_select('changed')
methods =
set_initial_values: ->
@data 'initial-value-hash', @val()
@data 'initial-value-str', $(@find("option").get()[@.prop("selectedIndex")]).text()
changed: ->
if @val() == "custom"
methods.open_custom.apply(@)
setModalTabbing()
else
methods.set_initial_values.apply(@)
open_custom: ->
@data "recurring-select-active", true
new RecurringSelectDialog(@)
@blur()
save: (new_rule) ->
@find("option[data-custom]").remove()
new_json_val = JSON.stringify(new_rule.hash)
# TODO: check for matching name, and replace that value if found
if $.inArray(new_json_val, @find("option").map -> $(@).val()) == -1
methods.insert_option.apply @, [new_rule.str, new_json_val]
@val new_json_val
methods.set_initial_values.apply @
@.trigger "recurring_select:save"
current_rule: ->
str: @data("initial-value-str")
hash: $.parseJSON(@data("initial-value-hash"))
cancel: ->
@val @data("initial-value-hash")
@data "recurring-select-active", false
@.trigger "recurring_select:cancel"
insert_option: (new_rule_str, new_rule_json) ->
separator = @find("option:disabled")
if separator.length == 0
separator = @find("option")
separator = separator.last()
new_option = $(document.createElement("option"))
new_option.attr "data-custom", true
if new_rule_str.substr(new_rule_str.length - 1) != "*"
new_rule_str+="*"
new_option.text new_rule_str
new_option.val new_rule_json
new_option.insertBefore separator
methods: ->
methods
$.fn.recurring_select = (method) ->
if method of methods
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ) );
else
$.error( "Method #{method} does not exist on jQuery.recurring_select" );
$.fn.recurring_select.options = {
monthly: {
show_week: [true, true, true, true, false, false]
}
}
$.fn.recurring_select.texts = {
locale_iso_code: "en"
repeat: "Repeat"
last_day: "Last Day"
frequency: "Frequency"
daily: "Daily"
weekly: "Weekly"
monthly: "Monthly"
yearly: "Yearly"
every: "Every"
days: "day(s)"
weeks_on: "week(s) on"
months: "month(s)"
years: "year(s)"
day_of_month: "Day of month"
day_of_week: "Day of week"
cancel: "Cancel"
ok: "OK"
summary: "Summary"
first_day_of_week: 0
days_first_letter: ["S", "M", "T", "W", "T", "F", "S" ]
order: ["1st", "2nd", "3rd", "4th", "5th", "Last"]
show_week: [true, true, true, true, false, false]
}
# ========================= 508 Accessiblity ===============================
setModalTabbing = ->
tabbables = $('#rs_modal').find(':tabbable')
$('#rs_modal').off('keydown').on 'keydown', (e) ->
`var x`
if $(e.target).is(tabbables.first()) and e.which == 9 and e.shiftKey
e.preventDefault()
x = tabbables.last()
x.focus()
else if $(e.target).is(tabbables.last()) and e.which == 9 and !e.shiftKey
e.preventDefault()
x = tabbables.first()
x.focus()
return
return