Sha256: 449a3e84808d85059b4d1bfe8a83d89a70c655d16fa275015589d7200a0e167b

Contents?: true

Size: 1.24 KB

Versions: 7

Compression:

Stored size: 1.24 KB

Contents

module Locomotive
  class DocumentPickerInput < ::SimpleForm::Inputs::Base

    include Locomotive::SimpleForm::BootstrapHelpers
    include Locomotive::SimpleForm::Inputs::FasterTranslate

    def input(wrapper_options)
      data = extract_data

      row_wrapping do
        (col_wrapping('field col-xs-9', 11) do
          hidden_field(data)
        end) + (col_wrapping('button col-xs-3 text-right', 1) do
          link_to_edit
        end)
      end
    end

    def hidden_field(data)
      @builder.hidden_field(:"#{attribute_name}_id", {
        class:  'form-control',
        data:   data
      })
    end

    def link_to_edit
      label     = options[:edit][:label]
      css_class = 'btn btn-primary btn-sm edit'

      if url = options[:edit][:url]
        template.content_tag(:a, label, href: url, class: css_class)
      else
        ''
      end
    end

    def extract_data
      options[:picker].tap do |data|
        data[:per_page] ||= Locomotive.config.ui[:per_page]
        data[:label]    = document_label(data[:label_method])
      end
    end

    def document_label(label_method)
      if document = self.object.send(attribute_name.to_sym)
        document.send(label_method.to_sym)
      else
        nil
      end
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
locomotivecms-3.0.0.rc6 app/inputs/locomotive/document_picker_input.rb
locomotivecms-3.0.0.rc5 app/inputs/locomotive/document_picker_input.rb
locomotivecms-3.0.0.rc4 app/inputs/locomotive/document_picker_input.rb
locomotivecms-3.0.0.rc3 app/inputs/locomotive/document_picker_input.rb
locomotivecms-3.0.0.rc2 app/inputs/locomotive/document_picker_input.rb
locomotivecms-3.0.0.rc1 app/inputs/locomotive/document_picker_input.rb
locomotivecms-3.0.0.pre.beta.1 app/inputs/locomotive/document_picker_input.rb