Six days and about 24 man-hours later, I've got something neat to show you.
It's a new option type for Serendipity, called 'sequence'. You just add a sequence option to your template or plugin, and it returns the order that the user wants the items to be in. If the user has Javascript, it displays a draggable list, just like the plugin configuration page. If the user doesn't have Javascript, it displays up and down arrows on each entry, just like the plugin configuration page. In fact, I borrowed heavily from the plugin configuration page's code.
Whether JavaScript is enabled or not, the entire form is submitted, and all the plugin or template variables will be set correctly.
How to Use the Sequence Widget/Selector/Type/Whatever
The easiest case is to add an array such as the following to your theme options or plugin introspection:
Code: Select all
array(
'var' => 'category_precedence',
'name' => 'Category Precedence',
'description' => 'TESTING/UNUSED: The order in which categories will be tested',
'type' => 'sequence',
'items' => array('cat1', 'cat2', 'cat3'),
),
In this case, the items cat1, cat2, and cat3 will be displayed in a draggable list (or, if the user has no Javascript, in a list with up and down arrows). When the user submits changes, you'll get a list with the items in the desired order, separated by commas; for instance, 'cat1,cat3,cat2'.
I recognize that sometimes you won't want to display the actual item IDs themselves. For instance, when we want the user to choose the precedences of categories, we wouldn't want the user's choices to be 1,7,18,24,32; we'd want to show him category names.
To display something different for any item, just modify your array like this:
Code: Select all
array(
'var' => 'category_precedence',
'name' => 'Category Precedence',
'description' => 'TESTING/UNUSED: The order in which categories will be tested',
'type' => 'sequence',
'items' => array('1' => array('display' => 'Category 1 Name'),
'27' => array('display' => 'Category 27 Name'),
'34' => array('display' => 'Category 34 Name'))
But we're not done yet! Sometimes a displayable name won't be enough. You may want thumbnails to improve the user experience. In that case, just add the 'img' key to your array, with a full URL. (Use serendipity_getTemplateFile() to find an image in the currently-used templates.)
Code: Select all
array(
'var' => 'category_precedence',
'name' => 'Category Precedence',
'description' => 'TESTING/UNUSED: The order in which categories will be tested',
'type' => 'sequence',
'items' => array('1' => array('display' => 'This', 'img' => 'http://judebert.com/wasted_youth/classic.gif'),
'2' => array('display' => 'That', 'img' => serendipity_getTemplateFile('img/minus.png')),
'3' => array('display' => 'The Other', 'img' => serendipity_getTemplateFile('img/plus.png')) )
),
You can mix-and-match these styles as much as you want. Any item that doesn't have an 'img' associated with it will get no image. Any item that doesn't have a 'display' associated with it will be displayed using the item ID. You can have display variables for some items and no display variables for other items. It's all good.
I've added the sequence type to the serendipity_event_advtypes plugin v0.5, now committed to the repository. I've tested it with Serendipity 1.2.1 (which is the least it requires), under FireFox 2.0 with Javascript enabled and disabled. I need help testing it in other browsers, and advice on whether this is a good format for inputs.
The aim is to get this into the Serendipity core on the next minor release, so I want to make sure I'm not making any assumptions. Thanks!