<commit_before><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="im"%>

<!-- template.jsp -->


<tiles:importAttribute/>
<html:xhtml/>
<script type="text/javascript" src="js/autocompleter.js"></script>
<link rel="stylesheet" href="css/autocompleter.css" type="text/css"/>
<link rel="stylesheet" type="text/css" href="css/template.css"/>



<script type="text/javascript">
  <!--

  var fixedOps = new Array();

  /***********************************************************
   * Called when user chooses a constraint operator. If the
   * user picks an operator contained in fixedOptionsOps then
   * the input box is hidden and the user can only choose
   **********************************************************/
  function updateConstraintForm(index, attrOpElement, attrOptsElement, attrValElement)
  {
    if (attrOptsElement == null)
      return;

    for (var i=0 ; i<fixedOps[index].length ; i++)
    {
      if (attrOpElement.value == fixedOps[index][i])
      {
        document.getElementById("operandEditSpan" + index).style.display = "none";
        attrValElement.value = attrOptsElement.value; // constrain value
        return;
      }
    }
    document.getElementById("operandEditSpan" + index).style.display = "";
  }

  /***********************************************************
   * Use bag checkbox has been clicked.
   **********************************************************/
  function clickUseBag(index)
  {
    var useBag = document.templateForm["useBagConstraint("+index+")"].checked;

    document.templateForm["attributeOps("+index+")"].disabled=useBag;
    if (document.templateForm["attributeOptions("+index+")"])
      document.templateForm["attributeOptions("+index+")"].disabled=useBag;
    document.templateForm["attributeValues("+index+")"].disabled=useBag;
    document.templateForm["bag("+index+")"].disabled=!useBag;
    document.templateForm["bagOp("+index+")"].disabled=!useBag;
  }

  function initClickUseBag(index)
  {
    if(selectedBagName){
      document.templateForm["bag("+index+")"].value=selectedBagName;
      document.templateForm["useBagConstraint("+index+")"].checked = true;
    }
    clickUseBag(index);
  }

  /***********************************************************
   * Init attribute value with selected item and hide input box if
   * required
   **********************************************************/
  /*function initConstraintForm(index, attrOpElement, attrOptsElement, attrValElement)
  {
    if (attrOptsElement == null)
      return;

    attrValElement.value = attrOptsElement.value;
    updateConstraintForm(index, attrOpElement, attrOptsElement, attrValElement);
  }*/

  /***************Handle display of help windows******************************/
  var helpMsgArray = new Array();
  var ourDate;
  var isIE = '${iePre7}';
  function displayHelpMsg(e, id) {
      if(isIE != 'true') {
      // IE is retarded and doesn't pass the event object
          if (e == null)
              e = window.event;

          // IE uses srcElement, others use target
          var target = e.target != null ? e.target : e.srcElement;
          // grab the clicked element's position
          _clientX = e.clientX;
          _clientY = e.clientY;

          // grab the clicked element's position
           _offsetX = ExtractNumber(target.style.left);
           _offsetY = ExtractNumber(target.style.top);

          $(id).style.left = (_clientX + _offsetX) + "px";
          $(id).style.top = (_clientY + _offsetY) + "px";
          Effect.Appear(id, { duration: 0.30 });
          helpMsgArray[helpMsgArray.length] = id;
          ourDate = new Date().getTime();
     } else {
         $(id).style.position = "relative";
         $(id).style.display = "block";
     }
  }
  document.body.onclick = function clearHelpMsg() {
      newDate = new Date().getTime();
      if(newDate > (ourDate + 100)){
      for(var i=0;i<helpMsgArray.length;i++) {
          Effect.Fade(helpMsgArray[i], { duration: 0.30 });
          $('DivShim').style.display = "none";
      }
      }
  }
  function ExtractNumber(value)
  {
      var n = parseInt(value);

      return n == null || isNaN(n) ? 0 : n;
  }

   function forwardToLinks()
   {
       document.getElementById('actionType').value = 'links';
       document.templateForm.submit();
   }

  //-->
</script>


<tiles:get name="objectTrail.tile"/>
<div class="body" align="center">
<im:boxarea stylename="plainbox" fixedWidth="60%">
  <html:form action="/templateAction">
    <h2 class="templateTitle">
    <c:set var="templateTitle" value="${fn:replace(templateQuery.title,'-->','&nbsp;<img src=\"images/tmpl_arrow.png\" style=\"vertical-align:middle\">&nbsp;')}" />
  ${templateTitle}
    <tiles:insert name="setFavourite.tile">
        <tiles:put name="name" value="${templateQuery.name}"/>
        <tiles:put name="type" value="template"/>
    </tiles:insert></h2>
    <div class="templateDescription">${templateQuery.description}</div>
    <ol class="templateForm">
      <c:set var="index" value="${0}"/>
      <c:forEach items="${templateQuery.editableNodes}" var="node"><commit_msg>Javascript validation that  bags are not used when link is generated.<commit_after><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="im"%>

<!-- template.jsp -->


<tiles:importAttribute/>
<html:xhtml/>
<script type="text/javascript" src="js/autocompleter.js"></script>
<link rel="stylesheet" href="css/autocompleter.css" type="text/css"/>
<link rel="stylesheet" type="text/css" href="css/template.css"/>



