<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:tal="http://xml.zope.org/namespaces/tal"
      xmlns:metal="http://xml.zope.org/namespaces/metal"
      xmlns:i18n="http://xml.zope.org/namespaces/i18n"
      i18n:domain="plone">

  <head><title></title></head>

  <body>

    <!-- TextArea Widgets -->

    <metal:view_macro define-macro="view"
            tal:define="kssClassesView context/@@kss_field_decorator_view;
                        getKssClasses nocall:kssClassesView/getKssClassesInlineEditable;">
        <span metal:define-macro="textarea-field-view"
            tal:define="kss_class python:getKssClasses(fieldName,
                              templateId='widgets/textarea', macro='textarea-field-view');
                              uid context/UID|nothing;"
            tal:attributes="class kss_class;
                            id string:parent-fieldname-$fieldName-$uid">
            <span metal:define-slot="inside"
                  tal:replace="accessor">textarea</span>
        </span>
    </metal:view_macro>

    <metal:define define-macro="area_edit">
      <tal:define
          define="base python:hasattr(value, 'isUnit');
                  binary python:base and value.isBinary() or context.isBinary(fieldName);
                  content python: not not base and value.getRaw() or value;
                  content python: not binary and content or '';
                  content_length python:len(unicode(content, 'utf-8'));
                  append_only widget/append_only|nothing;
                  maxlength widget/maxlength|nothing;
                  tcname string:textCounter_${fieldName};
                  keypress string:textCounter(this, '${tcname}', ${maxlength});">

        <textarea
            class="blurrable firstToFocus"
            tal:attributes="name fieldName;
                            id fieldName;
                            cols widget/cols;
                            rows widget/rows;
                            placeholder widget/placeholder|nothing;
                            onkeydown python:test(maxlength, keypress, None);
                            onkeyup python:test(maxlength, keypress, None);"
            tal:define="content python:not append_only and content or '';"
            tal:content="content">content</textarea>

            <div tal:condition="maxlength"
                 i18n:translate="label_characters_remaining">
                <input readonly="readonly"
                       type="text"
                       name=""
                       maxlength="4"
                       size="4"
                       value=""
                       i18n:name="count"
                       tal:define="remaining python:(int(maxlength) - content_length) + content.count('\n')"
                       tal:attributes="name tcname;
                                       value remaining;
                                       id string:maxlength_${fieldName};" />
                characters remaining
            </div>

            <fieldset tal:condition="append_only">
              <legend i18n:translate=""
                      tal:define="label widget/label"
                      tal:content="string:HISTORY: ${label}">
                label
              </legend>
              <span i18n:translate=""
                    tal:condition="python:(content_length &lt; 333)"
                    tal:content="accessor">content</span>
                    <textarea readonly="readonly" i18n:translate=""
                              tal:condition="python:(content_length &gt;= 333)"
                              tal:content="content"
                              tal:attributes="cols widget/cols;
                                              rows widget/rows;">
                      content
                    </textarea>
            </fieldset>

      </tal:define>
    </metal:define>

    <metal:define define-macro="area_format">
      <tal:define
          define="field_text_format string:${fieldName}_text_format;
                  contentType python:request.get(field_text_format, context.getContentType(fieldName));
                  get_act python:getattr(field, 'getAllowedContentTypes', False);
                  allowable_ct python:get_act and get_act(here) or ('text/plain',);
                  mimetypes python:[t for t in allowable_ct if t.startswith('text/')];
                  contenttype python:hasattr(field, 'getContentType') and field.getContentType(here) or ''">

        <tal:condition condition="python:len(mimetypes) > 1">
        <div style="text-align: right; margin-right: 0.75em;">
          <label i18n:translate="label_format">Format</label>
          <select tal:define="textareaview context/@@at_textarea_widget;
                              selection python:textareaview.getSelected(mimetypes, contenttype)"
                  tal:attributes="id string:${fieldName}_text_format;
                                  name string:${fieldName}_text_format;">
            <option selected="selected"
                    value=""
                    tal:attributes="value contentType"
                    tal:condition="python:contenttype not in mimetypes">
              (no change)
            </option>
            <option tal:repeat="item mimetypes"
                    tal:content="python:textareaview.lookupMime(item)"
                    tal:attributes="value item;
                                    selected python:item in selection and 'selected' or None;"
                    />
          </select>
        </div>
        </tal:condition>
        <tal:condition condition="python:len(mimetypes) == 1">
          <input type="hidden"
                 name=""
                 value=""
                 tal:attributes="name field_text_format;
                                 value python:mimetypes[0]"
                 />
        </tal:condition>
      </tal:define>
    </metal:define>

    <metal:define define-macro="edit">
      <metal:use use-macro="field_macro | context/widgets/field/macros/edit">
        <metal:fill fill-slot="widget_body">
          <metal:block use-macro="context/widgets/textarea/macros/area_edit" />
          <metal:block use-macro="context/widgets/textarea/macros/area_format" />
        </metal:fill>
      </metal:use>
    </metal:define>

    <metal:define define-macro="search">
      <metal:use use-macro="context/widgets/field/macros/edit">
        <metal:fill fill-slot="widget_body">

          <metal:block use-macro="context/widgets/textarea/macros/area_edit" />

        </metal:fill>
      </metal:use>
    </metal:define>

  </body>

</html>
