Class: Interview::ImageAttribute

Inherits:
Attribute show all
Defined in:
lib/interview/image_attribute.rb

Instance Attribute Summary collapse

Attributes inherited from Attribute

#align, #caption, #caption_as_placeholder, #hide_caption, #hide_tooltip, #html_class, #link, #method, #nil_value, #on_changed, #only_for, #style, #surrounding_tag

Attributes inherited from Control

#parent

Instance Method Summary collapse

Methods inherited from Attribute

#initialize, #render, #tooltip, #value

Methods inherited from Control

#ancestors, build, definition, #find_attribute, #find_attribute!, inherited, #initialize, #render, #set_attributes, #set_defaults

Constructor Details

This class inherits a constructor from Interview::Attribute

Instance Attribute Details

#hide_if_not_existsObject

  • Modul UploadBuffer muss für write vorhanden sein

  • json ansicht auf bild muss vorhanden sein



7
8
9
# File 'lib/interview/image_attribute.rb', line 7

def hide_if_not_exists
  @hide_if_not_exists
end

#image_styleObject

  • Modul UploadBuffer muss für write vorhanden sein

  • json ansicht auf bild muss vorhanden sein



7
8
9
# File 'lib/interview/image_attribute.rb', line 7

def image_style
  @image_style
end

#objectObject

  • Modul UploadBuffer muss für write vorhanden sein

  • json ansicht auf bild muss vorhanden sein



7
8
9
# File 'lib/interview/image_attribute.rb', line 7

def object
  @object
end

Instance Method Details

#render_readObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/interview/image_attribute.rb', line 9

def render_read
  image_style = @image_style || :thumb
  
  return '' if value.nil? and @hide_if_not_exists
  
  html = Builder::XmlMarkup.new
  opts = {class: "image_#{image_style}"}
  opts[:class] += ' ' + @html_class.join(' ') unless @html_class.empty? or @surrounding_tag
  html.div opts do
    if value
      html << h.image_tag(value.url(image_style), class: 'image img-responsive')
    else
      html << h.image_tag('missing_thumb.png', class: 'image img-responsive')
    end
  end
  return html.target!
end

#render_writeObject



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
# File 'lib/interview/image_attribute.rb', line 27

def render_write
  image_style = @image_style || :thumb
  
  html = Builder::XmlMarkup.new
  html.div class: 'image_attribute_container' do
    unless value.nil? and @hide_if_not_exists
      html.div class: 'inline-block' do
        html << h.image_tag(value.url(image_style), class: 'image img-responsive')
      end
    end
  
    html.div class: 'inline-block' do
      html.div class: "clearfix" do
        html.span class: "btn btn-default fileinput-button" do
          html.span "Bild hochladen" # todo
          html << h.file_field_tag("upload_buffer[attachment]", class: 'upload_image',
            data: {url: "/upload_buffers.json", type: 'POST'})
        end
      end
      html << Interview::ProgressBar.new(hidden: true).render
      html << form_builder.hidden_field(:upload_buffer_id, class: 'upload_buffer_id')
  
      # if attachment.exists?
      #   html << form_builder.check_box("destroy_#{@method}")
      #   html.text! ' Datei löschen'
      # end
    end
  end
  return html.target!
end