Enh: Added Make Private/ Make Public link to wall entry controls

Fix: Wallentry loader + badge render issue
This commit is contained in:
buddh4 2017-03-28 17:36:06 +02:00
parent 844dfa9a65
commit b6d74b39a3
10 changed files with 177 additions and 57 deletions

View File

@ -25,6 +25,7 @@ HumHub Change Log
- Fix: Default stream sort setting not applied
- Enh: Show different login message, when registration is disabled
- Fix: Norwegian translation code for Yii messages
- Enh: Added Make Private/ Make Public link to wall entry controls
1.2.0-beta.3 (March 20, 2017)

View File

@ -74,6 +74,7 @@ class Events extends \yii\base\Object
$content = $event->sender->object;
$stackWidget->addWidget(widgets\DeleteLink::className(), ['content' => $content], ['sortOrder' => 100]);
$stackWidget->addWidget(widgets\VisibilityLink::className(), ['contentRecord' => $content], ['sortOrder' => 250]);
$stackWidget->addWidget(widgets\NotificationSwitchLink::className(), ['content' => $content], ['sortOrder' => 300]);
$stackWidget->addWidget(widgets\PermaLink::className(), ['content' => $content], ['sortOrder' => 400] );
$stackWidget->addWidget(widgets\PinLink::className(), ['content' => $content], ['sortOrder' => 500]);

View File

@ -12,6 +12,7 @@ use Yii;
use yii\web\HttpException;
use humhub\components\Controller;
use humhub\modules\content\models\Content;
use humhub\modules\content\permissions\CreatePublicContent;
/**
* ContentController is responsible for basic content objects.
@ -110,7 +111,6 @@ class ContentController extends Controller
*/
public function actionUnarchive()
{
Yii::$app->response->format = 'json';
$this->forcePostRequest();
$json = array();
@ -125,7 +125,39 @@ class ContentController extends Controller
$json['success'] = true;
}
return $json;
return $this->asJson($json);
}
/**
* Switches the content visibility for the given content.
*
* @param type $id content id
* @return \yii\web\Response
* @throws HttpException
*/
public function actionToggleVisibility($id)
{
$this->forcePostRequest();
$content = Content::findOne(['id' => $id]);
if(!$content) {
throw new HttpException(400, Yii::t('ContentController.base', 'Invalid content id given!'));
} elseif(!$content->canEdit()) {
throw new HttpException(403);
} elseif($content->isPrivate() && !$content->container->permissionManager->can(new CreatePublicContent())) {
throw new HttpException(403);
}
if($content->isPrivate()) {
$content->visibility = Content::VISIBILITY_PUBLIC;
} else {
$content->visibility = Content::VISIBILITY_PRIVATE;
}
return $this->asJson([
'success' => $content->save(),
'state' => $content->visibility
]);
}
/**
@ -135,8 +167,6 @@ class ContentController extends Controller
*/
public function actionPin()
{
Yii::$app->response->format = 'json';
$this->forcePostRequest();
$json = array();
@ -156,7 +186,7 @@ class ContentController extends Controller
$json['error'] = Yii::t('ContentModule.controllers_ContentController', "Could not load requested object!");
}
return $json;
return $this->asJson($json);
}
/**
@ -166,11 +196,9 @@ class ContentController extends Controller
*/
public function actionUnPin()
{
Yii::$app->response->format = 'json';
$this->forcePostRequest();
$json = array();
$json = [];
$json['success'] = false;
$content = Content::findOne(['id' => Yii::$app->request->get('id', "")]);
@ -179,13 +207,11 @@ class ContentController extends Controller
$json['success'] = true;
}
return $json;
return $this->asJson($json);
}
public function actionNotificationSwitch()
{
Yii::$app->response->format = 'json';
$this->forcePostRequest();
$json = array();
@ -199,7 +225,7 @@ class ContentController extends Controller
$json['success'] = true;
}
return $json;
return $this->asJson($json);
}
}

View File

