<commit_before><?php $sf_response->addJavaScript('date') ?>
<?php $sf_response->addJavaScript('/vendor/yui/datasource/datasource-min') ?>
<?php $sf_response->addJavaScript('/vendor/yui/container/container-min') ?>
<?php $sf_response->addJavaScript('dialog') ?>
<?php $sf_response->addJavaScript('multiDelete') ?>

<?php use_helper('Javascript') ?>

<div class="section">

  <table id="relatedEntities" class="table table-bordered">
    <caption>
      <?php echo __('Related corporate bodies, persons or families') ?>
    </caption><thead>
      <tr>
        <th style="width: 20%">
          <?php echo __('Name') ?>
        </th><th style="width: 15%">
          <?php echo __('Category') ?>
        </th><th style="width: 15%">
          <?php echo __('Type') ?>
        </th><th style="width: 15%">
          <?php echo __('Dates') ?>
        </th><th style="width: 25%">
          <?php echo __('Description') ?>
        </th><th style="text-align: center; width: 10%">
          <?php echo image_tag('delete', array('align' => 'top', 'class' => 'deleteIcon')) ?>
        </th>
      </tr>
    </thead><tbody>
      <?php foreach ($resource->getActorRelations() as $item): ?>
        <tr class="<?php echo 0 == @++$row % 2 ? 'even' : 'odd' ?> related_obj_<?php echo $item->id ?>" id="<?php echo url_for(array($item, 'module' => 'relation')) ?>">
          <td>
            <?php if ($resource->id == $item->objectId): ?>
              <?php echo render_title($item->subject) ?>
            <?php else: ?>
              <?php echo render_title($item->object) ?>
            <?php endif; ?>
          </td><td>
            <?php if ($item->type->parentId == QubitTerm::ROOT_ID): ?>
              <?php echo $item->type ?>
            <?php else: ?>
              <?php echo $item->type->parent ?>
            <?php endif; ?>
          </td><td>
            <?php if ($item->type->parentId != QubitTerm::ROOT_ID): ?>
              <?php if ($resource->id != $item->objectId): ?>
                <?php echo $item->type.' '.render_title($resource) ?>
              <?php elseif (0 < count($converseTerms = QubitRelation::getBySubjectOrObjectId($item->type->id, array('typeId' => QubitTerm::CONVERSE_TERM_ID)))): ?>
                <?php echo $converseTerms[0]->getOpposedObject($item->type).' '.render_title($resource) ?>
              <?php endif; ?>
            <?php endif; ?>
          </td><td>
            <?php echo Qubit::renderDateStartEnd($item->date, $item->startDate, $item->endDate) ?>
          </td><td>
            <?php echo $item->description ?>
          </td><td style="text-align: center">
            <input class="multiDelete" name="deleteRelations[]" type="checkbox" value="<?php echo url_for(array($item, 'module' => 'relation')) ?>"/>
          </td>
        </tr>
      <?php endforeach; ?>
    </tbody>
  </table>

<?php

// Template for new display table rows
$editHtml = image_tag('pencil', array('alt' => 'edit', 'style' => 'align: top'));

$rowTemplate = json_encode(<<<value
<tr id="{{$form->getWidgetSchema()->generateName('id')}}">
  <td>
    {{$form->resource->renderName()}}
  </td><td>
    {{$form->type->renderName()}}
  </td><td>
    {{$form->subType->renderName()}}
  </td><td>
    {{$form->date->renderName()}}
  </td><td>
    {{$form->description->renderName()}}
  </td><td style="text-align: right">
    $editHtml <button class="delete-small" name="delete" type="button"/>
  </td>
</tr>

value
);

$url = url_for($resource);

