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 // And finally remove the entry from the database
return parent::delete($useWhere); 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() function show()
{ {
$att = $this->notice->attachments(); $attachments = $this->notice->attachments();
if (empty($att)) return 0; $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(); $this->showListStart();
foreach ($att as $n=>$attachment) { foreach ($attachments as $att) {
$item = $this->newListItem($attachment); $item = $this->newListItem($att);
$item->show(); $item->show();
} }
$this->showListEnd(); $this->showListEnd();
return count($att); return count($attachments);
} }
function showListStart() function showListStart()

View File

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

View File

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