Sha256: 22c506cba237efbe86d543d6154f0b687cba9b121bfb2fd04ab26e99459f6e3b

Contents?: true

Size: 1.47 KB

Versions: 4

Compression:

Stored size: 1.47 KB

Contents

module KonoUtils
  module Object
    module Cell
      module Forms # namespace
        module Fields
          # La cella base dei componenti della form contiene sempre la form come model
          class DateTimeField < Base

            def show(&block)

              bf = ActiveSupport::SafeBuffer.new
              bf << form.input(attribute_name, field_options)

              bf << content_tag(:script, :type => "text/javascript") do
                raw "(function(){
              $('##{datetime_picker_identifier}').datetimepicker({
                #{ input_value }
                locale: '#{I18n.locale}',
                keepOpen: false,
                debug: false,
                format: '#{input_picker_format}'
              });
            })();
           "
              end

              bf
            end

            ##
            # Carica il valore nel js per poterlo avere precaricato nel campo
            #
            def input_value
              value = form.object.send(attribute_name)
              value.is_a?(DateTime) ? "date: moment('#{value&.rfc2822}')," : ''
            end

            def input_picker_format
              "L LT"
            end

            def base_field_options
              super.merge(as: :tempus_dominus, date_time_picker_identifier: datetime_picker_identifier)
            end

            def datetime_picker_identifier
              @_unique ||= SecureRandom.uuid
            end

          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
kono_utils_bootstrap_view4-0.2.1 app/concepts/kono_utils/object/cell/forms/fields/date_time_field.rb
kono_utils_bootstrap_view4-0.2 app/concepts/kono_utils/object/cell/forms/fields/date_time_field.rb
kono_utils_bootstrap_view4-0.1.2 app/concepts/kono_utils/object/cell/forms/fields/date_time_field.rb
kono_utils_bootstrap_view4-0.1.1 app/concepts/kono_utils/object/cell/forms/fields/date_time_field.rb