<commit_before><?php use_javascript('/gnCorePlugin/js/main.js') ?>
<?php use_javascript('/gnCorePlugin/vendor/jquery/js/jquery-ui-1.8rc3.custom.min.js') ?>
<?php use_javascript('/gnCorePlugin/vendor/ajaxupload/ajaxupload.js') ?>
<?php $panel_suffix = isset($panel_suffix) ? $panel_suffix : rand() ?>
<?php $description_text = __('Description goes here...') ?>
<fieldset>
  <legend><?php echo __('Asset Collection') ?></legend>
  <?php if($object->isNew()): ?>
  <p><?php echo __('Please create page before adding assets.'); ?></p>
  <?php else: ?>
  <p><?php echo __('Files to be linked to this page can be added here. Once uploaded you can drag them to change the order they appear.') ?></p>
    <ul class="gn-core-upload-panel clearfix" id="gnCoreUploadPanel<?php echo $panel_suffix ?>">
      <?php foreach($object->getAssets() as $asset): ?>
      <li id="<?php echo $asset->getId() ?>" class="gn-core-upload-item <?php echo ($asset->isImage()) ? 'thumbnail' : 'other' ?>">
        <span class="delete">&times;</span>
        <?php if($asset->isImage()): ?>
          <span class="insert" onclick="injectTextIntoCurrent('![<?php echo $description_text; ?>](asset:<?php echo $asset->getOriginalFilename() ?>|right)')">&nbsp;</span>
          <img src="<?php echo gnAssetToolkit::getThumbnailPath($asset->getSystemPath(), array('maxWidth' => 150, 'maxHeight' => 50, 'minHeight' => 50, 'minWidth' => 50)) ?>" />
        <?php else: ?>
          <span class="insert" onclick="injectTextIntoCurrent('[<?php echo $description_text; ?>](asset:<?php echo $asset->getOriginalFilename() ?>)')">&nbsp;</span>
          <img src="<?php echo '/gnCorePlugin/images/mime-types/' . gnAssetToolkit::translateExtensionToBase($asset->getOriginalFilename()) . '.png' ?>" />
          <?php echo $asset->getOriginalFilename(); ?>
        <?php endif; ?>
      </li>
      <?php endforeach; ?>
    </ul>
    <p>
      <button class="button" id="uploadImageButton<?php echo $panel_suffix ?>"><?php echo __('Upload a file') ?></button>
      <span id="gnCoreUploadPanelMessage<?php echo $panel_suffix ?>"></span>
    </p>
    <?php endif; ?>
</fieldset>
<?php echo $form['_csrf_token']->render(); ?>
<?php echo $form['model']->render(); ?>

