=============================
 Batching of the person list
=============================

The person list ist batched, the batch size can be configured in the user
preferences:

Set up
======

We need a browser to access the address book:

>>> browser = get_browser('mgr')

And many persons in the address book:

>>> from icemac.addressbook.testing import create_person
>>> ab = layer['addressbook']
>>> for i in xrange(1, 22):
...    create_person(ab, ab, u'Tester %s' % i, return_obj=False)

Default batching size
=====================

The defaut batching size is 20 items per batch, so batching links are
rendered for the current person list:

>>> browser.open('http://localhost/ab/person-list.html')
>>> print browser.contents
<!DOCTYPE ...
    </tr>
  </tbody>
</table>
  <div class="batch">
    <a href="http://localhost/ab/person-list.html?table-batchSize=20&table-batchStart=0" class="current first">1</a>
<a href="http://localhost/ab/person-list.html?table-batchSize=20&table-batchStart=20" class="last">2</a>
  </div>
</div>
    </div>
   <div id="foot">
  ...

In the preferences view this number is shown:

>>> browser.getLink('Preferences').click()
>>> browser.getControl('batch size').value
'20'

Batch size bigger than item number
==================================

When there are less items than the batch size, no batching links are
displayed:

>>> from icemac.addressbook.testing import in_out_widget_select, get_messages
>>> in_out_widget_select(browser, 'form.widgets.columns',
...     [browser.getControl('person -- last name', index=0)])
>>> browser.getControl('batch size').value = '21'
>>> browser.getControl('Apply').click()
>>> get_messages(browser)
['Data successfully updated.']
>>> browser.getLink('Person list').click()
>>> print browser.contents
<!DOCTYPE ...
</table>
  <div class="batch">
 </div>
</div>
    </div>
<BLANKLINE>
    <div id="foot">
  ...

Too little batch size
=====================

The minimum batch size is 1, otherwise an error message is displayed:

>>> browser.getLink('Preferences').click()
>>> browser.getControl('batch size').value = '0'
>>> browser.getControl('Apply').click()
>>> get_messages(browser)
[]
>>> browser.url
'http://localhost/ab/++preferences++/ab/@@index.html'
>>> print browser.contents
<!DOCTYPE ...
  <div class="error">Value is too small</div>
  ...

Litte batch size
================

With a little batch size batch spachers are displayed:

>>> browser.getControl('batch size').value = '1'
>>> browser.getControl('Apply').click()
>>> get_messages(browser)
['Data successfully updated.']
>>> browser.getLink('Person list').click()
>>> print browser.contents
<!DOCTYPE ...
<div class="batch">
  <a href="http://localhost/ab/person-list.html?table-batchSize=1&table-batchStart=0" class="current first">1</a>
<a href="http://localhost/ab/person-list.html?table-batchSize=1&table-batchStart=1">2</a>
<a href="http://localhost/ab/person-list.html?table-batchSize=1&table-batchStart=2">3</a>
<a href="http://localhost/ab/person-list.html?table-batchSize=1&table-batchStart=3">4</a>
…
<a href="http://localhost/ab/person-list.html?table-batchSize=1&table-batchStart=20" class="last">21</a>
</div>
  ...
