mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-11-18 16:19:06 +01:00
Added LSformElement_valueWithUnit
This commit is contained in:
parent
c8e3daf5fd
commit
a3fdebd362
4 changed files with 243 additions and 0 deletions
14
public_html/css/default/LSformElement_valueWithUnit.css
Normal file
14
public_html/css/default/LSformElement_valueWithUnit.css
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
input.LSformElement_valueWithUnit {
|
||||||
|
width: 3em !important;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
select.LSformElement_valueWithUnit {
|
||||||
|
width: 6em;
|
||||||
|
}
|
||||||
|
|
||||||
|
span.LSformElement_valueWithUnit_unknown {
|
||||||
|
color: #f59a67;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?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 valueWithUnit
|
||||||
|
*
|
||||||
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||||
|
*/
|
||||||
|
class LSattr_html_valueWithUnit extends LSattr_html {
|
||||||
|
|
||||||
|
var $LSformElement_type = 'valueWithUnit';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
168
public_html/includes/class/class.LSformElement_valueWithUnit.php
Normal file
168
public_html/includes/class/class.LSformElement_valueWithUnit.php
Normal file
|
@ -0,0 +1,168 @@
|
||||||
|
<?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.
|
||||||
|
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Element valueWithUnit d'un formulaire pour LdapSaisie
|
||||||
|
*
|
||||||
|
* Cette classe définis les éléments valueWithUnit des formulaires.
|
||||||
|
* Elle étant la classe basic LSformElement.
|
||||||
|
*
|
||||||
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
class LSformElement_valueWithUnit extends LSformElement {
|
||||||
|
|
||||||
|
var $fieldTemplate = 'LSformElement_valueWithUnit_field.tpl';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retourne les unites de l'attribut
|
||||||
|
*
|
||||||
|
* @retval array|False Le tableau contenant en cle les seuils et en valeur les labels des unites.
|
||||||
|
* Si le parametre units n'est pas defini, cette fonction retournera False
|
||||||
|
**/
|
||||||
|
function getUnits() {
|
||||||
|
if (isset($this -> params['html_options']['units']) && is_array($this -> params['html_options']['units'])) {
|
||||||
|
$units=array();
|
||||||
|
foreach($this -> params['html_options']['units'] as $sill => $label) {
|
||||||
|
$units[$sill]=__($label);
|
||||||
|
}
|
||||||
|
return $units;
|
||||||
|
}
|
||||||
|
LSerror :: addErrorCode('LSformElement_valueWithUnit_01',$this -> name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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();
|
||||||
|
|
||||||
|
$values_and_units=array();
|
||||||
|
$units=$this -> getUnits();
|
||||||
|
|
||||||
|
if ($units) {
|
||||||
|
foreach ($this -> values as $value) {
|
||||||
|
if (ereg('^([0-9]*)$',$value,$regs)) {
|
||||||
|
$infos = array(
|
||||||
|
'value' => $regs[1]
|
||||||
|
);
|
||||||
|
foreach($units as $sill => $label) {
|
||||||
|
if ($infos['value'] >= $sill) {
|
||||||
|
if ($infos['value'] % $sill == 0) {
|
||||||
|
$infos['valueWithUnit']=$infos['value']/$sill;
|
||||||
|
$infos['unitSill']=$sill;
|
||||||
|
$infos['unitLabel']=$label;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$values_and_units[$value] = $infos;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$values_and_units[$value] = array(
|
||||||
|
'unknown' => _('Incorrect value')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LSsession :: addCssFile('LSformElement_valueWithUnit.css');
|
||||||
|
|
||||||
|
$return['html']=$this -> fetchTemplate(
|
||||||
|
NULL,
|
||||||
|
array(
|
||||||
|
'values_and_units' => $values_and_units,
|
||||||
|
'units' => $units
|
||||||
|
)
|
||||||
|
);
|
||||||
|
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(
|
||||||
|
'units' => $this -> getUnits()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
$return[$this -> name]=array();
|
||||||
|
if (isset($_POST[$this -> name.'_valueWithUnit'])) {
|
||||||
|
if(!is_array($_POST[$this -> name.'_valueWithUnit'])) {
|
||||||
|
$_POST[$this -> name.'_valueWithUnit'] = array($_POST[$this -> name.'_valueWithUnit']);
|
||||||
|
}
|
||||||
|
if(isset($_POST[$this -> name.'_unitFact']) && !is_array($_POST[$this -> name.'_unitFact'])) {
|
||||||
|
$_POST[$this -> name.'_unitFact'] = array($_POST[$this -> name.'_unitFact']);
|
||||||
|
}
|
||||||
|
foreach($_POST[$this -> name.'_valueWithUnit'] as $key => $val) {
|
||||||
|
if (!empty($val)) {
|
||||||
|
$f = 1;
|
||||||
|
if (isset($_POST[$this -> name.'_unitFact'][$key]) && ($_POST[$this -> name.'_unitFact'][$key]!=1)) {
|
||||||
|
$f = $_POST[$this -> name.'_unitFact'][$key];
|
||||||
|
}
|
||||||
|
$return[$this -> name][$key] = ($val*$f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isset($_POST[$this -> name.'_value'])) {
|
||||||
|
if (!is_array($_POST[$this -> name.'_value'])) {
|
||||||
|
$_POST[$this -> name.'_value']=array($_POST[$this -> name.'_value']);
|
||||||
|
}
|
||||||
|
$return[$this -> name]=array_merge($return[$this -> name],$_POST[$this -> name.'_value']);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Error Codes
|
||||||
|
*/
|
||||||
|
LSerror :: defineError('LSformElement_valueWithUnit_01',
|
||||||
|
_("LSformElement_valueWithUnit : Units configuration data are missing for the attribute %{attr}.")
|
||||||
|
);
|
||||||
|
?>
|
|
@ -0,0 +1,27 @@
|
||||||
|
{if $freeze}
|
||||||
|
{if $value}
|
||||||
|
{if $values_and_units[$value].unknown}
|
||||||
|
<span class='LSformElement_valueWithUnit_unknown'>{$values_and_units[$value].unknown}</span>
|
||||||
|
{else}
|
||||||
|
{if $values_and_units[$value].valueWithUnit}
|
||||||
|
{$values_and_units[$value].valueWithUnit}{$values_and_units[$value].unitLabel}
|
||||||
|
{else}
|
||||||
|
{$values_and_units[$value].value}
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
|
{else}
|
||||||
|
{$noValueTxt}
|
||||||
|
{/if}
|
||||||
|
{else}
|
||||||
|
{if $values_and_units[$value].valueWithUnit}
|
||||||
|
<input name='{$attr_name}_valueWithUnit[]' type=text class='LSformElement_valueWithUnit' value="{$values_and_units[$value].valueWithUnit}"/>
|
||||||
|
<select name='{$attr_name}_unitFact[]' class='LSform LSformElement_valueWithUnit'>
|
||||||
|
{html_options options=$units selected=$values_and_units[$value].unitSill}
|
||||||
|
</select>
|
||||||
|
{else}
|
||||||
|
<input name='{$attr_name}_value[]' type=text class='LSformElement_valueWithUnit' value="{$values_and_units[$value].value}"/>
|
||||||
|
{/if}
|
||||||
|
{if $values_and_units[$value].unknown}
|
||||||
|
<span class='LSformElement_valueWithUnit_unknown'>{$values_and_units[$value].unknown}</span>
|
||||||
|
{/if}
|
||||||
|
{/if}
|
Loading…
Reference in a new issue