Sha256: faaaff1aa7b2eae32ba9ab94cdb7596312f2a2147882764d51b9a410d29d228c

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

# FIXME: Use PositionSort
class @SlidePortlet

  constructor: (element) ->
    @element = $(element)
    @slideList = @element.find('.js-sortable')
    @addSlideBtn = $('.js-add-slide')

    @setBindings()

  setBindings: () =>
    @addSlideBtn.on('click', @addSlide)
    @element.on('click', '.js-remove-slide', @removeSlide)
    @slideList.sortable(axis: 'y')
    @slideList.on( "sortupdate", @updatePosition)

  addSlide: (event) =>
    event.preventDefault()
    $.ajax(
      url: "/admin/slides/new"
      data:
        locale: $('[data-locale]').data('locale')
    ).done( (data) => @slideList.append(data) )

  removeSlide: (event) =>
    event.preventDefault()
    portlet = $(event.currentTarget).closest('.portlet')
    portlet.find('input.js-destroy').val('1')
    portlet.hide()

  updatePosition: (event, ui) =>
    @slideList.find('.js-position').each((index, el) -> $(el).val(index+1))

$.fn.slidePortlet = () ->
  @each ->
    new SlidePortlet($(this))

jQuery ->
  $(".js-slides").each () ->
    $(this).slidePortlet()

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
georgia-0.8.0 app/assets/javascripts/georgia/components/portlets/slide.js.coffee
georgia-0.7.8 app/assets/javascripts/georgia/components/portlets/slide.js.coffee
georgia-0.7.7 app/assets/javascripts/georgia/components/portlets/slide.js.coffee