<commit_before>import $ from 'jquery';

/**
 * Property Relationship.
 */

class Relationship {

  /**
   * Initialize Property Relationship.
   */

  static init() {
    new Relationship().binds();
  }

  /**
   * Add new page to the list.
   *
   * @param {object} $this
   */

  add($this) {
    const $li    = $this.clone();
    const $prop  = $this.closest('.papi-property-relationship');
    const $right = $prop.find('.relationship-right');
    const $list  = $right.find('ul');
    const limit  = $right.data().limit;
    const append = limit === undefined || limit === -1 || $list.find('li').length < limit;

    if (append) {
      $li.find('span.icon').removeClass('plus').addClass('minus');
      $li.find('input').attr('name', $li.find('input').data().name);

      $li.appendTo($list);
      this.triggerRule($prop);
    }
  }

  /**
   * Bind elements with functions.
   */

  binds() {
    const self = this;
    $('.relationship-right > ul').sortable({
      placeholder: 'ui-state-highlight',
      start: function (e, ui) {
        ui.item.addClass('sortable');
      },
      stop: function (e, ui) {
        ui.item.removeClass('sortable');
      }
    }).disableSelection();
    $(document).on('click', '.papi-property-relationship .relationship-left li', function (e) {
      e.preventDefault();
      self.add($(this));
    });
    $(document).on('click', '.papi-property-relationship .relationship-right li', function (e) {
      e.preventDefault();
      self.remove($(this));
    });
    $(document).on('keyup', '.papi-property-relationship input[type=search]', this.search);
    $(document).on('papi/property/repeater/added', '[data-property="relationship"]', this.update);
  }

  /**
   * Remove the selected page.
   *
   * @param {object} $this
   */

  remove($this) {
    const $prop = $this.closest('.papi-property-relationship');
    $this.remove();
    this.triggerRule($prop);
  }

  /**
   * Search for a page in the list.
   *
   * @param {object} e
   */

  search(e) {
    e.preventDefault();

    const $this = $(this);
    const $list = $this.closest('.papi-property-relationship').find('.relationshio-left ul');
    const val   = $this.val().toLowerCase();

    $list.find('li').each(function () {
      let $li = $(this);
      if ($li.text().toLowerCase().indexOf(val) === -1) {
        $li.addClass('papi-hide');
      } else {
        $li.removeClass('papi-hide');
      }
    });
  }

  /**
   * Trigger conditional rule.
   *
   * @param {object} $prop
   */

  triggerRule($prop) {
    let $list = $prop.find('.relationship-right ul');

    $prop
      .find('[data-papi-rule]')
      .data('papi-rule-value', $list.children().length)
      .trigger('change');
  }

  /**
   * Fix name attribute when added to a repeater.
   *
   * @param {object} e
   */

  update(e) {
    e.preventDefault();

    let   $this = $(this);
    const $prop = $this.prev();

    $prop.find('.relationship-left [name]').each(function () {
      $this = $(this);
      $this.data('name', $this.attr('name'));
      $this.removeAttr('name');
    });
  }

}

export default Relationship;<commit_msg>Removed data-papi-rule-value from relationship<commit_after>import $ from 'jquery';

/**
 * Property Relationship.
 */

class Relationship {

  /**
   * Initialize Property Relationship.
   */

  static init() {
    new Relationship().binds();
  }

  /**
   * Add new page to the list.
   *
   * @param {object} $this
   */

  add($this) {
    const $li    = $this.clone();
    const $prop  = $this.closest('.papi-property-relationship');
    const $right = $prop.find('.relationship-right');
    const $list  = $right.find('ul');
    const limit  = $right.data().limit;
    const append = limit === undefined || limit === -1 || $list.find('li').length < limit;

    if (append) {
      $li.find('span.icon').removeClass('plus').addClass('minus');
      $li.find('input').attr('name', $li.find('input').data().name);

      $li.appendTo($list);
      this.triggerRule($prop);
    }
  }

  /**
   * Bind elements with functions.
   */

  binds() {
    const self = this;
    $('.relationship-right > ul').sortable({
      placeholder: 'ui-state-highlight',
      start: function (e, ui) {
        ui.item.addClass('sortable');
      },
      stop: function (e, ui) {
        ui.item.removeClass('sortable');
      }
    }).disableSelection();
    $(document).on('click', '.papi-property-relationship .relationship-left li', function (e) {
      e.preventDefault();
      self.add($(this));
    });
    $(document).on('click', '.papi-property-relationship .relationship-right li', function (e) {
      e.preventDefault();
      self.remove($(this));
    });
    $(document).on('keyup', '.papi-property-relationship input[type=search]', this.search);
    $(document).on('papi/property/repeater/added', '[data-property="relationship"]', this.update);
  }

  /**
   * Remove the selected page.
   *
   * @param {object} $this
   */

  remove($this) {
    const $prop = $this.closest('.papi-property-relationship');
    $this.remove();
    this.triggerRule($prop);
  }

  /**
   * Search for a page in the list.
   *
   * @param {object} e
   */

  search(e) {
    e.preventDefault();

    const $this = $(this);
    const $list = $this.closest('.papi-property-relationship').find('.relationshio-left ul');
    const val   = $this.val().toLowerCase();

    $list.find('li').each(function () {
      let $li = $(this);
      if ($li.text().toLowerCase().indexOf(val) === -1) {
        $li.addClass('papi-hide');
      } else {
        $li.removeClass('papi-hide');
      }
    });
  }

  /**
   * Trigger conditional rule.
   *
   * @param {object} $prop
   */

  triggerRule($prop) {
    let $list = $prop.find('.relationship-right ul');

    $prop
      .find('[data-papi-rule]')
      .trigger('change');
  }

  /**
   * Fix name attribute when added to a repeater.
   *
   * @param {object} e
   */

  update(e) {
    e.preventDefault();

    let   $this = $(this);
    const $prop = $this.prev();

    $prop.find('.relationship-left [name]').each(function () {
      $this = $(this);
      $this.data('name', $this.attr('name'));
      $this.removeAttr('name');
    });
  }

}

export default Relationship;
{'fraction_non_alphanumeric': 0.20157278125501524, 'fraction_numerical': 0.0006419515326592842, 'mean_word_length': 2.577497129735936, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4328912', 'n_tokens_mistral': 2083, 'n_tokens_neox': 2019, 'n_words': 380}