Sha256: bc0abfc96d3ce43c464eb07c38aa964d041861e15d7de3962e197a22c82eab4c

Contents?: true

Size: 1.82 KB

Versions: 3

Compression:

Stored size: 1.82 KB

Contents

buildFields = (element) ->
  $element = $(element)
  $ul = $('<ul/>')
  tsFields = $element.data('tsFields')
  tsNewUrl = $element.data('tsNewUrl')
  tsParentId = $element.data('tsParentId')

  for field in tsFields
    $li = $('<li/>')
    $input = $('<input/>')

    $input
      .attr({type: "text", name: "text", placeholder: field})
      .data({'ts-field': field, 'ts-new-url': tsNewUrl})
      .on 'change', (e) ->
        $(@).parent().parent().data($(@).data('ts-field'), $(@).val())
      .appendTo($li)

    $li.appendTo($ul)

  $li = $('<li/>')
  $button = $('<button/>')
  $button
    .html('<i class="ion-ios-checkmark-outline"></i>')
    .addClass('ts-button')
    .addClass('ts-button-primary')
    .data({'ts-field': field, 'ts-new-url': tsNewUrl, 'ts-parent-id': tsParentId})
    .on 'click', ->
      data = {}
      data[$(@).data('ts-field')] = $(@).parent().parent().data($(@).data('ts-field'))
      data['parent_id'] = $(@).data('ts-parent-id') if $(@).data('ts-parent-id') 
      console.log data
      $.ajax
        type: "POST"
        url: $(@).data('ts-new-url')
        dataType: 'json'
        contentType: 'application/json'
        data: JSON.stringify(data)
        success: (data, status) -> window.location.reload()
    .appendTo($li)
  $li.appendTo($ul)

  $ul

setUpDrops = (elements)->
  drops = []
  for element in elements
    drop = new Drop
      target: $(element)[0]
      content: buildFields(element)[0]
      position: 'bottom center'
      openOn: 'click'
      classes: 'drop-theme-arrows-bounce-dark'
    $(element).data('drop', drop)
    drops.push drop

  drops

class window.TS.NewModel
  constructor: (@elements) ->
    @drops = []

  enable: ->
    @disable()
    @drops = setUpDrops(@elements)

  disable: ->
    for drop in @drops
      drop.close()
      drop.remove()
      drop.destroy()
    @drops = []

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
type_station-0.0.3 app/assets/javascripts/type_station/editables/new_model.js.coffee
type_station-0.0.2 app/assets/javascripts/type_station/editables/new_model.js.coffee
type_station-0.0.1 app/assets/javascripts/type_station/editables/new_model.js.coffee