Sha256: 2956b2ccb572750e2a55bb6b98920b68f6462c2878739d6278d6b3461a3ab374

Contents?: true

Size: 1.63 KB

Versions: 28

Compression:

Stored size: 1.63 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_id = associated_resource.data("label-input")
      label_input = $("#" + label_input_id)
      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           = $(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
  
  autoupdate_labels($('.associated-resource'))
  
  $('.positionable .sortable').live 'sortupdate', ->
    update_positions $(@)

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
fullstack-admin-0.1.51 app/assets/javascripts/support/nested_forms.js.coffee
fullstack-admin-0.1.50 app/assets/javascripts/support/nested_forms.js.coffee
fullstack-admin-0.1.49 app/assets/javascripts/support/nested_forms.js.coffee
fullstack-admin-0.1.48 app/assets/javascripts/support/nested_forms.js.coffee
fullstack-admin-0.1.47 app/assets/javascripts/support/nested_forms.js.coffee
fullstack-admin-0.1.46 app/assets/javascripts/support/nested_forms.js.coffee
fullstack-admin-0.1.45 app/assets/javascripts/support/nested_forms.js.coffee
fullstack-admin-0.1.44 app/assets/javascripts/support/nested_forms.js.coffee
fullstack-admin-0.1.43 app/assets/javascripts/support/nested_forms.js.coffee
fullstack-admin-0.1.42 app/assets/javascripts/support/nested_forms.js.coffee
fullstack-admin-0.1.41 app/assets/javascripts/support/nested_forms.js.coffee
fullstack-admin-0.1.40 app/assets/javascripts/support/nested_forms.js.coffee
fullstack-admin-0.1.39 app/assets/javascripts/support/nested_forms.js.coffee
fullstack-admin-0.1.38 app/assets/javascripts/support/nested_forms.js.coffee
fullstack-admin-0.1.37 app/assets/javascripts/support/nested_forms.js.coffee
fullstack-admin-0.1.36 app/assets/javascripts/support/nested_forms.js.coffee
fullstack-admin-0.1.35 app/assets/javascripts/support/nested_forms.js.coffee
fullstack-admin-0.1.34 app/assets/javascripts/support/nested_forms.js.coffee
fullstack-admin-0.1.33 app/assets/javascripts/support/nested_forms.js.coffee
fullstack-admin-0.1.32 app/assets/javascripts/support/nested_forms.js.coffee