Class: FileInput

Inherits:
FormtasticBootstrap::Inputs::FileInput
  • Object
show all
Defined in:
app/inputs/file_input.rb

Instance Method Summary collapse

Instance Method Details

#to_htmlObject



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
# File 'app/inputs/file_input.rb', line 2

def to_html
  bootstrap_wrapping do
    attachment = object.send(method)
    
    info_popup = "" 
    with_geom = attachment.styles.values.select do |decl|
      decl.geometry
    end
      
    if with_geom.any?
      infos = "<table class='table table-striped'>"
      with_geom.each do |s|
        infos << "<tr><th>#{s.name}</th><td>#{s.geometry}</td></tr>"
      end
      infos << "</table>"
      title = I18n.t('fullstack.admin.info', :default => "Info")
      content = template.send :h, infos
      info_popup << "&nbsp; <i class='icon icon-info-sign' title='#{title}' data-content='#{content}' data-toggle='popover'></i>"
    end
    
    
    if !attachment.exists?
      <<-eos
        <span class="file-input-attachment-filename">
          <i class="icon icon-file"></i> (#{I18n.t('fullstack.admin.no_file_uploaded', :default => "No file uploaded")})
        </span> 
        <span>#{info_popup}</span>
      
        <a class="btn btn-small file-input-choose-file-button" href="javascript:void(0)">
          <i class="icon icon-upload"></i>
          #{I18n.t('fullstack.admin.choose_a_file', :default => "Choose a file")}
        </a>
      eos
    
    else
      preview_menu = ""
      
      preview_menu << template.(:li, template.link_to(I18n.t('fullstack.admin.original', :default => "Original"), 
      attachment.url(:original),
      :target => "_blank"
      
      ))
      
      preview_menu << template.(:li, "", :class => :divider) if !attachment.styles.empty?
      
      attachment.styles.map do |name, decl|
        preview_menu << template.(:li,  template.link_to(name.to_s.humanize, attachment.url(name), :target => "_blank"))
      end

      <<-eos
      
      <span  class="file-input-attachment-filename"><i class="icon icon-file"></i> #{template.send(:html_escape, attachment.url.split("/").last.split("?").first)} </span> 
      <span>#{info_popup}</span>
      
      <a class="btn btn-small file-input-choose-file-button" href="javascript:void(0)">
        <i class="icon icon-upload"></i>
        #{I18n.t('fullstack.admin.change', :default => "Change")}
      </a>
      <span class="dropdown">
        <a class="btn dropdown-toggle btn-small" data-toggle="dropdown" href="#">
          <i class="icon icon-eye-open"></i>
          #{I18n.t('fullstack.admin.preview', :default => "Preview")}
          <span class="caret"></span>
        </a>
        <ul class="dropdown-menu">
          #{preview_menu}
        </ul>
      
      </span>
      
      #{template.button(
        I18n.t('fullstack.admin.delete', :default => "Delete"),
        "javascript:void(0)",
        :type => :danger, :class => "file-input-delete-attachment-button btn-small", :"data-toggle" => :button
        )}
      
      eos
    
    end.html_safe << builder.file_field(method, :style => "display:none;") << (builder.check_box("#{method}_delete", :class => "file-input-delete-attachment-checkbox", :style => "display:none;") if attachment.exists?)
  end
end