Commit 929184ed authored by lphuberdeau's avatar lphuberdeau

[MOD] Adding an option to control the display of the relations field

parent 04a0f98f
......@@ -50,6 +50,16 @@ class Tracker_Field_Relation extends Tracker_Field_Abstract
1 => tr('Yes'),
),
),
'display' => array(
'name' => tr('Display'),
'description' => tr('Control how the relations are displayed in view mode'),
'filter' => 'word',
'options' => array(
'list' => tr('List'),
'count' => tr('Count'),
'toggle' => tr('Count with toggle for list'),
),
),
),
),
);
......@@ -121,7 +131,14 @@ class Tracker_Field_Relation extends Tracker_Field_Abstract
if ($context['list_mode'] === 'csv') {
return $this->getConfiguration('value');
} else {
return $this->renderTemplate('trackeroutput/relation.tpl', $context);
$display = $this->getOption('display');
if (! in_array($display, array('list', 'count', 'toggle'))) {
$display = 'list';
}
return $this->renderTemplate('trackeroutput/relation.tpl', $context, array(
'display' => $display,
));
}
}
......
{if $field.relations or $field.inverts}
<ul id="display_f{$field.fieldId|escape}">
{foreach from=$field.relations item=identifier}
<li>{object_link identifier=$identifier}</li>
{/foreach}
{foreach from=$field.inverts item=identifier}
<li>{object_link identifier=$identifier}</li>
{/foreach}
</ul>
{jq}
$('#display_f{{$field.fieldId|escape}}').sortList();
{/jq}
{if $data.display eq 'count'}
{tr _0=$field.relations|count + $field.inverts|count}%0 element(s){/tr}
{else}
<div id="display_f{$field.fieldId|escape}">
{if $data.display eq 'toggle'}
<a class="toggle" href="#display_f{$field.fieldId|escape}">{tr _0=$field.relations|count + $field.inverts|count}%0 element(s){/tr}</a>
{/if}
<ul>
{foreach from=$field.relations item=identifier}
<li>{object_link identifier=$identifier}</li>
{/foreach}
{foreach from=$field.inverts item=identifier}
<li>{object_link identifier=$identifier}</li>
{/foreach}
</ul>
</div>
{jq}
$('#display_f{{$field.fieldId|escape}} ul').each(function () {
var list = this;
$(this).sortList();
$(this).parent().find('.toggle').click(function () {
$(list).toggle();
return false;
}).each(function () {
$(list).hide();
});
});
{/jq}
{/if}
{/if}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment