<?xml version="1.0" encoding="UTF-8"?>
<actions>

<meta>
  <description>Template für das BiblioMonde-System</description>
  <variable name="baseurl"><description>Katalog-URL (inklusive .dll/, ohne Parameter)</description></variable>
  <variable name="style" default="Portal2"><description>Katalog-Style</description></variable>
</meta>


<action id="connect">
  <s>style := get('style', 'Portal2'),
     accountUrl := x"{$baseurl}/APS_ZONES?fn=MyZone"
   (:  accountUrl := x"{$baseurl}/APS_ACCOUNT?Style={$style}&SubStyle=&Theme=&Lang=GER&ResponseEncoding=utf-8&Parent=APS_OPAC&BrowseAsHloc=11" :)
(:     accountUrl := x"{$baseurl}/APS_ZONES?fn=MyLoans&Lang=GER" :)
  </s>
  
<!--  <page url="{$baseurl}/APS_OPAC?Style={$style}">
    <template>
      <t:switch-prioritized>
        <a t:condition="matches(@href, 'APS_ACCOUNT|/APS_ZONES.*fn=Account')">{accountUrl := @href}</a>
        <h2>Das System ist gerade offline<t:s>vl:raise(.)</t:s></h2>
      </t:switch-prioritized>
    </template>
  </page>-->
</action>

<action id="search-connect">
 <!-- <page url="{$baseurl}/APS_OPAC?Style={get('style', 'Portal2')}">
    <template>
      <a t:condition="matches(@href, '/APS_QUICK_SEARCH')">{searchUrl := replace(@href, "QUICK_SEARCH", "ADVANCED_SEARCH")}</a>
    </template>
  </page>-->
  <s>style := get('style', 'Portal2'), accountUrl := x"{$baseurl}/APS_ACCOUNT?fn=advancedsearch&Style={$style}&BrowseAsHloc=-2"</s>

  <page url="{$baseurl}/APS_ZONES?fn=advancedsearch&Style={$style}"> 
    <template><body>
<!--      <a t:condition="matches(@href, 'APS_ACCOUNT|/APS_ZONES.*fn=Account')">{accountUrl := @href}</a>-->
      <FORM NAME="ExpertSearch">
        {$search-start:=form(.),
         $search-branches := (), 
         $search-branch-values := ()}
      <div class="inSearchLimits" >
        <div class="floatingBox">
          <table>
            <tr>Stadtteilbibliothek</tr>
            <tr><td>
              <table>
                <tr><input>{search-branches := ($search-branches, ..), search-branch-values := ($search-branch-values, @value)}</input></tr>*
              </table>
            </td></tr>
          </table>
        </div>
      </div>?
      </form>
    </body></template>
  </page>
</action>

<action id="search"> 
  <variable name="search-keys">{"author": "au=", "title": "ti=", "keywords": "su=", "isbn": "sb=", "year": "dp="}</variable>
  
  <s>
    i := 1,
    requestId := 0,
    request := uri-combine($search-start.url, 
      (for $key in jn:keys($book) return if ($book($key) != "" and exists($search-keys($key))) then (
              {x"q.form.t{$i}&#46;expr": $book($key), x"q.form.t{$i}&#46;term": $search-keys($key)},
              (i := $i + 1)[2]
            ) else (),
       if (exists(get("search-branch-values", ())[get("search-branch-id", 0)])) then {"q.limits.limit": $search-branch-values[$search-branch-id]} else () ) )
  </s>
  
  <page url="{$request}" templateFile="searchList">
  
  </page>
  <s>search-next-page-available := true()</s>
  <s>requestId := 1</s>  
</action>

<action id="search-next-page"> 
  <page url="{$baseurl}/{$obj}?Style={$style}&SubStyle=&Lang=GER&ResponseEncoding=utf-8&ResponseEncoding=utf-8&Method=FetchIncrementalBrowseDown&RequestId={$requestId}&" templateFile="searchList"/>
  <s>requestId := $requestId + 1</s>
</action>


<action id="search-details"> 
  <if test="contains($book.home-url, '&View=ISBD&')"><s>$book.home-url:=replace($book.home-url, "&View=ISBD&", "&View=Annotated&")</s></if> <!-- needed for cologne -->
  <page url="{$book.home-url}" templateFile="searchDetails"/>
