Commit ac25758c authored by Carsten  Rose's avatar Carsten Rose
Browse files

Refs #8348 - Add header, separator and disabled menu entries. Download PDF is...

Refs #8348 - Add header, separator and disabled menu entries. Download PDF is ok. New: '||' are required to separate menu entries.
parent c3a8b180
Pipeline #1858 passed with stage
in 2 minutes and 33 seconds
......@@ -5603,6 +5603,8 @@ Column: _link
|x | |Copy to |y:[some content] |y:this will be copied |Click on it copies the value of 'y:' to the clipboard. Optional a file ('F:...') might be specified as source. |
| | |clipboard | | |See `copyToClipboard`_. |
+---+---+--------------+-----------------------------------+---------------------------+----------------------------------------------------------------------------------------------------------------------------------------+
| | |Dropdown menu |z |z||p:home|t:Home |Creates a dropdown menu. SEe `dropdownMenu`_. |
+---+---+--------------+-----------------------------------+---------------------------+----------------------------------------------------------------------------------------------------------------------------------------+
| | |Text |t:<text> |t:Firstname Lastname | |
+---+---+--------------+-----------------------------------+---------------------------+----------------------------------------------------------------------------------------------------------------------------------------+
| | |Render |r:<mode> |r:3 |See: `render-mode`_, Default: 0 |
......@@ -6849,6 +6851,65 @@ Excel export samples::
# With parameter (via SIP) - get the Parameter on page 'exceldata' with '{{arg1:S}}' and '{{arg2:S}}'
SELECT CONCAT('d:final.xlsx|t:Excel (parameter)|uid:32&arg1=hello&arg2=world') AS _excel
.. _dropdownMenu:
Dropdown Menu
-------------
Creates a menu with custom links. The same notation and options are used as with regular QFQ links.
Format String::
<dropdown menu symbol options>||<menu entry 1>||<menu entry 2>||...
Each menu entry is separated by two bars! A menu entry itself might contain multiple single bars.
Example 1::
SELECT 'z||p:home|t:Home|o:Jump to home||p:person&form=person&r=123|t:Edit: John Doe|s' AS _link
This defines a menu (three vertical buttons) - a click on it shows two menu entries: 'Home' and 'Edit: John Doe'
Format the dropdown menu symbol:
* *Glyph*: Via `G:<glyphicon name>` any glyphicon can be defined. To hide the default glyph, specify: `G:0`.
* *Text*: Via `t:Menu` an additional text will be displayed for the menu symbol.
* *Tooltip*: Via `o:Detail menu` a tooltip is defined.
* *Render mode*: Via `r:3` the menu is disabled. No menu entries / links / sip are rendered.
* *Button*: Via `b` the dropdown meny symbol will be rendered with a button. Also `b:<style>` might set the BS color.
Format a menu entry:
* *qfq link*: All options as with a regular QFQ link.
* *header*: If a text starts with '===', it becomes a header in the dropdown menu. Multiple headers are possible. Headers can't be a link. An additional `r:1` is necessary.
* *separator*: If a text is exactly '---', it becomes a separator line between two menu entries. An additional `r:1` is necessary.
* *disabled menu entry*: If a text starts with '---' (like separator), the following text becomes a disable menu entry. An additional `r:1` is necessary.
Example 2::
SELECT CONCAT('z|t:Menu|G:0|o:Please select an option',
'||p:home|t:Home|o:Jump to home|G:glyphicon-home|b:0',
'||r:1|t:---',
'||p:person&form=person&r=123|t:Edit: John Doe|s|q:Really edit?|G:glyphicon-user|b:0',
'||t:===Header|r:1',
'||d|p:form&form=person&r=',p.id,'|s|t:Download Person|b:0',
'||r:1|t:---Disabled entry') AS _link
Line 1: The dropdown menu symbol definition, with a text 'Menu' `t:Menu`, but without the three vertical bullets `G:0`
and a tooltip for the menu `o:Please select an option`.
Line 2: First menu entry. Directs to T3 page 'home' `p:home`. `t:Home` sets the menu entry text. `G:glyphicon-home` set's
glyphicon symbol in the menu entry. `b:0` switches off the button, which has been implicit activated by the use of `G:...`.
Line 3: A separator line.
Line 4: A SIP encoded edit record link, with a question dialog.
Line 5: A header line.
Line 6: A PDF download.
Line 7: A disabled menu entry.
.. _drag_and_drop:
......
......@@ -418,21 +418,19 @@ class Link {
foreach ($paramArr as $tokenStr) {
$tokenArr = explode(PARAM_TOKEN_DELIMITER, $tokenStr, 2);
switch ($tokenArr[0] ?? '') {
// No further need: skip
case TOKEN_DROPDOWN:
$tokenCollect[] = ''; // In case there are no further options given, it's necessary to have at least one
break;
// Indicator to start menu entry: force a flush of existing token and start a new round.
case TOKEN_URL:
case TOKEN_MAIL:
case TOKEN_PAGE:
case TOKEN_DOWNLOAD:
case TOKEN_COPY_TO_CLIPBOARD:
case '':
// New menu entry
$menuEntryStrArr[] = implode(PARAM_DELIMITER, $tokenCollect);
// New menu entry.
if (!empty($tokenCollect)) {
$menuEntryStrArr[] = implode(PARAM_DELIMITER, $tokenCollect);
}
$tokenCollect = array();
$tokenCollect[] = $tokenStr;
// $tokenCollect[] = $tokenStr;
break;
default:
......@@ -440,10 +438,10 @@ class Link {
}
}
// Flush remaining element
// Flush remaining element.
$menuEntryStrArr[] = implode(PARAM_DELIMITER, $tokenCollect);
// Remove first array element - that's the menu, not the menu entry. Render the menu.
// Remove first array element - that's the menu, not a menu entry. Render the menu.
$flagMenuEnabled = false;
$dropdownSymbol = $this->renderDropdownSymbol(array_shift($menuEntryStrArr), $htmlId, $flagMenuEnabled);
......@@ -481,14 +479,43 @@ class Link {
*/
private function renderDropdown(string $dropdownSymbol, array $menuEntryLinkArr, $htmlId, $flagMenuEnabled) {
$ul = '';
$li = '';
$attribute = '';
if ($flagMenuEnabled) {
$tmp = '';
foreach ($menuEntryLinkArr as $link) {
$tmp .= '<li>' . $link . '</li>';
$attribute = '';
switch (substr($link, 0, 3)) {
case '---':
$link = substr($link, 3);
if ($link == '') {
# Separator
$attribute = ' role="separator" class="divider"';
} else {
# Disabled
$attribute = ' class="disabled"';
if (false === strstr($link, '<a ')) {
# If there is no '<a>'-tag, the 'disabled' class is broken - set a fake one.
$link = Support::wrapTag('<a href="#">', $link);
}
}
break;
case '===':
// Header
$link = substr($link, 3);
$attribute = ' class="dropdown-header"';
break;
default:
break;
}
$li .= '<li' . $attribute . '>' . $link . '</li>';
}
$ul = Support::wrapTag('<ul class="dropdown-menu" aria-labelledby="' . $htmlId . '">', $tmp);
$ul = Support::wrapTag('<ul class="dropdown-menu" aria-labelledby="' . $htmlId . '">', $li);
}
return Support::wrapTag('<span class="dropdown">', $dropdownSymbol . $ul);
......@@ -550,9 +577,6 @@ class Link {
$paramArr[TOKEN_ATTRIBUTE] .= ' id="' . $htmlId . '"';
return $this->renderLink(KeyValueStringParser::unparse($paramArr, PARAM_TOKEN_DELIMITER, PARAM_DELIMITER));
// $symbol = '<span class="glyphicon glyphicon-option-vertical dropdown-toggle" id="' . $htmlId . '" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"></span>';
}
/**
......
......@@ -1466,25 +1466,39 @@ EOF;
public function testLinkDropdown() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
$expect = '<span class="dropdown"><span class="glyphicon glyphicon-option-vertical dropdown-toggle" id="0.123 1234 0" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"></span><ul class="dropdown-menu" aria-labelledby="0.123 1234 0"></ul></span>';
$expect = '<span class="dropdown"><span title="Details" class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true" id="0.123 1234 0" ><span class="glyphicon glyphicon-option-vertical" ></span></span><ul class="dropdown-menu" aria-labelledby="0.123 1234 0"></ul></span>';
// Empty definition
$expect = '<span class="dropdown"><span title="Details" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true" class="dropdown-toggle" id="0.123 1234 0" ><span class="glyphicon glyphicon-option-vertical" ></span></span><ul class="dropdown-menu" aria-labelledby="0.123 1234 0"></ul></span>';
$result = $link->renderLink('z');
$this->assertEquals($expect, $result);
$expect = '<span class="dropdown"><span class="glyphicon glyphicon-option-vertical dropdown-toggle" id="0.123 1234 1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"></span><ul class="dropdown-menu" aria-labelledby="0.123 1234 1"></ul></span>';
// Empty definition.
$expect = '<span class="dropdown"><span title="Details" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true" class="dropdown-toggle" id="0.123 1234 1" ><span class="glyphicon glyphicon-option-vertical" ></span></span><ul class="dropdown-menu" aria-labelledby="0.123 1234 1"></ul></span>';
$result = $link->renderLink('z:');
$this->assertEquals($expect, $result);
$expect = '<span class="dropdown"><span class="glyphicon glyphicon-option-vertical dropdown-toggle" id="0.123 1234 2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"></span><ul class="dropdown-menu" aria-labelledby="0.123 1234 2"></ul></span>';
// Dropdown menu with text, custom Glyph and a tooltip.
$expect = '<span class="dropdown"><span title="Open menu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true" class="dropdown-toggle" id="0.123 1234 2" ><span class="glyphicon glyph-icon-left" ></span> Menu</span><ul class="dropdown-menu" aria-labelledby="0.123 1234 2"></ul></span>';
$result = $link->renderLink('z|t:Menu|G:glyph-icon-left|o:Open menu');
$this->assertEquals($expect, $result);
$expect = '<span class="dropdown"><span class="glyphicon glyphicon-option-vertical dropdown-toggle" id="0.123 1234 3" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"></span><ul class="dropdown-menu" aria-labelledby="0.123 1234 3"><li><a href="?id=home" >Home</a></li></ul></span>';
$result = $link->renderLink('z|t:Menu|G:glyph-icon-left|o:Open menu|p:home|t:Home');
// Dropdown menu with menu entry.
$expect = '<span class="dropdown"><span title="Open menu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true" class="dropdown-toggle" id="0.123 1234 3" ><span class="glyphicon glyph-icon-left" ></span> Menu</span><ul class="dropdown-menu" aria-labelledby="0.123 1234 3"><li><a href="?id=home" >Home</a></li></ul></span>';
$result = $link->renderLink('z|t:Menu|G:glyph-icon-left|o:Open menu||p:home|t:Home');
$this->assertEquals($expect, $result);
$expect = '<span class="dropdown"><span class="glyphicon glyphicon-option-vertical dropdown-toggle" id="0.123 1234 4" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"></span><ul class="dropdown-menu" aria-labelledby="0.123 1234 4"><li><a href="index.php?id=home&s=badcaffee1234" >Home</a></li><li><a href="?id=back" title="Navigate back" >Back</a></li></ul></span>';
$result = $link->renderLink('z|t:Menu|G:glyph-icon-left|o:Open menu|p:home|t:Home|s|p:back|t:Back|o:Navigate back');
// Dropdown menu disabled.
$expect = '<span class="dropdown"><span title="Open menu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true" class="dropdown-toggle disabled" id="0.123 1234 4" ><span class="glyphicon glyph-icon-left text-muted" ></span> <span class="text-muted">Menu</span></span></span>';
$result = $link->renderLink('z|t:Menu|G:glyph-icon-left|o:Open menu|r:3||p:home|t:Home');
$this->assertEquals($expect, $result);
// Dropdown menu with two entries, one is SIP encoded.
$expect = '<span class="dropdown"><span title="Open menu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true" class="dropdown-toggle" id="0.123 1234 5" ><span class="glyphicon glyph-icon-left" ></span> Menu</span><ul class="dropdown-menu" aria-labelledby="0.123 1234 5"><li><a href="index.php?id=home&s=badcaffee1234" >Home</a></li><li><a href="?id=back" title="Navigate back" >Back</a></li></ul></span>';
$result = $link->renderLink('z|t:Menu|G:glyph-icon-left|o:Open menu||p:home|t:Home|s||p:back|t:Back|o:Navigate back');
$this->assertEquals($expect, $result);
// Dropdown menu header, separator and disabled entry.
$expect = '<span class="dropdown"><span title="Open menu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true" class="dropdown-toggle" id="0.123 1234 6" ><span class="glyphicon glyph-icon-left" ></span> Menu</span><ul class="dropdown-menu" aria-labelledby="0.123 1234 6"><li><a href="index.php?id=home&s=badcaffee1234" >Home</a></li><li><a href="?id=back" title="Navigate back" >Back</a></li><li role="separator" class="divider"></li><li class="dropdown-header">Header</li><li class="disabled"><a href="#">Disabled entry</a></li></ul></span>';
$result = $link->renderLink('z|t:Menu|G:glyph-icon-left|o:Open menu||p:home|t:Home|s||p:back|t:Back|o:Navigate back||r:1|t:---||t:===Header|r:1||r:1|t:---Disabled entry');
$this->assertEquals($expect, $result);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment