Commit e03327b0 authored by Robert Lyon's avatar Robert Lyon
Browse files

Adjusting the textbox so it can show/hide comments (Bug #1037531)



The comments will be displayed (or hidden) below the block by clicking
on the 'Comments (x)' link. There is also a 'close' link at the bottom
of the comment list as well to close them.

Change-Id: Ie4328872d861879975f6a6d86c8832892b8a37dd
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent b7a06a40
......@@ -16,7 +16,7 @@ $string['Comment'] = 'Comment';
$string['Comments'] = 'Comments';
$string['comment'] = 'comment';
$string['comments'] = 'comments';
$string['addcomment'] = 'Add comment';
$string['Allow'] = 'Allow';
$string['allowcomments'] = 'Allow comments';
$string['approvalrequired'] = 'Comments are moderated. If you choose to make this comment public, it will not be visible to others until it is approved by the owner.';
......
......@@ -497,6 +497,46 @@ class ArtefactTypeComment extends ArtefactType {
return $newest[0];
}
/**
* Fetching the comments for an artefact to display on a view
*
* @param object $artfact The artefact to display comments for
* @param object $view The view on which the artefact appears
* @param int $blockid The id of the block instance that connects the artefact to the view
* @param bool $html Whether to return the information rendered as html or not
*
* @return array $commentcount, $comments The count of comments and either the comments
* or the html to render them.
*/
public function get_artefact_comments_for_view($artefact, $view, $blockid, $html = true) {
if (empty($blockid) || !is_object($artefact) || !is_object($view)) {
throw new MaharaException('we do not have the right information to display the comments');
}
$commentoptions = ArtefactTypeComment::get_comment_options();
$commentoptions->limit = 0;
$commentoptions->view = $view;
$commentoptions->artefact = $artefact;
$commentoptions->onview = true;
$comments = ArtefactTypeComment::get_comments($commentoptions);
$commentcount = isset($comments->count) ? $comments->count : 0;
$artefacturl = get_config('wwwroot') . 'artefact/artefact.php?view=' . $view->get('id') . '&artefact=' . $artefact->get('id');
if ($html) {
$smarty = smarty_core();
$smarty->assign('artefacturl', $artefacturl);
$smarty->assign('blockid', $blockid);
$smarty->assign('commentcount', $commentcount);
$smarty->assign('comments', $comments);
$smarty->assign('allowcomments', $artefact->get('allowcomments'));
$render = $smarty->fetch('artefact/artefactcommentsview.tpl');
return array($commentcount, $render);
}
else {
return array($commentcount, $comments);
}
}
public static function deleted_messages() {
return array(
'author' => 'commentremovedbyauthor',
......
......@@ -59,20 +59,11 @@ class PluginBlocktypeTextbox extends PluginBlocktype {
$smarty->assign('attachments', $attachments);
$smarty->assign('count', count($attachments));
}
if ($artefact->get('allowcomments')) {
require_once(get_config('docroot') . 'lib/view.php');
$view = new View($viewid);
$commentoptions = ArtefactTypeComment::get_comment_options();
$commentoptions->view = $view;
$commentoptions->artefact = $artefact;
$comments = ArtefactTypeComment::get_comments($commentoptions);
$commentcount = isset($comments->count) ? $comments->count : 0;
$artefacturl = get_config('wwwroot') . 'artefact/artefact.php?view=' . $viewid . '&artefact=' . $configdata['artefactid'];
$smarty->assign('artefacturl', $artefacturl);
$smarty->assign('commentcount', $commentcount);
}
require_once(get_config('docroot') . 'lib/view.php');
$view = new View($viewid);
list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'));
$smarty->assign('commentcount', $commentcount);
$smarty->assign('comments', $comments);
return $smarty->fetch('blocktype:textbox:content.tpl');
}
......
......@@ -24,7 +24,6 @@
{if $artefact->get('tags')}<div class="tags">{str tag=tags}: {list_tags owner=$artefact->get('owner') tags=$artefact->get('tags')}</div>{/if}
{/if}
{if $commentcount || $commentcount === 0}
<div class="comments">
<a href="{$artefacturl}">{str tag=Comments section=artefact.comment} ({$commentcount})</a>
</div>
{/if}
\ No newline at end of file
{$comments|safe}
{/if}
......@@ -260,6 +260,16 @@ ul.artefactchooser-subtabs li.current a:active {
.feedbacktable .deleteddetails {
color: #666666;
}
.comments {
padding-top: 5px;
}
.addcomment {
padding-left: 6px;
}
.commentlink,
.nocomments {
padding-right: 5px;
}
/* view menu */
.feedback {
background: url(../images/feedback.png) no-repeat 0 0;
......
<div class="comments">
{if $commentcount > 0}
<a class="commentlink" id="block_{$blockid}" href="{$artefacturl}">{str tag=Comments section=artefact.comment} ({$commentcount})</a>
{else}
{if $allowcomments}
<span id='block_{$blockid}' class="nocomments">{str tag=Comments section=artefact.comment} ({$commentcount})</span>
{/if}
{/if}
{if $allowcomments}
<a class="addcomment bar-before" href="{$artefacturl}">{str tag=addcomment section=artefact.comment}</a>
{/if}
</div>
<div class="feedbacktablewrapper">
<div id="feedbacktable_{$blockid}" class="feedbacktable">
{$comments->tablerows|safe}
</div>
</div>
\ No newline at end of file
......@@ -101,6 +101,13 @@ ul.colnav li.selected span {
padding: 8px 5px;
}
/* feedback */
.feedbacktablewrapper {
margin-top: 5px;
border: 1px dotted #000;
padding: 4px;
display: none;
text-align: left;
}
.feedbacktable .r0,
.feedbacktable .r1 {
background: none;
......
......@@ -277,6 +277,37 @@ var showmore = {$showmore};
addLoadEvent(function () {
paginator = {$feedback->pagination_js}
});
\$j(function() {
\$j('#column-container .blockinstance-content .commentlink').each(function() {
var blockid = \$j(this).attr('id').match(/\d+/);
// only use comments expander if there are comments on the artefact
\$j(this).on('click', function(e) {
var commentlink = \$j(this);
var chtml = commentlink.parent().parent().find('#feedbacktable_' + blockid).parent();
// add a 'close' link at the bottom of the list for convenience
if (\$j('#closer_' + blockid).length == 0) {
var closer = \$j('<a id="closer_' + blockid + '" href="#">Close</a>').click(function(e) {
\$j(this).parent().toggle(400, function() {
commentlink.focus();
});
e.preventDefault();
});
chtml.append(closer);
}
chtml.toggle(400, function() {
if (chtml.is(':visible')) {
chtml.find('a').first().focus();
}
else {
commentlink.focus();
}
});
e.preventDefault();
});
});
});
EOF;
// collection top navigation
......
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