Class: Interview::ImageGalleryAttribute

Inherits:
Attribute show all
Defined in:
lib/interview/image_gallery_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

#image_styleObject

Returns the value of attribute image_style.



4
5
6
# File 'lib/interview/image_gallery_attribute.rb', line 4

def image_style
  @image_style
end

#light_box_image_styleObject

Returns the value of attribute light_box_image_style.



4
5
6
# File 'lib/interview/image_gallery_attribute.rb', line 4

def light_box_image_style
  @light_box_image_style
end

#objectObject

Returns the value of attribute object.



4
5
6
# File 'lib/interview/image_gallery_attribute.rb', line 4

def object
  @object
end

#submethodObject

Returns the value of attribute submethod.



4
5
6
# File 'lib/interview/image_gallery_attribute.rb', line 4

def submethod
  @submethod
end

Instance Method Details

#render_readObject



6
7
8
9
10
11
12
13
14
# File 'lib/interview/image_gallery_attribute.rb', line 6

def render_read
  submethod = @submethod || 'attachment'
  image_style = @image_style || :thumb
  images = value
  
  html = Builder::XmlMarkup.new
  render_gallery(html, images, submethod, image_style, @light_box_image_style)
  return html.target!
end

#render_writeObject



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

def render_write
  object = @object || find_attribute(:object)
  submethod = @submethod || 'attachment'
  image_style = @image_style || :thumb
  images = object.send @method
  model = images.klass.model_name.singular
  
  html = Builder::XmlMarkup.new
  html.div class: 'image-upload-group' do
  
    html << form_builder.hidden_field("#{@method.singularize}_ids", class: 'image-ids')

    render_gallery(html, images, submethod, image_style, @light_box_image_style)

    light_box_image_url = @light_box_image_style ? "#{@light_box_image_style}_url" : 'url'
    html.script id: 'image-thumb-script', type: 'text/x-tmpl' do
      html.a href: "{%=o.#{light_box_image_url}%}", class: 'img-link' do
        html.img class: 'img-thumb', src: "{%=o.thumb_url%}"
      end
    end

    html.div class: "clearfix" do
      html.span class: "btn btn-default fileinput-button" do
        html.span "Bilder hinzufügen" # todo
        html << h.file_field_tag("#{model}[#{submethod}]", class: 'multiple-image-upload', multiple: true,
          data: {url: "/#{model.pluralize}.json", type: 'POST'})
      end
    end

    html.div class: '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
  end
  
  return html.target!
end