<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="action_types here/listActionTypes;
                 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 Actions</h3>

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

<hr/>

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

<form method="POST"
      tal:attributes="action here/absolute_url" 
      tal:define="form_actions python:here.listFormActions(1, **filters);">
   <input type="hidden" name="override:int" value="1" />
<table border="0" tal:condition="form_actions" metal:define-macro="edit_actions">
   <tr>
      <td>&nbsp;</td>
      <td class="form-label">Template/Script</td>
      <td class="form-label">Status</td>
      <td class="form-label">Context</td>
      <td class="form-label">Button</td>
      <td class="form-label">Action</td>
      <td class="form-label">Argument</td>
   </tr>
   <tr tal:repeat="action form_actions">
       <td class="form-element">
          <input type="checkbox" 
                 tal:attributes="name python:'del_id_'+str(repeat['action'].index);" />
          <input type="hidden" 
                 tal:attributes="name python:'old_object_id_'+str(repeat['action'].index);
                                 value action/getObjectId;" />
          <input type="hidden" 
                 tal:attributes="name python:'old_status_'+str(repeat['action'].index);
                                 value action/getStatus;" />
          <input type="hidden" 
                 tal:attributes="name python:'old_context_type_'+str(repeat['action'].index);
                                 value action/getContextType;" />
          <input type="hidden" 
                 tal:attributes="name python:'old_button_'+str(repeat['action'].index);
                                 value action/getButton;" />
       </td>
       <td tal:condition="fixed_object">
          <span tal:replace="action/getObjectId" />
          <input type="hidden" 
                 tal:attributes="name python:'object_id_'+str(repeat['action'].index);
                                 value action/getObjectId" />
       </td>
       <td tal:condition="not:fixed_object" class="form-element">
          <input type="text" size="15"
                 tal:attributes="name python:'object_id_'+str(repeat['action'].index);
                                 value action/getObjectId" />
       </td>
       <td class="form-element">
          <input type="text" size="10"
                 tal:attributes="name python:'status_'+str(repeat['action'].index);
                                 value action/getStatus" />
       </td>
       <td class="form-element">
          <select tal:attributes="name python:'context_type_'+str(repeat['action'].index);">
             <option value=""
                     tal:attributes="selected python:test(action.getContextType() is None, 'selected', None);">Any</option>
             <option tal:repeat="context_type availableContextTypes"
                     tal:attributes="value context_type;
                                     selected python:test(action.getContextType() == context_type, 'selected', None);"
  		             tal:content="context_type" />
          </select>
       </td>
       <td class="form-element">
          <input type="text" size="10"
                 tal:attributes="name python:'button_'+str(repeat['action'].index);
                                 value action/getButton" />
       </td>
       <td class="form-element">
          <select tal:attributes="name python:'action_type_'+str(repeat['action'].index);">
             <option tal:repeat="action_type action_types"
                     tal:attributes="value action_type/getId;
                                     selected python:test(action.getActionType() == action_type.getId(), 'selected', None);"
  		             tal:content="action_type/getId" />
          </select>
       </td>
       <td class="form-element">
          <input type="text" size="50"
                 tal:attributes="name python:'action_arg_'+str(repeat['action'].index);
                                 value action/getActionArg" />
       </td>
   </tr>
   <tr>
</table>

<p tal:condition="not:form_actions"><i>No actions have been specified</i></p>

<table tal:condition="form_actions">
<tr>
   <td class="form-element"><input type="submit" name="manage_editFormActions:method" value="Save"/></td>
   <td class="form-element"><input type="submit" name="manage_delFormActions:method" value="Delete"/></td>
</tr>
</table>
</form>

<hr />

<h3 class="form-help">Add a New Form Action 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_action">
   <tr>
       <td class="form-label">Template/Script</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">Status</td>
       <td class="form-element">
          <input type="text" name="new_status" size="10" />
       </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">Action type</td>
       <td class="form-element">
          <select name="new_action_type">
             <option tal:repeat="action_type action_types"
                     tal:attributes="value action_type/getId;"
  		             tal:content="action_type/getId" />
          </select>
       </td>
   </tr>
   <tr>
       <td class="form-label">Action argument</td>
       <td class="form-element">
          <input type="text" name="new_action_arg" size="50" />
       </td>
   </tr>
</table>

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

<hr/>


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

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

<p tal:condition="not:form_actions"><i>No actions have been specified</i></p>

<table tal:condition="form_actions">
<tr>
   <td class="form-element"><input type="submit" name="manage_editFormActions:method" value="Save"/></td>
   <td class="form-element"><input type="submit" name="manage_delFormActions:method" value="Delete"/></td>
</tr>
</table>
</form>

<hr/>

<h3 class="form-help">Add Default Action</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_action" />

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

</div>


<div tal:condition="python:not here.writableDefaults() and fixed_object">

<h3 class="form-help">Default Actions</h3>

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

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

   <tr class="list-header">
      <td class="form-label">Template/Script</td>
      <td class="form-label">Status</td>
      <td class="form-label">Context</td>
      <td class="form-label">Button</td>
      <td class="form-label">Action</td>
      <td class="form-label">Argument</td>
   </tr>

   <tal:block tal:repeat="action form_actions">
   <tr tal:define="oddrow repeat/action/odd;"
       tal:attributes="class python:test(oddrow, 'row-hilite', 'row-normal')">
       <td class="list-item" tal:content="action/getObjectId" />
       <td class="list-item" tal:content="action/getStatus" />
       <td class="list-item" tal:define="context_type action/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 action/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="action/getActionType" />
       <td class="list-item" tal:content="action/getActionArg" />
   </tr>
   </tal:block>

</table>

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

<hr/>
<a name="docs"></a>
<h3>Definitions</h3>
<ul>
   <li><b>Template/Script</b>: The Controller Page Template or Controller Python
       Script for which you are setting actions.  Note that these <i>will only
       affect</i> Controller Page Templates and Controller Python Scripts that return a
       ControllerState object.  These actions <i>will be ignored</i> for ordinary 
       PageTemplates, ordinary Python Scripts, DTML Methods and DTML Documents.</li>
   <li><b>Status</b>: The status for which the given action is executed.  
       Validators typically return 'success' or 'failure' as their status.</li>
   <li><b>Context</b>: The type of context object for which the given action is 
       executed.  This lets you set different actions for different types 
       of content objects.</li>
   <li><b>Button</b>: The button for which the given action is executed.  This 
       lets you set different actions depending on which button on a form is 
       pressed.  Leave the button field blank to use the same action 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 Controller Page Template, you can specify what happens when this button is pressed by
       entering <tt>button1</tt> in the button field.</li>
   <li><b>Action</b>: The type of action to execute.  The available types of 
       actions are as follows:
       <ul>
           <li tal:repeat="action_type action_types">
              <b tal:content="action_type/getId" />: <span tal:replace="action_type/getDescription" />
           </li>
       </ul></li>
   <li><b>Argument</b>: The argument for the specified action. This must be a TALES expression.</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>