Removing excessive "inline" attachment listings

This commit is contained in:
Mikael Nordfeldth 2014-08-05 11:30:45 +02:00
parent 17b9614ff8
commit 1c04601a9c
4 changed files with 27 additions and 14 deletions

View File

@ -541,4 +541,11 @@ class File extends Managed_DataObject
// And finally remove the entry from the database
return parent::delete($useWhere);
}
public function getTitle()
{
$title = $this->title ?: $this->filename;
return $title ?: null;
}
}

View File

@ -74,18 +74,28 @@ class AttachmentList extends Widget
*/
function show()
{
$att = $this->notice->attachments();
if (empty($att)) return 0;
$attachments = $this->notice->attachments();
$representable = false;
foreach ($attachments as $key=>$att) {
// Only show attachments representable with a title
if ($att->getTitle() === null) {
unset($attachments[$key]);
}
}
if (!count($attachments)) {
return 0;
}
$this->showListStart();
foreach ($att as $n=>$attachment) {
$item = $this->newListItem($attachment);
foreach ($attachments as $att) {
$item = $this->newListItem($att);
$item->show();
}
$this->showListEnd();
return count($att);
return count($attachments);
}
function showListStart()

View File

@ -63,7 +63,7 @@ class AttachmentListItem extends Widget
}
function title() {
return $this->attachment->title ?: $this->attachment->filename;
return $this->attachment->getTitle();
}
function linkTitle() {

View File

@ -35,12 +35,8 @@ class InlineAttachmentList extends AttachmentList
{
function showListStart()
{
$this->out->elementStart('div', array('class' => 'attachments'));
}
function showListEnd()
{
$this->out->elementEnd('div');
$this->out->element('h2', null, _('Attachments'));
parent::showListStart();
}
/**
@ -72,7 +68,7 @@ class InlineAttachmentListItem extends AttachmentListItem
{
// XXX: RDFa
// TODO: add notice_type class e.g., notice_video, notice_image
$this->out->elementStart('span', array('class' => 'inline-attachment'));
$this->out->elementStart('li', array('class' => 'inline-attachment'));
}
/**
@ -84,6 +80,6 @@ class InlineAttachmentListItem extends AttachmentListItem
*/
function showEnd()
{
$this->out->elementEnd('span');
$this->out->elementEnd('li');
}
}