<kupu:feature
    name="wysiwyg_support"
    implementation="plone"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:kupu="http://kupu.oscom.org/namespaces/dist"
    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="kupu"
    >
  <kupu:id>$Id: wysiwyg_support.kupu 196330 2007-12-05 16:14:02Z duncan $</kupu:id>

  <kupu:part name="editorbox">

    <div metal:define-macro="wysiwygEditorBox" id="kupu-editor"
        tal:define="name fieldName|inputname;
                editorid string:kupu-editor-${name}"
        tal:attributes="id editorid">
     <tal:usekupu define="fname fieldName|inputname|nothing;
                  usekupu python:here.contentUsesKupu(fname);">
      <div tal:condition="usekupu">
        <kupu:define-slot name="has_kupu" />
      </div>

      <div tal:condition="not:usekupu">
        <kupu:define-slot name="not_has_kupu" />
      </div>
     </tal:usekupu>
    </div>
  </kupu:part>

  <kupu:part name="eventhandler">
    <script type="text/javascript"
      tal:content="string:
      addEventHandler(window, 'load',  function() { initPloneKupu('${editorid}'); }, document);"></script>
  </kupu:part>

  <kupu:part name="textarea">
    <textarea
        cols="80"
        rows="25"
        name="fieldName"
        tal:content="inputvalue"
        tal:attributes="name fieldName|inputname;
                        id fieldName|inputname;
                        onfocus onfocus|nothing;
                        onblur onblur|nothing;
                        rows rows|default;
                        cols cols|default;">
    </textarea>
     <input type="hidden" name="text_format:default" value="text/html"
        tal:define="fieldName fieldName|inputname|nothing;
                val python:fieldName and 'text/html' or 'html';
                fieldName python:test(fieldName, fieldName+'_', '') + 'text_format:default';"
        tal:attributes="name fieldName;value val;"
     />
  </kupu:part>

  <kupu:part name="textformatselector">

<div metal:define-macro="textFormatSelector" class="field">
 <tal:usekupu define="fname fieldName|inputname|nothing;
              usekupu python:here.contentUsesKupu(fname);">
  <tal:editor tal:condition="usekupu">
     <input type="hidden" name="text_format" value="text/html"
        tal:define="fieldName fieldName|inputname|nothing;
                val python:fieldName and 'text/html' or 'html';
                fieldName python:fieldName and fieldName+'_text_format' or 'text_format';"
        tal:attributes="name fieldName;value val;"
     />
  </tal:editor>                 
  <tal:noeditor  tal:condition="not:usekupu">
    <tal:archetypes tal:condition="fieldName|nothing">
         <div metal:use-macro="here/widgets/visual/macros/area_format" />
         <span tal:condition="python:portal.kupu_library_tool.isKupuEnabled(REQUEST=context.REQUEST, context=context, fieldName=fieldName)"
                tal:define="global kupu_convert_message_generated python:True">
           <a href="#"
                tal:attributes="href python:portal.kupu_library_tool.forcekupu_url(fieldName);"
                i18n:translate="convert-to-kupu"
                >Convert to HTML and edit with the visual editor</a></span>
    </tal:archetypes>
    <tal:nonat condition="not:fieldName|nothing"
               define="text_format text_format | python: getattr(here,'text_format','html');">
     <label for="text_format" i18n:translate="label_format">Format</label>

     <div class="formHelp" i18n:translate="help_format">
       If you are unsure of which format to use, just select Plain
       Text and type the document as you usually do.
     </div>

     <input class="noborder"
            type="radio"
            name="text_format"
            value="structured-text"
            id="cb_structuredtext"
            tal:attributes="checked python:test(text_format=='structured-text', 1, None);"
            />
     <label for="cb_structuredtext" i18n:translate="structured_text">Structured Text</label> <br />

     <input class="noborder"
            type="radio"
            name="text_format"
            value="html"
            id="cb_html"
            tal:attributes="checked python:test(text_format=='html', 1, None);"
            />
     <label for="cb_html" i18n:translate="format_html">HTML</label> <br />

     <input class="noborder"
            type="radio"
            name="text_format"
            value="plain"
            id="cb_plain"
            tal:attributes="checked python:test(text_format=='plain', 1, None);"
            />
     <label for="cb_plain" i18n:translate="plain_text">Plain Text</label>
    </tal:nonat>
  </tal:noeditor>
 </tal:usekupu>
</div>

  </kupu:part>

</kupu:feature>