</action>

<action id="internal-login">
  <page url="{$accountUrl}">
    <template>
      <t:switch-prioritized>
        <form name="LoginForm">  {form := form(., {"BRWR": $username, "PIN": $password})} </form>
        <h2>Das System ist gerade offline<t:s>vl:raise(.)</t:s></h2>
      </t:switch-prioritized>
    </template>
  </page>
  
  <page url="{$form}" templateFile="loggedIn"/>
</action>




<action id="order-single"> 
  <call action="internal-login"/>
  
  <page url="{$book._order-url}" templateFile="orderConfirmation"/> 
</action> 

<action id="internal-order-confirmed">
  <s>form := form-combine($confirm-form, {"MakeResTypeDef.Reservation.RecipientLocn": $choose-result, "Confirm": 1})</s>
  <page url="{$form}" test="$choose-result ne -1">
    <template>
      <td>Die Vormerkung wurde erfolgreich durchgeführt.<t:s>book.statusId := "ordered"</t:s></td>
    </template>
  </page>
</action>


<action id="update-all">  
  <s>ordersListUrl := ()</s>
  <call action="internal-login"/>
    
  <s>requestId := 0</s>
  <page url="{$bookListUrl}" templateFile="list"/> 
  
  <s>requestId := 1</s>
  
  <loop test="not($bFoundBottom)">
    <page url="{$baseurl}/{$obj}?Style={$style}&SubStyle=&Lang=GER&ResponseEncoding=utf-8&ResponseEncoding=utf-8&Method=FetchIncrementalBrowseDown&RequestId={$requestId}&" templateFile="list"/> 
    <s>requestId := $requestId + 1</s>
  </loop>

 
  <page url="{$ordersListUrl}" templateFile="listOrders"/> 
  <!--
  <s>requestId := 1</s>
  
  <loop test="not($bFoundBottom)">
    <page url="{$baseurl}/{$obj}?Style={$style}&SubStyle=&Lang=GER&ResponseEncoding=utf-8&ResponseEncoding=utf-8&Method=FetchIncrementalBrowseDown&RequestId={$requestId}&"> 
    <template><body>{bFoundBottom := (./text())[1]/matches(., "bFoundBottom *= *1")}</body></template>
    </page>
    <s>requestId := $requestId + 1</s>
  </loop>-->
  
</action>

<action id="renew-list">  
  <s>renew-ids := for $book in $renew-books return x"item:IN={$book.id};AT={$book.author}/{$book.title}"</s>
  
  <page url="{$bulkRenew}" templateFile="bulkRenew"/>

  <s>renewConfirm := form-combine($baseForm, $options)</s>  
  <page url="{$renewConfirm}"/>
  
  <call action="update-all"/>  
  
</action>


<action id="cancel-single">
  <page url="{$book._cancel-url}" templateFile="cancelConfirm"/>
  <page url="{$cancel-form}"> 
<!--    <template>
      <head>
       <META NAME="ZonesObjName">{obj:=@CONTENT, bFoundBottom := false()}</META>
      </head> 
    </template>-->
  </page>

<!--  <s>requestId := 1</s>    
  <loop test="not($bFoundBottom)">
    <page url="{$baseurl}/{$obj}?Style={$style}&SubStyle=&Lang=GER&ResponseEncoding=utf-8&ResponseEncoding=utf-8&Method=FetchIncrementalBrowseDown&RequestId={$requestId}&"> 
    <template><body>{bFoundBottom := (./text())[1]/matches(., "bFoundBottom *= *1")}</body></template>
    </page>
    <s>requestId := $requestId + 1</s>
  </loop>-->
  <call action="update-all"/>  <!-- cancel urls change after cancelling. strangely, the old urls still work in firefox. but in videlibri we need to get new urls -->
</action>

<action id="catalogue">  
  <call action="connect"/>
  <s>url:=x"{$baseurl}/APS_OPAC?Style=Portal2"</s>
</action>

<!--http://katalog.stadtbibliothek.luebeck.de/alswww2.dll/Obj_577491377434134?
dateReq=1377434653896-->
</actions>
