Sha256: 238756417ca407d3afd540963a71065c27f085f5c461bb66c7d2e336a8e7bab6

Contents?: true

Size: 798 Bytes

Versions: 2

Compression:

Stored size: 798 Bytes

Contents

initSelect = ->
  $item = $('.select2-add-link')
  url = $item.data('relListUrl')

  $item.select2(
    multiple : false
    placeholder : 'Enter search phrase'

    initSelection : (element, callback) ->
      ids = element.val().replace(/\s*/g, '').split(',')
      $.getJSON(url, {search : {id : ids}}).done (data) ->
        data = if isMultiple then data else data[0]
        $item.select2('enable', true)
        callback(data)

    ajax :
      url : url
      dataType : 'json'
      data : (term) -> {q : term}
      results : (data) -> {results : data}
  ).on 'change', (e) ->
    sendNew(e.added.link_url)


sendNew = (linkUrl) ->
  $.ajax
    url : linkUrl
    type : 'PUT'
    success : ->
      location.reload()


$ ->
  $(document)
    .on('ready page:load init-select', initSelect)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rademade_admin-0.0.3 app/assets/javascripts/rademade_admin/app/common/related-index.coffee
rademade_admin-0.0.2 app/assets/javascripts/rademade_admin/app/common/related-index.coffee