Skip to content

Commit 4308998

Browse files
committed
Releasing 1.1.2
2 parents ba0961e + 7ab385f commit 4308998

File tree

11 files changed

+220
-13
lines changed

11 files changed

+220
-13
lines changed

src/WebApp/BootstrapTheme/MenuItemRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function render() {
4949

5050
protected function createLink($component) {
5151
$rc = '#';
52-
$pageLink = $component->getPageLink();
52+
$pageLink = $component->getLink();
5353
if ($pageLink != NULL) {
5454
$rc = $pageLink;
5555
}

src/WebApp/BootstrapTheme/MmenuLayout.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ protected function renderMenuItem($item, $level) {
131131
$rc = '';
132132
if ($item != NULL) {
133133
$rc = '<li>';
134-
$link = $item->getPageLink();
134+
$link = $item->getLink();
135135
if ($level == 0) {
136136
$icon = $item->getIcon();
137137
if ($icon == NULL) $icon = '';
138-
$icon = '<span class="mmenu-icon">'.$icon.'</span>';
138+
$icon = '<span class="mmenu-icon" title="'.htmlentities($item->getLabel()).'">'.$icon.'</span>';
139139
}
140140

141141
if ($link != NULL) {

src/WebApp/Service/AbstractLinkBuilder.php renamed to src/WebApp/Builder/AbstractLinkBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace WebApp\Service;
3+
namespace WebApp\Builder;
44

55
/** Descendants only need to declare methods like getViewLink(), getEditLink() etc. */
66
class AbstractLinkBuilder implements \TgUtils\LinkBuilder {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace WebApp\Builder;
4+
5+
abstract class AbstractMenuBuilder implements MenuBuilder {
6+
7+
protected $app;
8+
9+
public function __construct($app) {
10+
$this->app = $app;
11+
}
12+
13+
}
14+
15+

src/WebApp/Builder/MenuBuilder.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace WebApp\Builder;
4+
5+
interface MenuBuilder {
6+
7+
public function getMenu($subject, $params = NULL);
8+
9+
}
10+
11+
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace WebApp\Component\Data;
4+
5+
/**
6+
* Usage (with LinkBuilder or LinkBuilderService):
7+
* $menu = new ContextMenu($app, $dataObject, $linkBuilderService);
8+
* $group1 = $menu->createGroup();
9+
* $item1 = $group1->createItem('View this object')->setAction('view');
10+
* $item2 = $group1->createItem('Edit this object')->setAction('edit');
11+
*
12+
* Usage (without LinkBuilder or LinkBuilderService):
13+
* $menu = new ContextMenu($app, $dataObject);
14+
* $group1 = $menu->createGroup();
15+
* $item1 = $group1->createItem('View this object')->setLink('/path/to/view.html');
16+
* $item2 = $group1->createItem('Edit this object')->setLink('/path/to/edit.html');
17+
*
18+
* You can also give a label to the group:
19+
* $group1 = $menu->createGroup('Actions');
20+
*
21+
* It is recommended to subclass ContextMenu and populate the menu after calling the parent
22+
* constructor.
23+
*
24+
* Use the context menu with DropDown (the context menu must be complete at this time):
25+
* $dropDown->setMenu($menu);
26+
*/
27+
class ContextMenu extends Div {
28+
29+
protected $app;
30+
protected $subject;
31+
protected $groups;
32+
protected $linkBuilder;
33+
34+
public function __construct($parent, $app, $subject, $linkBuilder = NULL) {
35+
parent::__construct($parent);
36+
$this->app = $app;
37+
$this->subject = $subject;
38+
$this->groups = array();
39+
if ($linkBuilder != NULL) {
40+
if (is_a($linkBuilder, 'WebApp\\Service\\LinkBuilderService')) {
41+
$this->linkBuilder = $linkBuilder->getBuilder($subject);
42+
} else {
43+
$this->linkBuilder = $linkBuilder;
44+
}
45+
}
46+
}
47+
48+
public function createGroup($label = NULL) {
49+
$rc = new ContextMenuGroup($this, $this->app, $this->subject, $label);
50+
$rc->setLinkBuilder($this->linkBuilder);
51+
$this->groups[] = $rc;
52+
return $rc;
53+
}
54+
55+
public function getMenu() {
56+
return $this->groups;
57+
}
58+
59+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace WebApp\Component;
4+
5+
class ContextMenuGroup extends ContextMenuItem {
6+
7+
protected $items;
8+
9+
public function __construct($parent, $app, $subject, $label = NULL) {
10+
parent::__construct($parent, $app, $subject, $label);
11+
$this->items = array();
12+
}
13+
14+
public function createGroup($label = NULL) {
15+
$rc = new ContextMenuGroup($this->parent, $this->app, $this->subject, $label);
16+
$rc->setLinkBuilder($this->linkBuilder);
17+
$this->items[] = $rc;
18+
return $rc;
19+
}
20+
21+
public function createItem($label = NULL) {
22+
$rc = new ContextMenuItem($this->parent, $this->app, $this->subject, $label);
23+
$rc->setLinkBuilder($this->linkBuilder);
24+
$this->items[] = $rc;
25+
return $rc;
26+
}
27+
28+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace WebApp\Component;
4+
5+
class ContextMenuItem extends MenuItem {
6+
7+
protected $app;
8+
protected $subject;
9+
protected $linkBuilder;
10+
11+
public function __construct($parent, $app, $subject, $label = NULL) {
12+
parent::__construct($parent, $label);
13+
$this->app = $app;
14+
$this->subject = $subject;
15+
}
16+
17+
public function setLinkBuilder($linkBuilder) {
18+
$this->linkBuilder = $linkBuilder;
19+
}
20+
21+
public function getLinkBuilder() {
22+
return $this->linkBuilder;
23+
}
24+
25+
public function setAction($action = \TgUtils\LinkBuilder::VIEW, $params = NULL) {
26+
if ($this->linkBuilder != NULL) {
27+
$this->setLink($linkBuilder->getLink($this->subject, $action, $params));
28+
} else {
29+
$this->setLink('#'.$action);
30+
}
31+
return $this;
32+
}
33+
34+
}

src/WebApp/Component/MenuItem.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
class MenuItem extends Container {
88

99
protected $label;
10-
protected $pageLink;
10+
protected $link;
1111
protected $linkTarget;
1212
protected $icon;
1313

1414
public function __construct($parent, $label, $pageLink, $icon = NULL) {
1515
parent::__construct($parent);
1616
$this->setLabel($label);
1717
$this->setLinkTarget(NULL);
18-
$this->setPageLink($pageLink);
18+
$this->setLink($pageLink);
1919
$this->setIcon($icon);
2020
}
2121

@@ -25,17 +25,24 @@ public function getLabel() {
2525

2626
public function setLabel($value) {
2727
$this->label = $value;
28+
return $this;
29+
}
30+
31+
public function setLink($link) {
32+
$this->link = $link;
33+
return $this;
34+
}
35+
36+
public function getLink() {
37+
return $this->link;
2838
}
2939

3040
public function getPageLink() {
31-
return $this->pageLink;
41+
return $this->getLink();
3242
}
3343

3444
public function setPageLink($value) {
35-
$this->pageLink = $value;
36-
if ((strlen($value) > 4) && (substr($value, 0,4) == 'http')) {
37-
$this->setLinkTarget('blank');
38-
}
45+
return $this->setLink($value);
3946
}
4047

4148
public function getIcon() {
@@ -44,6 +51,7 @@ public function getIcon() {
4451

4552
public function setIcon($value) {
4653
$this->icon = $value;
54+
return $this;
4755
}
4856

4957
public function getLinkTarget() {
@@ -52,5 +60,6 @@ public function getLinkTarget() {
5260

5361
public function setLinkTarget($value) {
5462
$this->linkTarget = $value;
63+
return $this;
5564
}
5665
}

src/WebApp/Service/LinkBuilderService.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
namespace WebApp\Service;
44

5-
class LinkBuilderService extends AbstractService {
5+
class LinkBuilderService extends AbstractService implements \TgUtils\LinkBuilder {
6+
7+
protected $builders;
68

79
public function __construct($app) {
810
parent::__construct($app);
911
$this->builders = array();
1012
}
1113

12-
public function getLink($subject, $action = LinkBuilder::VIEW, $params = NULL) {
14+
public function getLink($subject, $action = \TgUtils\LinkBuilder::VIEW, $params = NULL) {
1315
$builder = $this->getBuilder($subject);
1416
if ($builder != NULL) {
1517
return $builder->getLink($subject, $action, $params);

0 commit comments

Comments
 (0)