Sha256: 36579c189737573017a8911b82c866ebd2d04bcbf51b864cd9a5120c545fc5a4

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

module Dynaspan
  module ApplicationHelper

    def dynaspan_text_field(master_ds_object,*parameters)
      dynaspan_text('field', master_ds_object, parameters)
    end

    def dynaspan_text_area(master_ds_object,*parameters)
      dynaspan_text('area', master_ds_object, parameters)
    end

    private

    def dynaspan_counter
      @count_for_viewspace = @count_for_viewspace.to_i + 1
    end

    def dynaspan_text(kind, master_ds_object,*parameters)
      parameters.flatten!
      if parameters.first.is_a? Symbol
        attr_object = nil
        attrib = parameters.first
        edit_text = parameters.try(:[],1)
      elsif parameters[1].is_a? Symbol
        attr_object, attrib = parameters
        edit_text = parameters.try(:[],2)
      else
        raise 'You did not provide a symbol for the form field.'
      end
      edit_text = nil unless edit_text.is_a? String
      options = (parameters[-1].is_a?(Hash) ? parameters[-1] : {})
      options.default = nil
      render(
          partial: "dynaspan/dynaspan_text_#{kind}",
          locals: {
            master_ds_object: master_ds_object,
            attr_object: attr_object,
            attrib: attrib,
            unique_ref_id: dynaspan_counter,
            dyna_span_edit_text: edit_text,
            hidden_fields: options[:hidden_fields],
            ds_callback_on_update: options[:callback_on_update],
            ds_callback_with_values: options[:callback_with_values]
          }
      )
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dynaspan-0.1.1 app/helpers/dynaspan/application_helper.rb