Skip to content
Snippets Groups Projects
Commit 9d9421f0 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

Merge branch 'update_renderer_class' into 'main'

Update renderer class: add select box

See merge request !17
parents 9e107311 2e922231
No related branches found
No related tags found
1 merge request!17Update renderer class: add select box
...@@ -72,4 +72,20 @@ $aReplace['{{NAVI_LEFT}}']='' ...@@ -72,4 +72,20 @@ $aReplace['{{NAVI_LEFT}}']=''
'nav', ['class'=>'mt-2'], 'nav', ['class'=>'mt-2'],
$renderAdminLTE->getSidebarNavigation($aSidebarNav) $renderAdminLTE->getSidebarNavigation($aSidebarNav)
); );
``` ```
\ No newline at end of file
### Navigation hacks
#### Sidebar
To render a horizontal line in the sidebar menu, add a navigation item with label '-'
```php
$aSidebarNav[]=['href'=>'#', 'label'=>'-'];
```
In your css file add a rule:
```css
.nav-item hr{color: #505860; border-top: 1px solid; height: 1px; padding: 0; margin: 0; }
```
## Select
Draw aselect box with option fields
### Syntax
```php
$renderAdminLTE->getFormSelect($aOptions);
```
### Return
{string} html code
### Parameters
* $aOptions - {array} options to describe the element
Option fields:
Key | Description
--- | ---
options | List of option tags<br> - value - value in the option<br> - label - visible text in the option<br>other keys are attributes in the option
Styling for select tag:
Key | Description
--- | ---
class | optional: additional css classes
size | optional: visible option lines
Content:
Key | Description
--- | ---
name | name attribute for sending form data
value | value of the input field/ visible text; for checkbox and radio: the data to send when sending a form
### Example
#### Simple select box
```php
$renderAdminLTE->getFormSelect(array
(
'label' => 'Select contact',
'name' => 'contact',
'tag' => 'select',
'size' => 1,
'options' => [
['value' => '', 'label' => 'select'],
['value' => '1', 'label' => 'Tom'],
['value' => '2', 'label' => 'Dick', 'selected' => 1 ],
['value' => '3', 'label' => 'Harry'],
],
));
```
You get a label, an select box wrapped in a ``<div class="form-group row">``.
```html
<div class="form-group row">
<label for="contact-39c4c14176af359d95e81c45078f27f3" class="col-sm-2 col-form-label">Select contact</label>
<div class="col-sm-10">
<div class="form-group">
<select name="contact" tag="select" size="1" class="form-control ">
<option value="">select</option>
<option value="1">Tom</option>
<option value="2" selected="1">Dick</option>
<option value="3">Harry</option>
</select>
</div>
</div>
</div>
```
...@@ -11,6 +11,7 @@ require_once 'htmlelements.class.php'; ...@@ -11,6 +11,7 @@ require_once 'htmlelements.class.php';
* 2023-09-11 <axel.hahn@unibe.ch> add shadows on card + callout * 2023-09-11 <axel.hahn@unibe.ch> add shadows on card + callout
* 2023-09-27 <axel.hahn@unibe.ch> add form input fields * 2023-09-27 <axel.hahn@unibe.ch> add form input fields
* 2023-11-17 <axel.hahn@unibe.ch> add tabbed content; "=" renders hamburger item * 2023-11-17 <axel.hahn@unibe.ch> add tabbed content; "=" renders hamburger item
* 2024-05-03 <axel.hahn@unibe.ch> add line in sidebar menu; add getFormSelect
* ====================================================================== * ======================================================================
* *
* @author Axel * @author Axel
...@@ -669,7 +670,12 @@ class renderadminlte { ...@@ -669,7 +670,12 @@ class renderadminlte {
/** /**
* get a navigation items for sidebar * Get a navigation items for sidebar
* Links can be nested with the key "children".
*
* Remark: for a horizontal line ($aLink['label']='-') this css is required
* .nav-item hr{color: #505860; border-top: 1px solid; height: 1px; padding: 0; margin: 0; }
*
* @param array $aLinks list of link items * @param array $aLinks list of link items
*/ */
public function getNavi2Items($aLinks){ public function getNavi2Items($aLinks){
...@@ -677,7 +683,14 @@ class renderadminlte { ...@@ -677,7 +683,14 @@ class renderadminlte {
if (!$aLinks || !is_array($aLinks) || !count($aLinks)){ if (!$aLinks || !is_array($aLinks) || !count($aLinks)){
return false; return false;
} }
foreach($aLinks as $aLink){ foreach($aLinks as $aLink){
if ($aLink['label']=='-') {
// TODO: draw a nice line
$sReturn.='<li class="nav-item"><hr></li>';
continue;
}
// to render active or open links: // to render active or open links:
$aLink['class']='nav-link' . (isset($aLink['class']) ? ' '.$aLink['class'] : ''); $aLink['class']='nav-link' . (isset($aLink['class']) ? ' '.$aLink['class'] : '');
...@@ -1117,7 +1130,7 @@ class renderadminlte { ...@@ -1117,7 +1130,7 @@ class renderadminlte {
* A colored box with large icon, text and a value. * A colored box with large icon, text and a value.
* https://adminlte.io/docs/3.2/components/boxes.html * https://adminlte.io/docs/3.2/components/boxes.html
* *
* @param type $aOptions hash with keys for all options * @param array $aOptions hash with keys for all options
* styling: * styling:
* - type - color of the box; one of [none]|danger|dark|info|primary|secondary|success|warning * - type - color of the box; one of [none]|danger|dark|info|primary|secondary|success|warning
* - iconbg - background color or type of icon; use it for default type (type="") * - iconbg - background color or type of icon; use it for default type (type="")
...@@ -1242,7 +1255,7 @@ class renderadminlte { ...@@ -1242,7 +1255,7 @@ class renderadminlte {
* return a text input field: * return a text input field:
* https://adminlte.io/themes/v3/pages/forms/general.html * https://adminlte.io/themes/v3/pages/forms/general.html
* *
* @param type $aOptions hash with keys for all options * @param array $aOptions hash with keys for all options
* styling: * styling:
* - type - field type: text, email, password, hidden and all other html 5 input types * - type - field type: text, email, password, hidden and all other html 5 input types
* content * content
...@@ -1310,8 +1323,8 @@ class renderadminlte { ...@@ -1310,8 +1323,8 @@ class renderadminlte {
} }
/** /**
* return a textare field .. or html editor using summernote * return a textarea field .. or html editor using summernote
* @param type $aOptions hash with keys for all options * @param array $aOptions hash with keys for all options
* styling: * styling:
* - type - field type: [none]|html * - type - field type: [none]|html
* content * content
...@@ -1348,6 +1361,58 @@ class renderadminlte { ...@@ -1348,6 +1361,58 @@ class renderadminlte {
} }
/**
* return a select box field
* @param array $aOptions hash with keys for all options
* styling:
* - class - css class
* option fields
* - options - array of options with keys per item:
* - value - value in the option
* - label - visible text in the option
* other keys are attributes in the option
* select tag
* - label - label tag
* - name - name attribute for sending form
* other keys are attributes in the select
* @return string
*/
public function getFormSelect($aOptions){
$aElement=$aOptions;
$aElement['class']=''
. 'form-control '
. (isset($aOptions['class']) ? $aOptions['class']: '')
;
$sLabel=isset($aOptions['label']) ? $aOptions['label'] : '';
$sFormid=(isset($aOptions['id'])
? $aOptions['id']
: (isset($aOptions['name']) ? $aOptions['name'] : 'field' ).'-'.md5(microtime(true))
);
$sOptionTags='';
foreach($aOptions['options'] as $aField){
$optionText=$aField['label'];
unset($aField['label']);
$sOptionTags.=$this->_tag('option', $aField, $optionText )."\n";
}
foreach(['_infos', 'label', 'debug','type', 'value', 'options'] as $sDeleteKey){
if(isset($aElement[$sDeleteKey])){
unset($aElement[$sDeleteKey]);
}
}
return $this->getHorizontalFormElement(
$this->_tag('div', ['class'=>'form-group'],
$this->_tag('select', $aElement, $sOptionTags)
),
$sLabel,
$sFormid
);
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// //
// PUBLIC FUNCTIONS :: CONTENT - TABBED CONTENT // PUBLIC FUNCTIONS :: CONTENT - TABBED CONTENT
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment