From f5bfa2e5e3474488c2d374e52435a02dbae04919 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Thu, 16 Oct 2008 15:00:21 +0000 Subject: [PATCH] =?UTF-8?q?-=20LSformElement=5Fdate=20=09->=20Refonte=20en?= =?UTF-8?q?=20utilisant=20les=20templates=20-=20LSformElement=5Fssh=5Fkey?= =?UTF-8?q?=20=09->=20Correction=20du=20fieldTemplate=20qui=20ne=20pr?= =?UTF-8?q?=C3=A9voyait=20pas=20une=20valeur=20vide?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../class/class.LSformElement_date.php | 57 +++---------------- trunk/includes/js/LSformElement_date.js | 10 ++-- trunk/includes/js/LSformElement_date_field.js | 12 ++-- .../default/LSformElement_ssh_key_field.tpl | 4 +- 4 files changed, 26 insertions(+), 57 deletions(-) diff --git a/trunk/includes/class/class.LSformElement_date.php b/trunk/includes/class/class.LSformElement_date.php index 36c1aba5..3594643d 100644 --- a/trunk/includes/class/class.LSformElement_date.php +++ b/trunk/includes/class/class.LSformElement_date.php @@ -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'] = "\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'] = "\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 "".$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 ""._("; - } /** * Retourne le nurméro du premier jour de la semaine diff --git a/trunk/includes/js/LSformElement_date.js b/trunk/includes/js/LSformElement_date.js index d8fc4699..e51d350d 100644 --- a/trunk/includes/js/LSformElement_date.js +++ b/trunk/includes/js/LSformElement_date.js @@ -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); }, diff --git a/trunk/includes/js/LSformElement_date_field.js b/trunk/includes/js/LSformElement_date_field.js index 48a8d63a..9bbb87e0 100644 --- a/trunk/includes/js/LSformElement_date_field.js +++ b/trunk/includes/js/LSformElement_date_field.js @@ -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); diff --git a/trunk/templates/default/LSformElement_ssh_key_field.tpl b/trunk/templates/default/LSformElement_ssh_key_field.tpl index 2fcf1c7c..6a4cef82 100644 --- a/trunk/templates/default/LSformElement_ssh_key_field.tpl +++ b/trunk/templates/default/LSformElement_ssh_key_field.tpl @@ -1,8 +1,10 @@ {if $freeze} {if $value.type} {$value.shortTxt}... (Type : {$value.type}) {$value.mail}

{$value.value}

- {else} + {elseif $value.shortTxt} {$value.shortTxt}... ({$unknowTypeTxt})

{$value.value}

+ {else} + {$noValueTxt} {/if} {else}