Skip to content

Commit

Permalink
bug:2540 When default photos order is only by rank, failure outside a…
Browse files Browse the repository at this point in the history
…lbums

define a default order_by + some javascript for limit number of fields

git-svn-id: http://piwigo.org/svn/trunk@12872 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
mistic100 committed Jan 10, 2012
1 parent 758f9dd commit e349749
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
14 changes: 12 additions & 2 deletions admin/configuration.php
Expand Up @@ -135,24 +135,34 @@
{
$order_by = array();
$order_by_inside_category = array();

for ($i=0; $i<count($_POST['order_by_field']); $i++)
{
if ($i>5) continue;
if ($_POST['order_by_field'][$i] == '')
if ( $i >= (count($sort_fields)-1) ) break; // limit to the number of available parameters
if ( empty($_POST['order_by_field'][$i]) )
{
array_push($page['errors'], l10n('No field selected'));
break;
}
else
{
// there is no rank outside categories
if ($_POST['order_by_field'][$i] != 'rank')
{
$order_by[] = $_POST['order_by_field'][$i].' '.$_POST['order_by_direction'][$i];
}
$order_by_inside_category[] = $_POST['order_by_field'][$i].' '.$_POST['order_by_direction'][$i];
}
}
// must define a default order_by if user want to order by rank only
if ( count($order_by) == 0 )
{
$order_by = array('id ASC');
}

$_POST['order_by'] = 'ORDER BY '.implode(', ', $order_by);
$_POST['order_by_inside_category'] = 'ORDER BY '.implode(', ', $order_by_inside_category);
unset($_POST['order_by_field']);
}
}

Expand Down
38 changes: 29 additions & 9 deletions admin/themes/default/template/configuration.tpl
Expand Up @@ -115,24 +115,44 @@
</li>

{if !$ORDER_BY_IS_CUSTOM}
{footer_script require='jquery'}{literal}
{footer_script require='jquery'}
// counters for displaying of addFilter link
fields = {$main.order_by|@count}; max_fields = {$main.order_field_options|@count}; max_fields--;

{literal}
function updateAddFilterLink() {
if (fields >= max_fields) {
$('.addFilter').css('display', 'none');
} else {
$('.addFilter').css('display', '');
}
}

function updateRemoveFilterTrigger() {
$(".removeFilter").click(function () {
$(this).parent('span.filter').remove();
fields--;
updateAddFilterLink();
});
}

jQuery(document).ready(function () {
$('.addFilter').click(function() {
rel = $(this).attr('rel');
$(this).prev('span.filter').clone().insertBefore($(this));
$(this).prev('span.filter').children('select[name="order_by_field[]"]').val('');
$(this).prev('span.filter').children('select[name="order_by_direction[]"]').val('ASC');
$(".removeFilter").click(function () {
$(this).parent('span.filter').remove();
});
fields++;
updateAddFilterLink();
updateRemoveFilterTrigger();
});

$(".removeFilter").click(function () {
$(this).parent('span.filter').remove();
});
updateRemoveFilterTrigger();
updateAddFilterLink();
});
{/literal}{/footer_script}
{/literal}
{/footer_script}
{/if}
</ul>
</fieldset>
Expand Down

0 comments on commit e349749

Please sign in to comment.