mirror of
https://github.com/humhub/humhub.git
synced 2025-01-17 14:18:27 +01:00
Enh: Added getContextMenu for defining wallentry context options.
Enh: Added editMode to WallEntry for allowing modal based edits.
This commit is contained in:
parent
0d50f3f69d
commit
d1bedb8edb
@ -73,12 +73,11 @@ class Events extends \yii\base\Object
|
|||||||
$stackWidget = $event->sender;
|
$stackWidget = $event->sender;
|
||||||
$content = $event->sender->object;
|
$content = $event->sender->object;
|
||||||
|
|
||||||
$stackWidget->addWidget(widgets\DeleteLink::className(), ['content' => $content]);
|
$stackWidget->addWidget(widgets\DeleteLink::className(), ['content' => $content], ['sortOrder' => 100]);
|
||||||
$stackWidget->addWidget(widgets\EditLink::className(), ['content' => $content, 'wallEntryWidget' => $stackWidget->wallEntryWidget]);
|
$stackWidget->addWidget(widgets\NotificationSwitchLink::className(), ['content' => $content], ['sortOrder' => 300]);
|
||||||
$stackWidget->addWidget(widgets\NotificationSwitchLink::className(), ['content' => $content]);
|
$stackWidget->addWidget(widgets\PermaLink::className(), ['content' => $content], ['sortOrder' => 400] );
|
||||||
$stackWidget->addWidget(widgets\PermaLink::className(), ['content' => $content]);
|
$stackWidget->addWidget(widgets\PinLink::className(), ['content' => $content], ['sortOrder' => 500]);
|
||||||
$stackWidget->addWidget(widgets\PinLink::className(), ['content' => $content]);
|
$stackWidget->addWidget(widgets\ArchiveLink::className(), ['content' => $content], ['sortOrder' => 600]);
|
||||||
$stackWidget->addWidget(widgets\ArchiveLink::className(), ['content' => $content]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,26 +23,28 @@ class EditLink extends \yii\base\Widget
|
|||||||
/**
|
/**
|
||||||
* @var \humhub\modules\content\components\ContentActiveRecord
|
* @var \humhub\modules\content\components\ContentActiveRecord
|
||||||
*/
|
*/
|
||||||
public $content = null;
|
public $model = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \humhub\modules\content\models\WallEntry
|
* @var string edit route.
|
||||||
*/
|
*/
|
||||||
public $wallEntryWidget;
|
public $url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the widget.
|
* Executes the widget.
|
||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
$editUrl = $this->wallEntryWidget->getEditUrl();
|
if(!$this->url) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ($editUrl !== "" && $this->content->content->canWrite()) {
|
if ($this->model->content->canWrite()) {
|
||||||
return $this->render('editLink', array(
|
return $this->render('editLink', [
|
||||||
'id' => $this->content->content->object_id,
|
'id' => $this->model->content->object_id,
|
||||||
'content' => $this->content,
|
'content' => $this->model,
|
||||||
'editUrl' => $editUrl
|
'editUrl' => $this->url
|
||||||
));
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
40
protected/humhub/modules/content/widgets/EditLinkModal.php
Normal file
40
protected/humhub/modules/content/widgets/EditLinkModal.php
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @link https://www.humhub.org/
|
||||||
|
* @copyright Copyright (c) 2015 HumHub GmbH & Co. KG
|
||||||
|
* @license https://www.humhub.com/licences
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace humhub\modules\content\widgets;
|
||||||
|
|
||||||
|
use Yii;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit Link for Wall Entries
|
||||||
|
*
|
||||||
|
* This widget will be attached to the WallEntryControls and displays
|
||||||
|
* the "Edit" Link to the Content Objects if the editMode is set to EDIT_MODE_MODAL.
|
||||||
|
*
|
||||||
|
* @package humhub.modules_core.wall.widgets
|
||||||
|
* @since 1.2
|
||||||
|
*/
|
||||||
|
class EditLinkModal extends EditLink
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the widget.
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
if(!$this->url) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->model->content->canWrite()) {
|
||||||
|
return '<li>'.\yii\helpers\Html::a('<i class="fa fa-pencil"></i>'. Yii::t('ContentModule.widgets_views_editLink', 'Edit') , '#',
|
||||||
|
['class' => "stream-entry-edit-link", 'data-action-click' => "editModal", 'data-action-url' => $this->url]).'</li>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -21,6 +21,16 @@ use humhub\modules\space\models\Space;
|
|||||||
*/
|
*/
|
||||||
class WallEntry extends Widget
|
class WallEntry extends Widget
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Edit form is loaded to the wallentry itself.
|
||||||
|
*/
|
||||||
|
const EDIT_MODE_INLINE = 'inline';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit form is loaded into a modal.
|
||||||
|
*/
|
||||||
|
const EDIT_MODE_MODAL = 'modal';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The content object
|
* The content object
|
||||||
@ -43,6 +53,13 @@ class WallEntry extends Widget
|
|||||||
*/
|
*/
|
||||||
public $editRoute = "";
|
public $editRoute = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the way the edit of this wallentry is displayed.
|
||||||
|
*
|
||||||
|
* @var type
|
||||||
|
*/
|
||||||
|
public $editMode = self::EDIT_MODE_INLINE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The wall entry layout to use
|
* The wall entry layout to use
|
||||||
*
|
*
|
||||||
@ -83,8 +100,8 @@ class WallEntry extends Widget
|
|||||||
*/
|
*/
|
||||||
public function getEditUrl()
|
public function getEditUrl()
|
||||||
{
|
{
|
||||||
if ($this->editRoute === "") {
|
if (empty($this->editRoute)) {
|
||||||
return "";
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't show edit link, when content container is space and archived
|
// Don't show edit link, when content container is space and archived
|
||||||
@ -95,6 +112,34 @@ class WallEntry extends Widget
|
|||||||
return $this->contentObject->content->container->createUrl($this->editRoute, ['id' => $this->contentObject->id]);
|
return $this->contentObject->content->container->createUrl($this->editRoute, ['id' => $this->contentObject->id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of contextmenu items either in form of a single array:
|
||||||
|
*
|
||||||
|
* ['label' => 'mylabel', icon => 'fa-myicon', 'data-action-click' => 'myaction', ...]
|
||||||
|
*
|
||||||
|
* or as widget type definition:
|
||||||
|
*
|
||||||
|
* [MyWidget::class, [...], [...]]
|
||||||
|
*
|
||||||
|
* If an $editRoute is set this function will include an edit button.
|
||||||
|
* The edit logic can be changed by changing the $editMode.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* @since 1.2
|
||||||
|
*/
|
||||||
|
public function getContextMenu()
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
if (!empty($this->editRoute)) {
|
||||||
|
if($this->editMode === self::EDIT_MODE_INLINE) {
|
||||||
|
$result[] = [EditLink::class, ['model' => $this->contentObject, 'url' => $this->getEditUrl()], ['sortOrder' => 200]];
|
||||||
|
} else if($this->editMode === self::EDIT_MODE_MODAL) {
|
||||||
|
$result[] = [EditLinkModal::class, ['model' => $this->contentObject, 'url' =>$this->getEditUrl()], ['sortOrder' => 200]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders the wall entry output
|
* Renders the wall entry output
|
||||||
*
|
*
|
||||||
|
@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace humhub\modules\content\widgets;
|
||||||
|
|
||||||
|
use yii\helpers\ArrayHelper;
|
||||||
|
use yii\helpers\Html;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic WallEntryControlLink.
|
||||||
|
*
|
||||||
|
* @since 1.2
|
||||||
|
* @author buddh4
|
||||||
|
*/
|
||||||
|
class WallEntryControlLink extends \humhub\components\Widget
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object derived from HActiveRecordContent
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $label;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object derived from HActiveRecordContent
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $icon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var type
|
||||||
|
*/
|
||||||
|
public $options = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
$this->label = ArrayHelper::remove($this->options, 'label', 'Label');
|
||||||
|
$icon = ArrayHelper::remove($this->options, 'icon');
|
||||||
|
|
||||||
|
if($icon) {
|
||||||
|
$this->icon = '<i class="fa '.$icon.'"></i> ';
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayHelper::remove($this->options, 'sortOrder');
|
||||||
|
parent::init();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
return '<li>'.\yii\helpers\Html::a($this->icon.$this->label, '#', $this->options).'</li>';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
namespace humhub\modules\content\widgets;
|
namespace humhub\modules\content\widgets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This widget is responsible for rendering the context menu for wallentries.
|
||||||
|
*
|
||||||
|
* The default context menu can be extended by overwriting the getContextMenu function of
|
||||||
|
* the WallEntryWidget.
|
||||||
|
*/
|
||||||
class WallEntryControls extends \humhub\widgets\BaseStack
|
class WallEntryControls extends \humhub\widgets\BaseStack
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -14,6 +20,65 @@ class WallEntryControls extends \humhub\widgets\BaseStack
|
|||||||
* @var \humhub\modules\content\models\WallEntry
|
* @var \humhub\modules\content\models\WallEntry
|
||||||
*/
|
*/
|
||||||
public $wallEntryWidget;
|
public $wallEntryWidget;
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
foreach ($this->wallEntryWidget->getContextMenu() as $menuItem) {
|
||||||
|
if (!is_array($menuItem) || empty($menuItem)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$linkDefinition = $this->getWallEntryLinkDefinition($menuItem);
|
||||||
|
$this->addWidget($linkDefinition[0], $linkDefinition[1], $linkDefinition[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::run();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the widget definition for the given $menuItem.
|
||||||
|
* The $menuItem can either be given as single array:
|
||||||
|
*
|
||||||
|
* ['label' => 'mylabel', icon => 'fa-myicon', 'data-action-click' => 'myaction', ...]
|
||||||
|
*
|
||||||
|
* or as widget type definition:
|
||||||
|
*
|
||||||
|
* [MyWidget::class, [...], [...]]
|
||||||
|
*
|
||||||
|
* @param type $menuItem
|
||||||
|
* @return type
|
||||||
|
*/
|
||||||
|
protected function getWallEntryLinkDefinition($menuItem)
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
if (\yii\helpers\ArrayHelper::isAssociative($menuItem)) { // ['label' => 'xy', 'icon' => ...] -> WallEntryControlLink
|
||||||
|
$result[0] = WallEntryControlLink::class;
|
||||||
|
$result[1] = ['options' => $menuItem];
|
||||||
|
$result[2] = [];
|
||||||
|
$result[2]['sortOrder'] = isset($menuItem['sortOrder']) ? $menuItem['sortOrder'] : null;
|
||||||
|
} else { // [MyWidget::class, [..WidgetOptions..], [sortOrder..]] -> Widget type definition
|
||||||
|
$result[0] = $menuItem[0];
|
||||||
|
$result[1] = isset($menuItem[1]) ? $menuItem[1] : null;
|
||||||
|
$result[2] = isset($menuItem[2]) ? $menuItem[2] : null;
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the given $array is an associative array or not.
|
||||||
|
*
|
||||||
|
* @param array $arr
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
function isAssoc($arr)
|
||||||
|
{
|
||||||
|
if (array() === $arr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return array_keys($arr) !== range(0, count($arr) - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -67,8 +67,6 @@ humhub.module('space', function (module, require, $) {
|
|||||||
archive : archive,
|
archive : archive,
|
||||||
unarchive : unarchive,
|
unarchive : unarchive,
|
||||||
isSpacePage: isSpacePage,
|
isSpacePage: isSpacePage,
|
||||||
setSpace: setSpace,
|
setSpace: setSpace
|
||||||
enableModule: enableModule,
|
|
||||||
disableModule: disableModule
|
|
||||||
});
|
});
|
||||||
});
|
});
|
@ -84,14 +84,15 @@ class BaseStack extends \yii\base\Widget
|
|||||||
|
|
||||||
$out = $widgetClass::widget($widget[1]);
|
$out = $widgetClass::widget($widget[1]);
|
||||||
|
|
||||||
if ($out != "") {
|
if (!empty($out)) {
|
||||||
$content .= $out;
|
$content .= $out;
|
||||||
if ($i != count($this->getWidgets()))
|
if ($i != count($this->getWidgets())) {
|
||||||
$content .= $this->seperator;
|
$content .= $this->seperator;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print str_replace('{content}', $content, $this->template);
|
return str_replace('{content}', $content, $this->template);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -139,16 +140,17 @@ class BaseStack extends \yii\base\Widget
|
|||||||
* @param array $params widget definition
|
* @param array $params widget definition
|
||||||
* @param array $options extra option array with e.g. "sortOrder"
|
* @param array $options extra option array with e.g. "sortOrder"
|
||||||
*/
|
*/
|
||||||
public function addWidget($className, $params = array(), $options = array())
|
public function addWidget($className, $params = [], $options = [])
|
||||||
{
|
{
|
||||||
if (!isset($options['sortOrder']))
|
if (!isset($options['sortOrder'])) {
|
||||||
$options['sortOrder'] = 100;
|
$options['sortOrder'] = 100;
|
||||||
|
}
|
||||||
|
|
||||||
$this->widgets[] = array(
|
$this->widgets[] = [
|
||||||
$className,
|
$className,
|
||||||
$params,
|
$params,
|
||||||
$options
|
$options
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -134,6 +134,17 @@ humhub.module('ui.modal', function(module, require, $) {
|
|||||||
$content.append('<div class="modal-body" />');
|
$content.append('<div class="modal-body" />');
|
||||||
loader.set(this.getBody());
|
loader.set(this.getBody());
|
||||||
this.isFilled = false;
|
this.isFilled = false;
|
||||||
|
|
||||||
|
//reset listeners:
|
||||||
|
this.resetListener();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets some listeners of this modal isntance.
|
||||||
|
* @returns {undefined}
|
||||||
|
*/
|
||||||
|
Modal.prototype.resetListener = function() {
|
||||||
|
this.$.off('submitted');
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -576,6 +587,8 @@ humhub.module('ui.modal', function(module, require, $) {
|
|||||||
if(!module.global.$.is(':visible')) {
|
if(!module.global.$.is(':visible')) {
|
||||||
module.global.show();
|
module.global.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.global.$.trigger('submitted');
|
||||||
}).catch(function(error) {
|
}).catch(function(error) {
|
||||||
module.log.error(error, true);
|
module.log.error(error, true);
|
||||||
});
|
});
|
||||||
@ -591,7 +604,7 @@ humhub.module('ui.modal', function(module, require, $) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
var modal = (id) ? module.get(id) : module.global;
|
var modal = (id) ? module.get(id) : module.global;
|
||||||
modal.load(evt).catch(function(err) {
|
return modal.load(evt).catch(function(err) {
|
||||||
module.log.error(err, true);
|
module.log.error(err, true);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user