Sha256: c9d85d1e2267eb25d0bb672b0ac93ffe149a37824c161d44532183a87ed465bf

Contents?: true

Size: 1.72 KB

Versions: 3

Compression:

Stored size: 1.72 KB

Contents

$(document).ready ->
  $('a.btn-delete-associated-resource').live 'click', ->
    self = $(@)
    associated_resource = $(@).closest(".associated-resource")
    
    if !self.hasClass("active")
      associated_resource.removeClass("deleted");
      associated_resource.find("input.destroy-associated-resource").val('0')
    else
      associated_resource.addClass("deleted");
      associated_resource.find("input.destroy-associated-resource").val('1')

  autoupdate_labels = (associated_resources) ->
    associated_resources.each ->
      associated_resource = $(@)
      label_input = $(associated_resource.find("input[type='text']")[0])
      label_input.change ->
        associated_resource.find(".associated-resource-label").text(label_input.val())
  
  update_positions = (sortable) ->
    sortable.find('input.associated-resource-position').each (i, e) ->
      $(@).val(i)

  $(".btn-add-associated-resource").click ->
    associated_resources        = $(@).closest(".associated-resources")
    associated_resources_index  = associated_resources.find(".associated-resources-index")
    resource_fields_template    = associated_resources.find(".resource-fields-template")
    new_id = new Date().getTime()
    template_instance           = $( $.parseHTML(resource_fields_template.html().replace(/___index___/g, new_id)) )
    associated_resources_index.append(template_instance)
    autoupdate_labels(associated_resources_index.find('.associated-resource:last'))
    update_positions associated_resources_index
    associated_resources_index.find('.associated-resource:last').find(".btn[data-toggle='modal']").click()
  
  autoupdate_labels($('.associated-resource'))
  
  $('.positionable .sortable').live 'sortupdate', ->
    update_positions $(@)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fullstack-admin-0.2.26 app/assets/javascripts/fullstack/admin/src/nested_forms.js.coffee
fullstack-admin-0.2.25 app/assets/javascripts/fullstack/admin/src/nested_forms.js.coffee
fullstack-admin-0.2.24 app/assets/javascripts/fullstack/admin/src/nested_forms.js.coffee