<!-- macros for rendering edit/create forms
     $Id$ -->

<metal:block define-macro="edit" i18n:domain="loops">
    <form method="post" enctype="multipart/form-data"
          id="dialog_form" class="dialog"
          dojoType="dijit.form.Form"
          tal:define="langInfo view/languageInfo;
                      languages langInfo/availableLanguages;
                      language langInfo/language;
                      useI18N view/useI18NForEditing;
                      innerForm request/inner_form | string:inner_concept_edit_form.html;">
      <input type="hidden" name="form.action" value="edit"
             tal:attributes="value view/form_action" />
      <input type="hidden" name="version"
             tal:attributes="value request/version | nothing" />
      <table cellpadding="3" class="form">
        <tbody>
          <tr>
            <th colspan="5" class="headline"
                tal:attributes="colspan python: useI18N and 4 or 5">
              <span tal:replace="view/title"
                    i18n:translate="">Edit Information Object</span>
            </th>
          <th tal:condition="useI18N"
              style="vertical-align: bottom; text-align: right;
                     padding-right: 1em">
            <select name="loops.language" id="loops.language"
                    tal:attributes="onChange
                            string:return replaceFieldsNodeForLanguage(
                                    'form.fields', 'loops.language',
                                    '${view/virtualTargetUrl}/$innerForm')">
              <option tal:repeat="lang languages"
                      tal:content="lang"
                      tal:attributes="selected python: lang == language;">en</option>
            </select>
          </th>
        </tr></tbody>

        <tbody><tr><td colspan="5" style="padding-right: 15px">
              <div id="form.fields">
                <metal:fields use-macro="view/fieldRenderers/fields" />
              </div>
        </td></tr></tbody>

        <tbody>
          <tr>
            <td colspan="5" class="headline"
                i18n:translate="">Assign Parent Concepts</td>
          </tr>
          <tr metal:use-macro="view/template/macros/assignments" />
          <tr metal:use-macro="view/template/macros/search_concepts" />
          <tal:custom define="customMacro view/customMacro"
                      condition="customMacro">
            <tr metal:use-macro="customMacro" />
          </tal:custom>
          <tr metal:use-macro="view/template/macros/versioning" />
          <tr metal:use-macro="view/template/macros/buttons" />
        </tbody>
      </table>
    </form>
</metal:block>


<metal:block define-macro="create" i18n:domain="loops">
    <form method="post" enctype="multipart/form-data"
          id="dialog_form" class="dialog"
          tal:define="qualifier request/qualifier | string:resource;
                      innerForm request/inner_form | string:inner_form.html;
                      typeToken python: request.get('form.type')
                                    or view.defaultTypeToken;
                      fixedType request/fixed_type | nothing">
      <input type="hidden" name="form.action" value="create"
             tal:attributes="value view/form_action" />
      <table cellpadding="3" class="form">
        <tbody><tr><th colspan="5" class="headline">
              <span tal:content="view/title"
                    i18n:translate="">Create Information Object</span>
              <select name="form.type" id="form.type"
                      tal:condition="not:fixedType"
                      tal:attributes="onChange
                            string:return replaceFieldsNode(
                                    'form.fields', 'form.type',
                                    '${view/url}/$innerForm')">
                <option value=".loops/concepts/note"
                        i18n:translate=""
                        tal:repeat="type python:
                            view.getTypesVocabulary((qualifier,))"
                        tal:content="type/title"
                        tal:attributes="value type/token;
                                        selected python:
                               type.token == typeToken">
                  Note
                </option>
              </select>
              <input type="hidden" name="form.type"
                     tal:condition="fixedType"
                     tal:attributes="value typeToken" />
        </th></tr></tbody>

        <tbody><tr><td colspan="5">
              <div id="form.fields">
                <metal:fields use-macro="view/fieldRenderers/fields" />
              </div>
        </td></tr></tbody>

        <tbody>
          <tr>
            <td colspan="5" class="headline"
                i18n:translate="">Assign Parent Concepts</td>
          </tr>
          <tr metal:use-macro="view/template/macros/assignments" />
          <tr metal:use-macro="view/template/macros/search_concepts" />
          <tal:custom define="customMacro view/customMacro"
                      condition="customMacro">
            <tr metal:use-macro="customMacro" />
          </tal:custom>
          <tr metal:use-macro="view/template/macros/buttons" />
        </tbody>
      </table>
    </form>
