LSattr_html :: select_list : add translate_labels option

This commit is contained in:
Benjamin Renard 2018-09-19 18:56:47 +02:00
parent c7c66bf481
commit 8e1e747754
5 changed files with 37 additions and 7 deletions

View file

@ -46,6 +46,7 @@
)
)
),
'translate_labels' => [booléen],
'sort' => [Booléen],
'sortDirection' => '[ASC|DESC]'
),]]>
@ -175,6 +176,12 @@
</listitem>
</varlistentry>
<varlistentry>
<term>translate_labels</term>
<listitem>
<simpara>Booléen permettant d'activer/désactiver la traduction des labels (Par defaut : <literal>Vrai</literal>).</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>sort</term>

View file

@ -103,19 +103,35 @@ class LSattr_html_select_list extends LSattr_html{
}
else {
$vk=$ldapObject->getFData($vk);
$vl=$ldapObject->getFData(__($vl));
if (isset($options['translate_labels']) && !$options['translate_labels']) {
$vl=$ldapObject->getFData($vl);
}
else {
$vl=$ldapObject->getFData(__($vl));
}
$subRetInfos[$vk]=$vl;
}
}
self :: _sort($subRetInfos,$options);
if (isset($options['translate_labels']) && !$options['translate_labels']) {
$subRetLabel = $ldapObject->getFData($val_label['label']);
}
else {
$subRetLabel = $ldapObject->getFData(__($val_label['label']));
}
$retInfos[] = array (
'label' => $ldapObject->getFData(__($val_label['label'])),
'label' => $subRetLabel,
'possible_values' => $subRetInfos
);
}
else {
$val_key=$ldapObject->getFData($val_key);
$val_label=$ldapObject->getFData(__($val_label));
if (isset($options['translate_labels']) && !$options['translate_labels']) {
$val_label=$ldapObject->getFData($val_label);
}
else {
$val_label=$ldapObject->getFData(__($val_label));
}
$retInfos[$val_key]=$val_label;
}
}
@ -300,8 +316,14 @@ class LSattr_html_select_list extends LSattr_html{
$attr_values = array();
elseif (!is_array($attr_values))
$attr_values = array($attr_values);
foreach($attr_values as $attr_value)
$retInfos[$attr_value] = __($attr_value);
if (isset($options['translate_labels']) && !$options['translate_labels']) {
foreach($attr_values as $attr_value)
$retInfos[$attr_value] = $attr_value;
}
else {
foreach($attr_values as $attr_value)
$retInfos[$attr_value] = __($attr_value);
}
}
else
LSerror :: addErrorCode('LSattr_html_select_list_02',$attr);

View file

@ -47,6 +47,7 @@ class LSformElement_select_box extends LSformElement_select {
if (!$this -> isFreeze()) {
LSsession :: addCssFile('LSformElement_select_box.css');
}
$this -> fetchVariables['translate_labels'] = ((isset($this -> params['translate_labels']) && !$this -> params['translate_labels'])?false:true);
return parent :: getDisplay();
}

View file

@ -217,7 +217,7 @@ if (loadDir(LS_OBJECTS_DIR) && loadDir(LS_LOCAL_DIR.LS_OBJECTS_DIR)) {
add($attr['html_options']['mail']['msg']);
// LSattr_html_select_list
if (($attr['html_type']=='select_list' || $attr['html_type']=='select_box') && is_array($attr['html_options']['possible_values']) && !$withoutselectlist) {
if (($attr['html_type']=='select_list' || $attr['html_type']=='select_box') && is_array($attr['html_options']['possible_values']) && (!isset($attr['html_options']['translate_labels']) || $attr['html_options']['translate_labels']) && !$withoutselectlist) {
foreach($attr['html_options']['possible_values'] as $pkey => $pname) {
if (is_array($pname)) {
add($pname['label']);

View file

@ -19,7 +19,7 @@
<ul class='LSformElement_selectbox_sub_values'>
{foreach from=$label.possible_values item=l key=v name=LSformElement_selectbox_sub_values}
<li>
<input type='{if $multiple}checkbox{else}radio{/if}' name='{$attr_name|escape:"htmlall"}[]' class='LSformElement_selectbox' id='LSformElement_selectbox_{$attr_name|escape:"htmlall"}_{$smarty.foreach.LSformElement_selectbox.index}_{$smarty.foreach.LSformElement_selectbox_sub_values.index}' value='{$v|escape:"htmlall"}' {if in_array($v,$values)}checked{/if}/> <label for='LSformElement_selectbox_{$attr_name|escape:"htmlall"}_{$smarty.foreach.LSformElement_selectbox.index}_{$smarty.foreach.LSformElement_selectbox_sub_values.index}'>{tr msg=$l}</label>
<input type='{if $multiple}checkbox{else}radio{/if}' name='{$attr_name|escape:"htmlall"}[]' class='LSformElement_selectbox' id='LSformElement_selectbox_{$attr_name|escape:"htmlall"}_{$smarty.foreach.LSformElement_selectbox.index}_{$smarty.foreach.LSformElement_selectbox_sub_values.index}' value='{$v|escape:"htmlall"}' {if in_array($v,$values)}checked{/if}/> <label for='LSformElement_selectbox_{$attr_name|escape:"htmlall"}_{$smarty.foreach.LSformElement_selectbox.index}_{$smarty.foreach.LSformElement_selectbox_sub_values.index}'>{if $translate_labels}{tr msg=$l}{else}{$l}{/if}</label>
</li>
{/foreach}
</ul>