Commit 0c289c75 authored by Carsten  Rose's avatar Carsten Rose
Browse files

WIP: DD wird noch span gewrapped. Ab jetzt Umstellung auf "renderLink wird...

WIP: DD wird noch span gewrapped. Ab jetzt Umstellung auf "renderLink wird nicht rekursiv aufgerufen".
parent dd4498a7
Pipeline #5090 passed with stages
in 4 minutes and 9 seconds
......@@ -1842,6 +1842,8 @@ const TOKEN_L_CONTENT = 'content';
const TOKEN_L_TIMEOUT = 'timeout';
const TOKEN_L_SSL = 'ssl';
const LINK_SPECIAL_MODE_DROPDOWN = 'dropdown';
const MONITOR_MODE_APPEND_0 = '0';
const MONITOR_MODE_APPEND_1 = '1';
const MONITOR_SESSION_FILE_SEEK = 'monitor-seek-file';
......
......@@ -305,12 +305,11 @@ class Link {
*
* @param array $vars
* @param $keyName
* @param $bsCssDisabled by default 'disabled'. For Bootstrap dropdown Button empty: Fake to misuse this function for rendering.
*
* @return mixed|string
* @throws \CodeException
*/
private function wrapLinkTextOnly(array $vars, $keyName, $bsCssDisabled) {
private function wrapLinkTextOnly(array $vars, $keyName) {
$text = $vars[$keyName];
if ($vars[NAME_BOOTSTRAP_BUTTON] == '' && $vars[FINAL_TOOL_TIP] == '' && $vars[NAME_ATTRIBUTE] == '') {
......@@ -323,7 +322,7 @@ class Link {
}
if ($vars[NAME_BOOTSTRAP_BUTTON] != '') {
$attributes .= Support::doAttribute('class', [$vars[NAME_BOOTSTRAP_BUTTON], $bsCssDisabled]);
$attributes .= Support::doAttribute('class', [$vars[NAME_BOOTSTRAP_BUTTON], 'disabled']);
}
return Support::wrapTag("<span $attributes>", $text);
......@@ -331,7 +330,36 @@ class Link {
}
/**
* Renders a BS-dropdown menu.
* In render mode 3,4,5 there is no '<a href ...>'. Nevertheless, tooltip and BS Button should be displayed.
* Do this by applying a '<span>' attribute around the text.
*
* @param array $vars
* @param $keyName
*
* @return mixed|string
* @throws \CodeException
*/
private function wrapDropdown(array $vars) {
$text = $vars[FINAL_CONTENT];
if ($vars[NAME_BOOTSTRAP_BUTTON] == '' && $vars[FINAL_TOOL_TIP] == '' && $vars[NAME_ATTRIBUTE] == '') {
return $text;
}
$attributes = Support::doAttribute('title', $vars[FINAL_TOOL_TIP]);
if ($vars[NAME_ATTRIBUTE] != '') {
$attributes .= $vars[NAME_ATTRIBUTE] . ' ';
}
if ($vars[NAME_BOOTSTRAP_BUTTON] != '') {
$attributes .= Support::doAttribute('class', [$vars[NAME_BOOTSTRAP_BUTTON], 'disabled']);
}
return Support::wrapTag("<span $attributes>", $text);
}
/**
* Renders a (BS)-Dropdown menu.
*
* @param string $str
* 'z|t:menu|b|o:click me' - the menu button to click on. A text 'menu', a BS button, a tooltip 'click me'.
......@@ -351,6 +379,7 @@ class Link {
$htmlId = Support::uniqIdQfq('dd_');
// Split 'z|t:menu|b|o:click me||p:detail&pId=1&s|t:Person 1||...'
$paramArr = KeyValueStringParser::explodeEscape(PARAM_DELIMITER, $str);
// Iterate over token. Find delimiter to separate dropdown definition and all menu entries.
......@@ -359,7 +388,7 @@ class Link {
switch ($tokenArr[0] ?? '') {
case TOKEN_DROPDOWN:
$tokenCollect[] = ''; // In case there are no further options given, it's necessary to have at least one
$tokenCollect[] = ''; // In case there are no further options given at all, 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.
......@@ -381,7 +410,7 @@ class Link {
$menuEntryStrArr[] = implode(PARAM_DELIMITER, $tokenCollect);
// Remove first array element - that's the menu, not a menu entry. Render the menu.
$flagMenuEnabled = false;
// $flagMenuEnabled = false;
// Final rendering of dropdown Menu
$dropdownSymbol = $this->renderDropdownSymbol(array_shift($menuEntryStrArr), $htmlId, $flagMenuEnabled);
......@@ -412,6 +441,19 @@ class Link {
* <li><a href="#">Separated link</a></li>
* </ul>
* </span>
*
* <div class="btn-group">
* <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
* <span class="glyphicon glyphicon-option-vertical"></span>Button text
* </button>
* <ul class="dropdown-menu" aria-labelledby="dropdownMenu11">
* <li><a href="#">Action</a></li>
* <li><a href="#">Another action</a></li>
* <li><a href="#">Something else here</a></li>
* <li role="separator" class="divider"></li>
* <li><a href="#">Separated link</a></li>
* </ul>
* </div>
* End
*
* @param string $dropdownSymbol
......@@ -454,25 +496,27 @@ class Link {
default:
break;
}
// Menu entries
$li .= '<li' . $attribute . '>' . $link . '</li>';
}
// Wrapped Menu entries
$ul = Support::wrapTag('<ul style="max-height: 70vh; overflow-y: auto" class="dropdown-menu" aria-labelledby="' . $htmlId . '">', $li);
}
return Support::wrapTag('<span class="dropdown">', $dropdownSymbol . $ul);
}
/**
* @param string $dropdownStr
* @param string $htmlId
* @param $flagMenuEnabled
* @param $rcFlagMenuEnabled
* @return string
* @throws \CodeException
* @throws \UserFormException
* @throws \UserReportException
*/
private function renderDropdownSymbol($dropdownStr, $htmlId, &$flagMenuEnabled) {
private function renderDropdownSymbol($dropdownStr, $htmlId, &$rcFlagMenuEnabled) {
$class = '';
$paramArr = KeyValueStringParser::parse($dropdownStr, PARAM_TOKEN_DELIMITER, PARAM_DELIMITER);
......@@ -483,7 +527,7 @@ class Link {
}
// All render mode <3 means: enabled
$flagMenuEnabled = ($paramArr[TOKEN_RENDER] ?? 0) < 3;
$rcFlagMenuEnabled = ($paramArr[TOKEN_RENDER] ?? 0) < 3;
// Misuse the link class to render the menu symbol: this gives tooltip, glyph, button, text ... - set render mode to '3' = 'no link'
$paramArr[TOKEN_RENDER] = '3';
......@@ -501,7 +545,7 @@ class Link {
$paramArr[TOKEN_ATTRIBUTE] = 'data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"';
}
if (!$flagMenuEnabled) {
if (!$rcFlagMenuEnabled) {
$class .= ' disabled';
// In case there is no button: set the text and glyphicon to 'muted'
if (($vars[NAME_BOOTSTRAP_BUTTON] ?? '') === '') {
......@@ -520,8 +564,8 @@ class Link {
$paramArr[TOKEN_ATTRIBUTE] .= ' class="dropdown-toggle' . $class . '"';
$paramArr[TOKEN_ATTRIBUTE] .= ' id="' . $htmlId . '"';
return $this->renderLink(KeyValueStringParser::unparse($paramArr, PARAM_TOKEN_DELIMITER, PARAM_DELIMITER),
'', '');
$str = KeyValueStringParser::unparse($paramArr, PARAM_TOKEN_DELIMITER, PARAM_DELIMITER);
return $this->renderLink($str, '', LINK_SPECIAL_MODE_DROPDOWN);
}
/**
......@@ -592,7 +636,7 @@ class Link {
*
* @param string $str Qualifier with params. 'report'-syntax. F.e.: u:www.example.com|P:home.gif|t:Home"
* @param string $strDefault Same as $str, but might give some defaults if corresponding values in $str are missing.
* @param string $bsCssDisabled CSS class name added to Bootstrap button class attribute. By default not given (it becomes 'disabled')
* @param string $specialMode '', 'dropdown'
*
* @return string The complete HTML encoded Link like
* <a href='http://example.com' class='external'><img src='icon.gif' title='help text'>Description</a>
......@@ -601,7 +645,7 @@ class Link {
* @throws \UserFormException
* @throws \UserReportException
*/
public function renderLink($str, $strDefault = '', $bsCssDisabled = 'disabled') {
public function renderLink($str, $strDefault = '', $specialMode = '') {
$tokenGiven = array();
$link = "";
......@@ -613,15 +657,17 @@ class Link {
switch ($str[0] ?? '') {
case TOKEN_DROPDOWN:
// Check for dropdown menu
// $str = $this->processDropdown($str, $rcMenuEntries);
// $specialMode = LINK_SPECIAL_MODE_DROPDOWN;
return $this->processDropdown($str);
break;
case TOKEN_WEBSOCKET:
return $this->processWebSocket($str);
break;
case TOKEN_REST_CLIENT:
$restClient = new RestClient();
return $restClient->process($str);
break;
default:
break;
......@@ -629,7 +675,7 @@ class Link {
$vars = $this->fillParameter($str, $tokenGiven, $strDefault);
$vars = $this->processParameter($vars, $tokenGiven);
$mode = $this->getModeRender($vars, $tokenGiven);
$mode = $this->getModeRender($vars, $tokenGiven, $specialMode);
if (isset($tokenGiven[TOKEN_DOWNLOAD]) && $tokenGiven[TOKEN_DOWNLOAD] === true) {
$this->store->setVar(SYSTEM_DOWNLOAD_POPUP, DOWNLOAD_POPUP_REQUEST, STORE_SYSTEM);
......@@ -648,13 +694,13 @@ class Link {
// 1: 'text'
case '1':
case '11':
$link = $this->wrapLinkTextOnly($vars, FINAL_CONTENT, $bsCssDisabled);
$link = $this->wrapLinkTextOnly($vars, FINAL_CONTENT);
break;
// 2: 'url'
case '2':
case '12':
$link = $this->wrapLinkTextOnly($vars, FINAL_HREF, $bsCssDisabled);
$link = $this->wrapLinkTextOnly($vars, FINAL_HREF);
break;
// 3: <a href=url ...>url</a>
......@@ -694,6 +740,17 @@ class Link {
case '26':
throw new \UserReportException ("Mode not implemented. internal render mode=$mode", ERROR_UNKNOWN_MODE);
break;
case '7':
switch ($specialMode) {
case LINK_SPECIAL_MODE_DROPDOWN:
$link = $this->wrapDropdown($vars);
break;
default:
throw new \UserReportException ("Unknown specialMode=$specialMode", ERROR_UNKNOWN_MODE);
break;
}
break;
case '8':
$link = substr($vars[FINAL_HREF], -SIP_TOKEN_LENGTH); // get only the last 13 characters (the sip)
break;
......@@ -1451,7 +1508,7 @@ EOF;
* @return string
* @throws \UserReportException
*/
private function getModeRender(array $vars, array $tokenGiven) {
private function getModeRender(array $vars, array $tokenGiven, $specialMode) {
if (isset($tokenGiven[TOKEN_COPY_TO_CLIPBOARD]) && $tokenGiven[TOKEN_COPY_TO_CLIPBOARD]) {
if ($vars[NAME_RENDER] == '0') {
......@@ -1459,6 +1516,10 @@ EOF;
}
}
if ($specialMode != '') {
return 7; // this is not r:7, it's meaning of $this->renderControl. A soon as there is a specialMode given, skip the rest.
}
if ($vars[NAME_MONITOR] == '1') {
return 1;
}
......
Supports Markdown
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