<?php if(!$object->isNew()): ?>
<script type="text/javascript">
$(document).ready(function() {

  var addDeleteAction = function(item) {
    $(item).parent().fadeTo('fast', 0.5);
    $.ajax({
      dataType: 'json',
      data: {
        id : $(item).parent().attr('id')
      },
      url: '<?php echo url_for('@gn_asset_delete?sf_format=json') ?>',
      success: function(data) {
        if(data.status === 'success')
        {
          $('#'+data.id).hide();
        }
      }
    });
    return false;
  }

	$(function() {
    $('#gnCoreUploadPanel<?php echo $panel_suffix ?> .delete').click(function() {
      addDeleteAction(this);
    });
		$("#gnCoreUploadPanel<?php echo $panel_suffix ?>").sortable(
      {
        opacity      : 0.7,
        update : function (event, ui) {
          $.ajax({
            dataType: 'json',
            data: {
              order : $('#gnCoreUploadPanel<?php echo $panel_suffix ?>').sortable('toArray')
            },
            url: '<?php echo url_for('@gn_asset_reorder?sf_format=json') ?>',
            success: function(data) {}
          });
        }
      }
    );
	});
  var button = $('#uploadImageButton<?php echo $panel_suffix ?>');
  var message = $('#gnCoreUploadPanelMessage<?php echo $panel_suffix ?>');
  new AjaxUpload(button,{
    action: '<?php echo url_for('@gn_asset_upload?sf_format=json') ?>',
    name: 'gn_asset[filename]',
    data: {
      'gn_asset[model_id]'   : '<?php echo $object->getId() ?>',
      'gn_asset[model]'      : '<?php echo get_class($sf_data->getRaw('object')) ?>',
      'gn_asset[_csrf_token]': '<?php echo $form['_csrf_token']->getValue(); ?>'
    },
    onSubmit : function(file, ext){
      message.text('<?php echo __('Uploading') ?>').fadeIn(0);
      this.disable();
    },
    onComplete: function(file, response){
      this.enable();
      var response = jQuery.parseJSON(response);
      message.addClass(response.status).text(response.message).fadeOut(4000);
      if(response.status === 'success')
      {
        var name = '';
          onclick = ' onclick="injectTextIntoCurrent(\'![<?php echo $description_text; ?>](asset:'+file+')\')"';
        if(response.type === 'other')
        {
          onclick = ' onclick="injectTextIntoCurrent(\'[<?php echo $description_text; ?>](asset:'+file+')\')"';
          name = ' ' + file;
        }
        $('<li id="'+ response.asset_id +'" class="gn-core-upload-item '+ response.type +'"></li>').appendTo(
          '#gnCoreUploadPanel<?php echo $panel_suffix ?>'
        ).html('<span class="delete">&times;</span><span class="insert" '+onclick+'>&nbsp;</span><img src="'+ response.location +'" />' + name);
        $('li#'+ response.asset_id +' span.delete').click(function() {
          addDeleteAction(this);
        });
      }
    }
  });
});
</script>
<?php endif; ?>
<commit_msg>Small change to the upload javascript to fix Safari bug.<commit_after><?php use_javascript('/gnCorePlugin/js/main.js') ?>
<?php use_javascript('/gnCorePlugin/vendor/jquery/js/jquery-ui-1.8rc3.custom.min.js') ?>
<?php use_javascript('/gnCorePlugin/vendor/ajaxupload/ajaxupload.js') ?>
<?php $panel_suffix = isset($panel_suffix) ? $panel_suffix : rand() ?>
<?php $description_text = __('Description goes here...') ?>
<fieldset>
  <legend><?php echo __('Asset Collection') ?></legend>
  <?php if($object->isNew()): ?>
  <p><?php echo __('Please create page before adding assets.'); ?></p>
  <?php else: ?>
  <p><?php echo __('Files to be linked to this page can be added here. Once uploaded you can drag them to change the order they appear.') ?></p>
    <ul class="gn-core-upload-panel clearfix" id="gnCoreUploadPanel<?php echo $panel_suffix ?>">
      <?php foreach($object->getAssets() as $asset): ?>
      <li id="<?php echo $asset->getId() ?>" class="gn-core-upload-item <?php echo ($asset->isImage()) ? 'thumbnail' : 'other' ?>">
        <span class="delete">&times;</span>
        <?php if($asset->isImage()): ?>
          <span class="insert" onclick="injectTextIntoCurrent('![<?php echo $description_text; ?>](asset:<?php echo $asset->getOriginalFilename() ?>|right)')">&nbsp;</span>
          <img src="<?php echo gnAssetToolkit::getThumbnailPath($asset->getSystemPath(), array('maxWidth' => 150, 'maxHeight' => 50, 'minHeight' => 50, 'minWidth' => 50)) ?>" />
        <?php else: ?>
          <span class="insert" onclick="injectTextIntoCurrent('[<?php echo $description_text; ?>](asset:<?php echo $asset->getOriginalFilename() ?>)')">&nbsp;</span>
          <img src="<?php echo '/gnCorePlugin/images/mime-types/' . gnAssetToolkit::translateExtensionToBase($asset->getOriginalFilename()) . '.png' ?>" />
          <?php echo $asset->getOriginalFilename(); ?>
        <?php endif; ?>
      </li>
      <?php endforeach; ?>
    </ul>
    <p>
      <button class="button" id="uploadImageButton<?php echo $panel_suffix ?>"><?php echo __('Upload a file') ?></button>
      <span id="gnCoreUploadPanelMessage<?php echo $panel_suffix ?>"></span>
    </p>
    <?php endif; ?>
</fieldset>
<?php echo $form['_csrf_token']->render(); ?>
<?php echo $form['model']->render(); ?>

<?php if(!$object->isNew()): ?>
<script type="text/javascript">
$(document).ready(function() {

  var addDeleteAction = function(item) {
    $(item).parent().fadeTo('fast', 0.5);
    $.ajax({
      dataType: 'json',
      data: {
        id : $(item).parent().attr('id')
      },
      url: '<?php echo url_for('@gn_asset_delete?sf_format=json') ?>',
      success: function(data) {
        if(data.status === 'success')
        {
          $('#'+data.id).hide();
        }
      }
    });
    return false;
  }

	$(function() {
    $('#gnCoreUploadPanel<?php echo $panel_suffix ?> .delete').click(function() {
      addDeleteAction(this);
    });
		$("#gnCoreUploadPanel<?php echo $panel_suffix ?>").sortable(
      {
        opacity      : 0.7,
        update : function (event, ui) {
          $.ajax({
            dataType: 'json',
            data: {
              order : $('#gnCoreUploadPanel<?php echo $panel_suffix ?>').sortable('toArray')
            },
            url: '<?php echo url_for('@gn_asset_reorder?sf_format=json') ?>',
            success: function(data) {}
          });
        }
      }
    );
	});
  var button = $('#uploadImageButton<?php echo $panel_suffix ?>');
  var message = $('#gnCoreUploadPanelMessage<?php echo $panel_suffix ?>');
  new AjaxUpload(button,{
    action: '<?php echo url_for('@gn_asset_upload?sf_format=json') ?>',
    name: 'gn_asset[filename]',
    data: {
      'gn_asset[model_id]'   : '<?php echo $object->getId() ?>',
      'gn_asset[model]'      : '<?php echo get_class($sf_data->getRaw('object')) ?>',
      'gn_asset[_csrf_token]': '<?php echo $form['_csrf_token']->getValue(); ?>'
    },
    onSubmit : function(file, ext){
      message.text('<?php echo __('Uploading') ?>').fadeIn(0);
      this.disable();
    },
    onComplete: function(file, response){
      this.enable();
      var response = jQuery.parseJSON(response);
      message.addClass(response.status).text(response.message).fadeOut(4000);
      if(response.status === 'success')
      {
        var name = '';
        var onclick = ' onclick="injectTextIntoCurrent(\'![<?php echo $description_text; ?>](asset:'+file+')\')"';
        if(response.type === 'other')
        {
          onclick = ' onclick="injectTextIntoCurrent(\'[<?php echo $description_text; ?>](asset:'+file+')\')"';
          name = ' ' + file;
        }
        $('<li id="'+ response.asset_id +'" class="gn-core-upload-item '+ response.type +'"></li>').appendTo(
          '#gnCoreUploadPanel<?php echo $panel_suffix ?>'
        ).html('<span class="delete">&times;</span><span class="insert" '+onclick+'>&nbsp;</span><img src="'+ response.location +'" />' + name);
        $('li#'+ response.asset_id +' span.delete').click(function() {
          addDeleteAction(this);
        });
      }
    }
  });
});
</script>
<?php endif; ?>

{'fraction_non_alphanumeric': 0.21235369332153045, 'fraction_numerical': 0.004131012097964001, 'mean_word_length': 3.3304940374787053, 'pattern_counts': {'":': 0, '<': 169, '<?xml version=': 0, '>': 209, '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': '1669207', 'n_tokens_mistral': 3234, 'n_tokens_neox': 3177, 'n_words': 620}