Make sure the sorting settings are actually stored on the collection.

This commit is contained in:
Timo Stollenwerk 2012-03-09 09:52:39 +01:00
parent caafc1e2d9
commit 9535d1d56d
3 changed files with 38 additions and 12 deletions

View File

@ -8,6 +8,10 @@ Changelog
prefixes.
[davisagli]
- Make sure the sorting settings are actually stored on the collection.
[timo]
1.0a1 (2011-10-28)
------------------

View File

@ -180,17 +180,17 @@
<div class="sortingField">
<div class="formHelp"><!-- --></div>
<label for="form.widgets.sort_on">
<label for="sort_on">
Sort on
</label>
<select name="form.widgets.sort_on" id="sort_on">
<select name="sort_on" id="sort_on">
<tal:index repeat="index python:sortable_indexes.keys()">
<option tal:attributes="value index; selected python:(request.has_key('sort_on') and request.sort_on == index) and 'selected' or nothing"
tal:content="python:sortable_indexes[index]['title']">Index</option>
</tal:index>
</select>
<input type="checkbox" name="form.widgets.sort_order" value="reverse" checked="checked" id="sort_order"/>
<input type="checkbox" name="sort_order" value="reverse" checked="checked" id="sort_order"/>
<label for="sort_order">Reversed order</label>
</div>

View File

@ -218,20 +218,42 @@
// Init
$.querywidget.init();
// Remove the hidden sort_on and sort_reversed z3c.form fields because
// they are hard-coded in the view. Read the values from these hidden
// fields and set the values of the hard-coded fields accordingly.
var sort_on = $('#form-widgets-sort_on').val();
var sort_reversed = $('#form-widgets-sort_reversed-0');
$('#formfield-form-widgets-sort_on').remove();
$('#formfield-form-widgets-sort_reversed').remove();
$('#sort_on').val(sort_on);
if (sort_reversed.attr('value') === 'selected') {
// We need two keep two fields for each sorting field ('#sort_on',
// '#sort_reversed'). The query results preview that calls
// '@@querybuilder_html_results' in plone.app.querystring expects a
// sort_on and sort_order param. To store the actual setting on the
// collection we need the two z3c.form-based fields
// ('#form-widgets-sort_on', '#form-widgets-sort_reversed')
// Synchronize the '#sort_on' field with the hidden
// #form-widgets-sort_on z3c.form field on load.
$('#sort_on').val($('#form-widgets-sort_on').val());
// Synchronize the '#sort_order' field with the hidden
// #form-widgets-sort_reversed z3c.form field on load.
if ($('#form-widgets-sort_reversed-0').attr('checked')) {
$('#sort_order').attr('checked', true);
} else {
$('#sort_order').attr('checked', false);
}
// Synchronize the z3c.form '#form-widgets-sort_on' field
// with the '#sort_on' field on user interaction
$("#sort_on").live('click', function () {
$('#form-widgets-sort_on').val($(this).val());
});
// Synchronize the z3c.form '#form-widgets-sort_reversed' field
// with the '#sort_order' field on user interaction.
$("#sort_order").live('click', function () {
$('#form-widgets-sort_reversed-0').attr('checked', $(this).attr('checked'));
});
// Hide the z3c.form widgets for sorting because they are only needed
// internally.
$('#formfield-form-widgets-sort_on').hide();
$('#formfield-form-widgets-sort_reversed').hide();
});
// Init widget