@ -220,18 +220,23 @@ class Content extends ContentDeprecated
}
/**
* Returns the public state of the contect object
* Checks if the content visiblity is set to public.
*
* @return boolean
*/
public function isPublic()
{
if ($this->visibility == self::VISIBILITY_PUBLIC) {
return true;
}
return false;
return $this->visibility === self::VISIBILITY_PUBLIC;
}
/**
* Checks if the content visiblity is set to private.
*
* @return boolean
*/
public function isPrivate()
{
return $this->visibility === self::VISIBILITY_PRIVATE;
}
/**

View File

@ -0,0 +1,47 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\content\widgets;
use yii\helpers\Url;
use humhub\modules\content\permissions\CreatePublicContent;
/**
* Visibility link for Wall Entries can be used to switch form public to private and vice versa.
*
* @package humhub.modules_core.wall.widgets
* @since 1.2
*/
class VisibilityLink extends \yii\base\Widget
{
/**
* @var \humhub\modules\content\components\ContentActiveRecord
*/
public $contentRecord;
/**
* @inheritdoc
*/
public function run()
{
$content = $this->contentRecord->content;
$contentContainer = $content->container;
if(!$content->canEdit()) {
return;
} else if($content->isPrivate() && !$contentContainer->permissionManager->can(new CreatePublicContent())) {
return;
}
return $this->render('visibilityLink', [
'content' => $content,
'toggleLink' => Url::to(['/content/content/toggle-visibility', 'id' => $content->id])
]);
}
}

View File

@ -10,11 +10,11 @@ $unarchiveLink = Url::to(['/content/content/unarchive', 'id' => $id]);
<li>
<?php if ($object->content->isArchived()): ?>
<a href="#" data-action-click="unarchive" data-action-url="<?= $unarchiveLink ?>">
<i class="fa fa-archive"></i> <?php echo Yii::t('ContentModule.widgets_views_archiveLink', 'Unarchive'); ?>
<i class="fa fa-archive"></i> <?= Yii::t('ContentModule.widgets_views_archiveLink', 'Unarchive'); ?>
</a>
<?php else: ?>
<?php else: ?>
<a href="#" data-action-click="archive" data-action-url="<?= $archiveLink ?>">
<i class="fa fa-archive"></i> <?php echo Yii::t('ContentModule.widgets_views_archiveLink', 'Move to archive'); ?>
<i class="fa fa-archive"></i> <?= Yii::t('ContentModule.widgets_views_archiveLink', 'Move to archive'); ?>
</a>
<?php endif; ?>
</li>

View File

@ -6,19 +6,20 @@ use humhub\modules\content\widgets\WallEntry;
?>
<li>
<?php if($mode === WallEntry::EDIT_MODE_INLINE) : ?>
<a href="#" class="stream-entry-edit-link" data-action-click="edit" data-action-url="<?= $editUrl ?>">
<i class="fa fa-pencil"></i> <?= Yii::t('ContentModule.widgets_views_editLink', 'Edit') ?>
</a>
<a href="#" class="stream-entry-cancel-edit-link" data-action-click="cancelEdit" style="display:none;">
<i class="fa fa-pencil"></i> <?= Yii::t('ContentModule.widgets_views_editLink', 'Cancel Edit') ?>
</a>
<?php elseif ($mode === WallEntry::EDIT_MODE_MODAL) : ?>
<a href="#" class="stream-entry-edit-link" data-action-click="editModal" data-action-url="<?= $editUrl ?>">
<i class="fa fa-pencil"></i><?= Yii::t('ContentModule.widgets_views_editLink', 'Edit') ?>
</a>
<?php elseif ($mode === WallEntry::EDIT_MODE_NEW_WINDOW) : ?>
<a href="<?= $editUrl ?>" class="stream-entry-edit-link">
<i class="fa fa-pencil"></i><?= Yii::t('ContentModule.widgets_views_editLink', 'Edit') ?>
</a>
<?php endif; ?>
<?php if($mode === WallEntry::EDIT_MODE_INLINE) : ?>
<a href="#" class="stream-entry-edit-link" data-action-click="edit" data-action-url="<?= $editUrl ?>">
<i class="fa fa-pencil"></i> <?= Yii::t('ContentModule.widgets_views_editLink', 'Edit') ?>
</a>
<a href="#" class="stream-entry-cancel-edit-link" data-action-click="cancelEdit" style="display:none;">
<i class="fa fa-pencil"></i> <?= Yii::t('ContentModule.widgets_views_editLink', 'Cancel Edit') ?>
</a>
<?php elseif ($mode === WallEntry::EDIT_MODE_MODAL) : ?>
<a href="#" class="stream-entry-edit-link" data-action-click="editModal" data-action-url="<?= $editUrl ?>">
<i class="fa fa-pencil"></i><?= Yii::t('ContentModule.widgets_views_editLink', 'Edit') ?>
</a>
<?php elseif ($mode === WallEntry::EDIT_MODE_NEW_WINDOW) : ?>
<a href="<?= $editUrl ?>" class="stream-entry-edit-link">
<i class="fa fa-pencil"></i><?= Yii::t('ContentModule.widgets_views_editLink', 'Edit') ?>
</a>
<?php endif; ?>
</li>

