Skip to content

Commit

Permalink
Merge pull request #553 from oxwall/profile_actions_event
Browse files Browse the repository at this point in the history
Mobile profile actions event
  • Loading branch information
GiperProger committed Feb 20, 2018
2 parents 8a92fd9 + d03ba24 commit e225a00
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 5 deletions.
Expand Up @@ -222,7 +222,7 @@ public function getGroupMenu( $group )
}

$contextActionMenu = new BASE_CMP_ContextAction();
$event = new OW_Event(self::EVENT_GROUP_MENU_CLASS, array("key" => $group["key"]), array(
$event = new OW_Event(self::EVENT_GROUP_MENU_CLASS, array("key" => $group["key"], "userId" => $this->userId), array(
"ow_profile_toolbar_group",
"ow_context_action_value_block"
));
Expand Down
Expand Up @@ -29,20 +29,23 @@
*/
class BASE_MCMP_ProfileActionToolbar extends BASE_MCMP_ButtonList
{
const EVENT_NAME = 'base.mobile.add_profile_action_toolbar';
const EVENT_NAME = "base.mobile.add_profile_action_toolbar";
const EVENT_GROUP_MENU_CLASS = "base.mobile.profile_action_toolbar_group_menu_class";

protected $userId;

/**
* Constructor.
*
* @param integer $userId
*/
public function __construct( $userId )
{
parent::__construct(array());

$this->userId = (int) $userId;

$event = new BASE_CLASS_EventCollector(self::EVENT_NAME, array('userId' => $this->userId));
$event = new BASE_CLASS_EventCollector(self::EVENT_NAME, array("userId" => $this->userId));

OW::getEventManager()->trigger($event);

Expand All @@ -57,4 +60,61 @@ public function __construct( $userId )

$this->items = $addedData;
}
}

public function onBeforeRender()
{
parent::onBeforeRender();

$this->initList();

$template = OW::getPluginManager()->getPlugin("base")->getMobileCmpViewDir() . "profile_action_toolbar.html";
$this->setTemplate($template);
}

protected function initList()
{
$itemGroups = array();
$buttons = array();

foreach ( $this->items as $item )
{
if ( isset($item["group"]) )
{
if ( empty($itemGroups[$item["group"]]) )
{
$itemGroups[$item["group"]] = array(
"key" => $item["group"],
"label" => isset($item["groupLabel"]) ? $item["groupLabel"] : null,
"context" => array()
);
}

$itemGroups[$item["group"]]["items"][] = $item;
}
else
{
$buttons[] = $this->prepareItem($item, "owm_btn_list_item");
}
}

$tplGroups = array();
foreach ( $itemGroups as $group )
{
$event = new OW_Event(self::EVENT_GROUP_MENU_CLASS, array("key" => $group["key"], "userId" => $this->userId), array(
"owm_btn_list_item_wrap",
"owm_view_more",
"owm_float_right"
));

OW::getEventManager()->trigger($event);
$contextAction = new BASE_MCMP_ContextAction($group["items"], $group["label"]);
$tplGroups[] = [
"classes" => implode(" ", $event->getData()),
"view" => $contextAction->render()
];
}

$this->assign("groups", $tplGroups);
$this->assign("buttons", $this->getSortedItems($buttons));
}
}
Expand Up @@ -11,5 +11,5 @@
</a>
</div>
{/foreach}

</div>
@@ -0,0 +1,15 @@
<div class="owm_btn_list owm_std_margin_bottom clearfix">
{foreach from=$groups item="group"}
<div class="{$group.classes}">
{$group.view}
</div>
{/foreach}
{foreach from=$buttons item="item"}
<div class="owm_btn_list_item_wrap owm_float_right">
<a {$item.attrs}>
<span class="owm_btn_list_item_c">{$item.label}</span>
</a>
</div>
{/foreach}

</div>

0 comments on commit e225a00

Please sign in to comment.