Sha256: 8d438773ea1cfe4a08f9b1020a54f91fb9a3ba64cb23712ccb502d4857b4473b

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

;jQuery(function($) {
  var selector_prefix = 'body.controller-e9-polls-polls', 
      $selector       = $(selector_prefix);

  /**
   * Adds a new nested assocation.  Depends on the nested association
   * js templates being loaded.
   */
  $('a.add-nested-association').click(function(e) {
    e.preventDefault();

    var $this   = $(this), 
        $parent = $this.closest('.nested-associations'),
        obj,
        template,
        index;

    try { 
      obj = TEMPLATES[this.getAttribute('data-association')];
    } catch(e) { return }

    template = obj.template.replace(new RegExp(obj.index++, 'g'), obj.index);

    $(template).appendTo($parent);
  });

  /**
   * Effectively destroys an added nested association, removing the container
   * the association is not persisted, or hiding it and setting the _destroy
   * parameter for the association if it is.
   */
  $('a.destroy-nested-association').live('click', function(e) {
    e.preventDefault();

    var $parent = $(this).closest('.nested-association').hide(),
        $destro = $parent.find('input[id$=__destroy]');

    if ($destro.length) {
      $destro.val('1');
    } else {
      $parent.remove();
    }
  });
});

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
e9_polls-1.0.1 e9_polls.js