Sha256: 600a945f8426832228ac5cdc89c0eda5924a97206b79120e356b4e4a7f0820d4

Contents?: true

Size: 974 Bytes

Versions: 7

Compression:

Stored size: 974 Bytes

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"
    ).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

7 entries across 7 versions & 1 rubygems

Version Path
georgia-0.7.6 app/assets/javascripts/georgia/components/portlets/slide.js.coffee
georgia-0.7.5 app/assets/javascripts/georgia/components/portlets/slide.js.coffee
georgia-0.7.4 app/assets/javascripts/georgia/components/portlets/slide.js.coffee
georgia-0.7.3 app/assets/javascripts/georgia/components/portlets/slide.js.coffee
georgia-0.7.2 app/assets/javascripts/georgia/components/portlets/slide.js.coffee
georgia-0.7.1 app/assets/javascripts/georgia/components/portlets/slide.js.coffee
georgia-0.7.0 app/assets/javascripts/georgia/components/portlets/slide.js.coffee