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

#4606 / _link: qualifier to render bootstrap button - implement token 'b:...'...

#4606 / _link: qualifier to render bootstrap button - implement token  'b:...' for link class. Manual is updated. Open: `pageX` should be recoded to use the new 'b:' instead of hardcoed behaviour to render a button.
parent ca6d0e3c
......@@ -4524,7 +4524,7 @@ Column: _link
+---+---+--------------+-----------------------------------+---------------------------+----------------------------------------------------------------------------------------------------------------------------------------+
| | |Render |r:<mode> |r:[0-5] |See: `render-mode`_, Default: 0 |
+---+---+--------------+-----------------------------------+---------------------------+----------------------------------------------------------------------------------------------------------------------------------------+
| | |Button |b[:0|1] |b, b:0, b:1 |If 'b' or 'b:1' a bootstrap button is created |
| | |Button |b[:0|1|<btn class>] | b:0, b:1, b:success |'b', 'b:1': a bootstrap button is created. 'b:0' disable the button. <btn class>: default, primary, success, info, warning,danger |
+---+---+--------------+-----------------------------------+---------------------------+----------------------------------------------------------------------------------------------------------------------------------------+
| |x |Picture |P:<filename> |P:bullet-red.gif |Picture '<img src="bullet-red.gif"alt="....">', default link class: internal. |
+---+---+--------------+-----------------------------------+---------------------------+----------------------------------------------------------------------------------------------------------------------------------------+
......
......@@ -145,23 +145,24 @@ class Link {
private $ttContentUid = '';
private $callTable = [
TOKEN_URL => 'buildUrl',
TOKEN_MAIL => 'buildMail',
TOKEN_PAGE => 'buildPage',
TOKEN_DOWNLOAD => 'buildDownload',
TOKEN_TOOL_TIP => 'buildToolTip',
TOKEN_PICTURE => 'buildPicture',
TOKEN_BULLET => 'buildBullet',
TOKEN_CHECK => 'buildCheck',
TOKEN_DELETE => 'buildDeleteIcon',
TOKEN_ACTION_DELETE => 'buildActionDelete',
TOKEN_EDIT => 'buildEdit',
TOKEN_HELP => 'buildHelp',
TOKEN_INFO => 'buildInfo',
TOKEN_NEW => 'buildNew',
TOKEN_SHOW => 'buildShow',
TOKEN_FILE => 'buildFile',
TOKEN_GLYPH => 'buildGlyph',
TOKEN_URL => 'buildUrl',
TOKEN_MAIL => 'buildMail',
TOKEN_PAGE => 'buildPage',
TOKEN_DOWNLOAD => 'buildDownload',
TOKEN_TOOL_TIP => 'buildToolTip',
TOKEN_PICTURE => 'buildPicture',
TOKEN_BULLET => 'buildBullet',
TOKEN_CHECK => 'buildCheck',
TOKEN_DELETE => 'buildDeleteIcon',
TOKEN_ACTION_DELETE => 'buildActionDelete',
TOKEN_EDIT => 'buildEdit',
TOKEN_HELP => 'buildHelp',
TOKEN_INFO => 'buildInfo',
TOKEN_NEW => 'buildNew',
TOKEN_SHOW => 'buildShow',
TOKEN_FILE => 'buildFile',
TOKEN_GLYPH => 'buildGlyph',
TOKEN_BOOTSTRAP_BUTTON => 'buildBootstrapButton',
];
private $tableVarName = [
......@@ -279,6 +280,19 @@ class Link {
}
/**
*
*/
private function checkForBootstrapButton($text, $bootstrapButtonClass) {
if ($bootstrapButtonClass == '') {
return $text;
}
$attribute = Support::doAttribute('class', [$bootstrapButtonClass, 'disabled']);
return Support::wrapTag("<span $attribute>", $text);
}
/**
* Build the whole link
*
......@@ -318,23 +332,23 @@ class Link {
// 1: 'text'
case '1':
$link = Support::wrapTag($vars[FINAL_ANCHOR], $vars[FINAL_CONTENT]);
// $link = $vars[FINAL_CONTENT];
$link = $this->checkForBootstrapButton($vars[FINAL_CONTENT], $vars[NAME_BOOTSTRAP_BUTTON]);
break;
case '11':
$link = Support::wrapTag($vars[FINAL_ANCHOR], $vars[FINAL_CONTENT]);
// $link = $vars[FINAL_CONTENT];
$link = $this->checkForBootstrapButton($vars[FINAL_CONTENT], $vars[NAME_BOOTSTRAP_BUTTON]);
// $link = $this->encryptMailtoJS($vars, false);
break;
// 2: 'url'
case '2':
$link = Support::wrapTag($vars[FINAL_ANCHOR], $vars[FINAL_HREF]);
// $link = $vars[FINAL_HREF];
$link = $this->checkForBootstrapButton($vars[FINAL_HREF], $vars[NAME_BOOTSTRAP_BUTTON]);
break;
case '12':
$link = Support::wrapTag($vars[FINAL_ANCHOR], $vars[FINAL_HREF]);
// $link = $vars[FINAL_HREF];
$link = $this->checkForBootstrapButton($vars[FINAL_HREF], $vars[NAME_BOOTSTRAP_BUTTON]);
// $link = $this->encryptMailtoJS($vars, false);
break;
......@@ -364,6 +378,7 @@ class Link {
//TODO: Alter Code, umstellen auf JS Client von RO. Vorlage koennte 'Delete' in Subrecord sein.
$link = "<a href=\"javascript: void(0);\" onClick=\"var del = new FR.Delete({recordId:'',sip:'',forward:'" .
$vars[NAME_PAGE] . "'});\" " . $vars[NAME_LINK_CLASS] . ">" . $vars[NAME_TEXT] . "</a>";
break;
}
return $link;
......@@ -395,6 +410,8 @@ class Link {
}
/**
* Iterate over all given token.
*
* @param string $str
* @param array $tokenGiven
*
......@@ -609,6 +626,11 @@ class Link {
throw new UserReportException ("Invalid value for token '$key': '$value''", ERROR_INVALID_VALUE);
}
break;
case TOKEN_BOOTSTRAP_BUTTON:
if ($value == '1') {
$value = 'btn-default';
}
break;
default:
}
......@@ -860,11 +882,12 @@ class Link {
$class = '';
}
//TODO: Old way to detect if BS Button should be rendered - should be replaced by 'b:'
if ($vars[NAME_GLYPH] !== '' && $vars[NAME_EXTRA_CONTENT_WRAP] == '') {
$class .= 'btn btn-default ';
$class = 'btn btn-default ' . $class;
}
return $class;
return implode(' ', [$vars[NAME_BOOTSTRAP_BUTTON], $class]);
}
/**
......@@ -1443,6 +1466,32 @@ EOF;
return $vars;
}
/**
* Called by $this->callTable
*
* @param $vars
* @param $value
*
* @return array
*/
private function buildBootstrapButton($vars, $value) {
$value = trim($value);
if ($value == '') {
return $vars;
}
// Just in case the user forgot 'btn-' in front of btn-default, btn-primary, btn-su...
if (substr($value, 0, 4) != 'btn-') {
$value = 'btn-' . $value;
}
$vars[NAME_BOOTSTRAP_BUTTON] = 'btn ' . $value;
return $vars;
}
/**
* Called by $this->callTable
*
......
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