Module: AttachedFilesListHelper::Render

Defined in:
app/helpers/attached_files_list_helper.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.hObject

Returns the value of attribute h.



14
15
16
# File 'app/helpers/attached_files_list_helper.rb', line 14

def h
  @h
end

.optionsObject

Returns the value of attribute options.



14
15
16
# File 'app/helpers/attached_files_list_helper.rb', line 14

def options
  @options
end

Class Method Details

.build_preview_picObject



73
74
75
76
77
78
79
80
81
82
83
# File 'app/helpers/attached_files_list_helper.rb', line 73

def build_preview_pic
  if @node.is_image?
    src = @node.url(:preview)
    url = @node.url(:base)
    "<a href='#{url}'><img src='#{src}'></a>"
  else
    klass = @node.file_css_class
    url = @node.url
    "<a href='#{url}'><i class='#{klass}'></i></a>"
  end
end

.childrenObject



107
108
109
110
111
# File 'app/helpers/attached_files_list_helper.rb', line 107

def children
  unless options[:children].blank?
    "<ol class='nested_set'>#{ options[:children] }</ol>"
  end
end

.controlsObject



94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/helpers/attached_files_list_helper.rb', line 94

def controls
  node = options[:node]

  edit_path = h.url_for(:controller => options[:klass].pluralize, :action => :edit, :id => node)
  show_path = h.url_for(:controller => options[:klass].pluralize, :action => :show, :id => node)

  "
    <div class='controls'>
      #{ h.link_to '', show_path, :class => :delete, :method => :delete, :data => { :confirm => 'Are you sure?' } }
    </div>
  "
end

.current_hostObject



39
40
41
# File 'app/helpers/attached_files_list_helper.rb', line 39

def current_host
  h.request.protocol + h.request.host_with_port
end

.render_node(h, options) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/helpers/attached_files_list_helper.rb', line 16

def render_node(h, options)
  @h, @options = h, options
  @node = options[:node]

  "
    <li data-node-id='#{ @node.id }'>
      <div class='item'>
        <i class='handle'></i>
        #{ rotate_links }
        <div class='preview_pic'>#{build_preview_pic}</div>
        <div class='file_block'>
          #{ show_link }
          #{ url_input }
          #{ watermark_switch }
          #{ show_size }
        </div>
        #{ controls }
      </div>
      #{ children }
    </li>
  "
end


65
66
67
68
69
70
71
# File 'app/helpers/attached_files_list_helper.rb', line 65

def rotate_links
  if @node.is_image?
    left  = h.link_to '', h.rotate_left_url(@node),  method: :patch, class: :left
    right = h.link_to '', h.rotate_right_url(@node), method: :patch, class: :right
    "<div class='rotate'>#{left} #{right}</div>"
  end
end


85
86
87
88
89
90
91
92
# File 'app/helpers/attached_files_list_helper.rb', line 85

def show_link
  node = options[:node]
  ns   = options[:namespace]
  title_field = options[:title]
  title = node.send(title_field)
  url = @node.is_image? ? @node.url(:base) : @node.url
  "<h4>#{ h.link_to(title, url)}</h4>"
end

.show_sizeObject



49
50
51
# File 'app/helpers/attached_files_list_helper.rb', line 49

def show_size
  "<div class='fsize'>#{@node.mb_size}</div>"
end

.url_inputObject



43
44
45
46
47
# File 'app/helpers/attached_files_list_helper.rb', line 43

def url_input
  opts = {nocache: false, timestamp: false}
  url = @node.is_image? ? @node.url(:base, opts) : @node.url(:original, opts)
  "<div class='url_input'>URL: <input class='file_url' value='#{current_host + url}'></div>"
end

.watermark_switchObject



53
54
55
56
57
58
59
60
61
62
63
# File 'app/helpers/attached_files_list_helper.rb', line 53

def watermark_switch
  if @node.is_image?
    link = if @node.watermark
      "<span class='wm_on'>Вкл.</span>"
    else
      "<span class='wm_off'>Выкл.</span>"
    end

    "<div class='watermark_switcher'>Водный знак: #{link}</div>"
  end
end