<metal:page define-macro="master">
   <metal:master use-macro="here/prefs_main_template/macros/master"
                 i18n:domain="kupuconfig">

      <metal:block metal:fill-slot="top_slot" define-slot="top_slot"
                   tal:define="dummy python:request.set('disable_border',1)" />

      <metal:fillbase fill-slot="base">
         <metal:baseslot define-slot="base">
            <base href="" tal:attributes="href template/absolute_url" />
         </metal:baseslot>
      </metal:fillbase>


      <metal:override fill-slot="column_two_slot" />

      <body>
         <div metal:fill-slot="prefs_configlet_content" metal:define-slot="prefs_configlet_main"
              tal:define="errors python:request.get('errors', {});"
              id="content">

            <metal:styleslot define-slot="style_slot" />

            <div class="documentEditable">

               <!-- simulating views -->
               <ul class="contentViews">
                  <li class="selected"
                      tal:attributes="class python:template.pt_source_file()=='kupu_config' and 'selected' or ''">
                     <a href=""
                        tal:attributes="href string:${here/absolute_url}/kupu_config"
                        i18n:translate="tab_config">Config</a>
                  </li>
                  <li class="selected"
                      tal:attributes="class python:template.pt_source_file()=='zmi_libraries' and 'selected' or ''">
                     <a href=""
                        tal:attributes="href string:${here/absolute_url}/zmi_libraries"
                        i18n:translate="tab_libraries">Libraries</a>
                  </li>
                  <li class="selected"
                      tal:attributes="class python:template.pt_source_file()=='zmi_resource_types' and 'selected' or ''">
                     <a href=""
                        tal:attributes="href string:${here/absolute_url}/zmi_resource_types"
                        i18n:translate="tab_resourcetypes">Resource Types</a>
                  </li>
                  <li class="selected"
                      tal:attributes="class python:template.pt_source_file()=='zmi_docs' and 'selected' or ''">
                     <a href=""
                        tal:attributes="href string:${here/absolute_url}/zmi_docs"
                        i18n:translate="tab_documentation">Documentation</a>
                  </li>
                  <li class="selected"
                      tal:attributes="class python:template.pt_source_file()=='zmi_links' and 'selected' or ''">
                     <a href=""
                        tal:attributes="href string:${here/absolute_url}/zmi_links"
                        i18n:translate="tab_links">Links</a>
                  </li>
                  <li class="selected"
                      tal:attributes="class python:template.pt_source_file()=='zmi_toolbar' and 'selected' or ''">
                     <a href=""
                        tal:attributes="href string:${here/absolute_url}/zmi_toolbar"
                        i18n:translate="tab_toolbar">Toolbar</a>
                  </li>
               </ul>

               <div class="contentActions">
                  &nbsp;
               </div>        
               <!-- End of tabs -->
               <div class="documentContent" metal:define-slot="kupu_content">
                  <h1 class="documentFirstHeading"
                      i18n:translate="heading_configuration">Kupu Configuration</h1>
                  <form action=""
                        name="configure_kupu"
                        method="post"
                        tal:attributes="action here/absolute_url"
                        tal:define="isTransformEnabled context/transformIsEnabled">

                     <fieldset>
                        <legend i18n:translate="legend_link_options">Link options</legend>
                        <div class="field">
                           <input type="hidden" name="linkbyuid:int:default" value="0" />
                           <input type="checkbox"
                                  class="noborder"
                                  name="linkbyuid:int"
                                  id = "kupu_linkbyuid"
                                  value="1"
                                  tal:attributes="checked here/getLinkbyuid" />
                           <label for="kupu_linkbyuid" i18n:translate="label_link_uid">Link using UIDs</label>

                           <div class="formHelp">
                              <tal:block i18n:translate="help_link_uid">
                                Links to objects on this site created by Kupu can use unique object ids
                                so that the links remain valid even if the target object is renamed or
                                moved elsewhere on the site.
                              </tal:block>
                              <span tal:condition="isTransformEnabled">
                                 <tal:block i18n:translate="help_transform_is_enabled">
                                   A portal transform to hide the UIDs from client browsers is
                                   currently operating for the fields:
                                 </tal:block>
                                 <blockquote tal:content="here/supportedCaptioning"></blockquote>
                              </span>
                              <span tal:condition="not:isTransformEnabled">
                                 <tal:block i18n:translate="help_enable_transform">
                                    If you enable this option a transform to hide UIDs and support image
                                    captioning from client browsers will also be enabled
                                 </tal:block>
                                 (<a i18n:translate="help_image_captioning_url"
                                     tal:attributes="href string:${context/absolute_url}/zmi_docs#images"
                                     href="zmi_docs#images">see image captioning documentation</a>).
                                 <tal:block i18n:translate="help_update_portal_transforms">
                                    If the transform does not enable itself automatically you may
                                    need to update your PortalTransforms product.
                                 </tal:block>
                              </span>
                           </div>

                        </div>

                     </fieldset>
                     <fieldset>
                        <legend i18n:translate="legend_caption">Captioning</legend>
                        <div class="field">
                           <input type="hidden" name="captioning:int:default" value="0" />
                           <label><input type="checkbox"
                           class="noborder" name="captioning:int"
                           value="1" tal:attributes="checked here/getCaptioning" />
                              <span i18n:translate="allow_captioned_images">Allow captioned images</span></label>

                           <div class="formHelp">
                              <span i18n:translate="help_image_uid_caption">
                                 Images which are linked using UID based links may be automatically captioned.
                              </span>

                              <div tal:condition="not:isTransformEnabled">
                                  <tal:block i18n:translate="help_enable_transform">
                                    If you enable this option a transform to hide UIDs and support image
                                    captioning from client browsers will also be enabled
                                  </tal:block>
                                  (<a i18n:translate="help_image_captioning_url"
                                      tal:attributes="href string:${context/absolute_url}/zmi_docs#images"
                                      href="zmi_docs#images">see image captioning documentation</a>).
                                  <tal:block i18n:translate="help_update_portal_transforms">
                                    If the transform does not enable itself automatically you may
                                    need to update your PortalTransforms product.
                                  </tal:block>
                                 <div i18n:translate="caption_maybe_supported">Fields which could support image captioning:</div>
                              </div>
                              <div tal:condition="isTransformEnabled" i18n:translate="caption_is_supported">
                                 Fields which appear to currently support image captioning:</div>
                              <blockquote tal:content="here/supportedCaptioning"></blockquote>
                              <div i18n:translate="caption_not_supported">Fields which use kupu but do not support image captioning:</div>
                              <blockquote tal:content="here/unsupportedCaptioning"></blockquote>
                           </div>
                        </div>
                     </fieldset>

                     <fieldset>
                        <legend i18n:translate="legend_refbrowser">Reference Browser</legend>
                        <div class="field">
                           <input type="hidden" name="refbrowser:int:default" value="0" />
                           <input type="checkbox"
                                  class="noborder"
                                  name="refbrowser:int"
                                  id = "kupu_refbrowser"
                                  value="1"
                                  tal:attributes="checked here/getRefBrowser" />
                           <label for="kupu_refbrowser" i18n:translate="label_refbrowser">Use Kupu Reference Browser</label>

                           <div class="formHelp" i18n:translate="help_refbrowser">Replace
                              ATReferenceBrowser widget with a widget which uses
                              Kupu's drawers instead of a popup window.</div>
                        </div>
                     </fieldset>

                     <fieldset tal:condition="not:exists:here/portal_skins/plone_ecmascript/formUnload.js">
                        <legend i18n:translate="legend_warning">Warn before losing changes</legend>
                        <div class="field">
                           <input type="hidden" name="installBeforeUnload:int:default" value="0" />
                           <input type="checkbox"
                                  class="noborder"
                                  name="installBeforeUnload:int"
                                  id = "kupu_installBeforeUnload"
                                  value="1"
                                  tal:attributes="checked here/installBeforeUnload|python:1" />
                           <label for="kupu_installBeforeUnload" i18n:translate="label_install_kupu">Install Kupu code to detect form changes</label>

                           <div class="formHelp" i18n:translate="help_navigate_away">Kupu can install a handler to warn before navigating
                              away from a page where a form (even the non-Kupu fields) has been edited.
                              Turn this off to prevent Kupu loading its own handler.
                           </div>
                        </div>
                     </fieldset>

                     <fieldset>
                        <legend i18n:translate="legend_filtersourceedit">HTML View</legend>
                        <div class="field">
                           <input type="hidden" name="filterSourceEdit:int:default" value="0" />
                           <input type="checkbox"
                                  class="noborder"
                                  name="filterSourceEdit:int"
                                  id = "kupu_filterSourceEdit"
                                  value="1"
                                  tal:attributes="checked here/getFiltersourceedit|python:1" />
                           <label for="kupu_filterSourceEdit" i18n:translate="label_filtersourceedit">Filter HTML in source view</label>

                           <div class="formHelp" i18n:translate="help_filter_source">When checked, Kupu's HTML view will display the
                              filtered HTML which will be sent to the server. Uncheck this box to see the raw HTML generated by the browser.
                           </div>
                        </div>

                     </fieldset>
                     <fieldset>
                        <legend
                               i18n:translate="legend_alloworiginalsize">Original Image Size</legend>
                        <div class="field">
                           <input type="hidden"
                                  name="allowOriginalImageSize:int:default" value="0" />
                           <input type="checkbox"
                                  class="noborder"
                                  name="allowOriginalImageSize:int"
                                  id = "kupu_allowOriginalImageSize"
                                  value="1"
                                  tal:attributes="checked here/getAllowOriginalImageSize|python:0" />
                           <label for="kupu_allowOriginalImageSize"
                                  i18n:translate="label_allowOriginalImageSize">Allow original size images</label>

                           <div class="formHelp"
                                i18n:translate="help_allow_original_image">
                              When checked, the image drawer will include
                              Original as an available size.
                           </div>
                        </div>

                     </fieldset>
                     <fieldset>
                        <legend i18n:translate="legend_styles">Styles</legend>
                        <div class="field">
                           <label for="table_classnames" i18n:translate="label_tables">Tables</label>
                           <div class="formHelp" i18n:translate="help_table_classes">Enter a list of class names to be made available in the table drawer</div>
                           <input type="hidden" name="table_classnames:list:default" value=" " />

                           <textarea name="table_classnames:lines" id="table_classnames"
                                     rows="5" cols="30" style="width:90%"
                                     tal:content="python:'\n'.join(here.getTableClassnames())">
                           </textarea>
                        </div>

                        <div class="field">
                           <label for="parastyles" i18n:translate="label_paragraph_styles">Styles</label>
                           <div class="formHelp" i18n:translate="help_paragraph_styles">Enter a list of styles to appear in the style pulldown. Format is title|tag or title|tag|className, one per line.</div>
                           <input type="hidden" name="parastyles:list:default" value=" " />
                           <textarea name="parastyles:lines" id="parastyles"
                                     rows="5" cols="30" style="width:90%"
                                     tal:content="python:'\n'.join(here.getParagraphStyles())">
                           </textarea>
                        </div>
                     </fieldset>

                     <fieldset>
                        <legend i18n:translate="legend_html_filter">HTML Filter</legend>

                        <div tal:condition="here/have_plone_filtering|nothing"
                             i18n:translate="use_plone_controlpanel">
                           Please use the <a href="#"
                           tal:attributes="href string:${context/portal_url}/@@filter-controlpanel"
                           i18n:name="plone_filter_controlpanel">
                              <span i18n:translate="plone_filter_controlpanel">Plone HTML filter control panel</span></a>
                              to set filtering options.
                        </div>
                        <table tal:condition="not:here/have_plone_filtering|nothing">
                           <tr>
                              <td></td>
                              <th i18n:translate="label_tags">Tags</th>
                              <th i18n:translate="label_attributes">Attributes</th>
                           </tr>

                           <tr>
                              <td></td>
                              <td colspan="2">
                                 <div class="formHelp" i18n:translate="help_remove_entities">Enter HTML tags and attributes to be removed when saving documents. (Uncheck to remove entries)</div>
                              </td>
                           </tr>

                           <tr tal:repeat="exclusion_tuple here/getHtmlExclusions">
                              <tal:with define="tags python:exclusion_tuple[0];
                                        attributes python:exclusion_tuple[1]">
                                 <td valign="top">
                                    <input type="hidden" name="html_exclusions.recordmark:records" value="1" />
                                    <input type="checkbox" name="html_exclusions.keep:records" checked="1"
                                           tal:attributes="value python:1;" />
                                    <input type="hidden" name="html_exclusions.tags:records:list"
                                           tal:repeat="tag tags"
                                           tal:attributes="value tag" />
                                    <input type="hidden" name="html_exclusions.attributes:records:list"
                                           tal:repeat="attr attributes"
                                           tal:attributes="value attr" />
                                 </td>

                                 <td valign="top"><div tal:replace="python:', '.join(tags)"></div>
                                    <em tal:condition="not:tags" i18n:translate="any_tag">Any tag</em>
                                 </td>
                                 <td valign="top"><div tal:replace="python:', '.join(attributes)"></div>
                                    <em tal:condition="not:attributes" i18n:translate="whole_tag_removed">Whole tag removed</em>
                                 </td>

                              </tal:with>
                           </tr>
                           <tr>
                              <td valign="top">
                                 <input type="hidden" name="html_exclusions.recordmark:records" value="1" />
                                 <input type="checkbox" name="html_exclusions.keep:records" checked="1" disabled="1"
                                        tal:attributes="value python:1;" />
                              </td>
                              <td valign="top">
                                 <textarea name="html_exclusions.tags:records"
                                           rows="5" cols="30"></textarea>
                              </td>

                              <td valign="top">
                                 <textarea name="html_exclusions.attributes:records"
                                           rows="5" cols="30"></textarea>
                              </td>
                           </tr>

                           <tr>
                              <td></td>
                              <th colspan="2" i18n:translate="label_style_whitelist">Style Whitelist</th></tr>
                           <tr>
                              <td></td>
                              <td colspan="2">
                                 <div class="formHelp" i18n:translate="help_style_whitelist">Enter a list of style elements to be permitted (one per line)</div>

                                 <textarea name="style_whitelist:lines"
                                           rows="5" cols="60"
                                           tal:content="python:'\n'.join(here.getStyleWhitelist())">
                                 </textarea>
                              </td>
                           </tr>

                           <tr>
                              <td></td>
                              <th colspan="2" i18n:translate="label_class_blacklist">Class Blacklist</th>
                           </tr>
                           <tr>
                              <td></td>
                              <td colspan="2">
                                 <div class="formHelp" i18n:translate="help_class_blacklist">Enter a list of classnames to be excluded (one per line)</div>

                                 <textarea name="class_blacklist:lines"
                                           rows="5" cols="60"
                                           tal:content="python:'\n'.join(here.getClassBlacklist())">
                                 </textarea>
                              </td>
                           </tr>
                        </table>
                     </fieldset>

                     <input class="context"
                            type="submit"
                            name="configure_kupu:method"
                            value="Save"
                            i18n:attributes="value button_save;"
                            />
                  </form>
               </div>
            </div>
         </div>
      </body>
   </metal:master>
</metal:page>