View File

@ -11,18 +11,20 @@ use humhub\modules\post\models\Post;
* @since 0.5
*/
?>
<?php if ($object->content->isPinned()) : ?>
<span class="label label-danger"><?= Yii::t('ContentModule.widgets_views_label', 'Pinned'); ?></span>
<?php endif; ?>
<span class="wallentry-labels">
<?php if ($object->content->isPinned()) : ?>
<span class="label label-danger"><?= Yii::t('ContentModule.widgets_views_label', 'Pinned'); ?></span>
<?php endif; ?>
<?php if ($object->content->isArchived()) : ?>
<span class="label label-warning"><?= Yii::t('ContentModule.widgets_views_label', 'Archived'); ?></span>
<?php endif; ?>
<?php if ($object->content->isArchived()) : ?>
<span class="label label-warning"><?= Yii::t('ContentModule.widgets_views_label', 'Archived'); ?></span>
<?php endif; ?>
<?php if ($object->content->isPublic()) : ?>
<span class="label label-success"><?= Yii::t('ContentModule.widgets_views_label', 'Public'); ?></span>
<?php endif; ?>
<?php if ($object->content->isPublic()) : ?>
<span class="label label-success"><?= Yii::t('ContentModule.widgets_views_label', 'Public'); ?></span>
<?php endif; ?>
<?php if (!$object instanceof Post) : ?>
<span class="label label-default"><?= $object->getContentName(); ?></span>
<?php endif; ?>
<?php if (!$object instanceof Post) : ?>
<span class="label label-default"><?= $object->getContentName(); ?></span>
<?php endif; ?>
<span>

View File

@ -0,0 +1,18 @@
<?php
/* @var $this humhub\components\View */
/* @var content humhub\modules\content\models\Content */
/* @var $toggleLink string */
?>
<li>
<?php if($content->isPrivate()) :?>
<a href="#" class="makePublicLink" data-action-click="toggleVisibility" data-action-url="<?= $toggleLink ?>">
<i class="fa fa-unlock makePublic"></i> <?= Yii::t('ContentModule.widgets_views_contentForm', 'Make public') ?>
</a>
<?php else: ?>
<a href="#" class="makePriavteLink" data-action-click="toggleVisibility" data-action-url="<?= $toggleLink ?>">
<i class="fa fa-lock makePrivate"></i> <?= Yii::t('ContentModule.widgets_views_contentForm', 'Make private') ?>
</a>
<?php endif; ?>
</li>

View File

@ -208,10 +208,12 @@ humhub.module('stream', function (module, require, $) {
var $loader = this.$.find('.stream-entry-loader');
if ($show === false) {
loader.reset($loader);
this.$.find('.wallentry-labels').show();
this.$.find('.preferences').show();
return;
}
this.$.find('.wallentry-labels').hide();
this.$.find('.preferences').hide();
loader.set($loader, {
'position': 'left',
@ -231,6 +233,23 @@ humhub.module('stream', function (module, require, $) {
additions.highlight(this.getContent());
};
StreamEntry.prototype.toggleVisibility = function (evt) {
this.loader();
var that = this;
client.post(evt).then(function(response) {
if(response.success) {
that.reload();
module.log.success('saved');
} else {
module.log.error(response, true);
that.loader(false);
}
}).catch(function (e) {
that.loader(false);
module.log.error(e, true);
});
};
StreamEntry.prototype.pin = function (evt) {
var that = this;
this.loader();
@ -603,13 +622,13 @@ humhub.module('stream', function (module, require, $) {
};
Stream.prototype.prependEntry = function (html, respectPinnedPosts) {
if(respectPinnedPosts) {
if (respectPinnedPosts) {
var $pinned = this.$.find('[data-stream-pinned="1"]:last');
if($pinned.length) {
if ($pinned.length) {
return this.after(html, $pinned);
}
}
return this._streamEntryAnimation(html, function ($html) {
this.$content.prepend($html);
});
@ -663,7 +682,7 @@ humhub.module('stream', function (module, require, $) {
Stream.prototype.addEntries = function (response, cfg) {
var that = this;
var result = '';
$.each(response.contentOrder, function (i, key) {
var $entry = that.entry(key);
if ($entry.length) {
@ -689,8 +708,8 @@ humhub.module('stream', function (module, require, $) {
} else {
promise = this.appendEntry($result);
}
promise.then(function() {
promise.then(function () {
that.$.trigger('humhub:stream:afterAddEntries', [response, $result]);
});