mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-12-22 16:33:48 +01:00
- 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:
parent
5c6e8ada08
commit
05fe7f0042
6 changed files with 41 additions and 187 deletions
|
@ -31,6 +31,9 @@
|
|||
*/
|
||||
|
||||
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
|
||||
|
@ -67,49 +70,22 @@ class LSformElement_password extends LSformElement {
|
|||
function getDisplay(){
|
||||
$GLOBALS['LSsession'] -> addCssFile('LSformElement_password.css');
|
||||
$return = $this -> getLabelInfos();
|
||||
$pwd = "";
|
||||
if (!$this -> isFreeze()) {
|
||||
$numberId=rand();
|
||||
$value_txt='';
|
||||
$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;
|
||||
$return['html'] = "<input type='$input_type' name='".$this -> name."[]' $value_txt id='$id' $class_txt/>\n";
|
||||
$return['html'] .= $autogenerate_html;
|
||||
$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";
|
||||
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 (($this -> params['html_options']['generationTool'])&&($this -> params['html_options']['autoGenerate'])&&(empty($this -> values))) {
|
||||
$pwd=$this->generatePassword();
|
||||
}
|
||||
|
||||
if (!empty($this -> values)) {
|
||||
$return['html'] .= "* "._('Modification uniquement').".";
|
||||
}
|
||||
$params = array(
|
||||
'generate' => ($this -> params['html_options']['generationTool']==True),
|
||||
'verify' => (!$this -> attr_html -> attribute -> ldapObject-> isNew())
|
||||
);
|
||||
$GLOBALS['LSsession'] -> addJSconfigParam($this -> name,$params);
|
||||
|
||||
$GLOBALS['LSsession'] -> addJSscript('LSformElement_password_field.js');
|
||||
$GLOBALS['LSsession'] -> addJSscript('LSformElement_password.js');
|
||||
}
|
||||
else {
|
||||
if (empty($this -> values)) {
|
||||
$return['html'] = _('Aucune valeur definie');
|
||||
}
|
||||
else {
|
||||
$return['html'] = "********";
|
||||
}
|
||||
|
||||
}
|
||||
$return['html'] = $this -> fetchTemplate(NULL,array('pwd' => $pwd));
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
|
|
@ -167,6 +167,13 @@ var LSdefault = new Class({
|
|||
|
||||
imagePath: function(image) {
|
||||
return this.LSjsConfig['LS_IMAGES_DIR'] + '/' + image;
|
||||
},
|
||||
|
||||
getParams: function(name) {
|
||||
if ($type(this.LSjsConfig[name])) {
|
||||
return this.LSjsConfig[name];
|
||||
}
|
||||
return new Hash();
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -1,149 +1,15 @@
|
|||
var LSformElement_password = new Class({
|
||||
initialize: function(){
|
||||
this.LSformElement_password_generate_inputHistory = [];
|
||||
$$('img.LSformElement_password_generate_btn').each(function(el) {
|
||||
el.addEvent('click',this.onLSformElement_password_generate_btnClick.bind(this,el));
|
||||
this.fields=new Hash();
|
||||
this.initialiseLSformElement_password();
|
||||
},
|
||||
|
||||
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);
|
||||
|
||||
$$('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() {
|
||||
|
|
|
@ -83,7 +83,7 @@ if (!isset($_ERRORS)) {
|
|||
}
|
||||
break;
|
||||
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'])) {
|
||||
$object = new $_REQUEST['objecttype']();
|
||||
$form = $object -> getForm($_REQUEST['idform']);
|
||||
|
@ -91,9 +91,7 @@ if (!isset($_ERRORS)) {
|
|||
$val = $field -> generatePassword();
|
||||
if ( $val ) {
|
||||
$data = array(
|
||||
'generatePassword' => $val,
|
||||
'fieldId' => $_REQUEST['fieldId'],
|
||||
'viewBtnId' => $_REQUEST['viewBtnId']
|
||||
'generatePassword' => $val
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -103,7 +101,7 @@ if (!isset($_ERRORS)) {
|
|||
}
|
||||
break;
|
||||
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'])) {
|
||||
$object = new $_REQUEST['objecttype']();
|
||||
$form = $object -> getForm($_REQUEST['idform']);
|
||||
|
@ -111,8 +109,7 @@ if (!isset($_ERRORS)) {
|
|||
$field=$form -> getElement($_REQUEST['attribute']);
|
||||
$val = $field -> verifyPassword($_REQUEST['fieldValue']);
|
||||
$data = array(
|
||||
'verifyPassword' => $val,
|
||||
'fieldId' => $_REQUEST['fieldId']
|
||||
'verifyPassword' => $val
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
|
3
trunk/templates/default/LSformElement_password.tpl
Normal file
3
trunk/templates/default/LSformElement_password.tpl
Normal file
|
@ -0,0 +1,3 @@
|
|||
<ul class='LSform' id='{$attr_name}'>
|
||||
<li>{include file=$fieldTemplate}</li>
|
||||
</ul>
|
5
trunk/templates/default/LSformElement_password_field.tpl
Normal file
5
trunk/templates/default/LSformElement_password_field.tpl
Normal file
|
@ -0,0 +1,5 @@
|
|||
{if $freeze}
|
||||
********
|
||||
{else}
|
||||
<input type='password' name='{$attr_name}[]' value="{$pwd}" class='LSformElement_password'/>
|
||||
{/if}
|
Loading…
Reference in a new issue