echo javascript_tag(<<<content
Drupal.behaviors.relatedAuthorityRecord = {
  attach: function (context)
    {
      // Add special rendering rules
      var handleFieldRender = function (fname)
        {
          if (-1 !== fname.indexOf('date')
              && 1 > this.getField('date').value.length
              && (0 < this.getField('startDate').value.length
                || 0 < this.getField('endDate').value.length))
          {
            return this.getField('startDate').value + ' - ' + this.getField('endDate').value;
          }

          return this.renderField(fname);
        }

      // Define dialog
      var dialog = new QubitDialog('actorRelation', {
        'displayTable': 'relatedEntities',
        'handleFieldRender': handleFieldRender,
        'newRowTemplate': $rowTemplate,
        'relationTableMap': function (response)
          {
            response.resource = response.object;
            if ('$url' === response.resource)
            {
              response.resource = response.subject;
              response.subType = response.converseSubType;
            }

            response.actor = ' $resource';

            return response;
          } });

      // Add edit button to rows
      jQuery('#relatedEntities tr[id]', context)
        .click(function ()
          {
            dialog.open(this.id);<commit_msg>Fix escaping in embedded-js string, refs #7818<commit_after><?php $sf_response->addJavaScript('date') ?>
<?php $sf_response->addJavaScript('/vendor/yui/datasource/datasource-min') ?>
<?php $sf_response->addJavaScript('/vendor/yui/container/container-min') ?>
<?php $sf_response->addJavaScript('dialog') ?>
<?php $sf_response->addJavaScript('multiDelete') ?>

<?php use_helper('Javascript') ?>

<div class="section">

  <table id="relatedEntities" class="table table-bordered">
    <caption>
      <?php echo __('Related corporate bodies, persons or families') ?>
    </caption><thead>
      <tr>
        <th style="width: 20%">
          <?php echo __('Name') ?>
        </th><th style="width: 15%">
          <?php echo __('Category') ?>
        </th><th style="width: 15%">
          <?php echo __('Type') ?>
        </th><th style="width: 15%">
          <?php echo __('Dates') ?>
        </th><th style="width: 25%">
          <?php echo __('Description') ?>
        </th><th style="text-align: center; width: 10%">
          <?php echo image_tag('delete', array('align' => 'top', 'class' => 'deleteIcon')) ?>
        </th>
      </tr>
    </thead><tbody>
      <?php foreach ($resource->getActorRelations() as $item): ?>
        <tr class="<?php echo 0 == @++$row % 2 ? 'even' : 'odd' ?> related_obj_<?php echo $item->id ?>" id="<?php echo url_for(array($item, 'module' => 'relation')) ?>">
          <td>
            <?php if ($resource->id == $item->objectId): ?>
              <?php echo render_title($item->subject) ?>
            <?php else: ?>
              <?php echo render_title($item->object) ?>
            <?php endif; ?>
          </td><td>
            <?php if ($item->type->parentId == QubitTerm::ROOT_ID): ?>
              <?php echo $item->type ?>
            <?php else: ?>
              <?php echo $item->type->parent ?>
            <?php endif; ?>
          </td><td>
            <?php if ($item->type->parentId != QubitTerm::ROOT_ID): ?>
              <?php if ($resource->id != $item->objectId): ?>
                <?php echo $item->type.' '.render_title($resource) ?>
              <?php elseif (0 < count($converseTerms = QubitRelation::getBySubjectOrObjectId($item->type->id, array('typeId' => QubitTerm::CONVERSE_TERM_ID)))): ?>
                <?php echo $converseTerms[0]->getOpposedObject($item->type).' '.render_title($resource) ?>
              <?php endif; ?>
            <?php endif; ?>
          </td><td>
            <?php echo Qubit::renderDateStartEnd($item->date, $item->startDate, $item->endDate) ?>
          </td><td>
            <?php echo $item->description ?>
          </td><td style="text-align: center">
            <input class="multiDelete" name="deleteRelations[]" type="checkbox" value="<?php echo url_for(array($item, 'module' => 'relation')) ?>"/>
          </td>
        </tr>
      <?php endforeach; ?>
    </tbody>
  </table>

<?php

// Template for new display table rows
$editHtml = image_tag('pencil', array('alt' => 'edit', 'style' => 'align: top'));

$rowTemplate = json_encode(<<<value
<tr id="{{$form->getWidgetSchema()->generateName('id')}}">
  <td>
    {{$form->resource->renderName()}}
  </td><td>
    {{$form->type->renderName()}}
  </td><td>
    {{$form->subType->renderName()}}
  </td><td>
    {{$form->date->renderName()}}
  </td><td>
    {{$form->description->renderName()}}
  </td><td style="text-align: right">
    $editHtml <button class="delete-small" name="delete" type="button"/>
  </td>
</tr>

value
);

$url = url_for($resource);
$actorTitle = esc_entities($resource->__toString());

echo javascript_tag(<<<content
Drupal.behaviors.relatedAuthorityRecord = {
  attach: function (context)
    {
      // Add special rendering rules
      var handleFieldRender = function (fname)
        {
          if (-1 !== fname.indexOf('date')
              && 1 > this.getField('date').value.length
              && (0 < this.getField('startDate').value.length
                || 0 < this.getField('endDate').value.length))
          {
            return this.getField('startDate').value + ' - ' + this.getField('endDate').value;
          }

          return this.renderField(fname);
        }

      // Define dialog
      var dialog = new QubitDialog('actorRelation', {
        'displayTable': 'relatedEntities',
        'handleFieldRender': handleFieldRender,
        'newRowTemplate': $rowTemplate,
        'relationTableMap': function (response)
          {
            response.resource = response.object;
            if ('$url' === response.resource)
            {
              response.resource = response.subject;
              response.subType = response.converseSubType;
            }

            response.actor = ' $actorTitle';

            return response;
          } });

      // Add edit button to rows
      jQuery('#relatedEntities tr[id]', context)
        .click(function ()
          {
            dialog.open(this.id);
{'fraction_non_alphanumeric': 0.19443874410014364, 'fraction_numerical': 0.004514672686230248, 'mean_word_length': 2.43688293370945, 'pattern_counts': {'":': 0, '<': 205, '<?xml version=': 0, '>': 284, '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': '1894297', 'n_tokens_mistral': 2975, 'n_tokens_neox': 2900, 'n_words': 583}