<!--
     Used for for related.jspx
     Presents related nodes for one type, plus the functionality to delete and add those.

-->
<mm:content
    type="text/html"
    expires="-1"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:jsp="http://java.sun.com/JSP/Page"
    xmlns:mm="http://www.mmbase.org/mmbase-taglib-2.0"
    >
  <jsp:directive.page session="true" errorPage="../error.jspx" />
  <mm:import externid="type">images</mm:import>
  <mm:import externid="new" />
  <mm:import externid="commit" />
  <mm:import externid="objectnumber" required="true" />
  <mm:import externid="rich_language" from="session">client</mm:import>
  <mm:locale language="$rich_language">
    <html>
      <head>
        <mm:link page="/mmbase/style/css/mmbase.css">
          <link href="${_}" rel="stylesheet" type="text/css"/>
        </mm:link>
      </head>
      <body>
        <div>
          <mm:import externid="offset">0</mm:import>
          <mm:import externid="search"></mm:import>
          <mm:cloud rank="basic user">
            <mm:present referid="new">
              <!-- new node form -->
              <mm:link>
                <form id="create" action="${_}" method="post" enctype="multipart/form-data">
                  <input type="hidden" name="objectnumber" value="${objectnumber}" />
                  <input type="hidden" name="type"         value="${type}" />
                  <mm:fieldlist nodetype="${type}" type="edit">
                    <p>
                      <mm:fieldinfo type="guiname" />: <mm:fieldinfo type="input" />
                    </p>
                  </mm:fieldlist>
                  <input type="submit" value="commit" name="commit" />
                </form>
              </mm:link>
            </mm:present>

            <mm:notpresent referid="new">
              <mm:present referid="commit">
                <!-- create the new node commited with the new node form -->
                <mm:createnode type="${type}">
                  <mm:fieldlist type="edit">
                    <mm:fieldinfo type="useinput" />
                  </mm:fieldlist>
                </mm:createnode>
              </mm:present>

              <!-- search tool -->
              <mm:link>
                <form id="search" action="${_}" method="post">
                  <input type="hidden" name="objectnumber" value="${objectnumber}" />
                  <input type="hidden" name="type"         value="${type}" />
                  <input type="hidden" name="offset"       value="0" />
                  <input name="search" value="${search}" />
                  <input type="submit" value="search" name="ssearch" />
                  <input type="submit" value="new" name="new" />
                </form>
              </mm:link>
              <mm:listnodescontainer type="${type}">

                <mm:isnotempty referid="search">
                  <!-- search action -->
                  <mm:composite operator="OR">
                    <mm:fieldlist nodetype="${type}" fields="title,subtitle,intro,body">
                      <mm:fieldinfo type="name">
                        <mm:constraint field="$_"  operator="LIKE" value="%${search}%" />
                      </mm:fieldinfo>
                    </mm:fieldlist>
                  </mm:composite>
                </mm:isnotempty>

                <mm:sortorder field="number" direction="down" />

                <mm:maxnumber value="20" />
                <mm:offset value="$offset" />

                <!-- paging -->
                <mm:previousbatches indexoffset="1">
                  <mm:link referids="_@offset,objectnumber,search?,type">
                    <a href="${_}"><mm:index /></a>
                  </mm:link> ,
                </mm:previousbatches>
                <mm:index offset="1" />
                <mm:nextbatches indexoffset="1">
                  ,
                  <mm:link referids="_@offset,objectnumber,search?,type">
                    <a href="${_}"><mm:index /></a>
                  </mm:link>
                </mm:nextbatches>

                <!-- result -->
                <table>
                  <tr>
                    <th><jsp:text> </jsp:text></th>
                    <mm:fieldlist nodetype="${type}" type="list">
                      <th><mm:fieldinfo type="guiname" /></th>
                    </mm:fieldlist>
                  </tr>
                  <mm:listnodes id="related" >
                    <tr>
                      <td>
                        <p onclick="window.opener.createRelation('${type}', ${objectnumber}, ${related}); window.close(); window.opener.focus();">
                          <mm:link page="/mmbase/style/images/create.gif">
                            <img src="${_}" alt="+" />
                          </mm:link>
                        </p>
                      </td>
                      <mm:fieldlist nodetype="${type}" type="list">
                        <td><mm:fieldinfo type="guivalue" /></td>
                      </mm:fieldlist>
                    </tr>
                  </mm:listnodes>
                </table>
              </mm:listnodescontainer>
            </mm:notpresent>
          </mm:cloud>
        </div>
      </body>
    </html>
  </mm:locale>
</mm:content>
