Add LSattr_html :: labeledValue

This commit is contained in:
Benjamin Renard 2018-05-16 19:29:08 +02:00
parent 2814dadb95
commit 0f7ac92767
8 changed files with 230 additions and 0 deletions

View file

@ -7,6 +7,7 @@
&conf-LSattr_html_date; &conf-LSattr_html_date;
&conf-LSattr_html_image; &conf-LSattr_html_image;
&conf-LSattr_html_jsonCompositeAttribute; &conf-LSattr_html_jsonCompositeAttribute;
&conf-LSattr_html_labeledValue;
&conf-LSattr_html_mail; &conf-LSattr_html_mail;
&conf-LSattr_html_maildir; &conf-LSattr_html_maildir;
&conf-LSattr_html_mailQuota; &conf-LSattr_html_mailQuota;

View file

@ -3,6 +3,7 @@
<!ENTITY conf-LSattr_html_date SYSTEM "LSattr_html_date.docbook"> <!ENTITY conf-LSattr_html_date SYSTEM "LSattr_html_date.docbook">
<!ENTITY conf-LSattr_html_image SYSTEM "LSattr_html_image.docbook"> <!ENTITY conf-LSattr_html_image SYSTEM "LSattr_html_image.docbook">
<!ENTITY conf-LSattr_html_jsonCompositeAttribute SYSTEM "LSattr_html_jsonCompositeAttribute.docbook"> <!ENTITY conf-LSattr_html_jsonCompositeAttribute SYSTEM "LSattr_html_jsonCompositeAttribute.docbook">
<!ENTITY conf-LSattr_html_labeledValue SYSTEM "LSattr_html_labeledValue.docbook">
<!ENTITY conf-LSattr_html_mail SYSTEM "LSattr_html_mail.docbook"> <!ENTITY conf-LSattr_html_mail SYSTEM "LSattr_html_mail.docbook">
<!ENTITY conf-LSattr_html_maildir SYSTEM "LSattr_html_maildir.docbook"> <!ENTITY conf-LSattr_html_maildir SYSTEM "LSattr_html_maildir.docbook">
<!ENTITY conf-LSattr_html_mailQuota SYSTEM "LSattr_html_mailQuota.docbook"> <!ENTITY conf-LSattr_html_mailQuota SYSTEM "LSattr_html_mailQuota.docbook">

View file

@ -0,0 +1,33 @@
<sect4 id="config-LSattr_html_labeledValue">
<title>LSattr_html_labeledValue</title>
<para>Ce type est utilisé pour la gestion des attributs dont la valeur est
prefixé d'un <literal>label</literal> et qui respecte le format suivant :
<literal>[label]valeur</literal>.</para>
<programlisting linenumbering="unnumbered">
<citetitle>Structure</citetitle>...
<![CDATA['html_options' => array(
'labels' => array ( // Liste des labels possible
'label1' => 'Libellé label1',
'label2' => 'Libellé label2',
[...]
),
),]]>
...
</programlisting>
<variablelist>
<title>Paramètres de configuration</title>
<varlistentry>
<term>labels</term>
<listitem>
<simpara>Tableau associatif obligatoire contenant en valeur clé, le
<literal>label</literal> utilisé dans la valeur stockée et en valeur
associée, le valeur d'affichage du <literal>label</literal>.</simpara>
</listitem>
</varlistentry>
</variablelist>
</sect4>

View file

@ -0,0 +1,32 @@
<?php
/*******************************************************************************
* Copyright (C) 2007 Easter-eggs
* http://ldapsaisie.labs.libre-entreprise.org
*
* Author: See AUTHORS file in top-level directory.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
******************************************************************************/
/**
* Type d'attribut HTML labeledValue
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*/
class LSattr_html_labeledValue extends LSattr_html {
var $LSformElement_type = 'labeledValue';
}

View file

