<actions>

<meta>
  <description>Template für die alten OCLC Bibliotheca WebOPACs
(für die neuen OPEN Bibliotheca OPACs, wähle System bibliothecaplus) </description>
  <variable name="baseurl"><description>Serveraddresse, inklusive Protokoll, ohne trailing /</description></variable>
  <variable name="DB" default=""><description>Datenbank</description></variable>
</meta>

<action id="connect"> 
  <s>starturl := $baseurl || "/index.asp" || ( get('DB', ())[.] ! x"?DB={.}" )   </s>
</action>
<action id="update-all">
  <s>follow1 := ()</s>
  <page url="{$starturl}"/>
  <page url="{$baseurl}/index.asp?kontofenster=start">
    <template>
      <t:switch prioritized="true">
        <FORM id="webopac" name="webopac"><t:s>vl:delete-current-books()</t:s>{follow1 := form(., {"AUSWEIS": $username, "PWD": $password})}<input name="AUSWEIS"/></FORM>
        <DIV class="kontozeile_center">{follow1 := $url}<!--seems we are still logged in--></DIV> 
      </t:switch>
    </template>
  </page>

  <page url="{$follow1}" templateFile="list"/>

</action>

<action id="renew-list">
  <s>l := for $b in $renew-books order by $b.renew-link descending return $b </s>
  <loop var="b" list="$l">
    <page url="{$b.renew-link}"><template><form>{form := form(., {"verlaengern": "Verlängern"})}</form></template></page>
    <page url="{$form}"/>
  </loop>
  <call action="update-all"/>
</action>

<action id="cancel-single">
  <page url="{$book.cancel-link}"><template><form>{form := form(., {"vorbdelbest": "Bestätigung"})}</form></template></page>
  <page url="{$form}"/> <!-- this returns the full of update-all list again-->
</action>






<action id="search-connect">
  <call action="connect"/>
  <s>loggedIn := false()</s>
  <page url="{$starturl}">
    <template><form name="webopac">{profi := form(., .//input[@name="link_profis"])}</form></template>
  </page>
  <page url="{$profi}">    
    <template><form name="webopac">{search := form(.)}</form></template>
  </page>
</action>

<action id="search">
    <s>   next-page := (),
          temp-year := (tokenize($book.year, "-"), $book.year),
          search-keys := {"title": "titel", "author": "verfasser", "keywords": "stichwort", "isbn": "isbn"},
          startSearch := request-combine($search, {|
            { "jahr_von": $temp-year[1], "jahr_bis": $temp-year[2] },
            (
              for $key in jn:keys($book) return if (boolean($book($key)) and exists($search-keys($key))) then (
                      {$search-keys($key): $book($key)}
                    ) else ()
            )
          |})
    </s>
    <page url="{$startSearch}" templateFile="searchList"/>
</action>

<action id="search-next-page">
  <page url="{$next-page}" templateFile="searchList"/>
</action>


<action id="search-details">
  <s>temp := if (not(exists($next-page))) then () 
             else if (contains($book._detailsBackScroll, "scrollAction=")) then $book._detailsBackScroll
             else $book._detailsBackScroll || "?scrollAction=1"
  </s>
  <page url="{$temp}"/>
  <page url="{$book._details}" templateFile="searchDetails"/>
</action>

<action id="order-single"> 
  <s>url := $book._order-url</s>
  <if test="not($loggedIn)">
    <page url="{$url}">
        <template>
          <FORM>{url := form(., {"AUSWEIS": $username, "PWD": $password})}</FORM>    
        </template>
    </page>
  </if>
  
  <page url="{$url}"><!-- templateFile="orderConfirmation"/> -->
    <template><form>{confirm-form := form(.)}
      <div class="kontomeldung">{$message}</div>?
      <t:switch prioritized="true">
        <SELECT NAME="VZST"  > 
          {vl:choose("internal-order-choosen", get("message", "ziel?"), option, option/@value)}
        </SELECT>
        <input type="submit" name="Vorbestellen" value="Bestätigung">
          { vl:confirm("internal-order-confirmed", concat(get("message", "bestätigen?"), string-join(preceding::table[1]/tr/join(td), $line-ending) )  )}
        </input>
      </t:switch>
    </form></template>
  </page>
  
  <s>$loggedIn := true()</s>
</action> 

<action id="internal-order-choosen">
  <if test="$choose-result ne -1">
    <s>form := form-combine($confirm-form, {"VZST": $choose-result})</s>
    <page url="{$form}">
      <template><form>{form := form(., {"Vorbestellen": "Bestätigung"})}</form></template>
    </page><!-- that is just like internal-order-confirmed. can we merge that?? -->
    <call action="internal-order-complete"/>
  </if>
</action>

<action id="internal-order-confirmed">
  <if test="$confirm-result">
    <s>form := form-combine($confirm-form, {"Vorbestellen": "Bestätigung"})</s>
    <call action="internal-order-complete"/>
  </if>
</action>

<action id="internal-order-complete">
  <page url="{$form}">
    <template><div class="kontomeldung">Die Vorbestellung wurde für Sie durchgeführt!<t:s>book.statusId := "ordered"</t:s></div></template>
  </page>
</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="catalogue">
  <call action="connect"/>
  <variable name="url" value="{$starturl}"/>
</action>

</actions>
