- LSformElement_select : Refonte en utilisant les templates

- LSformElement_password : Ajout d'un fichier oublié dans le dernier commit
This commit is contained in:
Benjamin Renard 2008-10-16 13:03:45 +00:00
parent 05fe7f0042
commit 6143be5488
4 changed files with 129 additions and 33 deletions

View file

@ -32,6 +32,9 @@
class LSformElement_select extends LSformElement { class LSformElement_select extends LSformElement {
var $template = 'LSformElement_select.tpl';
var $fieldTemplate = 'LSformElement_select.tpl';
/** /**
* Retourn les infos d'affichage de l'élément * Retourn les infos d'affichage de l'élément
* *
@ -41,38 +44,12 @@ class LSformElement_select extends LSformElement {
*/ */
function getDisplay(){ function getDisplay(){
$return = $this -> getLabelInfos(); $return = $this -> getLabelInfos();
// value $params = array();
if (!$this -> isFreeze()) { if (!$this -> isFreeze()) {
if ($this -> params['multiple']==0) {
$multiple_tag='';
}
else {
$multiple_tag='multiple';
}
$return['html'] = "<select name='".$this -> name."[]' $multiple_tag class='LSform'>\n";
foreach ($this -> params['text_possible_values'] as $choice_value => $choice_text) {
if (in_array($choice_value, $this -> values)) {
$selected=' selected';
}
else {
$selected='';
}
$return['html'].="<option value=\"".$choice_value."\"$selected>$choice_text</option>\n";
}
$return['html'].="</select>\n";
$GLOBALS['LSsession'] -> addJSscript('LSformElement_select.js'); $GLOBALS['LSsession'] -> addJSscript('LSformElement_select.js');
} }
else { $params['possible_values'] = $this -> params['text_possible_values'];
$return['html']="<ul class='LSform'>\n"; $return['html'] = $this -> fetchTemplate(NULL,$params);
foreach ($this -> values as $value) {
$return['html'].="<li>".$this -> params['text_possible_values'][$value]."</strong></li>";
}
if (empty($this -> values)) {
$return['html'] .= "<li>"._('Aucune valeur definie')."</li>\n";
}
$return['html'].="</ul>\n";
}
return $return; return $return;
} }

View file

@ -0,0 +1,107 @@
var LSformElement_password_field = new Class({
initialize: function(name,input){
this.name = name;
this.input = input;
this.params = varLSdefault.getParams(this.name);
LSdebug(this.params);
this.initialiseLSformElement_password_field();
},
initialiseLSformElement_password_field: function() {
// ViewBtn
this.viewBtn = new Element('img');
this.viewBtn.src = varLSdefault.imagePath('view.png');
this.viewBtn.addClass('btn');
this.viewBtn.addEvent('click',this.changeInputType.bind(this));
this.viewBtn.injectAfter(this.input);
// Verify
if (this.params['verify']) {
this.bgColor = this.input.getStyle('background-color');
this.verifyFx = new Fx.Tween(this.input,{property: 'background-color',duration:600});
this.verifyBtn = new Element('img');
this.verifyBtn.src = varLSdefault.imagePath('verify.png');
this.verifyBtn.addClass('btn');
this.verifyBtn.addEvent('click',this.onVerifyBtnClick.bind(this));
this.verifyBtn.injectAfter(this.input);
}
if (this.params['generate']) {
this.generateBtn = new Element('img');
this.generateBtn.src = varLSdefault.imagePath('generate.png');
this.generateBtn.addClass('btn');
this.generateBtn.addEvent('click',this.onGenerateBtnClick.bind(this));
this.generateBtn.injectAfter(this.input);
}
},
onGenerateBtnClick: function() {
var data = {
template: 'LSform',
action: 'generatePassword',
attribute: this.name,
objecttype: varLSform.objecttype,
idform: varLSform.idform
};
data.imgload=varLSdefault.loadingImgDisplay(this.generateBtn);
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onGenerateBtnClickComplete.bind(this)}).send();
},
onGenerateBtnClickComplete: function(responseText, responseXML) {
var data = JSON.decode(responseText);
if ( varLSdefault.checkAjaxReturn(data) ) {
this.input.value=data.generatePassword;
this.changeInputType();
}
},
changeInputType: function() {
if (this.input.type=='password') {
var newType = 'text';
this.viewBtn.src=varLSdefault.imagePath('hide.png');
}
else {
var newType = 'password';
this.viewBtn.src=varLSdefault.imagePath('view.png');
}
var newInput = new Element('input');
newInput.setProperty('name',this.input.getProperty('name'));
newInput.setProperty('type',newType);
newInput.setProperty('class',this.input.getProperty('class'));
newInput.setProperty('value',this.input.getProperty('value'));
newInput.injectAfter(this.input);
this.input.destroy();
this.input = newInput;
return newInput;
},
onVerifyBtnClick: function() {
var data = {
template: 'LSform',
action: 'verifyPassword',
attribute: this.name,
objecttype: varLSform.objecttype,
idform: varLSform.idform,
objectdn: varLSform.objectdn,
fieldValue: this.input.value
};
LSdebug(data);
data.imgload=varLSdefault.loadingImgDisplay(this.verifyBtn);
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onVerifyBtnClickComplete.bind(this)}).send();
},
onVerifyBtnClickComplete: function(responseText, responseXML) {
var data = JSON.decode(responseText);
if ( varLSdefault.checkAjaxReturn(data) ) {
if (data.verifyPassword) {
// ok
this.verifyFx.start('#73F386');
}
else {
// nok
this.verifyFx.start('#f59a67');
}
(function(){this.verifyFx.start(this.bgColor);}).delay(1000, this);
}
}
});

View file

@ -4,7 +4,7 @@ var LSformElement_select = new Class({
}, },
initialiseLSformElement_select: function() { initialiseLSformElement_select: function() {
$$('select.LSform').each(function(el) { $$('select.LSformElement_select').each(function(el) {
var btn = new Element('img'); var btn = new Element('img');
btn.setProperties({ btn.setProperties({
src: varLSdefault.imagePath('clear.png'), src: varLSdefault.imagePath('clear.png'),
@ -13,13 +13,12 @@ var LSformElement_select = new Class({
}); });
btn.addClass('btn'); btn.addClass('btn');
btn.setStyle('vertical-align','top'); btn.setStyle('vertical-align','top');
btn.addEvent('click',this.onClearBtnClick.bind(this,btn)); btn.addEvent('click',this.onClearBtnClick.bind(this,el));
btn.injectAfter(el); btn.injectAfter(el);
}, this); }, this);
}, },
onClearBtnClick: function(btn) { onClearBtnClick: function(select) {
var select = btn.getPrevious();
this.resetSelect(select); this.resetSelect(select);
}, },

View file

@ -0,0 +1,13 @@
{if $freeze}
<ul class='LSform'>
{foreach from=$values item=value}
<li>{$possible_values.$value}</li>
{foreachelse}
<li>{$noValueTxt}</li>
{/foreach}
</ul>
{else}
<select name='{$attr_name}[]' {if $multiple}multiple{/if} class='LSformElement_select'>
{html_options options=$possible_values selected=$values}
</select>
{/if}