Class: Interview::ImageAttribute

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

Instance Attribute Summary collapse

Attributes inherited from Attribute

#align, #caption, #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

  • Bild muss in eingener Klasse ausgelagert werden

  • object muss die Methode method_id= implementieren

  • method_id muss als parameter erlaubt werden

  • json ansicht auf bild muss vorhanden sein



9
10
11
# File 'lib/interview/image_attribute.rb', line 9

def hide_if_not_exists
  @hide_if_not_exists
end

#image_styleObject

  • Bild muss in eingener Klasse ausgelagert werden

  • object muss die Methode method_id= implementieren

  • method_id muss als parameter erlaubt werden

  • json ansicht auf bild muss vorhanden sein



9
10
11
# File 'lib/interview/image_attribute.rb', line 9

def image_style
  @image_style
end

#objectObject

  • Bild muss in eingener Klasse ausgelagert werden

  • object muss die Methode method_id= implementieren

  • method_id muss als parameter erlaubt werden

  • json ansicht auf bild muss vorhanden sein



9
10
11
# File 'lib/interview/image_attribute.rb', line 9

def object
  @object
end

#submethodObject

  • Bild muss in eingener Klasse ausgelagert werden

  • object muss die Methode method_id= implementieren

  • method_id muss als parameter erlaubt werden

  • json ansicht auf bild muss vorhanden sein



9
10
11
# File 'lib/interview/image_attribute.rb', line 9

def submethod
  @submethod
end

Instance Method Details

#render_readObject



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

def render_read
  submethod = @submethod || 'attachment'
  image_style = @image_style || :thumb
  object = @object || find_attribute(:object)
  image = value || object.association(@method).build
  
  attachment = image.send(submethod)
  return '' if not attachment.exists? 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
    html << h.image_tag(attachment.url(image_style), class: 'img-responsive')
  end
  return html.target!
end

#render_writeObject



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

def render_write
  object = @object || find_attribute(:object)
  submethod = @submethod || 'attachment'
  image_style = @image_style || :thumb
  image = object.send(@method) || object.association(@method).build
  attachment = image.send(submethod)
  model = image.class.model_name.singular
  
  html = Builder::XmlMarkup.new
  
  html << form_builder.hidden_field("#{@method.singularize}_id", class: 'image-id')
  
  html.div class: 'inline-block' do
    html << h.image_tag(attachment.url(image_style), id: 'image-tag')
  end
  
  html.div class: 'inline-block' do
    html.span class: "btn btn-default fileinput-button" do
      html.span "Select file..."
      html << h.file_field_tag("#{model}[#{submethod}]", class: 'image-upload', 
        data: {url: "/#{model.pluralize}.json", type: 'POST'})
    end
  
    # if attachment.exists?
    #   html << form_builder.check_box("destroy_#{@method}")
    #   html.text! ' Datei löschen'
    # end
  end
  
  html.div id: 'upload-progress' do
  end
  
  html.script id: 'upload-progress-script', type: 'text/x-tmpl' do
    html.div class: 'upload' do
      html.text! "{%=o.name%}"
      html.div class: 'progress' do
        html.div '', class: 'progress-bar bar', style: 'width: 0%'
      end
    end
  end
  
  return html.target!
end