diff --git a/protected/humhub/modules/activity/resources/js/humhub.activity.js b/protected/humhub/modules/activity/resources/js/humhub.activity.js index d9342130d0..7457b308a5 100644 --- a/protected/humhub/modules/activity/resources/js/humhub.activity.js +++ b/protected/humhub/modules/activity/resources/js/humhub.activity.js @@ -51,29 +51,13 @@ humhub.module('activity', function (module, require, $) { var ActivityStream = stream.Stream.extend(function (container, options) { var that = this; stream.Stream.call(this, container, { - loadInitialCount: STREAM_INIT_COUNT, + initLoadCount: STREAM_INIT_COUNT, loadCount: STREAM_LOAD_COUNT, streamEntryClass: ActivityStreamEntry, }); }); - /*ActivityStream.prototype.showLoader = function () { - var $loaderListItem = $('
  • '); - loader.append($loaderListItem); - this.$content.append($loaderListItem); - }; - - ActivityStream.prototype.hideLoader = function () { - this.$content.find('#activityLoader').remove(); - };*/ - - /*ActivityStream.prototype.onChange = function () { - if (!this.hasEntries()) { - this.$.html('
    ' + module.text('activityEmpty') + '
    '); - } - };*/ - ActivityStream.prototype.initScroll = function () { if(!this.$content.is(':visible')) { return; @@ -83,6 +67,9 @@ humhub.module('activity', function (module, require, $) { var scrolling = true; var that = this; this.$content.scroll(function (evt) { + if(that.lastEntryLoaded()) { + return; + } // save height of the overflow container var _containerHeight = that.$content.height(); // save scroll height diff --git a/protected/humhub/modules/content/components/ContentActiveRecord.php b/protected/humhub/modules/content/components/ContentActiveRecord.php index 3ff94940fc..6e9d7166a9 100644 --- a/protected/humhub/modules/content/components/ContentActiveRecord.php +++ b/protected/humhub/modules/content/components/ContentActiveRecord.php @@ -470,7 +470,7 @@ class ContentActiveRecord extends ActiveRecord implements ContentOwner, Movable public function canMove(ContentContainerActiveRecord $container = null) { if(!$this->canMove) { - return Yii::t('ContentModel.base', 'This content type can\'t be moved'); + return Yii::t('ContentModule.base', 'This content type can\'t be moved'); } return true; diff --git a/protected/humhub/modules/content/components/ContentContainerModuleManager.php b/protected/humhub/modules/content/components/ContentContainerModuleManager.php index 063444afa3..222381647c 100644 --- a/protected/humhub/modules/content/components/ContentContainerModuleManager.php +++ b/protected/humhub/modules/content/components/ContentContainerModuleManager.php @@ -82,6 +82,11 @@ class ContentContainerModuleManager extends \yii\base\Component */ public function isEnabled($id) { + // Workaround for core post module + if($id === 'post') { + return true; + } + return in_array($id, $this->getEnabled()); } diff --git a/protected/humhub/modules/content/controllers/ContentController.php b/protected/humhub/modules/content/controllers/ContentController.php index e2404c0d0a..d5bbb55319 100644 --- a/protected/humhub/modules/content/controllers/ContentController.php +++ b/protected/humhub/modules/content/controllers/ContentController.php @@ -8,6 +8,8 @@ namespace humhub\modules\content\controllers; +use humhub\libs\Html; +use humhub\modules\content\models\forms\MoveContentForm; use Yii; use yii\web\HttpException; use humhub\components\Controller; @@ -31,7 +33,7 @@ class ContentController extends Controller { return [ 'acl' => [ - 'class' => \humhub\components\behaviors\AccessControl::className(), + 'class' => \humhub\components\behaviors\AccessControl::class, ] ]; } @@ -267,6 +269,27 @@ class ContentController extends Controller return $this->asJson($json); } + public function actionMove($id) + { + $form = new MoveContentForm(['id' => $id]); + + if(!$form->content) { + throw new HttpException(404); + } + + if($form->load(Yii::$app->request->post()) && $form->save()) { + return $this->asJson([ + 'success' => true, + 'id' => $id, + 'target' => $form->getTargetContainer()->id, + 'message' => Yii::t('ContentModule.base', 'Content has been moved to {spacename}', ['spacename' => Html::encode($form->getTargetContainer()->getDisplayName())]) + ]); + } + + return $this->renderAjax('moveModal', ['model' => $form]); + + } + } ?> diff --git a/protected/humhub/modules/content/models/Content.php b/protected/humhub/modules/content/models/Content.php index 142f6fa713..bff53aa96e 100644 --- a/protected/humhub/modules/content/models/Content.php +++ b/protected/humhub/modules/content/models/Content.php @@ -412,7 +412,7 @@ class Content extends ContentDeprecated implements Movable // Check for legacy modules if(!$model->getModuleId()) { - return Yii::t('ContentModel.base', 'This content type can\'t be moved due to a missing module-id setting.'); + return Yii::t('ContentModule.base', 'This content type can\'t be moved due to a missing module-id setting.'); } if(!$container) { @@ -424,27 +424,27 @@ class Content extends ContentDeprecated implements Movable if(!$container->moduleManager->isEnabled($model->getModuleId())) { $module = Yii::$app->getModule($model->getModuleId()); $moduleName = ($module instanceof ContentContainerModule) ? $module->getContentContainerName($container) : $module->getName(); - return Yii::t('ContentModel.base', 'The module {moduleName} is not enabled on the selected target space.', ['moduleName' => $moduleName]); + return Yii::t('ContentModule.base', 'The module {moduleName} is not enabled on the selected target space.', ['moduleName' => $moduleName]); } // Check if the current user is allowed to move this content at all if(!$isContentOwner && !$this->container->can(ManageContent::class)) { - return Yii::t('ContentModel.base', 'You do not have the permission to move this content.'); + return Yii::t('ContentModule.base', 'You do not have the permission to move this content.'); } // Check if the current user is allowed to move this content to the given target space if(!$isContentOwner && !$container->can(ManageContent::class)) { - return Yii::t('ContentModel.base', 'You do not have the permission to move this content to the given space.'); + return Yii::t('ContentModule.base', 'You do not have the permission to move this content to the given space.'); } // Check if the content owner is allowed to create content on the target space $ownerPermissions = $container->getPermissionManager($this->createdBy); if($this->isPrivate() && !$ownerPermissions->can(CreatePrivateContent::class)) { - return Yii::t('ContentModel.base', 'The author of this content is not allowed to create private content within the selected space.'); + return Yii::t('ContentModule.base', 'The author of this content is not allowed to create private content within the selected space.'); } if($this->isPublic() && !$ownerPermissions->can(CreatePublicContent::class)) { - return Yii::t('ContentModel.base', 'The author of this content is not allowed to create public content within the selected space.'); + return Yii::t('ContentModule.base', 'The author of this content is not allowed to create public content within the selected space.'); } return true; diff --git a/protected/humhub/modules/content/models/forms/MoveContentForm.php b/protected/humhub/modules/content/models/forms/MoveContentForm.php new file mode 100644 index 0000000000..7241bf7ff9 --- /dev/null +++ b/protected/humhub/modules/content/models/forms/MoveContentForm.php @@ -0,0 +1,93 @@ +content = Content::findOne(['id' => $this->id]); + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [['target'], 'validateTarget'] + ]; + } + + public function validateTarget($attribute, $params, $validator) + { + $targetContainer = $this->getTargetContainer(); + + if(!$targetContainer) { + $this->addError($attribute, Yii::t('ContentModule.base', 'Invalid space selection.')); + } else { + $result = $this->content->canMove($targetContainer); + if($result !== true) { + $this->addError($attribute, $result); + } + } + } + + /** + * @return Space|null + */ + public function getTargetContainer() + { + if(!$this->targetContainer) { + $target = isset($this->target[0]) ? $this->target[0] : null; + + if($target) { + $this->targetContainer = Space::findOne(['guid' => $target]); + } + } + + return $this->targetContainer; + } + + public function save() + { + if(!$this->validate()) { + return false; + } + + $this->content->move($this->getTargetContainer()); + return true; + } +} \ No newline at end of file diff --git a/protected/humhub/modules/content/resources/js/humhub.content.js b/protected/humhub/modules/content/resources/js/humhub.content.js index 5bfe6ebe5f..a808f63f1c 100644 --- a/protected/humhub/modules/content/resources/js/humhub.content.js +++ b/protected/humhub/modules/content/resources/js/humhub.content.js @@ -117,6 +117,18 @@ humhub.module('content', function (module, require, $) { }); }; + var submitMove = function(evt) { + debugger; + modal.submit(evt).then(function(response) { + if(response.success) { + if(response.message) { + module.log.success(response.message); + } + event.trigger('humhub:content:afterMove', response); + } + }); + }; + var templates = { permalinkBody: '

    {info}

    ', permalinkFooter: '{buttonOpen}' @@ -124,6 +136,7 @@ humhub.module('content', function (module, require, $) { module.export({ Content: Content, - templates: templates + templates: templates, + submitMove: submitMove }); }); \ No newline at end of file diff --git a/protected/humhub/modules/content/views/content/moveModal.php b/protected/humhub/modules/content/views/content/moveModal.php new file mode 100644 index 0000000000..5c905629e3 --- /dev/null +++ b/protected/humhub/modules/content/views/content/moveModal.php @@ -0,0 +1,22 @@ + + + Yii::t('ContentModule.base', 'Move content')]) ?> + + + + + diff --git a/protected/humhub/modules/content/widgets/MoveLink.php b/protected/humhub/modules/content/widgets/MoveLink.php index d91ebd4794..42a19d2acb 100644 --- a/protected/humhub/modules/content/widgets/MoveLink.php +++ b/protected/humhub/modules/content/widgets/MoveLink.php @@ -9,14 +9,13 @@ namespace humhub\modules\content\widgets; use humhub\modules\content\permissions\ManageContent; -use yii\helpers\Url; -use humhub\modules\content\permissions\CreatePublicContent; +use Yii; /** - * Visibility link for Wall Entries can be used to switch form public to private and vice versa. + * MoveLink used to move a wallentry to another space. * * @package humhub.modules_core.wall.widgets - * @since 1.2 + * @since 1.3 */ class MoveLink extends WallEntryControlLink { @@ -24,27 +23,38 @@ class MoveLink extends WallEntryControlLink /** * @var \humhub\modules\content\components\ContentActiveRecord */ - public $contentRecord; + public $model; /** - * @inheritdoc + * @inheritdocs */ - public function run() + public $icon = 'fa-arrows-h'; + + /** + * @inheritdocs + */ + public $action = 'ui.modal.load'; + + /** + * @inheritdocs + */ + public function getLabel() { - $content = $this->contentRecord->content; - $contentContainer = $content->container; + return Yii::t('ContentModule.base', 'Move content'); + } - if($this->contentObject->isOwner() && $contentContainer->can(ManageContent::class)) { - return ''; - } + /** + * @inheritdocs + */ + public function getActionUrl() { + return $this->model->content->container->createUrl('/content/content/move', ['id' => $this->model->content->id]); + } - $this->action = 'move'; - $this->actionUrl = $contentContainer->createUrl(['']); - - - return $this->render('moveLink', [ - 'content' => $content, - 'toggleLink' => Url::to(['/content/content/toggle-visibility', 'id' => $content->id]) - ]); + /** + * @inheritdocs + */ + public function preventRender() + { + return !$this->model->isOwner() || !$this->model->content->container->can(ManageContent::class); } } \ No newline at end of file diff --git a/protected/humhub/modules/content/widgets/WallEntry.php b/protected/humhub/modules/content/widgets/WallEntry.php index 55b1c698cd..e42a361da6 100644 --- a/protected/humhub/modules/content/widgets/WallEntry.php +++ b/protected/humhub/modules/content/widgets/WallEntry.php @@ -183,15 +183,18 @@ class WallEntry extends Widget public function getContextMenu() { $result = []; + + $this->addControl($result, [DeleteLink::class, ['content' => $this->contentObject], ['sortOrder' => 100]]); + if (!empty($this->getEditUrl())) { $this->addControl($result, [EditLink::class, ['model' => $this->contentObject, 'mode' => $this->editMode, 'url' => $this->getEditUrl()], ['sortOrder' => 200]]); } - $this->addControl($result, [DeleteLink::class, ['content' => $this->contentObject], ['sortOrder' => 100]]); $this->addControl($result, [VisibilityLink::class, ['contentRecord' => $this->contentObject], ['sortOrder' => 250]]); $this->addControl($result, [NotificationSwitchLink::class, ['content' => $this->contentObject], ['sortOrder' => 300]]); $this->addControl($result, [PermaLink::class, ['content' => $this->contentObject], ['sortOrder' => 400]]); $this->addControl($result, [PinLink::class, ['content' => $this->contentObject], ['sortOrder' => 500]]); + $this->addControl($result, [MoveLink::class, ['model' => $this->contentObject], ['sortOrder' => 550]]); $this->addControl($result, [ArchiveLink::class, ['content' => $this->contentObject], ['sortOrder' => 600]]); if(isset($this->controlsOptions['add'])) { diff --git a/protected/humhub/modules/content/widgets/WallEntryControlLink.php b/protected/humhub/modules/content/widgets/WallEntryControlLink.php index 00cdb5d339..f0526af45f 100644 --- a/protected/humhub/modules/content/widgets/WallEntryControlLink.php +++ b/protected/humhub/modules/content/widgets/WallEntryControlLink.php @@ -51,6 +51,14 @@ class WallEntryControlLink extends \humhub\components\Widget $this->label = ArrayHelper::remove($this->options, 'label', 'Label'); } + if(!empty($this->getAction())) { + $this->options['data-action-click'] = $this->getAction(); + } + + if(!empty($this->getActionUrl())) { + $this->options['data-action-url'] = $this->getActionUrl(); + } + ArrayHelper::remove($this->options, 'sortOrder'); parent::init(); } @@ -60,9 +68,39 @@ class WallEntryControlLink extends \humhub\components\Widget */ public function run() { + if($this->preventRender()) { + return ''; + } + return '
  • '.$this->renderLink().'
  • '; } + /** + * This function may contain validation logic as permission checks. + * + * @return bool true if this link should be rendered false if not + */ + public function preventRender() + { + return false; + } + + /** + * @return string renders the actual link + */ + protected function renderLink() + { + return Html::a($this->renderLinkText(), '#', $this->options); + } + + /** + * @return string renders the link text with icon + */ + protected function renderLinkText() + { + return ($this->icon) ? ' '.$this->getLabel() : $this->getLabel(); + } + /** * @return string link label */ @@ -84,19 +122,21 @@ class WallEntryControlLink extends \humhub\components\Widget } /** - * @return string renders the actual link + * @return string|null action url + * @since 1.3 */ - protected function renderLink() + public function getActionUrl() { - return Html::a($this->renderLinkText(), '#', $this->options); + return null; } /** - * @return string renders the link text with icon + * @return string|null link action + * @since 1.3 */ - protected function renderLinkText() + private function getAction() { - return ($this->icon) ? ' '.$this->getLabel() : $this->getLabel(); + return $this->action; } } diff --git a/protected/humhub/modules/post/models/Post.php b/protected/humhub/modules/post/models/Post.php index 521b145aa9..3728b78f7e 100644 --- a/protected/humhub/modules/post/models/Post.php +++ b/protected/humhub/modules/post/models/Post.php @@ -28,12 +28,21 @@ use humhub\modules\user\models\User; */ class Post extends ContentActiveRecord implements Searchable { - /** * @inheritdoc */ public $wallEntryClass = 'humhub\modules\post\widgets\WallEntry'; + /** + * @inheritdoc + */ + public $moduleId = 'post'; + + /** + * @inheritdoc + */ + public $canMove = true; + /** * @inheritdoc */ diff --git a/protected/humhub/modules/stream/resources/js/humhub.stream.Stream.js b/protected/humhub/modules/stream/resources/js/humhub.stream.Stream.js index 9c3bd15902..1a162ec6a3 100644 --- a/protected/humhub/modules/stream/resources/js/humhub.stream.Stream.js +++ b/protected/humhub/modules/stream/resources/js/humhub.stream.Stream.js @@ -198,6 +198,10 @@ humhub.module('stream.Stream', function (module, require, $) { return this.state.loading === true; }; + Stream.prototype.lastEntryLoaded = function () { + return this.state.lastEntryLoaded === true; + }; + Stream.prototype.load = function (options) { return new StreamRequest(this, options).load() .then($.proxy(this.handleResponse, this)) diff --git a/protected/humhub/modules/stream/resources/js/humhub.stream.wall.js b/protected/humhub/modules/stream/resources/js/humhub.stream.wall.js index 4d8a516632..f01a898534 100644 --- a/protected/humhub/modules/stream/resources/js/humhub.stream.wall.js +++ b/protected/humhub/modules/stream/resources/js/humhub.stream.wall.js @@ -21,6 +21,7 @@ humhub.module('stream.wall', function (module, require, $) { var Filter = require('ui.filter').Filter; var string = require('util').string; var topic = require('topic'); + var view = require('ui.view'); /** * Stream implementation for main wall streams. @@ -43,9 +44,9 @@ humhub.module('stream.wall', function (module, require, $) { WallStream.prototype.initEvents = function () { var that = this; - this.on('humhub:stream:beforeLoadEntries', function () { + this.on('humhub:stream:beforeLoadEntries.wallStream', function () { $('#btn-load-more').hide(); - }).on('humhub:stream:afterAddEntries', function (evt, resp, res) { + }).on('humhub:stream:afterAddEntries.wallStream', function (evt, resp, res) { $.each(resp.contentSuppressions, function (key, contentSuppression) { var entry = that.entry(key); if(entry) { @@ -57,13 +58,25 @@ humhub.module('stream.wall', function (module, require, $) { if(!resp.isLast) { $('#btn-load-more').show(); } - }).on('humhub:stream:lastEntryLoaded', function () { + }).on('humhub:stream:lastEntryLoaded.wallStream', function () { $('#btn-load-more').hide(); }); - event.on('humhub:content:newEntry', function (evt, html) { + event.on('humhub:content:newEntry.wallStream', function (evt, html) { that.prependEntry(html, true); }); + + event.on('humhub:content:afterMove.wallStream', function (evt, response) { + var entry = that.entry(response.id); + debugger; + if(entry) { + if(view.getState().moduleId === 'dashboard') { + entry.reload(); + } else { + setTimeout($.proxy(entry.remove, entry), 1000); + } + } + }); }; WallStream.template = { @@ -119,7 +132,9 @@ humhub.module('stream.wall', function (module, require, $) { }; var unload = function() { + debugger; event.off('humhub:content:newEntry.wallStream'); + event.off('humhub:content:afterMove.wallStream'); event.off('humhub:topic:added.wallStream'); event.off('humhub:topic:removed.wallStream'); event.off('humhub:topic:updated.wallStream'); @@ -263,6 +278,7 @@ humhub.module('stream.wall', function (module, require, $) { module.export({ WallStream: WallStream, - WallStreamFilter: WallStreamFilter + WallStreamFilter: WallStreamFilter, + unload: unload }); }); diff --git a/protected/humhub/modules/ui/filter/widgets/PickerFilterInput.php b/protected/humhub/modules/ui/filter/widgets/PickerFilterInput.php index 9d5c47bb6d..55eacf546a 100644 --- a/protected/humhub/modules/ui/filter/widgets/PickerFilterInput.php +++ b/protected/humhub/modules/ui/filter/widgets/PickerFilterInput.php @@ -8,7 +8,7 @@ namespace humhub\modules\ui\filter\widgets; -use humhub\widgets\BasePickerField; +use humhub\modules\ui\form\widgets\BasePicker; use yii\helpers\ArrayHelper; class PickerFilterInput extends FilterInput @@ -25,7 +25,7 @@ class PickerFilterInput extends FilterInput public $pickerOptions = []; - public $picker = BasePickerField::class; + public $picker = BasePicker::class; /** * @var string data-action-click handler of the input event diff --git a/static/js/humhub/humhub.ui.view.js b/static/js/humhub/humhub.ui.view.js index 4c0c80c544..d068f41d70 100644 --- a/static/js/humhub/humhub.ui.view.js +++ b/static/js/humhub/humhub.ui.view.js @@ -15,8 +15,9 @@ humhub.module('ui.view', function (module, require, $) { }; var setState = function (moduleId, controlerId, action) { + debugger; state = { - title: title || document.title, + title: document.title, moduleId: moduleId, controllerId: controlerId, action: action @@ -33,7 +34,7 @@ humhub.module('ui.view', function (module, require, $) { module.initOnPjaxLoad = true; var init = function ($pjax) { - title = document.title; + //title = document.title; module.log.debug('Current view state', state); };