Commit 11a6875e authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Make inbox blocktype work like inbox (make messages readable, and update read/unread status)


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 49fa8fa1
......@@ -104,33 +104,6 @@ function markread(form, action) {
});
}
function updateUnreadCount(n, decrement) {
var newcount = -1;
forEach(getElementsByTagAndClassName('span', 'unreadmessagescontainer'), function(message) {
var countnode = message.firstChild;
if (decrement == 'decrement') {
var oldcount = parseInt(countnode.innerHTML);
newcount = (oldcount - n);
}
else {
newcount = n;
}
var messagenode = message.lastChild;
if (newcount == 1) { // jump through hoops to change between plural and singular
messagenode.innerHTML = get_string('unreadmessage');
}
else {
messagenode.innerHTML = get_string('unreadmessages');
}
countnode.innerHTML = newcount;
});
if (newcount > -1) {
forEach(getElementsByTagAndClassName('span', 'unreadmessagecount', 'right-nav'), function(element) {
element.innerHTML = newcount;
});
}
}
function showHideMessage(id) {
var message = $('message-' + id);
if (!message) {
......
......@@ -67,7 +67,7 @@ class PluginBlocktypeInbox extends SystemBlocktype {
$records = array();
if ($desiredtypes) {
$sql = "
SELECT n.*, t.name
SELECT n.id, n.subject, n.message, n.url, n.urltext, n.read, t.name AS type
FROM {notification_internal_activity} n JOIN {activity_type} t ON n.type = t.id
WHERE n.usr = ?
AND t.name IN (" . join(',', array_map('db_quote', $desiredtypes)) . ")
......@@ -85,22 +85,12 @@ class PluginBlocktypeInbox extends SystemBlocktype {
unset($records[$maxitems]);
}
$items = array();
if ($records) {
foreach($records as $record) {
$items[] = array(
'subject' => $record->subject,
'url' => $record->url,
'type' => $record->name,
);
}
}
$smarty = smarty_core();
if ($showmore) {
$smarty->assign('desiredtypes', implode(',', $desiredtypes));
}
$smarty->assign('items', $items);
$smarty->assign('blockid', 'blockinstance_' . $instance->get('id'));
$smarty->assign('items', $records);
return $smarty->fetch('blocktype:inbox:inbox.tpl');
}
......
<table>
{foreach from=$items item=i}
<tr>
<td>
<img src="{theme_url filename=cat('images/' $i.type '.gif')}" />
<td class="icon-container">
<div class="icon">
<img src="{theme_url filename=cat('images/' $i->type '.gif')}" />
</div>
</td>
<td>
{if $i.url}<a href="{$i.url|escape}">{/if}
{$i.subject|escape}
{if $i.url}</a>{/if}
{if $i->message}
<a href="" class="inbox-showmessage{if !$i->read} unread{/if}">{$i->subject|escape}</a>
<div class="inbox-message hidden" id="inbox-message-{$i->id}">{$i->message|clean_html}
{if $i->url}<br><a href="{$i->url|escape}" class="s">{if $i->urltext}{$i->urltext|escape} &raquo;{else}{str tag="more..."}{/if}</a>{/if}
</div>
{elseif $i->url}
<a href="{$i->url|escape}">{$i->subject|escape}</a>
{else}
{$i->subject|escape}
{/if}
</td>
</tr>
{/foreach}
</table>
{if $desiredtypes}
<a href="{$WWWROOT}account/activity?type={$desiredtypes|escape}">{str tag=More section=blocktype.inbox} &raquo;</a>
{/if}
\ No newline at end of file
{/if}
<script>
{literal}
addLoadEvent(function() {
forEach(
{/literal}
getElementsByTagAndClassName('a', 'inbox-showmessage', '{$blockid}'),
{literal}
function(element) {
connect(element, 'onclick', function(e) {
e.stop();
var message = getFirstElementByTagAndClassName('div', 'inbox-message', element.parentNode);
toggleElementClass('hidden', message);
if (hasElementClass(element, 'unread')) {
var id = getNodeAttribute(message, 'id').replace(/inbox-message-(\d+)$/, '$1');
var pd = {'readone':id};
sendjsonrequest(config.wwwroot + 'account/activity/index.json.php', pd, 'GET', function(data) {
removeElementClass(element, 'unread');
updateUnreadCount(1, 'decrement');
});
}
});
});
});
{/literal}
</script>
\ No newline at end of file
......@@ -685,3 +685,31 @@ function quotaUpdate(quotaused, quota) {
}, null, true);
}
}
function updateUnreadCount(n, decrement) {
var newcount = -1;
forEach(getElementsByTagAndClassName('span', 'unreadmessagescontainer'), function(message) {
var countnode = message.firstChild;
if (decrement == 'decrement') {
var oldcount = parseInt(countnode.innerHTML);
newcount = (oldcount - n);
}
else {
newcount = n;
}
var messagenode = message.lastChild;
if (newcount == 1) { // jump through hoops to change between plural and singular
messagenode.innerHTML = get_string('unreadmessage');
}
else {
messagenode.innerHTML = get_string('unreadmessages');
}
countnode.innerHTML = newcount;
});
if (newcount > -1) {
forEach(getElementsByTagAndClassName('span', 'unreadmessagecount', 'right-nav'), function(element) {
element.innerHTML = newcount;
});
}
}
......@@ -296,8 +296,18 @@ html>body #column-container {
}
/* Inbox */
.bt-inbox table td {
vertical-align: middle;
.bt-inbox td.icon-container {
vertical-align: top;
padding: 0;
width: 15px;
}
.bt-inbox td.icon-container .icon {
height: 1.4em;
vertical-align: bottom;
display: table-cell;
}
.inbox-showmessage.unread {
font-weight: bold;
}
/* tabs for the artefact chooser */
......
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