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
|
# File 'app/helpers/abracadabra/rails/view_helper.rb', line 4
def click_to_edit(instance, options)
instance_class = instance.class.to_s.underscore
link_class = "#{options[:class]} abracadabra".strip
link_id = options[:id] || nil
value = options[:value] || instance.send(options[:attribute])
method = options[:method] || "patch"
path = options[:path]
buttonless = options[:buttonless] || false
deletable = options[:deletable] || false
deletable_path = options[:deletable_path] || path
submit_on_blur = options[:submit_on_blur] || false
if options[:tab_to_next] || options[:tab_to_next] != false
if options[:tab_to_next] == true
tab_to_next = ".abracadabra"
else
tab_to_next = options[:tab_to_next]
end
else
tab_to_next = false
end
if !options[:remote].nil? && options[:remote] == false
remote = false
else
remote = true
end
data_type = options[:type].to_s.gsub(/^j+s+$/, "script") || "script"
deletable_type = options[:deletable_type].to_s.gsub(/^j+s+$/, "script") || "script"
link_to(
value,
"javascript:void(0)",
class: link_class,
id: link_id,
method: method.to_sym,
data: {
path: path,
attribute: options[:attribute],
class: instance_class,
type: data_type.to_sym,
buttonless: buttonless,
deletable: deletable,
deletable_path: deletable_path,
deletable_type: deletable_type.to_sym,
tab_to_next: tab_to_next,
submit_on_blur: submit_on_blur
},
remote: remote
)
end
|