<script type="text/javascript">
  <!--

  var fixedOps = new Array();

  /***********************************************************
   * Called when user chooses a constraint operator. If the
   * user picks an operator contained in fixedOptionsOps then
   * the input box is hidden and the user can only choose
   **********************************************************/
  function updateConstraintForm(index, attrOpElement, attrOptsElement, attrValElement)
  {
    if (attrOptsElement == null)
      return;

    for (var i=0 ; i<fixedOps[index].length ; i++)
    {
      if (attrOpElement.value == fixedOps[index][i])
      {
        document.getElementById("operandEditSpan" + index).style.display = "none";
        attrValElement.value = attrOptsElement.value; // constrain value
        return;
      }
    }
    document.getElementById("operandEditSpan" + index).style.display = "";
  }

  /***********************************************************
   * Use bag checkbox has been clicked.
   **********************************************************/
  function clickUseBag(index)
  {
    var useBag = document.templateForm["useBagConstraint("+index+")"].checked;

    document.templateForm["attributeOps("+index+")"].disabled=useBag;
    if (document.templateForm["attributeOptions("+index+")"])
      document.templateForm["attributeOptions("+index+")"].disabled=useBag;
    document.templateForm["attributeValues("+index+")"].disabled=useBag;
    document.templateForm["bag("+index+")"].disabled=!useBag;
    document.templateForm["bagOp("+index+")"].disabled=!useBag;
  }

  function initClickUseBag(index)
  {
    if(selectedBagName){
      document.templateForm["bag("+index+")"].value=selectedBagName;
      document.templateForm["useBagConstraint("+index+")"].checked = true;
    }
    clickUseBag(index);
  }

  /***********************************************************
   * Init attribute value with selected item and hide input box if
   * required
   **********************************************************/
  /*function initConstraintForm(index, attrOpElement, attrOptsElement, attrValElement)
  {
    if (attrOptsElement == null)
      return;

    attrValElement.value = attrOptsElement.value;
    updateConstraintForm(index, attrOpElement, attrOptsElement, attrValElement);
  }*/

  /***************Handle display of help windows******************************/
  var helpMsgArray = new Array();
  var ourDate;
  var isIE = '${iePre7}';
  function displayHelpMsg(e, id) {
      if(isIE != 'true') {
      // IE is retarded and doesn't pass the event object
          if (e == null)
              e = window.event;

          // IE uses srcElement, others use target
          var target = e.target != null ? e.target : e.srcElement;
          // grab the clicked element's position
          _clientX = e.clientX;
          _clientY = e.clientY;

          // grab the clicked element's position
           _offsetX = ExtractNumber(target.style.left);
           _offsetY = ExtractNumber(target.style.top);

          $(id).style.left = (_clientX + _offsetX) + "px";
          $(id).style.top = (_clientY + _offsetY) + "px";
          Effect.Appear(id, { duration: 0.30 });
          helpMsgArray[helpMsgArray.length] = id;
          ourDate = new Date().getTime();
     } else {
         $(id).style.position = "relative";
         $(id).style.display = "block";
     }
  }
  document.body.onclick = function clearHelpMsg() {
      newDate = new Date().getTime();
      if(newDate > (ourDate + 100)){
      for(var i=0;i<helpMsgArray.length;i++) {
          Effect.Fade(helpMsgArray[i], { duration: 0.30 });
          $('DivShim').style.display = "none";
      }
      }
  }
  function ExtractNumber(value)
  {
      var n = parseInt(value);

      return n == null || isNaN(n) ? 0 : n;
  }

   function forwardToLinks()
   {
   	   // needed validation that bag is not used, validation is performed in the Struts action as well
       if (isBagUsed()) {
            new Insertion.Bottom('error_msg','Link could not be created. This template contains list constraint(s). The service for this special template is not implemented yet. Solution: Don\'t use list contraint.<br/>');
            haserrors=1;
            Effect.Appear('error_msg');       
            return;
       }
       document.getElementById('actionType').value = 'links';
       document.templateForm.submit();
   }
   
   function isBagUsed() {
        // checks if bag is used, the presumption is that there aren't more than 10 bag constraints 
        for (var i = 0; i < 10; i++) {
            if (document.templateForm["useBagConstraint("+i+")"]) {
	            if (document.templateForm["useBagConstraint("+i+")"].checked) {
	                return true;
	            }                
            }
        }
        return false;
   }

  //-->
</script>


<tiles:get name="objectTrail.tile"/>
<div class="body" align="center">
<im:boxarea stylename="plainbox" fixedWidth="60%">
  <html:form action="/templateAction">
    <h2 class="templateTitle">
    <c:set var="templateTitle" value="${fn:replace(templateQuery.title,'-->','&nbsp;<img src=\"images/tmpl_arrow.png\" style=\"vertical-align:middle\">&nbsp;')}" />
  ${templateTitle}
    <tiles:insert name="setFavourite.tile">
        <tiles:put name="name" value="${templateQuery.name}"/>
        <tiles:put name="type" value="template"/>
    </tiles:insert></h2>
    <div class="templateDescription">${templateQuery.description}</div>
    <ol class="templateForm">
      <c:set var="index" value="${0}"/>
      <c:forEach items="${templateQuery.editableNodes}" var="node">
{'fraction_non_alphanumeric': 0.21685622135460872, 'fraction_numerical': 0.0035647598030894585, 'mean_word_length': 3.433032355154251, 'pattern_counts': {'":': 0, '<': 75, '<?xml version=': 0, '>': 74, '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': '4818026', 'n_tokens_mistral': 3537, 'n_tokens_neox': 3415, 'n_words': 689}