Add support for supannMailPrive, supannAdressePostalePrivee and supannTelephonePrive attributes

This commit is contained in:
Benjamin Renard 2021-06-09 15:48:46 +02:00
parent 077a44fdf9
commit 0ac0a7e068
13 changed files with 637 additions and 209 deletions

View file

@ -92,22 +92,46 @@ $GLOBALS['LS_SUPANN_CIVILITES'] = array (
* ), * ),
* ); * );
* *
* [ETIQUETTE] : l'étiquette de la valeur * [ETIQUETTE] : l'étiquette de la valeur (correspondant le plus souvent ou mainteneur de la nomenclature)
* [table] : le nom de la table : * [table] : le nom de la table :
* - roleGenerique : les rôles génériques * - mailPriveLabel: le label des mails privés des personnes (supannMailPrive)
* - typeEntite : les types d'entités * - adressePostalePriveeLabel: le label des adresses privées des personnes (supannAdressePostalePrivee)
* - empCorps : les corps d'appartenances des personnels * - telephonePriveLabel: le label des télépgones privés des personnes (supannTelephonePrive)
* - codeEtablissement : les codes d'établissement * - roleGenerique : les rôles génériques (supannRoleGenerique)
* - etuRegimeInscription : les régimes d'inscription étudiant * - typeEntite : les types d'entités (supannTypeEntite)
* - etuSecteurDisciplinaire : les secteurs disciplinaires de dîplomes ou d'enseignements * - empCorps : les corps d'appartenances des personnels (supannEmpCorps)
* - etuTypeDiplome : les types de diplôme * - codeEtablissement : les codes d'établissement (supannEtablissement)
* - etuDiplome : les diplômes * - etuRegimeInscription : les régimes d'inscription étudiant (supannEtuRegimeInscription)
* - etuEtape : les étapes des enseignements * - etuSecteurDisciplinaire : les secteurs disciplinaires de dîplomes ou d'enseignements (supannEtuSecteurDisciplinaire)
* - etuElementPedagogique : les éléments pédagogiques * - etuTypeDiplome : les types de diplôme (supannEtuTypeDiplome)
* - etuDiplome : les diplômes (supannEtuDiplome)
* - etuEtape : les étapes des enseignements (supannEtuEtape)
* - etuElementPedagogique : les éléments pédagogiques (supannEtuElementPedagogique)
* *
*/ */
$GLOBALS['supannNomenclatures'] = array ( $GLOBALS['supannNomenclatures'] = array (
'SUPANN' => array ( 'SUPANN' => array (
'mailPriveLabel' => array (
'SECOURS' => ___('Backup'),
'PERSO' => ___('Personal'),
'PARENTS' => ___('Parents'),
'PRO' => ___('Professional'),
),
'adressePostalePriveeLabel' => array (
'TEMP' => ___('Temporary'),
'PERSO' => ___('Personal'),
'PARENTS' => ___('Parents'),
'PRO' => ___('Professional'),
),
'telephonePriveLabel' => array (
'MOBPERSO' => ___('Personal mobile'),
'FIXEPERSO' => ___('Personal landline'),
'FIXEPARENTS' => ___('Parents landline'),
'MOBPARENTS' => ___('Parents mobile'),
'MOBPRO' => ___('Professional mobile'),
'FIXEPRO' => ___('Professional landline'),
'SECOURS' => ___('Backup'),
),
'roleGenerique' => array ( 'roleGenerique' => array (
"D00" => "MINISTRE", "D00" => "MINISTRE",
"D01" => "DIRECTEUR DU CABINET", "D01" => "DIRECTEUR DU CABINET",

View file

@ -22,3 +22,25 @@ div.supannLabeledValue_possibleValues li:hover {
background-color: #CCC; background-color: #CCC;
cursor: pointer; cursor: pointer;
} }
pre.LSformElement_supannLabeledValue_value {
display: inline-block;
font-family: 'Lucida Grande', Verdana, Arial, Sans-Serif;
margin: 0;
}
@media (min-width: 401px) {
select.LSformElement_supannLabeledValue_label, input.LSformElement_supannLabeledValue_label, span.LSformElement_supannLabeledValue_label {
width: 50px;
vertical-align: top;
}
input.LSformElement_supannLabeledValue_value, textarea.LSformElement_supannLabeledValue_value {
scrollbar-width: thin;
width: calc(150px - 1em);
}
textarea.LSformElement_supannLabeledValue_value {
height: 5em;
}
}

View file

@ -198,7 +198,7 @@ td.LSobject-list, tr.LSobject-list, table.LStable tbody td, table.LStable th {
padding: 2px; padding: 2px;
} }
.LSform input[type=text], .LSform input[type=password], .LSform select, .LSform textarea, ul.LSformElement_text_autocomplete, ul.LSformElement_select_object_edit, div.LSformElement_wysiwyg_container, ul.LSformElement_jsonCompositeAttribute:not(.LSformElement_jsonCompositeAttribute_fullWidth), dd.LSform-errors { .LSform input[type=text], .LSform input[type=password], .LSform select, .LSform textarea, ul.LSformElement_text_autocomplete, ul.LSformElement_select_object_edit, div.LSformElement_wysiwyg_container, ul.LSformElement_jsonCompositeAttribute:not(.LSformElement_jsonCompositeAttribute_fullWidth), dd.LSform-errors, input.LSformElement_supannLabeledValue_search {
width: 32vw; width: 32vw;
} }
@ -234,6 +234,14 @@ td.LSobject-list, tr.LSobject-list, table.LStable tbody td, table.LStable th {
width: calc(32vw - 8em); width: calc(32vw - 8em);
} }
.LSform select.LSformElement_supannLabeledValue_label, .LSform input.LSformElement_supannLabeledValue_label {
width: 6em;
}
.LSform input.LSformElement_supannLabeledValue_value, textarea.LSformElement_supannLabeledValue_value {
width: calc(32vw - 14rem);
}
input.LSformElement_select_object_searchAdd, ul.LSformElement_select_object_searchAdd { input.LSformElement_select_object_searchAdd, ul.LSformElement_select_object_searchAdd {
width: 17vw!important; width: 17vw!important;
box-sizing: border-box; box-sizing: border-box;

View file

@ -381,19 +381,40 @@ LSerror :: defineError('SUPANN_03',
* Vérifie si une valeur et son étiquette sont valide pour une table donnée * Vérifie si une valeur et son étiquette sont valide pour une table donnée
* *
* @param[in] $table La table de nomenclature * @param[in] $table La table de nomenclature
* @param[in] $label L'étiquette de la valeur * @param[in] $label L'étiquette de la valeur (optionnel)
* @param[in] $value La valeur * @param[in] $value La valeur
* *
* @retval booleab True si valide, False sinon * @retval booleab True si valide, False sinon
**/ **/
function supannValidateNomenclatureValue($table,$label,$value) { function supannValidateNomenclatureValue($table, $label, $value) {
$label=strtoupper($label); if ($label) {
if (isset($GLOBALS['supannNomenclatures'][$label]) && $label = strtoupper($label);
isset($GLOBALS['supannNomenclatures'][$label][$table]) && if (
isset($GLOBALS['supannNomenclatures'][$label][$table][$value])) { isset($GLOBALS['supannNomenclatures'][$label]) &&
return true; isset($GLOBALS['supannNomenclatures'][$label][$table]) &&
} isset($GLOBALS['supannNomenclatures'][$label][$table][$value])
return false; ) {
return array(
'table' => $table,
'label' => $label,
'value' => $value,
'translated' => $GLOBALS['supannNomenclatures'][$label][$table][$value],
);
}
}
else {
foreach($GLOBALS['supannNomenclatures'] as $label => $tables) {
if (!array_key_exists($table, $tables) || !array_key_exists($value, $tables[$table]))
continue;
return array(
'table' => $table,
'label' => $label,
'value' => $value,
'translated' => $tables[$table][$value],
);
}
}
return false;
} }
/** /**
@ -401,33 +422,57 @@ LSerror :: defineError('SUPANN_03',
* et de l'étiquette de la valeur. * et de l'étiquette de la valeur.
* *
* @param[in] $table La table de nomenclature * @param[in] $table La table de nomenclature
* @param[in] $label L'étiquette de la valeur * @param[in] $label L'étiquette de la valeur (optionnel)
* @param[in] $value La valeur * @param[in] $value La valeur
* *
* @retval array Le label de la valeur. En cas de valeur nor-reconnue, retourne * @retval array Le label de la valeur. En cas de valeur nor-reconnue, retourne
* la valeur en spécifiant qu'elle n'est pas reconnue. * la valeur en spécifiant qu'elle n'est pas reconnue.
**/ **/
function supannGetNomenclatureLabel($table,$label,$value) { function supannGetNomenclatureLabel($table, $label, $value) {
if (supannValidateNomenclatureValue($table,$label,$value)) { $translated = supannValidateNomenclatureValue($table, $label, $value);
$label=strtoupper($label); if ($translated)
return $GLOBALS['supannNomenclatures'][$label][$table][$value]; return $translated['translated'];
} return getFData(__("%{value} (unrecognized value)"), $value);
return getFData(__("%{value} (unrecognized value)"),$value); }
/**
* Retourne les valeurs possibles d'une table de nomenclature pour chaque fournisseur
*
* @param[in] $table La table de nomenclature
*
* @retval array Tableau contenant pour chaque fournisseur, les valeurs possibles de
* la table de nomenclature
**/
function supannGetNomenclatureTable($table) {
$retval=array();
foreach(array_keys($GLOBALS['supannNomenclatures']) as $provider) {
if (isset($GLOBALS['supannNomenclatures'][$provider][$table])) {
$retval[$provider] = $GLOBALS['supannNomenclatures'][$provider][$table];
}
}
return $retval;
} }
/** /**
* Retourne les valeurs possibles d'une table de nomenclature * Retourne les valeurs possibles d'une table de nomenclature
* *
* @param[in] $table La table de nomenclature * @param[in] $table La table de nomenclature
* @param[in] $add_provider_label Booléen définissant si le fournisseur de la valeur
* doit être ajouté en tant qu'étiquette de la valeur
* (optinel, par défaut: vrai)
* *
* @retval array Tableau contenant les valeurs possibles de la table * @retval array Tableau contenant les valeurs possibles de la table
* de nomenclature * de nomenclature
**/ **/
function supannGetNomenclatureTable($table) { function supannGetNomenclaturePossibleValues($table, $add_provider_label=True) {
$retval=array(); $retval = array();
foreach($GLOBALS['supannNomenclatures'] as $label => $tables) { foreach(array_keys($GLOBALS['supannNomenclatures']) as $provider) {
if (isset($GLOBALS['supannNomenclatures'][$label][$table])) { if (isset($GLOBALS['supannNomenclatures'][$provider][$table])) {
$retval[$label]=$GLOBALS['supannNomenclatures'][$label][$table]; foreach($GLOBALS['supannNomenclatures'][$provider][$table] as $value => $label) {
if ($add_provider_label)
$value = "{$provider}$value";
$retval[$value] = __($label);
}
} }
} }
return $retval; return $retval;

View file

@ -0,0 +1,32 @@
<?php
/*******************************************************************************
* Copyright (C) 2021 Easter-eggs
* https://ldapsaisie.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 supannAdressePostalePrivee
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*/
class LSattr_html_supannAdressePostalePrivee extends LSattr_html {
var $LSformElement_type = 'supannAdressePostalePrivee';
}

View file

@ -0,0 +1,32 @@
<?php
/*******************************************************************************
* Copyright (C) 2021 Easter-eggs
* https://ldapsaisie.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 supannMailPrive
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*/
class LSattr_html_supannMailPrive extends LSattr_html {
var $LSformElement_type = 'supannMailPrive';
}

View file

@ -0,0 +1,32 @@
<?php
/*******************************************************************************
* Copyright (C) 2021 Easter-eggs
* https://ldapsaisie.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 supannTelephonePrive
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*/
class LSattr_html_supannTelephonePrive extends LSattr_html {
var $LSformElement_type = 'supannTelephonePrive';
}

View file

@ -0,0 +1,76 @@
<?php
/*******************************************************************************
* Copyright (C) 2021 Easter-eggs
* https://ldapsaisie.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_supannLabeledValue');
LSsession :: loadLSaddon('supann');
/**
* Element supannAdressePostalePrivee d'un formulaire pour LdapSaisie
*
* Cette classe définis les éléments supannAdressePostalePrivee des formulaires.
* Elle etant la classe basic LSformElement_supannLabeledValue.
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*/
class LSformElement_supannAdressePostalePrivee extends LSformElement_supannLabeledValue {
var $supannLabelNomenclatureTable = 'adressePostalePriveeLabel';
var $valueFieldType = 'textarea';
/**
* Parse une valeur
*
* @param[in] $value La valeur
*
* @retval array Un tableau cle->valeur contenant value, translated et label
**/
public function parseValue($value) {
$retval = parent :: parseValue($value);
$retval['value'] = str_replace('$', "\n", $retval['value']);
$retval['translated'] = str_replace('$', "\n", $retval['translated']);
return $retval;
}
/**
* Recupère la valeur de l'élement passée en POST
*
* Cette méthode s'occupe de remplacer les retour à la ligne dans les valeur de l'attribut
* pas des caractères '$'.
* @see LSformElement::getPostData()
* @retval boolean true si la valeur est présente en POST, false sinon
*/
public function getPostData(&$return, $onlyIfPresent=false) {
$retval = parent :: getPostData($return, $onlyIfPresent);
if (isset($return[$this -> name])) {
$fixed_values = array();
foreach($return[$this -> name] as $value)
$fixed_values[] = str_replace("\n", "$", $value);
$return[$this -> name] = $fixed_values;
}
return $retval;
}
}

View file

@ -38,6 +38,10 @@ class LSformElement_supannLabeledValue extends LSformElement {
var $fieldTemplate = 'LSformElement_supannLabeledValue_field.tpl'; var $fieldTemplate = 'LSformElement_supannLabeledValue_field.tpl';
var $supannNomenclatureTable = null; var $supannNomenclatureTable = null;
var $supannLabelNomenclatureTable = null;
// HTML field type: text or textarea (only for field without nomenclature table)
var $valueFieldType = 'text';
/** /**
* Retourne les infos d'affichage de l'élément * Retourne les infos d'affichage de l'élément
@ -53,12 +57,25 @@ class LSformElement_supannLabeledValue extends LSformElement {
foreach($this -> values as $val) { foreach($this -> values as $val) {
$parseValues[]=$this -> parseValue($val); $parseValues[]=$this -> parseValue($val);
} }
$return['html'] = $this -> fetchTemplate(NULL,array('parseValues' => $parseValues)); $possibleLabels = (
$this -> supannLabelNomenclatureTable?
supannGetNomenclaturePossibleValues($this -> supannLabelNomenclatureTable, false):
null
);
$return['html'] = $this -> fetchTemplate(
NULL, array(
'parseValues' => $parseValues,
'nomenclatureTable' => $this -> supannNomenclatureTable,
'possibleLabels' => $possibleLabels,
'valueFieldType' => $this -> valueFieldType,
)
);
LStemplate :: addCssFile('LSformElement_supannLabeledValue.css'); LStemplate :: addCssFile('LSformElement_supannLabeledValue.css');
if (!$this -> isFreeze()) { if (!$this -> isFreeze()) {
LStemplate :: addJSconfigParam( LStemplate :: addJSconfigParam(
$this -> name, $this -> name,
array( array(
'nomenclatureTable' => boolval($this -> supannNomenclatureTable),
'searchBtn' => _('Modify'), 'searchBtn' => _('Modify'),
'noValueLabel' => _('No set value'), 'noValueLabel' => _('No set value'),
'noResultLabel' => _('No result'), 'noResultLabel' => _('No result'),
@ -80,13 +97,18 @@ class LSformElement_supannLabeledValue extends LSformElement {
* @retval array Un tableau cle->valeur contenant value, translated et label * @retval array Un tableau cle->valeur contenant value, translated et label
**/ **/
public function parseValue($value) { public function parseValue($value) {
$retval=array( $retval = array(
'value' => $value, 'value' => $value,
); );
$pv=supannParseLabeledValue($value); $pv = supannParseLabeledValue($value);
if ($pv) { if ($pv) {
$retval['label'] = $pv['label']; $retval['label'] = $pv['label'];
$retval['translated'] = supannGetNomenclatureLabel($this -> supannNomenclatureTable,$pv['label'],$pv['value']); if ($this -> supannLabelNomenclatureTable)
$retval['translated_label'] = supannGetNomenclatureLabel($this -> supannLabelNomenclatureTable, null, $pv['label']);
if ($this -> supannNomenclatureTable)
$retval['translated'] = supannGetNomenclatureLabel($this -> supannNomenclatureTable,$pv['label'],$pv['value']);
else
$retval['translated'] = $pv['value'];
} }
else { else {
$retval['label'] = 'no'; $retval['label'] = 'no';
@ -101,26 +123,38 @@ class LSformElement_supannLabeledValue extends LSformElement {
* *
* @param[in] $data The address to the array of data witch will be return by the ajax request * @param[in] $data The address to the array of data witch will be return by the ajax request
* *
* @retval void * @retval boolean True on success, False otherwise
**/ **/
public static function ajax_searchPossibleValues(&$data) { public static function ajax_searchPossibleValues(&$data) {
if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['pattern'])) && (isset($_REQUEST['idform'])) ) { // Check all parameters is provided
if (LSsession ::loadLSobject($_REQUEST['objecttype'])) { foreach(array('attribute', 'objecttype', 'pattern', 'idform') as $parameter)
$object = new $_REQUEST['objecttype'](); if (!isset($_REQUEST[$parameter]))
$form = $object -> getForm($_REQUEST['idform']); return;
$field=$form -> getElement($_REQUEST['attribute']); if (!LSsession ::loadLSobject($_REQUEST['objecttype']))
$data['possibleValues'] = $field -> searchPossibleValues($_REQUEST['pattern']); return;
} $object = new $_REQUEST['objecttype']();
} $form = $object -> getForm($_REQUEST['idform']);
$field = $form -> getElement($_REQUEST['attribute']);
$data['possibleValues'] = $field -> searchPossibleValues($_REQUEST['pattern']);
return true;
} }
/**
* Real private method to search possible values from pattern.
*
* @param[in] $pattern The search pattern
*
* @retval boolean|array Array of possible values, or False is case of error
**/
private function searchPossibleValues($pattern) { private function searchPossibleValues($pattern) {
$pattern=strtolower($pattern); if (!$this -> supannNomenclatureTable)
return false;
$pattern=withoutAccents(strtolower($pattern));
$retval=array(); $retval=array();
$table=supannGetNomenclatureTable($this -> supannNomenclatureTable); $table=supannGetNomenclatureTable($this -> supannNomenclatureTable);
foreach($table as $label => $values) { foreach($table as $label => $values) {
foreach($values as $v => $txt) { foreach($values as $v => $txt) {
if (strpos(strtolower($txt),$pattern)!==false) { if (strpos(withoutAccents(strtolower($txt)),$pattern)!==false) {
$retval[]=array( $retval[]=array(
'label' => $label, 'label' => $label,
'value' => "{".$label."}".$v, 'value' => "{".$label."}".$v,

View file

@ -0,0 +1,39 @@
<?php
/*******************************************************************************
* Copyright (C) 2021 Easter-eggs
* https://ldapsaisie.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_supannLabeledValue');
LSsession :: loadLSaddon('supann');
/**
* Element supannMailPrive d'un formulaire pour LdapSaisie
*
* Cette classe définis les éléments supannMailPrive des formulaires.
* Elle etant la classe basic LSformElement_supannLabeledValue.
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*/
class LSformElement_supannMailPrive extends LSformElement_supannLabeledValue {
var $supannLabelNomenclatureTable = 'mailPriveLabel';
}

View file

@ -0,0 +1,39 @@
<?php
/*******************************************************************************
* Copyright (C) 2021 Easter-eggs
* https://ldapsaisie.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_supannLabeledValue');
LSsession :: loadLSaddon('supann');
/**
* Element supannTelephonePrive d'un formulaire pour LdapSaisie
*
* Cette classe définis les éléments supannTelephonePrive des formulaires.
* Elle etant la classe basic LSformElement_supannLabeledValue.
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*/
class LSformElement_supannTelephonePrive extends LSformElement_supannLabeledValue {
var $supannLabelNomenclatureTable = 'telephonePriveLabel';
}

View file

@ -1,171 +1,191 @@
var LSformElement_supannLabeledValue_field_value = new Class({ var LSformElement_supannLabeledValue_field_value = new Class({
initialize: function(li,name,field_type){ initialize: function(li,name,field_type){
this.li=li; this.li=li;
this.name = name; this.name = name;
this.field_type = field_type; this.field_type = field_type;
this.params = varLSdefault.LSjsConfig[this.name]; this.params = varLSdefault.LSjsConfig[this.name];
this.input = this.li.getElement('input'); this.inputRawValue = this.li.getElement('input');
this.img = this.li.getElement('img.LSformElement_supannLabeledValue_label'); if (this.params.nomenclatureTable) {
this.span = this.li.getElement('span'); this.img = this.li.getElement('img.LSformElement_supannLabeledValue_label');
this.span = this.li.getElement('span');
this.inputSearch=new Element( this.inputSearch=new Element(
'input', 'input',
{ {
'class': 'LSformElement_supannLabeledValue_search', 'class': 'LSformElement_supannLabeledValue_search',
'styles': { 'styles': {
'display': 'none' 'display': 'none'
}
}
);
this.inputSearch.addEvent('keydown',this.onKeyUpInputSearch.bindWithEvent(this));
this.inputSearch.injectInside(this.li);
this.searchBtn=new Element(
'img',
{
'src': varLSdefault.imagePath('modify'),
'alt': this.params.searchBtn,
'title': this.params.searchBtn,
}
);
this.searchBtn.addEvent('click',this.toggleInputSearch.bind(this));
this.searchBtn.injectAfter(this.span);
this._lastSearch=null;
this._possibleValues=null;
},
toggleInputSearch: function() {
if (this.inputSearch.getStyle('display')=='none') {
this.inputSearch.setStyle('display','block');
this.inputSearch.focus();
}
else {
this.hidePossibleValues();
this.inputSearch.setStyle('display','none');
this.inputSearch.set('value','');
}
},
onKeyUpInputSearch: function(event) {
event = new Event(event);
if ((event.key=='enter')||(event.key=='tab')) {
event.stop();
if (this.inputSearch.value!="") {
this.launchSearch();
} }
} }
);
this.inputSearch.addEvent('keydown',this.onKeyUpInputSearch.bindWithEvent(this));
this.inputSearch.injectInside(this.li);
if (event.key=='esc') { this.searchBtn=new Element(
this.toggleInputSearch(); 'img',
{
'src': varLSdefault.imagePath('modify'),
'alt': this.params.searchBtn,
'title': this.params.searchBtn,
}
);
this.searchBtn.addEvent('click',this.toggleInputSearch.bind(this));
this.searchBtn.injectAfter(this.span);
this._lastSearch=null;
this._possibleValues=null;
}
else {
this.inputLabel = this.li.getElement('select.LSformElement_supannLabeledValue_label');
if (!this.inputLabel)
this.inputLabel = this.li.getElement('input.LSformElement_supannLabeledValue_label');
this.inputValue = this.li.getElement('input.LSformElement_supannLabeledValue_value');
if (!this.inputValue)
this.inputValue = this.li.getElement('textarea.LSformElement_supannLabeledValue_value');
if (!this.inputLabel || !this.inputValue) {
alert('toto');
return;
} }
}, this.inputLabel.addEvent('change', this.updateRawValue.bind(this));
this.inputValue.addEvent('change', this.updateRawValue.bind(this));
}
},
launchSearch: function() { toggleInputSearch: function() {
this.hidePossibleValues(); if (this.inputSearch.getStyle('display')=='none') {
this._lastSearch=this.inputSearch.value; this.inputSearch.setStyle('display','block');
var data = { this.inputSearch.focus();
attribute: this.name, }
objecttype: varLSform.objecttype, else {
idform: varLSform.idform, this.hidePossibleValues();
pattern: this.inputSearch.value this.inputSearch.setStyle('display','none');
}; this.inputSearch.set('value','');
data.imgload=varLSdefault.loadingImgDisplay(this.inputSearch); }
new Request({url: 'ajax/class/LSformElement_supannLabeledValue/searchPossibleValues', data: data, onSuccess: this.onSearchComplete.bind(this)}).send(); },
onKeyUpInputSearch: function(event) {
event = new Event(event);
if ((event.key=='enter')||(event.key=='tab')) {
event.stop();
if (this.inputSearch.value!="") {
this.launchSearch();
}
}
if (event.key=='esc') {
this.toggleInputSearch();
}
},
launchSearch: function() {
this.hidePossibleValues();
this._lastSearch=this.inputSearch.value;
var data = {
attribute: this.name,
objecttype: varLSform.objecttype,
idform: varLSform.idform,
pattern: this.inputSearch.value
};
data.imgload=varLSdefault.loadingImgDisplay(this.inputSearch);
new Request({url: 'ajax/class/LSformElement_supannLabeledValue/searchPossibleValues', data: data, onSuccess: this.onSearchComplete.bind(this)}).send();
}, },
onSearchComplete: function(responseText, responseXML) { onSearchComplete: function(responseText, responseXML) {
var data = JSON.decode(responseText); var data = JSON.decode(responseText);
if ( varLSdefault.checkAjaxReturn(data) ) { if ( varLSdefault.checkAjaxReturn(data) ) {
this.displayPossibleValues(data.possibleValues); this.displayPossibleValues(data.possibleValues);
} }
}, },
displayPossibleValues: function(possibleValues) { displayPossibleValues: function(possibleValues) {
if (this._possibleValues==null) { if (this._possibleValues==null) {
this._possibleValues=new Element( this._possibleValues=new Element(
'div', 'div',
{ {
'class': 'supannLabeledValue_possibleValues', 'class': 'supannLabeledValue_possibleValues',
} }
); );
this._possibleValues.injectInside(this.li); this._possibleValues.injectInside(this.li);
} }
var ul=new Element('ul'); var ul=new Element('ul');
possibleValues.each(function(v) { possibleValues.each(function(v) {
var li=new Element( var li=new Element(
'li', 'li',
{ {
'data-value': v.value, 'data-value': v.value,
'data-label': v.label, 'data-label': v.label,
'data-translated': v.translated, 'data-translated': v.translated,
} }
); );
if (v.label!='no') { if (v.label!='no') {
li.set('html',"<img src='"+varLSdefault.imagePath('supann_label_'+v.label)+"' alt='["+v.label+"]'/> "+v.translated); li.set('html',"<img src='"+varLSdefault.imagePath('supann_label_'+v.label)+"' alt='["+v.label+"]'/> "+v.translated);
} }
else { else {
li.set('html',v.translated); li.set('html',v.translated);
} }
li.injectInside(this); li.injectInside(this);
}, ul); }, ul);
if (ul.getElements('li').length==0) { if (ul.getElements('li').length==0) {
new Element( new Element(
'li', 'li',
{ {
'html': this.params.noResultLabel 'html': this.params.noResultLabel
} }
).injectInside(ul); ).injectInside(ul);
} }
else { else {
ul.getElements('li').each(function(li) { ul.getElements('li').each(function(li) {
li.addEvent('click',this.onClickPossibleValue.bindWithEvent(this)); li.addEvent('click',this.onClickPossibleValue.bindWithEvent(this));
}, this); }, this);
} }
ul.injectInside(this._possibleValues); ul.injectInside(this._possibleValues);
this._possibleValues.setStyle('display', 'block'); this._possibleValues.setStyle('display', 'block');
}, },
hidePossibleValues: function() { hidePossibleValues: function() {
if (this._possibleValues!=null) { if (this._possibleValues!=null) {
this._possibleValues.setStyle('display', 'none'); this._possibleValues.setStyle('display', 'none');
this._possibleValues.empty(); this._possibleValues.empty();
} }
}, },
onClickPossibleValue: function(event) { onClickPossibleValue: function(event) {
this.hidePossibleValues(); this.hidePossibleValues();
event = new Event(event); event = new Event(event);
var li=$(event.target); var li=$(event.target);
if (event.target.tagName=='IMG') { if (event.target.tagName=='IMG') {
li=li.getParent(); li=li.getParent();
} }
this.input.set('value',li.get('data-value')); this.inputRawValue.set('value',li.get('data-value'));
if (li.get('data-label')!='no') { if (li.get('data-label')!='no') {
if (this.img==null) { if (this.img==null) {
this.img=new Element('img',{'class': 'LSformElement_supannLabeledValue_label'}); this.img=new Element('img',{'class': 'LSformElement_supannLabeledValue_label'});
this.img.injectBefore(this.span); this.img.injectBefore(this.span);
} }
this.img.set('src',varLSdefault.imagePath('supann_label_'+li.get('data-label'))); this.img.set('src',varLSdefault.imagePath('supann_label_'+li.get('data-label')));
} }
this.span.set('html',li.get('data-translated')); this.span.set('html',li.get('data-translated'));
this.span.set('title',li.get('data-value')); this.span.set('title',li.get('data-value'));
this.toggleInputSearch(); this.toggleInputSearch();
}, },
clear: function() { updateRawValue: function(event) {
if (this.img) { this.inputRawValue.set('value', '{'+this.inputLabel.value+'}'+this.inputValue.value);
this.img.dispose(); },
this.img=null;
} clear: function() {
this.input.set('value',''); if (this.img) {
if (this.span) { this.img.dispose();
this.span.set('html',this.params.noValueLabel); this.img=null;
} }
}, this.inputRawValue.set('value','');
if (this.span) {
this.span.set('html',this.params.noValueLabel);
}
},
}); });

View file

@ -1,22 +1,47 @@
{if $freeze} {if $freeze}
{if isset($parseValue)} {if isset($parseValue)}
{if !empty($parseValue.label) and $parseValue.label!='no'} {if isset($parseValue.translated_label)}
<span class='LSformElement_supannLabeledValue_label'>{tr msg=$parseValue.translated_label}&nbsp;:</span>
{elseif !empty($parseValue.label) and $parseValue.label!='no'}
{assign var=clabel value=$parseValue.label} {assign var=clabel value=$parseValue.label}
<img src='{img name="supann_label_$clabel"}' alt='[{$clabel|escape:"htmlall"}]' title='{$clabel|escape:"htmlall"}'/> <img src='{img name="supann_label_$clabel"}' alt='[{$clabel|escape:"htmlall"}]' title='{$clabel|escape:"htmlall"}'/>
{/if} {/if}
<span title='{$parseValue.value|escape:"htmlall"}'>{$parseValue.translated|escape:"htmlall"}</span> {if $valueFieldType == 'textarea'}
<pre class='LSformElement_supannLabeledValue_value' {if $nomenclatureTable}title='{$parseValue.value|escape:"htmlall"}'{/if}>{$parseValue.translated|escape:"htmlall"}</pre>
{else}
<span {if $nomenclatureTable}title='{$parseValue.value|escape:"htmlall"}'{/if}>{$parseValue.translated|escape:"htmlall"}</span>
{/if}
{else} {else}
{$noValueTxt|escape:"htmlall"} {$noValueTxt|escape:"htmlall"}
{/if} {/if}
{else} {else}
<input type='hidden' name='{$attr_name|escape:"htmlall"}[]' value='{if $parseValue}{$parseValue.value|escape:"htmlall"}{/if}'/> <input type='hidden' name='{$attr_name|escape:"htmlall"}[]' value='{if $parseValue}{$parseValue.value|escape:"htmlall"}{/if}'/>
{if $parseValue and !empty($parseValue.label) and $parseValue.label!='no'} {if $nomenclatureTable}
{assign var=clabel value=$parseValue.label} {if $parseValue and !empty($parseValue.label) and $parseValue.label!='no'}
<img class='LSformElement_supannLabeledValue_label' src='{img name="supann_label_$clabel"}' alt='[{$clabel|escape:"htmlall"}]' title='{$clabel|escape:"htmlall"}'/> {assign var=clabel value=$parseValue.label}
{/if} <img class='LSformElement_supannLabeledValue_label' src='{img name="supann_label_$clabel"}' alt='[{$clabel|escape:"htmlall"}]' title='{$clabel|escape:"htmlall"}'/>
{if $parseValue} {/if}
<span title='{$parseValue.value|escape:"htmlall"}'>{$parseValue.translated|escape:"htmlall"}</span> {if $parseValue}
<span title='{$parseValue.value|escape:"htmlall"}'>{$parseValue.translated|escape:"htmlall"}</span>
{else}
<span>{$noValueTxt|escape:"htmlall"}</span>
{/if}
{else} {else}
<span>{$noValueTxt|escape:"htmlall"}</span> {if $possibleLabels}
<select class='LSformElement_supannLabeledValue_label'>
{if $parseValue}
{html_options options=$possibleLabels selected=$parseValue.label}
{else}
{html_options options=$possibleLabels}
{/if}
</select>
{else}
<input type='text' class='LSformElement_supannLabeledValue_label'{if $parseValue} value='{$parseValue.label|escape:"htmlall"}'{/if}/>
{/if}
{if $valueFieldType == 'textarea'}
<textarea class='LSformElement_supannLabeledValue_value'>{if $parseValue}{$parseValue.translated|escape:"htmlall"}{/if}</textarea>
{else}
<input type='text' class='LSformElement_supannLabeledValue_value'{if $parseValue} value='{$parseValue.translated|escape:"htmlall"}'{/if}/>
{/if}
{/if} {/if}
{/if} {/if}