Class: ActionAdmin::AttachmentInput

Inherits:
SimpleForm::Inputs::Base
  • Object
show all
Defined in:
app/inputs/action_admin/attachment_input.rb

Instance Method Summary collapse

Instance Method Details

#attachment(image_url = nil) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'app/inputs/action_admin/attachment_input.rb', line 36

def attachment(image_url=nil)
  image  =  :img, nil, src: image_url, class: 'width-100 margin-bottom-1', data: { src: 'file.preview.url', url: "#{template.root_url.chomp('/')}[src]" }
  remove =  :a, 'Remove', class: 'button alert small hollow margin-0', data: { remove: '' }
  change =  :a, 'Change', class: 'button success small hollow margin-0', data: { open: input_html_id }
  remove =  :div, remove, class: 'cell auto text-left'
  change =  :div, change, class: 'cell shrink'
  buttons =  :div, remove + change, class: 'panel-section expanded border last grid-x'

   :div, hidden_input + image + buttons, class: 'attachment text-center', data: { list_item: '' }
end

#attachment_urlObject



32
33
34
# File 'app/inputs/action_admin/attachment_input.rb', line 32

def attachment_url
  object.send(attribute_name).try(:file_url, :preview)
end

#empty_inputObject



20
21
22
# File 'app/inputs/action_admin/attachment_input.rb', line 20

def empty_input
  @builder.hidden_field(:"#{attribute_name}_id", value: '', id: nil)
end

#hidden_inputObject



24
25
26
# File 'app/inputs/action_admin/attachment_input.rb', line 24

def hidden_input
  @builder.hidden_field(:"#{attribute_name}_id", data: { value: :id })
end

#input(wrapper_options) ⇒ Object



3
4
5
6
7
8
# File 'app/inputs/action_admin/attachment_input.rb', line 3

def input(wrapper_options)
  modal = options.fetch :modal, 'media-modal'
  html  =  :div, input_placeholder, id: input_html_id, data: { media_attach: modal }

  html + input_template
end

#input_html_idObject



28
29
30
# File 'app/inputs/action_admin/attachment_input.rb', line 28

def input_html_id
  hidden_input[/id=\"(.*)\"/, 1].dasherize
end

#input_placeholderObject



10
11
12
13
14
15
16
17
18
# File 'app/inputs/action_admin/attachment_input.rb', line 10

def input_placeholder
  span    =  :span, 'No thumbnail', class: 'margin-bottom-1'
  icon    =  :i, nil, class: 'mdi mdi-camera-off'
  button  =  :a, 'Add Thumbnail', data: { open: input_html_id }, class: 'button success small hollow margin-0'
  content =  :div, empty_input + icon + span + button, class: 'no-content hide', data: { empty_state: '' }
  image   = attachment(attachment_url) if attachment_url.present?

  content + (:div, image, data: { list_remove: '' }, class: 'attachments')
end

#input_templateObject



47
48
49
# File 'app/inputs/action_admin/attachment_input.rb', line 47

def input_template
   :script, attachment, id: "#{input_html_id}-item-template", type: 'text/template'
end

#label(wrapper_options) ⇒ Object



51
52
53
# File 'app/inputs/action_admin/attachment_input.rb', line 51

def label(wrapper_options)
  ''
end