Standardise new function name

This commit is contained in:
John BOTELLA 2019-03-01 15:33:23 +01:00
parent 162c3249cf
commit 421c009e58
2 changed files with 147 additions and 45 deletions

View File

@ -7924,23 +7924,22 @@ function roundUpToNextMultiple($n, $x = 5)
/** /**
* @param string $label label of badge no html : use in alt attribute for accessibility * @param string $label label of badge no html : use in alt attribute for accessibility
* @param string $html optional : label of badge with html * @param string $html optional : label of badge with html
* @param string $type type of badge : Primary Secondary Success Danger Warning Info Light Dark status0 status1 status2 status3 status4 status5 status6 status7 status8 status9 * @param string $type type of badge : Primary Secondary Success Danger Warning Info Light Dark status0 status1 status2 status3 status4 status5 status6 status7 status8 status9
* @param string $mode * @param string $mode default '' , pill, dot
* @param array $params * @param array $params various params for future : recommended rather than adding more fuction arguments
* @return string * @return string
*/ */
function badgeHelper($label, $html='', $type='primary', $mode='', $url='', $params=array()) function dol_get_badge($label, $html = '', $type = 'primary', $mode = '', $url = '', $params=array())
{ {
$attr=array(
'class'=>'badge'.(!empty($mode)?' badge-'.$mode:'').(!empty($type)?' badge-'.$type:'')
);
if(empty($html)){ if(empty($html)){
$html = $label; $html = $label;
} }
$attr=array(
'class'=>'badge'.(!empty($mode)?' badge-'.$mode:'').(!empty($type)?' badge-'.$type:'')
,'aria-label'=>$label
);
if(!empty($url)){ if(!empty($url)){
$attr['href'] = $url; $attr['href'] = $url;
} }
@ -7949,6 +7948,7 @@ function badgeHelper($label, $html='', $type='primary', $mode='', $url='', $para
{ {
$attr['class'].= ' classfortooltip'; $attr['class'].= ' classfortooltip';
$attr['title'] = $html; $attr['title'] = $html;
$attr['aria-label'] = $label;
$html=''; $html='';
} }
@ -7959,6 +7959,7 @@ function badgeHelper($label, $html='', $type='primary', $mode='', $url='', $para
} }
} }
// TODO: add hook
// escape all attribute // escape all attribute
$attr = array_map('dol_escape_htmltag', $attr); $attr = array_map('dol_escape_htmltag', $attr);
@ -7971,24 +7972,35 @@ function badgeHelper($label, $html='', $type='primary', $mode='', $url='', $para
$compiledAttributes = !empty($TCompiledAttr)?implode(' ',$TCompiledAttr):''; $compiledAttributes = !empty($TCompiledAttr)?implode(' ',$TCompiledAttr):'';
$tag = !empty($url)?'a':'span'; $tag = !empty($url)?'a':'span';
return '<'.$tag.' '.$compiledAttributes.'>'.$html.'</'.$tag.'>'; return '<'.$tag.' '.$compiledAttributes.'>'.$html.'</'.$tag.'>';
} }
/**
* @param string $label label of badge no html : use in alt attribute for accessibility
* @param string $html optional : label of badge with html
* @param string $type type of badge : Primary Secondary Success Danger Warning Info Light Dark status0 status1 status2 status3 status4 status5 status6 status7 status8 status9
* @param string $mode default '' , pill, dot
* @param array $params various params for future : recommended rather than adding more function arguments
*/
function dol_print_badge($label, $html = '', $type = 'primary', $mode = '', $url = '', $params = array())
{
print dol_get_badge($label, $html, $type, $mode, $url, $params);
}
/** /**
* @param string $statusLabel label of badge no html : use in alt attribute for accessibility * @param string $statusLabel label of badge no html : use in alt attribute for accessibility
* @param string $html optional : label of badge with html * @param string $html optional : label of badge with html
* @param string $statusType status0 status1 status2 status3 status4 status5 status6 status7 status8 status9 : image name or badge name * @param string $statusType status0 status1 status2 status3 status4 status5 status6 status7 status8 status9 : image name or badge name
* @param int $displayMode for retrocompatibility 0=label only, 1=label + Picto, 2=Picto, 3=Picto + label * @param int $displayMode for retrocompatibility 0=label only, 1=label + Picto, 2=Picto, 3=Picto + label
* @param string $url * @param string $url
* @param array $params * @param array $params various params for future : recommended rather than adding more function arguments
* @return string * @return string
*/ */
function statusHelper($statusLabel='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array()) function dol_get_status($statusLabel = '', $html = '', $statusType = 'status0', $displayMode = 0, $url = '', $params = array())
{ {
global $conf; global $conf;
// image's filename are still in French // image's filename are still in French
$statusImg=array( $statusImg=array(
@ -8004,6 +8016,8 @@ function statusHelper($statusLabel='', $html='', $statusType='status0', $display
,'status9' => 'statut9' ,'status9' => 'statut9'
); );
// TODO : add a hook
if($displayMode==0){ if($displayMode==0){
$return = !empty($html)?$html:$statusLabel; $return = !empty($html)?$html:$statusLabel;
} }
@ -8018,22 +8032,19 @@ function statusHelper($statusLabel='', $html='', $statusType='status0', $display
$htmlImg = img_picto($statusLabel, $statusType); $htmlImg = img_picto($statusLabel, $statusType);
} }
if($displayMode === 1){
if($displayMode===1){
$return = $htmlLabel .' '. $htmlImg; $return = $htmlLabel .' '. $htmlImg;
} }
elseif($displayMode===2){ elseif($displayMode === 2){
$return = $htmlImg; $return = $htmlImg;
} }
elseif($displayMode===3){ elseif($displayMode === 3){
$return = $htmlImg .' '. $htmlLabel; $return = $htmlImg .' '. $htmlLabel;
} }
else{ else{
$return = !empty($html)?$html:$statusLabel; $return = !empty($html)?$html:$statusLabel;
} }
} }
// Use new badge // Use new badge
@ -8042,8 +8053,104 @@ function statusHelper($statusLabel='', $html='', $statusType='status0', $display
$mode = 'pill'; $mode = 'pill';
if($displayMode == 2)$mode = 'dot'; if($displayMode == 2)$mode = 'dot';
$return = badgeHelper($statusLabel, $html,$statusType,$mode); $return = dol_get_badge($statusLabel, $html,$statusType,$mode);
} }
return $return; return $return;
} }
/**
* @param string $statusLabel label of badge no html : use in alt attribute for accessibility
* @param string $html optional : label of badge with html
* @param string $statusType status0 status1 status2 status3 status4 status5 status6 status7 status8 status9 : image name or badge name
* @param int $displayMode for retrocompatibility 0=label only, 1=label + Picto, 2=Picto, 3=Picto + label
* @param string $url
* @param array $params various params for future : recommended rather than adding more function arguments
*/
function dol_print_status($statusLabel='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
{
print dol_get_status($statusLabel, $html, $statusType, $displayMode, $url, $params);
}
/**
* @param string $label label of button no html : use in alt attribute for accessibility $html is not empty
* @param string $html optional : content with html
* @param string $actionType default, delete, danger
* @param string $url
* @param string $id attribute id of button
* @param int $userRight user action right
* @param array $params various params for future : recommended rather than adding more function arguments
* @return string
*/
function dol_get_buttonAction($label, $html = '', $actionType = 'default', $url = '', $id = '', $userRight = 1, $params=array())
{
$class = 'butAction' ;
if($actionType == 'danger' || $actionType == 'delete'){
$class = 'butActionDelete' ;
}
$attr=array(
'class' => $class
,'href' => empty($url)?'':$url
);
if(empty($html)){
$html = $label;
}else{
$attr['aria-label'] = $label;
}
if(empty($userRight)){
$attr['class'] = 'butActionRefused';
$attr['href'] = '';
}
if(empty($id)){
$attr['id'] = $id;
}
// Override attr
if(!empty($params['attr']) && is_array($params['attr'])){
foreach($params['attr'] as $key => $value){
$attr[$key] = $value;
}
}
if(isset($attr['href']) && empty($attr['href'])){
unset($attr['href']);
}
// TODO : add a hook
// escape all attribute
$attr = array_map('dol_escape_htmltag', $attr);
$TCompiledAttr = array();
foreach($attr as $key => $value){
$TCompiledAttr[] = $key.'="'.$value.'"';
}
$compiledAttributes = !empty($TCompiledAttr)?implode(' ',$TCompiledAttr):'';
$tag = !empty($attr['href'])?'a':'span';
return '<div class="inline-block divButAction"><'.$tag.' '.$compiledAttributes.'>'.$html.'</'.$tag.'></div>';
}
/**
* @param string $label label of button no html : use in alt attribute for accessibility $html is not empty
* @param string $html optional : content with html
* @param string $actionType default, delete, danger
* @param string $url
* @param string $id attribute id of button
* @param int $userRight user action right
* @param array $params various params for future : recommended rather than adding more function arguments
*/
function dol_print_buttonAction($label, $html = '', $actionType = 'default', $url = '', $id = '', $userRight = 1, $params=array())
{
print dol_get_buttonAction($label, $html, $actionType, $url, $id, $userRight, $params);
}

View File

@ -276,50 +276,45 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
<h2 id="helper">Use badge helper function</h2> <h2 id="helper">Use badge helper function</h2>
<p>Using the badgeHelper function provide in core/lib/functions.lib.php. This function is recommended for code uniformisation and easy maintain</p> <p>Using the dol_get_badge function provide in core/lib/functions.lib.php. This function is recommended for code uniformisation and easy maintain</p>
<?php print badgeHelper('your label for accessibility', 'your label <u>with</u> <em>html</em>', 'primary') ?> <?php dol_print_badge('your label for accessibility', 'your label <u>with</u> <em>html</em>', 'primary') ?>
<?php print badgeHelper('your label for accessibility', 'your label <u>with</u> <em>html</em>', 'danger', 'pill') ?> <?php dol_print_badge('your label for accessibility', 'your label <u>with</u> <em>html</em>', 'danger', 'pill') ?>
<?php print badgeHelper('your label for accessibility', 'your label <u>with</u> <em>html</em>', 'warning', 'dot') ?> <?php dol_print_badge('your label for accessibility', 'your label <u>with</u> <em>html</em>', 'warning', 'dot') ?>
<figure class="highlight"><pre> <figure class="highlight"><pre>
&lt;?php print badgeHelper('your label for accessibility', 'your label &lt;u&gt;with&lt;/u&gt; &lt;em&gt;html&lt;/em&gt;', 'danger', 'pill') ?&gt; &lt;?php dol_print_badge('your label for accessibility', 'your label &lt;u&gt;with&lt;/u&gt; &lt;em&gt;html&lt;/em&gt;', 'danger', 'pill') ?&gt;
&lt;?php print badgeHelper('your label for accessibility', 'your label &lt;u&gt;with&lt;/u&gt; &lt;em&gt;html&lt;/em&gt;', 'warning', 'dot') ?&gt; &lt;?php dol_print_badge('your label for accessibility', 'your label &lt;u&gt;with&lt;/u&gt; &lt;em&gt;html&lt;/em&gt;', 'warning', 'dot') ?&gt;
</pre></figure> </pre></figure>
<h2 id="helper">Use status helper function</h2> <h2 id="helper">Use status helper function</h2>
<p>Using the statusHelper function provide in core/lib/functions.lib.php. This function is recommended for code uniformisation and easy maintain</p> <p>Using the dol_get_status function provide in core/lib/functions.lib.php. This function is recommended for code uniformisation and easy maintain</p>
<?php <?php
$saveGlobalConf = $conf->global->MAIN_STATUS_USES_CSS; $saveGlobalConf = $conf->global->MAIN_STATUS_USES_CSS;
$conf->global->MAIN_STATUS_USES_CSS = 1; $conf->global->MAIN_STATUS_USES_CSS = 1;
?> ?>
<h4>Using hidden global conf MAIN_STATUS_USES_CSS=1</h4> <h4>Using hidden global conf MAIN_STATUS_USES_CSS=1</h4>
<p><?php print statusHelper('your label for accessibility', 'your label <u>with</u> <em>html</em>', 'status4') ?></p> <p><?php dol_print_status('your label for accessibility', 'your label <u>with</u> <em>html</em>', 'status4') ?></p>
<p><?php print statusHelper('your label for accessibility', 'your label <u>with</u> <em>html</em>', 'status4',1) ?></p> <p><?php dol_print_status('your label for accessibility', 'your label <u>with</u> <em>html</em>', 'status4',1) ?></p>
<p><?php print statusHelper('your label for accessibility', 'your label <u>with</u> <em>html</em>', 'status4',2) ?></p> <p><?php dol_print_status('your label for accessibility', 'your label <u>with</u> <em>html</em>', 'status4',2) ?></p>
<p><?php print statusHelper('your label for accessibility', 'your label <u>with</u> <em>html</em>', 'status4',3) ?></p> <p><?php dol_print_status('your label for accessibility', 'your label <u>with</u> <em>html</em>', 'status4',3) ?></p>
<?php $conf->global->MAIN_STATUS_USES_CSS = 0; ?> <?php $conf->global->MAIN_STATUS_USES_CSS = 0; ?>
<h4>Disabled hidden global conf : MAIN_STATUS_USES_CSS=0</h4> <h4>Disabled hidden global conf : MAIN_STATUS_USES_CSS=0</h4>
<p><?php print statusHelper('your label for accessibility', 'your label <u>with</u> <em>html</em>', 'status4') ?></p> <p><?php dol_print_status('your label for accessibility', 'your label <u>with</u> <em>html</em>', 'status4') ?></p>
<p><?php print statusHelper('your label for accessibility', 'your label <u>with</u> <em>html</em>', 'status4',1) ?></p> <p><?php dol_print_status('your label for accessibility', 'your label <u>with</u> <em>html</em>', 'status4',1) ?></p>
<p><?php print statusHelper('your label for accessibility', 'your label <u>with</u> <em>html</em>', 'status4',2) ?></p> <p><?php dol_print_status('your label for accessibility', 'your label <u>with</u> <em>html</em>', 'status4',2) ?></p>
<p><?php print statusHelper('your label for accessibility', 'your label <u>with</u> <em>html</em>', 'status4',3) ?></p> <p><?php dol_print_status('your label for accessibility', 'your label <u>with</u> <em>html</em>', 'status4',3) ?></p>
<?php $conf->global->MAIN_STATUS_USES_CSS = $saveGlobalConf; ?> <?php $conf->global->MAIN_STATUS_USES_CSS = $saveGlobalConf; ?>
<figure class="highlight"><pre> <figure class="highlight"><pre>
&lt;?php print statusHelper('your label for accessibility', 'your label &lt;u&gt;with&lt;/u&gt; &lt;em&gt;html&lt;/em&gt;', 'status4') ?&gt; &lt;?php dol_print_status('your label for accessibility', 'your label &lt;u&gt;with&lt;/u&gt; &lt;em&gt;html&lt;/em&gt;', 'status4') ?&gt;
&lt;?php print statusHelper('your label for accessibility', 'your label &lt;u&gt;with&lt;/u&gt; &lt;em&gt;html&lt;/em&gt;', 'status4',1) ?&gt; &lt;?php dol_print_status('your label for accessibility', 'your label &lt;u&gt;with&lt;/u&gt; &lt;em&gt;html&lt;/em&gt;', 'status4',1) ?&gt;
&lt;?php print statusHelper('your label for accessibility', 'your label &lt;u&gt;with&lt;/u&gt; &lt;em&gt;html&lt;/em&gt;', 'status4',2) ?&gt; &lt;?php dol_print_status('your label for accessibility', 'your label &lt;u&gt;with&lt;/u&gt; &lt;em&gt;html&lt;/em&gt;', 'status4',2) ?&gt;
&lt;?php print statusHelper('your label for accessibility', 'your label &lt;u&gt;with&lt;/u&gt; &lt;em&gt;html&lt;/em&gt;', 'status4',3) ?&gt; &lt;?php dol_print_status('your label for accessibility', 'your label &lt;u&gt;with&lt;/u&gt; &lt;em&gt;html&lt;/em&gt;', 'status4',3) ?&gt;
</pre></figure> </pre></figure>
</main> </main>