Class: ActionAdmin::SlugInput

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

Instance Method Summary collapse

Instance Method Details

#edit_buttonObject



53
54
55
56
# File 'app/inputs/action_admin/slug_input.rb', line 53

def edit_button
  opts = { class: 'edit-button mdi mdi-pencil', data: { edit: '' } }
  template. :span, nil, opts
end

#empty_valueObject



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

def empty_value
  prefix('Not defined')
end

#input(wrapper_options) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/inputs/action_admin/slug_input.rb', line 3

def input(wrapper_options)
  input_html_options[:placeholder] ||= raw_label_text
  input_html_options[:type]        ||= 'text'
  input_html_options[:class]       ||= []
  input_html_options[:class]        += ['small', 'edit-input']

  opts = { class: 'inline-edit-box', data: { inline_edit_box: '' } }

  template.(:div, opts) do
    template.concat preview_link
    template.concat super
    template.concat edit_button
    template.concat save_button
  end
end

#input_valueObject



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

def input_value
  object.try(attribute_name)
end

#label(wrapper_options) ⇒ Object



63
64
65
# File 'app/inputs/action_admin/slug_input.rb', line 63

def label(wrapper_options)
  ''
end

#prefix(text) ⇒ Object



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

def prefix(text)
  "#{raw_label_text}: #{text}"
end


48
49
50
51
# File 'app/inputs/action_admin/slug_input.rb', line 48

def preview_link
  data = { preview: '', value: value_pattern, placeholder: empty_value }
  template. :small, preview_value, class: 'edit-preview', data: data
end

#preview_valueObject



44
45
46
# File 'app/inputs/action_admin/slug_input.rb', line 44

def preview_value
  input_value.present? ? prefix(url) : empty_value
end

#save_buttonObject



58
59
60
61
# File 'app/inputs/action_admin/slug_input.rb', line 58

def save_button
  opts = { class: 'save-button mdi mdi-check', data: { save: '' } }
  template. :span, nil, opts
end

#urlObject



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

def url
  method = options.fetch :url, ActionAdmin.config.app_urls
  template.try(method, object) unless object.new_record?
end

#value_patternObject



36
37
38
39
40
41
42
# File 'app/inputs/action_admin/slug_input.rb', line 36

def value_pattern
  if url.present?
    prefix "#{url}".sub("#{input_value}", '[val]')
  else
    prefix "#{template.root_url}[val]"
  end
end