Sha256: 86d98a466e8c3df359d55840e754139fe6293ae9b6039fcbb1e84bdaec8f2fb6

Contents?: true

Size: 1.17 KB

Versions: 58

Compression:

Stored size: 1.17 KB

Contents

module EgovUtils
  module Helpers
    module Tags
      class FileuidField < ActionView::Helpers::Tags::TextField

        def render
          res = super
          res << @template_object.javascript_tag(javascript_str(@options.stringify_keys))
          res
        end

        private
          def all_agendas
            %w(C Cd D Dt Dtm E EPR EVC EXE L Nc Nt Ntm P PP Rod Sd T Td Tm U)
          end

          def javascript_str(options)
            agendas = all_agendas
            agendas &= options.delete('agendas') if options['agendas']
            index = name_and_id_index(options)
            tag_id = options.fetch("id") { tag_id(index) }

            str = "$(function(){"
            str << "  $('##{tag_id}').fileUid({ available_agendas: #{ agendas.to_json } });"
            str << "  var destroy_evt_method = function(evt){"
            str << "    $('##{tag_id}').fileUid('destroy');"
            str << "    $(document).off('turbolinks:before-cache', destroy_evt_method);"
            str << "  };"
            str << "  $(document).on('turbolinks:before-cache', destroy_evt_method);"
            str << "});"
            str
          end

      end
    end
  end
end

Version data entries

58 entries across 58 versions & 1 rubygems

Version Path
egov_utils-1.5.0.alpha15 lib/egov_utils/helpers/tags/fileuid_field.rb
egov_utils-1.5.0.alpha14 lib/egov_utils/helpers/tags/fileuid_field.rb
egov_utils-1.5.0.alpha13 lib/egov_utils/helpers/tags/fileuid_field.rb
egov_utils-1.5.0.alpha12 lib/egov_utils/helpers/tags/fileuid_field.rb
egov_utils-1.5.0.alpha11 lib/egov_utils/helpers/tags/fileuid_field.rb
egov_utils-1.5.0.alpha10 lib/egov_utils/helpers/tags/fileuid_field.rb
egov_utils-1.5.0.alpha9 lib/egov_utils/helpers/tags/fileuid_field.rb
egov_utils-1.5.0.alpha8 lib/egov_utils/helpers/tags/fileuid_field.rb
egov_utils-1.5.0.alpha7 lib/egov_utils/helpers/tags/fileuid_field.rb
egov_utils-1.5.0.alpha6 lib/egov_utils/helpers/tags/fileuid_field.rb
egov_utils-1.5.0.alpha5 lib/egov_utils/helpers/tags/fileuid_field.rb
egov_utils-1.5.0.alpha4 lib/egov_utils/helpers/tags/fileuid_field.rb
egov_utils-1.4.5 lib/egov_utils/helpers/tags/fileuid_field.rb
egov_utils-1.4.4 lib/egov_utils/helpers/tags/fileuid_field.rb
egov_utils-1.5.0.alpha3 lib/egov_utils/helpers/tags/fileuid_field.rb
egov_utils-1.5.0.alpha2 lib/egov_utils/helpers/tags/fileuid_field.rb
egov_utils-1.5.0.alpha1 lib/egov_utils/helpers/tags/fileuid_field.rb
egov_utils-1.4.3 lib/egov_utils/helpers/tags/fileuid_field.rb
egov_utils-1.4.2 lib/egov_utils/helpers/tags/fileuid_field.rb
egov_utils-1.4.1 lib/egov_utils/helpers/tags/fileuid_field.rb