<h1 tal:replace="structure here/manage_page_header">Header</h1>
<h2 tal:define="manage_tabs_message options/manage_tabs_message | nothing"
    tal:replace="structure here/manage_tabs">Tabs</h2>

<div tal:define="availableContextTypes here/listContextTypes;
                 fixed_object python:test(here.id=='portal_form_controller', None, here.id);
                 filters python:fixed_object and {'object_id':fixed_object} or {};">

<h3>Form and Script Validators</h3>

<p>This tool lets you set or override the default sequence of validators that are 
executed when a Controller Page Template is submitted or before a Controller
Python Script is executed.  <a href="#docs">Learn more</a>.</p>

<hr/>

<h3 class="form-help">Edit Form / Script Validator Overrides</h3>

<form method="POST"
      tal:attributes="action here/absolute_url" 
      tal:define="form_validators python:here.listFormValidators(1, **filters);">
   <input type="hidden" name="override:int" value="1" />
<table border="0" tal:condition="form_validators" metal:define-macro="edit_validators">
   <tr>
      <td>&nbsp;</td>
      <td class="form-label">Template</td>
      <td class="form-label">Context</td>
      <td class="form-label">Button</td>
      <td class="form-label">Validators</td>
   </tr>
   <tr tal:repeat="validator form_validators">
       <td class="form-element">
          <input type="checkbox" 
                 tal:attributes="name python:'del_id_'+str(repeat['validator'].index);" />
          <input type="hidden" 
                 tal:attributes="name python:'old_object_id_'+str(repeat['validator'].index);
                                 value validator/getObjectId;" />
          <input type="hidden" 
                 tal:attributes="name python:'old_context_type_'+str(repeat['validator'].index);
                                 value validator/getContextType;" />
          <input type="hidden" 
                 tal:attributes="name python:'old_button_'+str(repeat['validator'].index);
                                 value validator/getButton;" />
       </td>
       <td tal:condition="fixed_object">
          <span tal:replace="validator/getObjectId" />
          <input type="hidden" 
                 tal:attributes="name python:'object_id_'+str(repeat['validator'].index);
                                 value validator/getObjectId" />
       </td>
       <td tal:condition="not:fixed_object" class="form-element">
          <input type="text" 
                 tal:attributes="name python:'object_id_'+str(repeat['validator'].index);
                                 value validator/getObjectId" size="15" />
       </td>
       <td class="form-element">
          <select tal:attributes="name python:'context_type_'+str(repeat['validator'].index);">
             <option value=""
                     tal:attributes="selected python:test(validator.getContextType() is None, 'selected', None);">Any</option>
             <option tal:repeat="context_type availableContextTypes"
                     tal:attributes="value context_type;
                                     selected python:test(validator.getContextType() == context_type, 'selected', None);"
  		             tal:content="context_type" />
          </select>
       </td>
       <td class="form-element">
          <input type="text" 
                 tal:attributes="name python:'button_'+str(repeat['validator'].index);
                                 value validator/getButton" size="10" />
       </td>
       <td class="form-element">
          <input type="text" 
                 tal:attributes="name python:'validators_'+str(repeat['validator'].index);
                                 value python:', '.join(validator.getValidators());" size="50" />
       </td>
   </tr>
</table>

<p tal:condition="not:form_validators"><i>No validators have been specified</i></p>

<table tal:condition="form_validators">
<tr>
   <td class="form-element"><input type="submit" name="manage_editFormValidators:method" value="Save"/></td>
   <td class="form-element"><input type="submit" name="manage_delFormValidators:method" value="Delete"/></td>
</tr>
</table>
</form>

<hr />

<h3 class="form-help">Add a New Form / Script Validator Override</h3>

<form method="POST"
      tal:attributes="action here/absolute_url">
   <input type="hidden" name="override:int" value="1" />
<table border="0" metal:define-macro="add_validators">
   <tr>
       <td class="form-label">Template</td>
       <td tal:condition="fixed_object">
          <span tal:replace="fixed_object" />
          <input type="hidden" name="new_object_id"
                 tal:attributes="value fixed_object" />
       </td>
       <td tal:condition="not:fixed_object" class="form-element">
          <input type="text" name="new_object_id" size="15" />
       </td>
   </tr>
   <tr>
       <td class="form-label">Context type</td>
       <td class="form-element">
          <select name="new_context_type">
             <option value="">Any</option>
             <option tal:repeat="context_type availableContextTypes"
                     tal:attributes="value context_type;"
  		             tal:content="context_type" />
          </select>
       </td>
   </tr>
   <tr>
       <td class="form-label">Button</td>
       <td class="form-element">
          <input type="text" name="new_button" size="10" />
       </td>
   </tr>
   <tr>
       <td class="form-label">Validators</td>
       <td class="form-element">
          <input type="text" name="new_validators" size="50" />
       </td>
   </tr>