</metal:block>


<metal:assignments define-macro="assignments">
    <tbody id="form.assignments">
      <tr tal:repeat="type view/presetTypesForAssignment">
        <td><span i18n:translate="">Type</span>: </td>
        <td><b i18n:translate="" tal:content="type/title" /></td>
        <td><span i18n:translate="">Concept</span>: </td>
        <td colspan="2">
          <select name="form.assignments.selected:list">
            <tal:concepts repeat="concept python: view.conceptsForType(type['token'])">
              <option tal:attributes="value concept/token"
                      i18n:translate=""
                      tal:content="concept/title">Zope Corp</option>
            </tal:concepts>
          </select>
        </td>
      </tr>
      <tr tal:repeat="relation view/assignments">
        <td colspan="5">
          <input type="hidden" name="form.assignments.old:list"
                 tal:attributes="value relation/uidToken"
                 tal:condition="relation/other" />
          <input type="checkbox" checked name="form.assignments.selected:list"
                 tal:attributes="value relation/uidToken;" />
          <span tal:content="relation/title">Something</span>
          (<span i18n:translate="" tal:content="relation/typeTitle">Topic</span>)
        </td>
      </tr>
    </tbody>
</metal:assignments>


<tr metal:define-macro="search_concepts">
    <td><label for="concept.search.type"><span i18n:translate="">Type</span>:</label></td>
    <td>
      <select id="concept.search.type"
              onChange="setConceptTypeForComboBox('concept.search.type', 'concept.search.text')">
        <tal:types repeat="type view/conceptTypesForSearch">
          <option value="loops:*"
                  i18n:translate=""
                  tal:attributes="value type/token"
                  tal:content="type/title">Topic</option>
        </tal:types>
      </select>&nbsp;&nbsp;
    </td>
    <td>
      <label for="concept.search.text">
        <span i18n:translate="">Concept</span>:</label></td>
    <td>
      <input type="hidden"
             id="concept.search.predicate"
             tal:attributes="value view/defaultPredicateUid" />
      <div dojoType="dojox.data.QueryReadStore" jsId="conceptSearch"
           url="listConceptsForComboBox.js?searchType=" >
      </div>
      <input dojoType="dijit.form.FilteringSelect" store="conceptSearch"
             autoComplete="False" labelAttr="label"
             name="concept.search.text" id="concept.search.text" />
    </td>
    <td>
      <input type="button" value="Select"
             i18n:attributes="value"
             onClick="addConceptAssignment('concept', 'assignments')" />
    </td>
</tr>


<metal:versioning define-macro="versioning"
                  tal:define="versionInfo view/versionInfo"
                  tal:condition="versionInfo">
      <tr>
        <td colspan="5" i18n:translate="" class="headline">Versioning</td>
      </tr>
      <tr>
        <td colspan="2">
          <span i18n:translate="">Version</span>:
          <span tal:content="versionInfo">1.1 (current, released)</span>
        </td>
        <td title="Select if you want to create a new version"
            i18n:attributes="title">
          <input type="checkbox"
                 name="version.create" id="version.create"
                 value="create" />
          <label for="version.create"><span i18n:translate="">New version</span>:</label>
        </td>
        <td colspan="2">
          <select name="version.level">
              <option value="1" i18n:translate="">minor</option>
              <option value="0" i18n:translate="">major</option>
          </select>
        </td>
      </tr>
</metal:versioning>


<tr metal:define-macro="buttons" i18n:domain="" class="buttons">
            <td colspan="5">
              <input value="Save" type="submit"
                     i18n:attributes="value"
                     tal:attributes="onClick python: view.closeAction(True)">
              <input type="button" value="Cancel" onClick="dlg.hide();"
                     i18n:attributes="value"
                     tal:attributes="onClick view/closeAction">
            </td>
</tr>


<!-- overridden field renderers -->

<metal:html define-macro="input_html">
    <textarea name="field" rows="3" style="width: 450px"
           dojoType="dijit.Editor"
           tal:define="width field/width|nothing;
                       height field/height|python:3"
           tal:attributes="name name; id name;
                           rows python: height or 3;
                           style python:
                                'width: %s' % (width and str(width)+'px' or '450px');"
           tal:content="data/?name|string:">
    </textarea>
</metal:html>
