Sha256: 9c9effb868699e950db46b498d6638a9008504cd8dccf3b245b18dc13d1fce25

Contents?: true

Size: 1.07 KB

Versions: 26

Compression:

Stored size: 1.07 KB

Contents

class window.GridInput
  constructor: (el) ->
    @cont = $(el)
    @ids = @cont.data('val')
    @attr = @cont.data('attr')
    @active_css = 'active'
    @initHandlers()
    @initData()

  initHandlers: ->
    self = this
    @cont.on 'click', '.grid_input-item', (e) ->
      e.preventDefault()
      $el = $(this)
      $el.toggleClass(self.active_css)
      el_val = $el.data('id')
      active = $el.hasClass(self.active_css)
      if active
        self.ids.push(el_val)
      else
        self.ids = _.without(self.ids, el_val)
      $el.find('input').prop('checked', active)

    @cont.on 'click', '.grid_input-item input', (e) ->
      e.preventDefault()

    @cont.closest('form').submit(@serialize) if @attr

  initData: ->
    @cont.find("[data-id=#{id}]").click() for id in @ids

  serialize: =>
    @cont.children('input.grid_input-input').remove()
    @cont.prepend("<input class='grid_input-input' type='hidden' name='#{@attr}' value='#{id}'>") for id in @ids

$.fn.gridInput = ->
  @each ->
    $el = $(this)
    $el.data('GridInput') or $el.data('GridInput', new GridInput(this))

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
ab_admin-0.11.0 app/assets/javascripts/ab_admin/components/grid_input.js.coffee
ab_admin-0.10.0 app/assets/javascripts/ab_admin/components/grid_input.js.coffee
ab_admin-0.9.0 app/assets/javascripts/ab_admin/components/grid_input.js.coffee
ab_admin-0.8.3 app/assets/javascripts/ab_admin/components/grid_input.js.coffee
ab_admin-0.8.2 app/assets/javascripts/ab_admin/components/grid_input.js.coffee
ab_admin-0.8.1 app/assets/javascripts/ab_admin/components/grid_input.js.coffee
ab_admin-0.8.0 app/assets/javascripts/ab_admin/components/grid_input.js.coffee
ab_admin-0.7.0 app/assets/javascripts/ab_admin/components/grid_input.js.coffee
ab_admin-0.6.1 app/assets/javascripts/ab_admin/components/grid_input.js.coffee
ab_admin-0.6.0 app/assets/javascripts/ab_admin/components/grid_input.js.coffee
ab_admin-0.5.0 app/assets/javascripts/ab_admin/components/grid_input.js.coffee
ab_admin-0.4.0 app/assets/javascripts/ab_admin/components/grid_input.js.coffee
ab_admin-0.3.6 app/assets/javascripts/ab_admin/components/grid_input.js.coffee
ab_admin-0.3.5 app/assets/javascripts/ab_admin/components/grid_input.js.coffee
ab_admin-0.3.4 app/assets/javascripts/ab_admin/components/grid_input.js.coffee
ab_admin-0.3.3 app/assets/javascripts/ab_admin/components/grid_input.js.coffee
ab_admin-0.3.2 app/assets/javascripts/ab_admin/components/grid_input.js.coffee
ab_admin-0.3.1 app/assets/javascripts/ab_admin/components/grid_input.js.coffee
ab_admin-0.3.0 app/assets/javascripts/ab_admin/components/grid_input.js.coffee
ab_admin-0.2.3 app/assets/javascripts/ab_admin/components/grid_input.js.coffee