</table>

<table>
<tr>
   <td class="form-element"><input type="submit" name="manage_addFormValidators:method" value="Add"/></td>
</tr>
</table>
</form>

<hr/>

<div tal:condition="here/writableDefaults">
<h3 class="form-help">Edit Default Validators</h3>

<form method="POST"
      tal:attributes="action here/absolute_url" 
      tal:define="form_validators python:here.listFormValidators(0, **filters);">
   <input type="hidden" name="override:int" value="0" />
<table border="0" tal:condition="form_validators" metal:use-macro="template/macros/edit_validators" />

<p tal:condition="not:form_validators"><i>No validators have been specified</i></p>

<table tal:condition="form_validators">
<tr>
   <td class="form-element"><input type="submit" name="manage_editFormValidators:method" value="Save"/></td>
   <td class="form-element"><input type="submit" name="manage_delFormValidators:method" value="Delete"/></td>
</tr>
</table>
</form>

<hr/>

<h3 class="form-help">Add Default Validator</h3>

<form method="POST"
      tal:attributes="action here/absolute_url">
   <input type="hidden" name="override:int" value="0" />

<table border="0" metal:use-macro="template/macros/add_validators" />

<table>
<tr>
   <td class="form-element"><input type="submit" name="manage_addFormValidators:method" value="Add"/></td>
</tr>
</table>
</form>

</div>

<div tal:condition="python:not here.writableDefaults() and fixed_object">
<h3 class="form-help">Default Validators</h3>

<div tal:define="form_validators python:here.listFormValidators(0, **filters);">

<table width="100%" cellspacing="0" cellpadding="2" border="0" tal:condition="form_validators">

   <tr class="list-header">
      <td class="form-label">Template</td>
      <td class="form-label">Context</td>
      <td class="form-label">Button</td>
      <td class="form-label">Validators</td>
   </tr>

   <tal:block tal:repeat="validator form_validators">
   <tr tal:define="oddrow repeat/validator/odd;"
       tal:attributes="class python:test(oddrow, 'row-hilite', 'row-normal')">
       <td class="list-item" tal:content="validator/getObjectId" />
       <td class="list-item" tal:define="context_type validator/getContextType">
          <span tal:condition="context_type" tal:replace="context_type"/>
          <span tal:condition="not:context_type" tal:omit-tag="">Any</span>
       </td>
       <td class="list-item" tal:define="button validator/getButton">
          <span tal:condition="button" tal:replace="button"/>
          <span tal:condition="not:button" tal:omit-tag="">Any</span>
       </td>
       <td class="list-item" tal:content="python: ', '.join(validator.getValidators())" />
   </tr>
   </tal:block>

</table>

<p tal:condition="not:form_validators"><i>No validators have been specified</i></p>
</div>
</div>

<hr />
<a name="docs"></a>
<h3>Definitions</h3>
<ul>
   <li><b>Template</b>: The Controller Page Template / Controller Python Script 
       for which you are setting validators.  The form/script in question 
       <i>must</i> be a Controller Page Template / Controller Python Script.
       If it is an ordinary Python Script, Page Template, a DTML Method, or a 
       DTML Document <i>these validators will be ignored!</i></li>
   <li><b>Context</b>: The type of context object for which the given sequence
       of validating scripts is executed.  This lets you set different validators
       for different types of content objects.</li>
   <li><b>Button</b>: The button for which the given sequence of validating 
       scripts is executed.  This lets you set different validators depending
       on which button on a form is pressed.  Leave the button field blank
       to use the same validators for any button.  To use this functionality, you must name each button in the template
       <tt>form.button.NAME</tt>.  For example, if you have <tt>&lt;input name="form.button.button1" type="submit"&gt;</tt>
       in your page template, you can specify what happens when this button is pressed by
       entering <i>button1</i> in the button field.</li>
   <li><b>Validators</b>: A comma-delimited sequence of Controller Validator script ids.</li>
</ul>
       
<a tal:attributes="href python:here.portal_url()+'/portal_form_controller/manage_docs'">Documentation</a>
<hr />
</div>
<h1 tal:replace="structure here/manage_page_footer">Footer</h1>