Render reaction record instantly

#56
This commit is contained in:
bleistivt 2015-01-11 10:27:29 +01:00
parent 8b22df1b6c
commit 257f33a3d3
2 changed files with 17 additions and 5 deletions

View File

@ -70,7 +70,7 @@ class ReactController extends Gdn_Controller {
$Item = $Model->GetID($ID);
if($Item) {
$Anchor = $AnchorID . $ID . ' .ReactMenu';
$Anchor = $AnchorID . $ID;
}
else {
throw new Gdn_UserException(T('Yaga.Action.InvalidTargetID'));
@ -98,7 +98,8 @@ class ReactController extends Gdn_Controller {
// It has passed through the gauntlet
$this->ReactionModel->Set($ID, $Type, $ItemOwnerID, $UserID, $ActionID);
$this->JsonTarget($Anchor, RenderReactionList($ID, $Type, FALSE), 'ReplaceWith');
$this->JsonTarget($Anchor . ' .ReactMenu', RenderReactionList($ID, $Type, FALSE), 'ReplaceWith');
$this->JsonTarget($Anchor . ' .ReactionRecord', RenderReactionRecord($ID, $Type, FALSE), 'ReplaceWith');
// Don't render anything
$this->Render('Blank', 'Utility', 'Dashboard');

View File

@ -56,10 +56,11 @@ if(!function_exists('RenderReactionRecord')) {
* @param int $ID
* @param string $Type 'discussion', 'activity', or 'comment'
*/
function RenderReactionRecord($ID, $Type) {
function RenderReactionRecord($ID, $Type, $Echo = TRUE) {
$Reactions = Yaga::ReactionModel()->GetRecord($ID, $Type);
$Limit = C('Yaga.Reactions.RecordLimit');
$ReactionCount = count($Reactions);
$RecordsString = '';
$i = 0;
foreach($Reactions as $Reaction) {
$i++;
@ -80,13 +81,23 @@ if(!function_exists('RenderReactionRecord')) {
'data-userid' => $User->UserID,
'title' => $DateTitle
);
echo Wrap($String, 'span', $Wrapttributes);
$RecordsString .= Wrap($String, 'span', $Wrapttributes);
}
if($Limit > 0 && $i >= $ReactionCount && $ReactionCount > $Limit) {
echo Plural($ReactionCount - $Limit, 'Yaga.Reactions.RecordLimit.Single', 'Yaga.Reactions.RecordLimit.Plural');
$RecordsString .= Plural($ReactionCount - $Limit, 'Yaga.Reactions.RecordLimit.Single', 'Yaga.Reactions.RecordLimit.Plural');
}
}
$AllRecordsString = Wrap($RecordsString, 'div', array('class' => 'ReactionRecord'));
if($Echo) {
echo $AllRecordsString;
return true;
}
else {
return $AllRecordsString;
}
}
}