Module: ViewMixins::Link

Defined in:
lib/view_mixins/link.rb

Instance Method Summary collapse

Instance Method Details



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
# File 'lib/view_mixins/link.rb', line 3

def ajax_link_to(*args, &block)
  if block_given?
    options = args.first || {}
    html_options = args.second
    ######### additional logic by ladas ##############
    html_options ||= {}
    html_options['onclick'] = "parse_link_and_load_page($(this)); return false;"
    #########################################
    link_to(capture(&block), options, html_options)
  else
    name = args[0]
    options = args[1] || {}
    html_options = args[2]
    ######### additional logic by ladas ##############
    html_options ||= {}
    html_options['onclick'] = "parse_link_and_load_page($(this)); return false;"
    #########################################
    html_options = convert_options_to_data_attributes(options, html_options)
    url = url_for(options)

    href = html_options['href']
    tag_options = tag_options(html_options)

    href_attr = "href=\"#{ERB::Util.html_escape(url)}\"" unless href
    "<a #{href_attr}#{tag_options}>#{ERB::Util.html_escape(name || url)}</a>".html_safe
  end
end

#ajax_post_link_to(*args, &block) ⇒ Object



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
# File 'lib/view_mixins/link.rb', line 31

def ajax_post_link_to(*args, &block)
  if block_given?
    options = args.first || {}
    html_options = args.second
    ######### additional logic by ladas ##############
    html_options ||= {}
    html_options['onclick'] = "parse_link_and_post($(this)); return false;"
    #########################################
    link_to(capture(&block), options, html_options)
  else
    name = args[0]
    options = args[1] || {}
    html_options = args[2]
    ######### additional logic by ladas ##############
    html_options ||= {}
    html_options['onclick'] = "parse_link_and_post($(this)); return false;"
    #########################################
    html_options = convert_options_to_data_attributes(options, html_options)
    url = url_for(options)

    href = html_options['href']
    tag_options = tag_options(html_options)

    href_attr = "href=\"#{ERB::Util.html_escape(url)}\"" unless href
    "<a #{href_attr}#{tag_options}>#{ERB::Util.html_escape(name || url)}</a>".html_safe
  end
end

#convert_settings_to_url(settings_json) ⇒ Object



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
# File 'lib/view_mixins/link.rb', line 88

def convert_settings_to_url settings_json
  # make sure its the same as build_url in ladas_loading.js

  settings = JSON.parse(settings_json)
  url = ""
  unless settings['url'].to_s.blank?
    url += settings['url'].to_s
  else
    unless settings['symlink_outer_controller'].to_s.blank?
      url += "/" + settings['symlink_outer_controller'].to_s
    end
    unless settings['symlink_outer_id'].to_s.blank?
      url += "/" + settings['symlink_outer_id'].to_s
    end
    unless settings['symlink_controller'].to_s.blank?
      url += "/" + settings['symlink_controller'].to_s
    end
    unless settings['symlink_id'].to_s.blank?
      url += "/" + settings['symlink_id'].to_s
    end
    unless settings['symlink_action'].to_s.blank?
      url += "/" + settings['symlink_action'].to_s
    end
    unless settings['symlink_params'].to_s.blank?
      url += settings['symlink_params'].to_s
    end
  end
  url
end

used only in jstree



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
# File 'lib/view_mixins/link.rb', line 60

def link_tree(*args, &block)
  if block_given?
    options = args.first || {}
    html_options = args.second
    ######### additional logic by ladas ##############
    html_options ||= {}
    html_options['onclick'] = "parse_link_and_load_page($(this)); return false;"
    #########################################
    link_to(capture(&block), options, html_options)
  else
    name = args[0]
    options = args[1] || {}
    html_options = args[2]
    ######### additional logic by ladas ##############
    html_options ||= {}
    html_options['onclick'] = "parse_link_and_load_page($(this)); return false;"
    #########################################
    html_options = convert_options_to_data_attributes(options, html_options)
    url = url_for(options)

    href = html_options['href']
    tag_options = tag_options(html_options)

    href_attr = "href=\"#{ERB::Util.html_escape(url)}\"" unless href
    "<a #{href_attr}#{tag_options}>#{ERB::Util.html_escape(name || url)}</a>".html_safe
  end
end