- LSdefault :

-> Ajout de la méthode getParams()
- LSformElement_password :
  -> Refonte en utilisant les templates
  -> Refonte Javascript en utilisant les JSparams via LSdefault et creation d'un
     LSformElement_password_field
This commit is contained in:
Benjamin Renard 2008-10-16 12:01:26 +00:00
parent 5c6e8ada08
commit 05fe7f0042
6 changed files with 41 additions and 187 deletions

View file

@ -32,6 +32,9 @@
class LSformElement_password extends LSformElement { class LSformElement_password extends LSformElement {
var $fieldTemplate = 'LSformElement_password_field.tpl';
var $template = 'LSformElement_password.tpl';
/** /**
* Recupère la valeur de l'élement passée en POST * Recupère la valeur de l'élement passée en POST
* *
@ -67,49 +70,22 @@ class LSformElement_password extends LSformElement {
function getDisplay(){ function getDisplay(){
$GLOBALS['LSsession'] -> addCssFile('LSformElement_password.css'); $GLOBALS['LSsession'] -> addCssFile('LSformElement_password.css');
$return = $this -> getLabelInfos(); $return = $this -> getLabelInfos();
$pwd = "";
if (!$this -> isFreeze()) { if (!$this -> isFreeze()) {
$numberId=rand(); if (($this -> params['html_options']['generationTool'])&&($this -> params['html_options']['autoGenerate'])&&(empty($this -> values))) {
$value_txt=''; $pwd=$this->generatePassword();
$input_type='password';
$autogenerate_html='';
$class_txt='';
// AutoGenerate
if (($this -> params['html_options']['generationTool'])||(!isset($this -> params['html_options']['generationTool']))) {
if (($this -> params['html_options']['autoGenerate'])&&(empty($this -> values))) {
$value_txt="value='".$this->generatePassword()."'";
$input_type='text';
}
$class_txt="class='LSformElement_password_generate'";
$id = "LSformElement_password_generate_btn_".$this -> name."_".$numberId;
$autogenerate_html = "<img src='".LS_IMAGES_DIR."/generate.png' id='$id' class='LSformElement_password_generate_btn'/>\n";
} }
$id = "LSformElement_password_".$this -> name."_".$numberId; $params = array(
$return['html'] = "<input type='$input_type' name='".$this -> name."[]' $value_txt id='$id' $class_txt/>\n"; 'generate' => ($this -> params['html_options']['generationTool']==True),
$return['html'] .= $autogenerate_html; 'verify' => (!$this -> attr_html -> attribute -> ldapObject-> isNew())
$id = "LSformElement_password_view_btn_".$this -> name."_".$numberId; );
$return['html'] .= "<img src='".LS_IMAGES_DIR."/view.png' id='$id' class='LSformElement_password_view_btn'/>\n"; $GLOBALS['LSsession'] -> addJSconfigParam($this -> name,$params);
if (!$this -> attr_html -> attribute -> ldapObject-> isNew()) {
$id = "LSformElement_password_verify_btn_".$this -> name."_".$numberId;
$return['html'] .= "<img src='".LS_IMAGES_DIR."/verify.png' id='$id' class='LSformElement_password_verify_btn' alt=\"".('Vérifier le mot de passe')."\" title=\"".('Vérifier le mot de passe')."\" />\n";
}
if (!empty($this -> values)) {
$return['html'] .= "* "._('Modification uniquement').".";
}
$GLOBALS['LSsession'] -> addJSscript('LSformElement_password_field.js');
$GLOBALS['LSsession'] -> addJSscript('LSformElement_password.js'); $GLOBALS['LSsession'] -> addJSscript('LSformElement_password.js');
} }
else { $return['html'] = $this -> fetchTemplate(NULL,array('pwd' => $pwd));
if (empty($this -> values)) {
$return['html'] = _('Aucune valeur definie');
}
else {
$return['html'] = "********";
}
}
return $return; return $return;
} }

View file

@ -167,6 +167,13 @@ var LSdefault = new Class({
imagePath: function(image) { imagePath: function(image) {
return this.LSjsConfig['LS_IMAGES_DIR'] + '/' + image; return this.LSjsConfig['LS_IMAGES_DIR'] + '/' + image;
},
getParams: function(name) {
if ($type(this.LSjsConfig[name])) {
return this.LSjsConfig[name];
}
return new Hash();
} }
}); });

View file

@ -1,149 +1,15 @@
var LSformElement_password = new Class({ var LSformElement_password = new Class({
initialize: function(){ initialize: function(){
this.LSformElement_password_generate_inputHistory = []; this.fields=new Hash();
$$('img.LSformElement_password_generate_btn').each(function(el) { this.initialiseLSformElement_password();
el.addEvent('click',this.onLSformElement_password_generate_btnClick.bind(this,el)); },
initialiseLSformElement_password: function() {
var getName = /^(.*)\[\]$/
$$('input.LSformElement_password').each(function(input) {
var name = getName.exec(input.name)[1];
this.fields[name] = new LSformElement_password_field(name,input);
}, this); }, this);
$$('img.LSformElement_password_view_btn').each(function(el) {
el.addEvent('click',this.onLSformElement_password_view_btnClick.bind(this,el));
}, this);
this.LSformElement_password_background_color = [];
$$('img.LSformElement_password_verify_btn').each(function(el) {
el.addEvent('click',this.onLSformElement_password_verify_btnClick.bind(this,el));
}, this);
this.initialiseLSformElement_password_generate();
},
initialiseLSformElement_password_generate: function() {
$$('input.LSformElement_password_generate').each(function(el) {
this.LSformElement_password_background_color[el.id] = el.getStyle('background-color');
el.addEvent('click',this.onLSformElement_password_verify_inputClick.bind(this,el));
el.addEvent('keyup',this.onLSformElement_password_generate_inputKeyUp.bind(this,el));
}, this);
},
onLSformElement_password_generate_btnClick: function(img) {
var getAttrNameAndId = /LSformElement_password_generate_btn_(.*)_([0-9]*)/
var getAttrNameAndIdValues = getAttrNameAndId.exec(img.id);
var attrName = getAttrNameAndIdValues[1];
var fieldId = 'LSformElement_password_' + attrName + '_' + getAttrNameAndIdValues[2];
var viewBtnId = 'LSformElement_password_view_btn_' + attrName + '_' + getAttrNameAndIdValues[2];
var data = {
template: 'LSform',
action: 'generatePassword',
attribute: attrName,
objecttype: $('LSform_objecttype').value,
idform: $('LSform_idform').value,
viewBtnId: viewBtnId,
fieldId: fieldId
};
data.imgload=varLSdefault.loadingImgDisplay(img);
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onLSformElement_password_generate_btnClickComplete.bind(this)}).send();
},
onLSformElement_password_generate_btnClickComplete: function(responseText, responseXML) {
var data = JSON.decode(responseText);
if ( varLSdefault.checkAjaxReturn(data) ) {
this.changeInputType($(data.fieldId),'text');
$(data.fieldId).value=data.generatePassword;
$(data.viewBtnId).setProperty('src',varLSdefault.imagePath('hide.png'));
this.LSformElement_password_generate_inputHistory[data.fieldId]=data.generatePassword;
}
},
onLSformElement_password_generate_inputKeyUp: function(input) {
if (input.type=='text') {
if((this.LSformElement_password_generate_inputHistory[input.id]!=input.value)&&(typeof(this.LSformElement_password_generate_inputHistory[input.id])!='undefined')&&(this.LSformElement_password_generate_inputHistory[input.id]!='')) {
this.onLSformElement_password_generate_inputModify(input);
}
}
},
onLSformElement_password_generate_inputModify: function(input) {
input.value='';
input = this.changeInputType(input,'password');
var getAttrNameAndId = /LSformElement_password_(.*)_([0-9]*)/
var attrNameAndId = getAttrNameAndId.exec(input.id);
var viewBtnId = 'LSformElement_password_view_btn_' + attrNameAndId[1] + '_' + attrNameAndId[2];
$(viewBtnId).setProperty('src',varLSdefault.imagePath('view.png'));
this.LSformElement_password_generate_inputHistory[input.id]='';
input.focus();
},
onLSformElement_password_view_btnClick: function(img) {
var getAttrNameAndId = /LSformElement_password_view_btn_(.*)_([0-9]*)/
var getAttrNameAndIdValues = getAttrNameAndId.exec(img.id);
var attrName = getAttrNameAndIdValues[1];
var fieldId = 'LSformElement_password_' + attrName + '_' + getAttrNameAndIdValues[2];
input = $(fieldId);
if (input.type=='password') {
input = this.changeInputType(input,'text');
img.setProperty('src',varLSdefault.imagePath('hide.png'));
}
else {
input = this.changeInputType(input,'password');
img.setProperty('src',varLSdefault.imagePath('view.png'));
}
input.focus();
},
changeInputType: function(input,newType) {
var newInput = new Element('input');
newInput.setProperty('name',input.getProperty('name'));
newInput.setProperty('type',newType);
newInput.setProperty('class',input.getProperty('class'));
newInput.setProperty('id',input.getProperty('id'));
newInput.setProperty('value',input.getProperty('value'));
newInput.injectAfter(input);
input.destroy();
this.initialiseLSformElement_password_generate();
return newInput;
},
onLSformElement_password_verify_btnClick: function(img) {
var getAttrNameAndId = /LSformElement_password_verify_btn_(.*)_([0-9]*)/
var getAttrNameAndIdValues = getAttrNameAndId.exec(img.id);
var attrName = getAttrNameAndIdValues[1];
var fieldId = 'LSformElement_password_' + attrName + '_' + getAttrNameAndIdValues[2];
var verifyBtnId = 'LSformElement_password_verify_btn_' + attrName + '_' + getAttrNameAndIdValues[2];
var data = {
template: 'LSform',
action: 'verifyPassword',
attribute: attrName,
objecttype: $('LSform_objecttype').value,
idform: $('LSform_idform').value,
fieldId: fieldId,
fieldValue: $(fieldId).value,
objectdn: $('LSform_objectdn').value
};
LSdebug(data);
data.imgload=varLSdefault.loadingImgDisplay(img);
new Request({url: 'index_ajax.php', data: data, onSuccess: this.onLSformElement_password_verify_btnClickComplete.bind(this)}).send();
},
onLSformElement_password_verify_btnClickComplete: function(responseText, responseXML) {
var data = JSON.decode(responseText);
if ( varLSdefault.checkAjaxReturn(data) ) {
if (data.verifyPassword) {
// ok
$(data.fieldId).setStyle('background-color','#73F386');
}
else {
// nok
$(data.fieldId).setStyle('background-color','#f59a67');
}
}
},
onLSformElement_password_verify_inputClick: function(input) {
input.setStyle('background-color',this.LSformElement_password_background_color[input.id]);
} }
}); });
window.addEvent(window.ie ? 'load' : 'domready', function() { window.addEvent(window.ie ? 'load' : 'domready', function() {

View file

@ -83,7 +83,7 @@ if (!isset($_ERRORS)) {
} }
break; break;
case 'generatePassword': case 'generatePassword':
if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['viewBtnId'])) && (isset($_REQUEST['fieldId'])) && (isset($_REQUEST['idform'])) ) { if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['idform'])) ) {
if ($GLOBALS['LSsession'] -> loadLSobject($_REQUEST['objecttype'])) { if ($GLOBALS['LSsession'] -> loadLSobject($_REQUEST['objecttype'])) {
$object = new $_REQUEST['objecttype'](); $object = new $_REQUEST['objecttype']();
$form = $object -> getForm($_REQUEST['idform']); $form = $object -> getForm($_REQUEST['idform']);
@ -91,9 +91,7 @@ if (!isset($_ERRORS)) {
$val = $field -> generatePassword(); $val = $field -> generatePassword();
if ( $val ) { if ( $val ) {
$data = array( $data = array(
'generatePassword' => $val, 'generatePassword' => $val
'fieldId' => $_REQUEST['fieldId'],
'viewBtnId' => $_REQUEST['viewBtnId']
); );
} }
} }
@ -103,7 +101,7 @@ if (!isset($_ERRORS)) {
} }
break; break;
case 'verifyPassword': case 'verifyPassword':
if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['fieldId'])) && (isset($_REQUEST['fieldValue'])) && (isset($_REQUEST['idform'])) && (isset($_REQUEST['objectdn'])) ) { if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['fieldValue'])) && (isset($_REQUEST['idform'])) && (isset($_REQUEST['objectdn'])) ) {
if ($GLOBALS['LSsession'] -> loadLSobject($_REQUEST['objecttype'])) { if ($GLOBALS['LSsession'] -> loadLSobject($_REQUEST['objecttype'])) {
$object = new $_REQUEST['objecttype'](); $object = new $_REQUEST['objecttype']();
$form = $object -> getForm($_REQUEST['idform']); $form = $object -> getForm($_REQUEST['idform']);
@ -111,8 +109,7 @@ if (!isset($_ERRORS)) {
$field=$form -> getElement($_REQUEST['attribute']); $field=$form -> getElement($_REQUEST['attribute']);
$val = $field -> verifyPassword($_REQUEST['fieldValue']); $val = $field -> verifyPassword($_REQUEST['fieldValue']);
$data = array( $data = array(
'verifyPassword' => $val, 'verifyPassword' => $val
'fieldId' => $_REQUEST['fieldId']
); );
} }
else { else {

View file

@ -0,0 +1,3 @@
<ul class='LSform' id='{$attr_name}'>
<li>{include file=$fieldTemplate}</li>
</ul>

View file

@ -0,0 +1,5 @@
{if $freeze}
********
{else}
<input type='password' name='{$attr_name}[]' value="{$pwd}" class='LSformElement_password'/>
{/if}