<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:i18n="http://xml.zope.org/namespaces/i18n"
      xmlns:metal="http://xml.zope.org/namespaces/metal"
      xmlns:tal="http://xml.zope.org/namespaces/tal"
      lang="en"
      metal:use-macro="context/main_template/macros/master"
      xml:lang="en"
      i18n:domain="ploneintranet"
>

  <metal:content fill-slot="content">
    <div class="document-body"
         id="document-body-library"
         tal:define="
           selected_groupby python:request.get('groupby', view.groupby);
           info view/info;
           pdf_enabled view/pdf_enabled|nothing;
           token context/@@authenticator/token;
         "
    >
      <div class="document-content"
           id="document-content-library"
      >
        <a class="pat-inject discrete-injection"
           href="${portal_url}/@@tip-of-the-day"
           data-pat-inject="source:#tod; target: self::element; trigger:autoload"
        ></a>

        <form class="canvas-toolbar pat-inject pat-autosubmit"
              id="library-toolbar"
              action="${here/absolute_url}/@@${view/__name__}#lib-groups"
              method="get"
        >
          <div class="canvas-toolbar-section view-options"
               id="library-toolbar-quick-navigation"
               tal:condition="view/groupby_menu_enabled"
          >
            <label class="bare pat-select">
              <select name="groupby"
                      tal:define="
                        selected_groupby python:request.get('groupby', view.groupby);
                      "
              >
                <option selected="${python:'selected' if selected_groupby == 'section' else None}"
                        value="section"
                        i18n:translate=""
                >
                Group by section
                </option>
                <option selected="${python:'selected' if selected_groupby == 'tag' else None}"
                        value="tag"
                        i18n:translate=""
                >
                Group by tag
                </option>
              </select>
            </label>
          </div>

          <div class="canvas-toolbar-section quick-navigation"
               id="library-toolbar-quick-navigation"
               tal:condition="view/show_back_button"
          >
            <a class="ueber-back-button pat-inject"
               href="${parent/absolute_url}#document-body-library"
               data-pat-inject="history: record"
               tal:define="
                 parent view/parent;
               "
            >${parent/title}</a>
          </div>

          <div class="canvas-toolbar-section navigation">
            <nav class="canvas-toolbar-subnav button-cluster pat-tabs pat-navigation"
                 tal:condition="view/show_sections_navigation"
            >
              <tal:sections define="
                              sections view/sections;
                            ">
                <a class="pat-inject ${section/current} ${section/cls}"
                   href="${section/absolute_url}#document-body-library"
                   data-pat-inject="
                    source: #library-section-contents; target: #library-section-contents &amp;&amp;
                    source: #library-toolbar-quick-navigation; target: #library-toolbar-quick-navigation &amp;&amp;
                    source: #library-toolbar-quick-functions; target: #library-toolbar-quick-functions; history: record"
                   tal:repeat="section sections"
                >${section/title}</a>
              </tal:sections>
            </nav>
          </div>
          <div class="canvas-toolbar-section quick-functions"
               id="library-toolbar-quick-functions"
          >
            <div class="functions"
                 id="page-functions"
            >

              <label class="canvas-toolbar-function canvas-toolbar-search-field ${python:'focus' if SearchableText else ''}"
                     tal:define="
                       SearchableText request/SearchableText|nothing;
                       request_tag view/request_tag|nothing;
                     "
              >
                <input minlength="2"
                       name="SearchableText"
                       placeholder="Search library items"
                       title="Search library items"
                       type="search"
                       value="${SearchableText}"
                       i18n:attributes="placeholder;title;"
                />
                <input name="Subject"
                       type="hidden"
                       value="${request_tag}"
                       tal:condition="request_tag"
                />
              </label>
              <a class="icon more pat-tooltip tooltip-inactive"
                 aria-expanded="false"
                 href="${here/absolute_url}/@@more-menu#more-menu"
                 data-pat-tooltip="source: ajax; position-list: tr"
                 tal:condition="view/show_options_menu"
                 i18n:translate=""
              >
              Options
              </a>
            </div>
          </div>
        </form>

        <div id="library-section-contents">
          <article class="pat-rich canvas-intro"
                   tal:condition="info"
          >
            <h1 class="${info/klass|nothing}">${context/title}</h1>
            <p class="description"
               tal:condition="info/description|nothing"
            >
          ${info/description}
            </p>
          </article>

          <div class="lib-groups pat-masonry"
               id="lib-groups"
               data-pat-masonry="column-width: .grid-sizer; gutter: 0; item-selector: .tile;"
               tal:define="
                 children view/children;
                 Batch python:modules['plone.batching'].Batch;
                 b_start python:int(request.get('b_start', 0));
                 batch python:Batch(list(children), view.batch_size, b_start);
               "
          >
            <div class="grid-sizer ${view/tile_class}"></div>
            <p class="pat-message notice"
               tal:condition="not:children"
               i18n:translate=""
            >
            No results found matching your query
            </p>
            <tal:children repeat="child batch">
              <div class="tile ${python:view.get_child_class(child)} ${view/tile_class}"
                   title="${child/title}${python:' — {}'.format(child_description) if child_description else None}"
                   tal:define="
                     portal_type child/portal_type;
                     is_office_file python:view.is_office_file(child);
                     is_audio_file python:view.is_audio_file(child);
                     is_pageish python:portal_type in view.pageish_portal_types;
                     is_contentish python:portal_type in view.contentish_portal_types;
                     is_folderish python:portal_type in view.folderish_portal_types;
                     is_rich python:portal_type in view.rich_portal_types;
                     is_link python:view.is_link(child);
                     is_youtube python:view.is_youtube(child);
                     is_video_file python:view.is_video_file(child);
                     preview_path python:view.preview_image_path(child);
                     child_url python:view.make_safe_url(child);
                     child_description child/description;
                   "
              >
                <div class="content">
                  <article class="document-preview-expansive ${python:'rich pat-rich' if is_rich else None} ${python:'link' if is_link else None}"
                           tal:condition="python: not is_folderish or (is_link and child_description)"
                  >
                    <section class="page-preview"
                             tal:condition="is_rich"
                    >
                      <tal:text replace="structure child/text/raw|nothing" />
                    </section>
                    <a class="follow pat-inject"
                       href="${python: child_url}#document-body-library"
                       data-pat-inject="history: record"
                       tal:condition="is_contentish"
                    >
                      <img src="${preview_path}"
                           title="${child/title}${python:' — {}'.format(child_description) if child_description else None}"
                           tal:condition="python:preview_path and not is_audio_file"
                      />
                      <p class="description"
                         tal:condition="is_link"
                      >
                       ${child_description}
                      </p>
                    </a>
                  </article>
                  <tal:folderish condition="is_folderish">
                    <h3>
                      <a class="title pat-inject"
                         href="${python: child_url}#document-body-library"
                         data-pat-inject="history: record"
                      >${child/title}</a>
                    </h3>
                    <p class="description"
                       tal:condition="child_description"
                    >${child_description}</p>
                  </tal:folderish>
                  <div class="sub-title"
                       tal:condition="not:is_folderish"
                  >
                    <a class="label pat-inject ${python:view.icon_label(child)}"
                       href="${python: child_url}#document-body-library"
                       data-pat-inject="history: record"
                    >
                      <strong class="document-title">${child/title}</strong>
                    </a>
                  </div>


                  <ul class="menu group-by-${view/groupby}"
                      tal:define="
                        nephews python:children[child];
                      "
                      tal:condition="nephews"
                  >
                    <tal:nephew repeat="nephew nephews">
                      <li class="${python: 'follow-page' if is_nephew_pageish else '' if is_linkish else 'follow-section'}"
                          tal:define="
                            is_nephew_pageish python:nephew.portal_type in view.pageish_portal_types;
                            is_linkish python:nephew.portal_type in view.linkish_portal_types;
                          "
                      >
                        <a class="${python:'pat-inject ' if not is_linkish else ''} ${python: view.icon(nephew.portal_type)}"
                           href="${python:nephew.getURL()}#document-body-library"
                           data-pat-inject="history: record"
                        >${nephew/title}</a>
                      </li>
                    </tal:nephew>
                  </ul>
                </div>
              </div>
            </tal:children>
            <a class="pat-inject infinite-scrolling-trigger"
               id="injection-target"
               href="${next_page_url}"
               data-pat-inject="source: #lib-groups; target: #injection-target::element; trigger: autoload-visible"
               tal:define="
                 next_page_url view/next_page_url;
               "
               tal:condition="next_page_url"
            >Loading&hellip;</a>
          </div>
        </div>
        <p tal:condition="not:view/enabled">
        Tag views are only supported with Solr. Please deploy with Solr.
        </p>
      </div>
    </div>

  </metal:content>

</html>
