Commit b44e024d authored by Tobias Zeuch's avatar Tobias Zeuch Committed by Robert Lyon
Browse files

Inbox and outbox: show 'reply' and 'reply all' links in own column



Bug 1387330: Show reply and reply all buttons in a separate column in the inbox
and outbox, like email clients usually do. Also remove the reply-links after
the message text.
The buttons should only appear where applicalbe, e.g. only show a button reply
all when there were multiple recipients and don't show a reply-button for system
messages. Also other links remain in the message text, like links to new pages
in new-page-access notifications.

Change-Id: I938dda6210f4a0a8ab57b56c654cf60931ef7a6a
Signed-off-by: default avatarTobias Zeuch <tobias.zeuch@kit.edu>
parent 9aae02c7
......@@ -117,12 +117,13 @@ function markread(form, action) {
});
}
function showHideMessage(id, table) {
var message = $('message-' + table + '-' + id);
if (!message) {
function toggleMessageDisplay(table, id) {
var messages = jQuery('#message-' + table + '-' + id);
if (messages.length <= 0) {
return;
}
jQuery(message).parents("tr.unread").removeClass("unread")
message = messages[0];
messages.parents("tr.unread").removeClass("unread");
if (hasElementClass(message, 'hidden')) {
var unread = getFirstElementByTagAndClassName(
'input', 'tocheckread', message.parentNode.parentNode
......@@ -140,10 +141,17 @@ function showHideMessage(id, table) {
updateUnreadCount(data);
});
}
removeElementClass(message, 'hidden');
}
else {
addElementClass(message, 'hidden');
var rows = messages.parents("tr");
if (rows.length > 0) {
if (jQuery(rows[0]).find(".messagedisplaylong.hidden").length > 0) {
jQuery(rows[0]).find(".messagedisplaylong").removeClass("hidden");
jQuery(rows[0]).find(".messagedisplayshort").addClass("hidden");
}
else {
jQuery(rows[0]).find(".messagedisplaylong").addClass("hidden");
jQuery(rows[0]).find(".messagedisplayshort").removeClass("hidden");
}
}
}
......@@ -182,6 +190,17 @@ addLoadEvent(function () {
connect('notifications_type', 'onchange', changeactivitytype);
});
jQuery(function() {
jQuery('#activitylist tr').hover(
function() {
jQuery(this).addClass('highlight');
},
function() {
jQuery(this).removeClass('highlight');
}
);
});
JAVASCRIPT;
$deleteall = pieform(array(
......
/**
* Multi-Recipient Notification Toggle Recipients
* @source: http://gitorious.org/mahara/mahara
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
function toggleMe(a, b){
var on = document.getElementById(a);
var off = document.getElementById(b);
if (!on || !off) {
return true;
}
on.style.display = "block";
off.style.display = "none";
return true;
}
......@@ -30,8 +30,8 @@ $string['fromuser'] = 'From';
$string['touser'] = 'To';
// Notification Inbox URL Text
$string['returnurltext'] = 'Reply';
$string['replyurltext'] = 'Reply all';
$string['reply'] = 'Reply';
$string['replyall'] = 'Reply all';
$string['linkindicator'] = '»';
$string['labeloutbox1'] = 'Sent';
......@@ -40,6 +40,7 @@ $string['labelinbox'] = 'Inbox';
$string['inboxdesc'] = 'Messages received from Mahara system and other users';
$string['nothingtorender'] = '';
$string['replybuttonplaceholder'] = '...';
$string['selectallread'] = 'All unread notifications';
$string['selectalldelete'] = 'All notifications for deletion';
......
......@@ -166,28 +166,30 @@ function activitylistin_html($type='all', $limit=10, $offset=0) {
'link' => null,
),
);
$record->canreply = false;
$record->canreplyall = false;
$record->startnewthread = true;
// read out sender name
$record->fromusrlink = false;
if ('usermessage' === $record->type) {
$record->url = false;
$record->urltext = false;
}
if (isset($record->from)) {
$record->fromusr = $record->from;
$fromuser = get_user($record->fromusr);
$record->fromusrlink = false;
if ($fromuser->deleted === '0') {
$record->fromusrlink = profile_url($record->fromusr);
if ('usermessage' === $record->type) {
$record->canreply = true;
}
}
}
else {
$record->fromusr = 0;
}
if ($record->type === 'usermessage') {
$fromusr = $record->from;
$record->url = 'user/sendmessage.php?id=' . $fromusr . '&oldreplyto=' . $record->id . '&returnto=inbox';
$record->urltext = get_string('sendmessageto', 'artefact.multirecipientnotification');
}
else {
$record->urltext = $record->urltext;
}
$record->return = null;
$record->date = format_date(strtotime($record->ctime), 'strfdaymonthyearshort');
......@@ -237,13 +239,13 @@ function activitylistin_html($type='all', $limit=10, $offset=0) {
}
// add link to reply to all users in the conversation, if there are
// more than one of them
$record->canreply = false;
$record->startnewthread = false;
if (count($record->userids) > 1) {
$record->return = 'artefact/multirecipientnotification/sendmessage.php?replyto=' . $msgidrecord->id . '&returnto=inbox';
$record->returnoutput = get_string('replyurltext', 'artefact.multirecipientnotification');
$record->filepath = "../../../artefact/multirecipientnotification/theme/images/";
$record->canreplyall = true;
}
else {
$record->return = null;
$record->canreplyall = false;
}
// preformat from user, add link to reply to sender only
if (isset($record->fromid)) {
......@@ -251,10 +253,8 @@ function activitylistin_html($type='all', $limit=10, $offset=0) {
$fromuser = get_user($record->fromid);
$record->fromusrlink = false;
if ($fromuser->deleted === '0') {
$record->canreply = true;
$record->fromusrlink = profile_url($record->fromid);
// replay to sender
$record->url = 'artefact/multirecipientnotification/sendmessage.php?id=' . $record->fromid . '&replyto=' . $record->id . '&returnto=inbox';
$record->urltext = get_string('returnurltext', 'artefact.multirecipientnotification');
}
}
else {
......@@ -307,31 +307,77 @@ function activityblocklistin($type='all', $limit=10, $offset=0) {
$return->count = $activitylist->count;
foreach ($activitylist->msgidrecords as $msgidrecord) {
// old messages without plugin
if ($msgidrecord->msgtable == 'notification_internal_activity') {
$sql = "
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.id = ?";
$records = get_records_sql_array($sql, array($msgidrecord->id));
if (count($records == '1')) {
$record = $records[0];
$record->msgtable = $msgidrecord->msgtable;
$return->records[] = $record;
$recordsarray = get_records_sql_array("SELECT a.*, at.name AS type, at.plugintype, at.pluginname
FROM {notification_internal_activity} a
INNER JOIN {activity_type} at ON a.type = at.id
WHERE a.id = ?", array($msgidrecord->id));
if (1 !== count($recordsarray)) {
continue;
}
$record = $recordsarray[0];
$record->canreply = false;
$record->canreplyall = false;
$record->startnewthread = true;
// read out sender name
if ('usermessage' === $record->type) {
$record->url = false;
$record->urltext = false;
}
if (isset($record->from)) {
$record->fromusr = $record->from;
$fromuser = get_user($record->fromusr);
if ($fromuser->deleted === '0') {
if ('usermessage' === $record->type) {
$record->canreply = true;
}
}
}
else {
$record->fromusr = 0;
}
$record->return = null;
$section = empty($record->plugintype) ? 'activity' : "{$record->plugintype}.{$record->pluginname}";
$record->strtype = get_string('type' . $record->type, $section);
$record->message = format_notification_whitespace($record->message);
// used to identify notification as internal for json-calls
$record->table = 'notification_internal_activity';
$return->records[] = $record;
// messages from plugin
}
else {
else if ($msgidrecord->msgtable === 'artefact_multirecipient_notification') {
$record = get_message_mr($userid, $msgidrecord->id);
if (null === $record) {
continue;
}
$record->url = 'artefact/multirecipientnotification/sendmessage.php?replyto=' . $msgidrecord->id . '&returnto=outbox';
if (count($record->userids)>1) {
$record->urltext = get_string('replyurltext', 'artefact.multirecipientnotification');
$record->strtype = $record->type;
$record->tousr = array();
$record->canreply = false;
$record->startnewthread = false;
if (count($record->userids) > 1) {
$record->canreplyall = true;
}
else {
$record->canreplyall = false;
}
// preformat from user
if (isset($record->fromid)) {
$record->fromusr = $record->fromid;
$fromuser = get_user($record->fromid);
if ($fromuser->deleted === '0') {
$record->canreply = true;
}
}
else {
$record->urltext = get_string('returnurltext', 'artefact.multirecipientnotification');
$record->fromusr = 0;
}
$record->msgtable = $msgidrecord->msgtable;
$record->message = format_notification_whitespace($record->message);
// used to identify notification as from this plugin for json-calls
$record->table = 'artefact_multirecipient_notification';
$return->records[] = $record;
}
}
......@@ -451,7 +497,9 @@ function activitylistout_html($type='all', $limit=10, $offset=0) {
continue;
}
$record = $recordsarray[0];
$record->canreplyall = false;
$record->canreply = false;
$record->startnewthread = true;
// read out receiver name
if (isset($record->usr)) {
$tousrarray = array(
......@@ -460,6 +508,7 @@ function activitylistout_html($type='all', $limit=10, $offset=0) {
);
if (!get_user($record->usr)->deleted) {
$tousrarray['link'] = profile_url($record->usr);
$record->canreply = true;
}
$record->tousr = array (
$tousrarray,
......@@ -481,10 +530,6 @@ function activitylistout_html($type='all', $limit=10, $offset=0) {
// we're in the outbox, so basically, this should hold for all messages
$record->fromusr = $USER->get('id');
}
if ($record->type === 'usermessage') {
$record->url = 'user/sendmessage.php?id=' . $record->usr . '&returnto=outbox';
$record->urltext = get_string('sendmessageto', 'artefact.multirecipientnotification');
}
$record->date = format_date(strtotime($record->ctime), 'strfdaymonthyearshort');
$section = empty($record->plugintype) ? 'activity' : "{$record->plugintype}.{$record->pluginname}";
......@@ -507,6 +552,9 @@ function activitylistout_html($type='all', $limit=10, $offset=0) {
// applicable - we don't link to deleted users. Those will be summed
// up in a single entry at the end of the list
$deletedcount = 0;
$record->canreply = false;
$record->canreplyall = false;
$record->startnewthread = false;
for ($i = 0; $i < count($record->userids); $i++) {
$tousr = get_user($record->userids[$i]);
if ($tousr->deleted) {
......@@ -525,14 +573,13 @@ function activitylistout_html($type='all', $limit=10, $offset=0) {
'link' => null,
);
}
// add link to reply to all users in the conversation, if there are
// more than one of them or only to the one recipient
$record->url = 'artefact/multirecipientnotification/sendmessage.php?replyto=' . $msgidrecord->id . '&returnto=outbox';
if (count($record->userids)>1) {
$record->urltext = get_string('replyurltext', 'artefact.multirecipientnotification');
}
else {
$record->urltext = get_string('returnurltext', 'artefact.multirecipientnotification');
if ($deletedcount < count($record->userids)) {
if ((count($record->userids) - $deletedcount) == 1) {
$record->canreply = true;
}
else {
$record->canreplyall = true;
}
}
if (isset($record->fromid)) {
......
......@@ -116,32 +116,21 @@ function markread(form, action) {
});
}
function showHideMessage(id, table) {
var message = $('message-' + table + '-' + id);
if (!message) {
function toggleMessageDisplay(table, id) {
var messages = jQuery('#message-' + table + '-' + id);
if (messages.length <= 0) {
return;
}
if (hasElementClass(message, 'hidden')) {
var unread = getFirstElementByTagAndClassName(
'input', 'tocheckread', message.parentNode.parentNode
);
var unreadicon = getFirstElementByTagAndClassName(
'img', 'unreadmessage', message.parentNode.parentNode
);
if (unread) {
var pd = {'readone':id, 'table':table};
sendjsonrequest('indexout.json.php', pd, 'GET', function(data) {
swapDOM(unread, IMG({'src' : {$star}, 'alt' : {$strread}}));
if (unreadicon) {
swapDOM(unreadicon, IMG({'src' : {$readicon}, 'alt' : getNodeAttribute(unreadicon, 'alt') + ' - ' + {$strread}}));
};
updateUnreadCount(data);
});
var rows = messages.parents("tr");
if (rows.length > 0) {
if (jQuery(rows[0]).find(".messagedisplaylong.hidden").length > 0) {
jQuery(rows[0]).find(".messagedisplaylong").removeClass("hidden");
jQuery(rows[0]).find(".messagedisplayshort").addClass("hidden");
}
else {
jQuery(rows[0]).find(".messagedisplaylong").addClass("hidden");
jQuery(rows[0]).find(".messagedisplayshort").removeClass("hidden");
}
removeElementClass(message, 'hidden');
}
else {
addElementClass(message, 'hidden');
}
}
......@@ -180,6 +169,17 @@ addLoadEvent(function () {
connect('notifications_type', 'onchange', changeactivitytype);
});
jQuery(function() {
jQuery('#activitylist tr').hover(
function() {
jQuery(this).addClass('highlight');
},
function() {
jQuery(this).removeClass('highlight');
}
);
});
JAVASCRIPT;
$deleteall = pieform(array(
......
......@@ -52,40 +52,9 @@ class PluginBlocktypeInbox extends SystemBlocktype {
if (record_exists('artefact_installed', 'name', 'multirecipientnotification', 'active', '1') && safe_require_plugin('artefact', 'multirecipientnotification')) {
global $USER;
$userid = $USER->get('id');
$activitylist = activitylistin(join(',', $desiredtypes), $maxitems);
$records = array();
foreach ($activitylist->msgidrecords as $msgidrecord) {
if ($msgidrecord->msgtable == 'notification_internal_activity') {
$sql = "
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.id = ?";
$notificationrecords = get_records_sql_array($sql, array($msgidrecord->id));
if (count($notificationrecords) === 1) {
$record = $notificationrecords[0];
// need to adjust the url to avoid it clashing with multiplerecipient url
$record->url = preg_replace('/replyto/', 'oldreplyto', $record->url);
$record->msgtable = $msgidrecord->msgtable;
$records[] = $record;
}
}
else {
$record = get_message_mr($userid, $msgidrecord->id);
if (null === $record) {
continue;
}
$record->url = 'artefact/multirecipientnotification/sendmessage.php?replyto=' . $msgidrecord->id . '&returnto=outbox';
if (count($record->userids) > 1) {
$record->urltext = get_string('replyurltext', 'artefact.multirecipientnotification');
}
else {
$record->urltext = get_string('returnurltext', 'artefact.multirecipientnotification');
}
$record->msgtable = $msgidrecord->msgtable;
$records[] = $record;
}
}
safe_require('artefact', 'multirecipientnotification');
$activitylist = activityblocklistin(join(',', $desiredtypes), $maxitems);
$records = $activitylist->records;
$showmore = ($activitylist->count > $maxitems);
// use a different template
$smartytemplate = 'blocktype:inbox:inboxmr.tpl';
......
{foreach from=$data item=item}
<script type="application/javascript" src="js/toggle_recipient.js"></script>
<tr class="{cycle values='r0,r1'}{if !$item->read} unread{/if}">
<td class="inboxicon">
<td class="inboxicon" onclick="toggleMessageDisplay('{$item->table}','{$item->id}');">
{if $item->read && $item->type == 'usermessage'}
<img src="{theme_url filename=cat('images/read' $item->type '.png')}" alt="{$item->strtype} - {str tag='read' section='activity'}" />
{elseif $item->strtype == 'usermessage'}
......@@ -19,15 +18,15 @@
{str tag="system"}
{/if}
</td>
<td>
<td onclick="toggleMessageDisplay('{$item->table}','{$item->id}');">
{if $item->message}
<a href="" onclick="showHideMessage({$item->id}, '{$item->table}'); return false;">
<a href="" onclick="return false;">
{if !$item->read} <span class="accessible-hidden">{str tag='unread' section='activity'}: </span> {/if}
{$item->subject|truncate:60}
<span class="accessible-hidden">{str tag='clickformore' section='artefact.multirecipientnotification'}</span>
</a>
<div id="message-{$item->table}-{$item->id}" class="hidden">{$item->message|safe}
<div id="message-{$item->table}-{$item->id}" class="hidden messagedisplaylong">{$item->message|safe}
{if $item->url}
<br />
<a href="{$WWWROOT}{$item->url}">
......@@ -39,9 +38,6 @@
{str tag='linkindicator' section="artefact.multirecipientnotification"}
</a>
{/if}
{if $item->return}
<br /><a href="{$WWWROOT}{$item->return}">{$item->returnoutput}</a>
{/if}
</div>
{elseif $item->url}
......@@ -51,20 +47,20 @@
{/if}
</td>
<td class="userlist">
{if $item->return}
<span id="short{$item->id}">
<a onclick="return toggleMe('long{$item->id}', 'short{$item->id}')" href="javascript:void(0)">
<img class="togglebtn" src="{theme_url filename='images/expand.png'}" />
{if count($item->tousr) > 1}
<span id="short{$item->id}" class="messagedisplayshort">
<a onclick="return false;" href="javascript:void(0)">
<img class="togglebtn" src="{theme_url filename='images/expand.png'}" onclick="toggleMessageDisplay('{$item->table}','{$item->id}');"/>
</a>
{assign var="tousr" value=$item->tousr[0]}
{if $tousr['link']}<a href="{$tousr['link']}">{/if}
{$tousr['display']|truncate:$maxnamestrlength}
{if $tousr['link']}</a>{/if}
</span>
<span style="display:none;" id="long{$item->id}">
<a onclick="return toggleMe('short{$item->id}', 'long{$item->id}')" href="javascript:void(0)">
<img class="togglebtn" src="{theme_url filename='images/expanded.png'}" />
</a>
<span class="hidden messagedisplaylong" id="long{$item->id}">
<a onclick="return false;" href="javascript:void(0)">
<img class="togglebtn" src="{theme_url filename='images/expanded.png'}" onclick="toggleMessageDisplay('{$item->table}','{$item->id}');"/>
</a>
<span class="recipientlist">
{foreach from=$item->tousr item=tousr key=break}
{if ($tousr['link'])}<a href="{$tousr['link']}">{/if}
......@@ -81,7 +77,28 @@
{if ($tousr['link'])}</a>{/if}
{/if}
</td>
<td>{$item->date}</td>
<td onclick="toggleMessageDisplay('{$item->table}','{$item->id}');">{$item->date}</td>
<td class="right" onclick="toggleMessageDisplay('{$item->table}','{$item->id}');">
{if ($item->canreply || $item->canreplyall)}
<span class="hidden messagedisplaylong">
{if $item->canreply}
<a title="{str tag=reply section=artefact.multirecipientnotification}" href="{$WWWROOT}artefact/multirecipientnotification/sendmessage.php?id={$item->fromusr}{if !$item->startnewthread}&replyto={$item->id}{/if}&returnto=outbox">
<img src="{theme_url filename='images/reply.png'}" alt="{str tag=reply section=artefact.multirecipientnotification}">
</a>
{/if}
{if $item->canreplyall}
<a title="{str tag=replyall section=artefact.multirecipientnotification}" href="{$WWWROOT}artefact/multirecipientnotification/sendmessage.php?replyto={$item->id}&returnto=outbox">
<img src="{theme_url filename='images/replyall.png'}" alt="{str tag=replyall section=artefact.multirecipientnotification}">
</a>
{/if}
</span>
<span class="messagedisplayshort">
<a href="javascript:void(0)" onclick="return false;">
{str tag='replybuttonplaceholder' section='artefact.multirecipientnotification'}
</a>
</span>
{/if}
</td>
<td class="center">
{if $item->read}
<img src="{theme_url filename='images/star.png'}" alt="{str tag=read section=activity}">
......
{foreach from=$data item=item}
<script type="application/javascript" src="js/toggle_recipient.js"></script>
<tr class="{cycle values='r0,r1'}">
<td class="inboxicon">
<td class="inboxicon" onclick="toggleMessageDisplay('{$item->table}','{$item->id}');">
{if $item->read && $item->type == 'usermessage'}
<img src="{theme_url filename=cat('images/read' $item->type '.png')}" alt="{$item->strtype} - {str tag='read' section='activity'}" />
{elseif $item->type == 'usermessage'}
......@@ -10,14 +9,14 @@
<img src="{theme_url filename=cat('images/' $item->type '.png')}" alt="{$item->strtype}" />
{/if}
</td>
<td>{$item->fromusr|display_name|truncate:$maxnamestrlength}</td>
<td>
<td onclick="toggleMessageDisplay('{$item->table}','{$item->id}');">{$item->fromusr|display_name|truncate:$maxnamestrlength}</td>
<td onclick="toggleMessageDisplay('{$item->table}','{$item->id}');">
{if $item->message}
<a href="" onclick="showHideMessage({$item->id}, '{$item->table}'); return false;">
<a href="" onclick="return false;">
{$item->subject|truncate:60}
<span class="accessible-hidden">{str tag='clickformore' section='artefact.multirecipientnotification'}</span>
</a>
<div id="message-{$item->table}-{$item->id}" class="hidden">
<div id="message-{$item->table}-{$item->id}" class="hidden messagedisplaylong">
{$item->message|safe}
{if $item->url}
<br />
......@@ -38,9 +37,9 @@
</td>
<td class="userlist">
{if count($item->tousr) > 1}
<span id="short{$item->id}">
<a onclick="return toggleMe('long{$item->id}', 'short{$item->id}');" href="javascript:void(0)">
<img class="togglebtn" src="{theme_url filename='images/expand.png'}" />
<span id="short{$item->id}" class="messagedisplayshort">
<a onclick="return false;" href="javascript:void(0)">
<img class="togglebtn" src="{theme_url filename='images/expand.png'}" onclick="toggleMessageDisplay('{$item->table}','{$item->id}');"/>
{*<span class="accessible-hidden">{str tag='clickformore' section='artefact.multirecipientnotification'}</span>*}
</a>
{assign var="tousr" value=$item->tousr[0]}
......@@ -48,9 +47,9 @@
{$tousr['display']|truncate:$maxnamestrlength}
{if $tousr['link']}</a>{/if}
</span>
<span style="display:none;" id="long{$item->id}">
<a onclick="return toggleMe('short{$item->id}', 'long{$item->id}');" href="javascript:void(0)">