Sha256: dbcb631fbfb2901d8a3d899e7a190ea5617dd13f41b715506119642bc7400226
Contents?: true
Size: 1.83 KB
Versions: 25
Compression:
Stored size: 1.83 KB
Contents
# frozen_string_literal: true class PgAssociableInput < SimpleForm::Inputs::StringInput include ActionView::Helpers::FormTagHelper include PgEngine::DefaultUrlOptions include Rails.application.routes.url_helpers include PgEngine::RouteHelper def hidden_input(_wrapper_options = {}) @builder.hidden_field(attribute_name) end def controller # Para que no rompa polymorphic_url en NamespaceDeductor end def input(wrapper_options = nil) atributo = attribute_name.to_s.gsub('_id', '') url_modal = options[:modal_url] || namespaced_path(clase_asociacion(atributo), prefix: :abrir_modal) url_search = options[:buscar_url] || namespaced_path(clase_asociacion(atributo), prefix: :buscar) input_html_options[:data] = { url_search:, url_modal: } input_html_options[:type] = 'text' merged_input_options = merge_wrapper_options(input_html_options, wrapper_options) build_input(merged_input_options) end def clase_asociacion(atributo) asociacion = object.class.reflect_on_all_associations.find { |a| a.name == atributo.to_sym } nombre_clase = asociacion.options[:class_name] nombre_clase = asociacion.name.to_s.camelize if nombre_clase.nil? Object.const_get(nombre_clase) end def build_input(input_options) content_tag('div', class: 'position-relative') do hidden_input + text_field_tag(nil, object.send(reflection.name).to_s, input_options) + limpiar + pencil end end def limpiar(_wrapper_options = nil) content_tag('a', href: 'javascript:void(0)', class: 'limpiar', title: 'Limpiar', tabindex: '0', data: { action: 'asociable#selectItem' }) do '<i class="bi bi-x-lg"></i>'.html_safe end end def pencil(_wrapper_options = nil) '<i tabindex="-1" class="bi bi-pencil pencil"></i>'.html_safe end end
Version data entries
25 entries across 25 versions & 1 rubygems