[%# 1.0@bugzilla.org %]
[%# The contents of this file are subject to the Mozilla Public
  # License Version 1.1 (the "License"); you may not use this file
  # except in compliance with the License. You may obtain a copy of
  # the License at http://www.mozilla.org/MPL/
  #
  # Software distributed under the License is distributed on an "AS
  # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  # implied. See the License for the specific language governing
  # rights and limitations under the License.
  #
  # The Original Code is the Bugzilla Testopia System
  #
  # The Initial Developer of the Original Code is Greg Hendricks.
  # Portions created by Greg Hendricks are Copyright (C) 2001
  # Greg Hendricks. All Rights Reserved.
  #
  # Contributor(s): Greg Hendricks <ghendricks@novell.com>
  #                 Karla Hendricks <palegreensocks@gmail.com>
  #%]
  
[%############################################################################%]
[%# Block for SELECT fields                                                  #%]
[%############################################################################%]

[% BLOCK select %]
    <label for="[% sel.name %]" accesskey="[% sel.accesskey %]"></label>
      <select name="[% sel.name %]" id="[% sel.name %]" 
      [%- "multiple=\"multiple\"" IF sel.mult %] 
      [%- "size=\"$sel.elements\"" IF sel.elements %] 
      [%- sel.events IF sel.events %] 
      [%- sel.style IF sel.style %]>
      [% FOREACH item = sel.list %]
        <option value="[% sel.byname ? item.name : item.id FILTER html %]" [% 'selected="selected"' IF (sel.default == item.name && item.name != '') || (sel.default == item.id || sel.default == 'all') %][% 'selected="selected"' IF (sel.deflist == 1 AND lsearch(sel.default, item.id)> -1) %]>
          [% item.name FILTER html %]</option>
      [% END %]
      </select>

[% END %] 

[% BLOCK navigation %]
[% SET MAX_LIMIT = 10000 %]
[% IF ajax %]
   [% url = "javascript:page(" %]
   [% pc  = ")" %]
[% ELSE %]
   [% url = "$table.get_page_url&page="%]
   [%# url = "$table.url_loc?direction=$direction&getlist=1&page="%]
[% END %]
[% pagesizelist = [{name => 25, id => 25},
                   {name => 50, id => 50},
                   {name => 100, id => 100},
                   {name => 500, id => 500}]%]
                   
<script type='text/javascript'>
   var [% table.type %]Table = {
  
    jumpToPage: function (page){
      var digit = /^\d+$/;
      page = page - 1;
      if ((page >= [% table.page_count %]) || (page < 0) || !digit.test(page)){
        alert('Invalid page number. Please enter a value between 1 and [% table.page_count %] ');
        return;
      }
      var url = '[% url %]' + page;
      document.location = url;
    }
  };
  function adjustPageSize(psize) {
    document.location = "[% url %]&pagesize=" + psize;
  }
</script>

<table align="center">
  <tr style="background-color: #eeeeee; ">
  [% IF table.page != 0 %]
    <td><a href="[% url %]0[% pc %]">&lt;&lt;&nbsp;First</a></td>
    <td><a href="[% url %][% table.page - 1 %][% pc %]">&lt;&nbsp;Previous</a></td>
  [% ELSE %]
    <td>&lt;&lt;&nbsp;First</td>
    <td>&lt;&nbsp;Previous</td>
  [% END %]
    <td align="center" style="font-size: medium">
    [% SET framewidth = 10 %]
    [% IF (table.page_count - 1) < framewidth %]
      [% SET p = 0 %]
      [% SET frame_end = table.page_count - 1 %]
    [% ELSIF (table.page_count - table.page) < (framewidth / 2) %]
      [% SET p = table.page_count - framewidth %]
      [% SET frame_end = table.page_count - 1 %]
      [% SET start_mark = '...' %]
    [% ELSIF table.page < (framewidth / 2) %]
      [% SET p = 0 %]
      [% SET frame_end = framewidth %]
      [% SET end_mark = '...' %]
    [% ELSE %]
      [% SET p = table.page - (framewidth / 2) %]
      [% SET frame_end = table.page + (framewidth / 2) %]
      [% SET start_mark = '...' %]
      [% SET end_mark = '...' %]
    [% END %]
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    [% start_mark %]
    [% WHILE p <= frame_end %]
      [% IF p != table.page %]
      <a href="[% url %][% p %][% pc %]">[% p + 1 %]</a>&nbsp;
      [% ELSE %]
      [% p + 1 %]
      [% END %]
      [% p = p + 1 %]
    [% END %]
    [% end_mark %]
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </td>
  [% IF table.page < table.page_count - 1 %]
    <td><a href="[% url %][% table.page + 1 %][% pc %]">Next&nbsp;&gt;</a></td>
    <td><a href="[% url %][% table.page_count - 1 %][% pc %]" title="Jump to Page [% table.page_count %]">Last&nbsp;&gt;&gt;</a></td>
  [% ELSE %]
    <td>Next&nbsp;&gt;</td>
    <td>Last&nbsp;&gt;&gt;</td>
  [% END %]
    
  </tr>
    <td colspan="5">
    <input type="button" onclick="[% table.type %]Table.jumpToPage(document.getElementById('jump_[% table.type %]').value)" value="Jump To Page">
    <input id="jump_[% table.type %]" size="4">
    &nbsp;Out of [% table.page_count %] pages
    &nbsp;&nbsp;&nbsp;
    View [% PROCESS select sel = {list    => pagesizelist,
                                  default => table.page_size,
                                  events  => 'onchange="adjustPageSize(this.value)"' }%]
    records&nbsp;at&nbsp;a&nbsp;time
    &nbsp;&nbsp;&nbsp;
  [% IF ajax %]
    <a href="[% url %]null,1[% pc %]">View&nbsp;All</a>&nbsp;
  [% ELSE %]
    [% IF table.list_count < MAX_LIMIT %]
    <a href="[% url %]&viewall=1">View&nbsp;All</a>&nbsp;
    [% ELSE %]
    <span style="color:gray">View&nbsp;All</span>
    [% END %]
  [% END %]
    </td>
    
  </tr>
  <tr><th colspan="5" style="font-size: 12pt;">[% table.list_count %] records found [% '(filtered)' IF filtered %]</th></tr>
</table>
[% END %]