@ -0,0 +1,128 @@
<?php
/*******************************************************************************
* Copyright (C) 2007 Easter-eggs
* http://ldapsaisie.labs.libre-entreprise.org
*
* Author: See AUTHORS file in top-level directory.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
******************************************************************************/
LSsession :: loadLSclass('LSformElement');
/**
* Element labeledValue d'un formulaire pour LdapSaisie
*
* Cette classe définis les éléments labeledValue des formulaires.
* Elle étant la classe basic LSformElement.
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*/
class LSformElement_labeledValue extends LSformElement {
var $template = 'LSformElement_labeledValue.tpl';
var $fieldTemplate = 'LSformElement_labeledValue_field.tpl';
/**
* Retourne les infos d'affichage de l'élément
*
* Cette méthode retourne les informations d'affichage de l'élement
*
* @retval array
*/
function getDisplay(){
$return = $this -> getLabelInfos();
$parseValues=array();
foreach($this -> values as $val) {
$parseValues[]=$this -> parseValue($val);
}
$return['html'] = $this -> fetchTemplate(NULL,array(
'labels' => $this -> params['html_options']['labels'],
'parseValues' => $parseValues,
'unrecognizedValueTxt' => __('(unrecognized value)'),
'unrecognizedLabelTxt' => __('(unrecognized label)'),
));
return $return;
}
/**
* Retourne le code HTML d'un champ vide
*
* @retval string Code HTML d'un champ vide.
*/
function getEmptyField() {
return $this -> fetchTemplate($this -> fieldTemplate,array(
'labels' => $this -> params['html_options']['labels'],
));
}
/**
* Parse une valeur
*
* @param[in] $value La valeur
*
* @retval array Un tableau cle->valeur contenant value et label
**/
function parseValue($value) {
$ret=array('raw_value' => $value);
if (preg_match('/^\[([^\]]*)\](.*)$/',$value,$m)) {
$ret['label'] = $m[1];
if (isset($this -> params['html_options']['labels'][$ret['label']]))
$ret['translated_label'] = $this -> params['html_options']['labels'][$ret['label']];
$ret['value'] = $m[2];
}
return $ret;
}
/**
* Recupère la valeur de l'élement passée en POST
*
* Cette méthode vérifie la présence en POST de la valeur de l'élément et la récupère
* pour la mettre dans le tableau passer en paramètre avec en clef le nom de l'élément
*
* @param[] array Pointeur sur le tableau qui recupèrera la valeur.
*
* @retval boolean true si la valeur est présente en POST, false sinon
*/
function getPostData(&$return) {
if($this -> isFreeze()) {
return true;
}
if (isset($_POST[$this -> name."_labels"]) && isset($_POST[$this -> name."_values"])) {
$return[$this -> name]=array();
if(!is_array($_POST[$this -> name."_labels"])) {
$_POST[$this -> name."_labels"] = array($_POST[$this -> name."_labels"]);
}
if(!is_array($_POST[$this -> name."_values"])) {
$_POST[$this -> name."_values"] = array($_POST[$this -> name."_values"]);
}
foreach($_POST[$this -> name."_labels"] as $key => $label) {
$val=$_POST[$this -> name."_values"][$key];
if (!empty($label) && (!empty($val)||(is_string($val)&&($val=="0")))) {
$return[$this -> name][$key] = "[$label]$val";
}
}
return true;
}
else {
$return[$this -> name] = array();
return true;
}
}
}

View file

@ -253,6 +253,13 @@ if (loadDir(LS_OBJECTS_DIR) && loadDir(LS_LOCAL_DIR.LS_OBJECTS_DIR)) {
} }
} }
// LSattr_html_labeledValue
if (is_array($attr['html_options']['labels'])) {
foreach($attr['html_options']['labels'] as $klabel => $plabel) {
add($plabel);
}
}
// LSattr_html_jsonCompositeAttribute // LSattr_html_jsonCompositeAttribute
if (is_array($attr['html_options']['components'])) { if (is_array($attr['html_options']['components'])) {
foreach($attr['html_options']['components'] as $c => $cconfig) { foreach($attr['html_options']['components'] as $c => $cconfig) {

View file

@ -0,0 +1,7 @@
<ul class='LSform {if $multiple && !$freeze} LSformElement_multiple{/if} LSformElement_labeledValue' id='{$attr_name}' data-fieldType="{$fieldType}">
{foreach from=$parseValues item=parseValue}
<li>{include file="ls:$fieldTemplate"}</li>
{foreachelse}
<li {if $freeze}class='noValue'{/if}>{include file="ls:$fieldTemplate"}</li>
{/foreach}
</ul>

View file

@ -0,0 +1,21 @@
{if $freeze}
{if isset($parseValue)}
{if $parseValue.label}
{if $parseValue.translated_label}
<span title='[{$parseValue.label|escape:'quotes'}]'>{$parseValue.translated_label}</span>
{else}
<span>{$parseValue.label} {$unrecognizedLabelTxt}</span>
{/if}
: <span>{$parseValue.value}</span>
{else}
<span>{$parseValue.raw_value}</span> {$unrecognizedValueTxt}
{/if}
{else}
{$noValueTxt}
{/if}
{else}
<select name='{$attr_name}_labels[]' class='LSformElement_labeledValue'>
{html_options options=$labels selected=$parseValue.label}
</select>
<input type="text" name='{$attr_name}_values[]' class='LSformElement_labeledValue' value='{if $parseValue.value}{$parseValue.value|escape:'quotes'}{else}{$parseValue.raw_value|escape:'quotes'}{/if}'/>
{/if}