    =========================================
    Editing sort order of address book fields
    =========================================

    The sort order of the fields of the entities can be changed globally. The
    places where fields are displayed in order are changed accordingly.

    Set up
    ======

    Create an address book and a browser to access it. Log in as
    `Administrator`:

    >>> from icemac.addressbook.testing import create_addressbook
    >>> from z3c.etestbrowser.wsgi import ExtendedTestBrowser as Browser
    >>> ab = create_addressbook()
    >>> browser = Browser()
    >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    >>> browser.open('http://localhost/++skin++AddressBook/ab')

    To show that the sort order includes user defined fields, we have to create
    one:

    >>> from icemac.addressbook.testing import create_field
    >>> _ = create_field(
    ...         ab, 'icemac.addressbook.person.Person', 'Bool', u'grown-up')

    The sort order of the fields can be changed in the master data area on each
    entity, for example we choose the `person` entity here:

    >>> browser.getLink('Master data').click()
    >>> browser.getLink('Entities').click()
    >>> browser.getLink('Edit fields', index=1).click()
    >>> browser.url
    'http://localhost/.../ab/++attribute++entities/icemac.addressbook.person.Person'

    The default sort order looks the following way (user defined field was
    sorted to the end):

    >>> print browser.contents
first name
last name
birth date
keywords
notes
grown-up Delete Edit
... Changing sort order =================== The sort order is changed using JavaScript (tested using Selenium). When the user hits the `Save sortorder` button a URL is generated and sent to the server: >>> from icemac.addressbook.testing import get_messages >>> browser.open(browser.url + ... '/@@save-sortorder.html?f:list=last_name&f:list=Field-1') >>> get_messages(browser) ['Saved sortorder.'] The fields are now ordered as they were in the URL (not mentioned fields are sorted to the end): >>> print browser.contents
last name
grown-up Delete Edit
first name
birth date
keywords
notes
...