- LSformElement_date

-> Refonte en utilisant les templates
- LSformElement_ssh_key
	-> Correction du fieldTemplate qui ne prévoyait pas une valeur vide
This commit is contained in:
Benjamin Renard 2008-10-16 15:00:21 +00:00
parent 7ee28a4a78
commit f5bfa2e5e3
4 changed files with 26 additions and 57 deletions

View file

@ -32,6 +32,8 @@
class LSformElement_date extends LSformElement {
var $fieldTemplate = 'LSformElement_date_field.tpl';
var $_php2js_format = array(
"a" => "a",
"A" => "A",
@ -132,18 +134,12 @@ class LSformElement_date extends LSformElement {
$return = $this -> getLabelInfos();
// value
if (!$this -> isFreeze()) {
$return['html'] = "<ul class='LSform'>\n";
if (empty($this -> values)) {
$return['html'] .= "<li>".$this -> getEmptyField()."</li>\n";
}
else {
foreach ($this -> values as $value) {
$multiple = $this -> getMultipleData();
$id = "LSform_".$this -> name."_".rand();
$return['html'] .= "<li><input type='text' name='".$this -> name."[]' value=\"".$value."\" id='".$id."'>".$this -> getBtnHTML().$multiple."</li>\n";
}
}
$return['html'] .= "</ul>\n";
$params = array(
'format' => $this -> php2js_format($this -> getFormat()),
'firstDayOfWeek' => $this -> getFirstDayOfWeek()
);
$GLOBALS['LSsession'] -> addJSconfigParam($this -> name,$params);
$GLOBALS['LSsession'] -> addCssFile('theme.css',LS_LIB_DIR.'jscalendar/skins/aqua/');
$GLOBALS['LSsession'] -> addJSscript('calendar.js',LS_LIB_DIR.'jscalendar/');
$GLOBALS['LSsession'] -> addJSscript('calendar-en.js',LS_LIB_DIR.'jscalendar/lang/');
@ -152,44 +148,9 @@ class LSformElement_date extends LSformElement {
$GLOBALS['LSsession'] -> addJSscript('LSformElement_date_field.js');
$GLOBALS['LSsession'] -> addJSscript('LSformElement_date.js');
}
else {
$return['html'] = "<ul class='LSform'>\n";
if (empty($this -> values)) {
$return['html'] .= "<li>"._('Aucune valeur definie')."</li>\n";
}
else {
foreach ($this -> values as $value) {
$return['html'] .= "<li>".$value."</li>\n";
}
}
$return['html'] .= "</ul>\n";
}
$return['html'] = $this -> fetchTemplate();
return $return;
}
/**
* Retourne le code HTML d'un champ vide
*
* @retval string Code HTML d'un champ vide.
*/
function getEmptyField() {
$multiple = $this -> getMultipleData();
return "<input type='text' name='".$this -> name."[]' id='LSform_".$this -> name."_".rand()."'>".$this -> getBtnHTML().$multiple;
}
/**
* Retour le code HTML du bouton
*
* @retval string Code HTML du bouton
*/
function getBtnHTML() {
$id = "LSformElement_data_calendar_btn_".rand();
$params = array(
'format' => $this -> php2js_format($this -> getFormat()),
'firstDayOfWeek' => $this -> getFirstDayOfWeek()
);
$GLOBALS['LSsession'] -> addJSconfigParam($id,$params);
return "<img id='$id' class='LSformElement_date_calendar_btn btn' src='".LS_IMAGES_DIR."/calendar.png' title='"._('Calendrier')."' alt='"._('Calendrier')."'/>";
}
/**
* Retourne le nurméro du premier jour de la semaine

View file

@ -2,17 +2,19 @@ var LSformElement_date = new Class({
initialize: function(){
this.fields = [];
this.initialiseLSformElement_date();
if (typeof(varLSform) != "undefined") {
if ($type(varLSform)) {
varLSform.addModule("LSformElement_date",this);
}
},
initialiseLSformElement_date: function(el) {
if (typeof(el) == 'undefined') {
if (!$type(el)) {
el = document;
}
el.getElements('img.LSformElement_date_calendar_btn').each(function(btn) {
this.fields[btn.id] = new LSformElement_date_field(btn);
var getName = /^(.*)\[\]$/
el.getElements('input.LSformElement_date').each(function(input) {
var name = getName.exec(input.name)[1];
this.fields[name] = new LSformElement_date_field(name,input);
}, this);
},

View file

@ -1,10 +1,15 @@
var LSformElement_date_field = new Class({
initialize: function(calendarBtn){
this.calendarBtn = calendarBtn;
initialize: function(name,input){
this.name = name;
this.input = input;
this.calendarBtn = new Element('img');
this.calendarBtn.src = varLSdefault.imagePath('calendar.png');
this.calendarBtn.addClass('btn');
this.calendarBtn.addEvent('click',this.onCalendarBtnClick.bind(this));
this.calendarBtn.injectAfter(this.input);
// Récupération des paramètres à partir de l'attribut 'rem' du bouton
this.params = varLSdefault.LSjsConfig[this.calendarBtn.id];
this.params = varLSdefault.LSjsConfig[this.name];
if (!$type(this.params)) {
this.params={};
}
@ -15,7 +20,6 @@ var LSformElement_date_field = new Class({
this.params.firstDayOfWeek=0;
}
this.input = calendarBtn.getParent().getFirst();
this.input.addEvent('click',this.onCalendarBtnClick.bind(this));
this.date = Date.parseDate(this.input.value,this.params.format);

View file

@ -1,8 +1,10 @@
{if $freeze}
{if $value.type}
<span class='LSformElement_ssh_key_short_display' title='{$span_title}'>{$value.shortTxt}...</span> (Type : {$value.type}) <a href='mailto:{$value.mail}'>{$value.mail}</a><p class='LSformElement_ssh_key_value'>{$value.value}</p>
{else}
{elseif $value.shortTxt}
<span class='LSformElement_ssh_key_short_display'>{$value.shortTxt}...</span> ({$unknowTypeTxt})<p class='LSformElement_ssh_key_value'>{$value.value}</p>
{else}
{$noValueTxt}
{/if}
{else}
<textarea name='{$attr_name}[]' class='LSform LSformElement_ssh_key'>{$value}</textarea>