From 05fe7f0042e800b7a751045a6611454fe2be14db Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Thu, 16 Oct 2008 12:01:26 +0000 Subject: [PATCH] =?UTF-8?q?-=20LSdefault=20:=20=20=20->=20Ajout=20de=20la?= =?UTF-8?q?=20m=C3=A9thode=20getParams()=20-=20LSformElement=5Fpassword=20?= =?UTF-8?q?:=20=20=20->=20Refonte=20en=20utilisant=20les=20templates=20=20?= =?UTF-8?q?=20->=20Refonte=20Javascript=20en=20utilisant=20les=20JSparams?= =?UTF-8?q?=20via=20LSdefault=20et=20creation=20d'un=20=20=20=20=20=20LSfo?= =?UTF-8?q?rmElement=5Fpassword=5Ffield?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../class/class.LSformElement_password.php | 50 ++---- trunk/includes/js/LSdefault.js | 7 + trunk/includes/js/LSformElement_password.js | 152 ++---------------- trunk/index_ajax.php | 11 +- .../default/LSformElement_password.tpl | 3 + .../default/LSformElement_password_field.tpl | 5 + 6 files changed, 41 insertions(+), 187 deletions(-) create mode 100644 trunk/templates/default/LSformElement_password.tpl create mode 100644 trunk/templates/default/LSformElement_password_field.tpl diff --git a/trunk/includes/class/class.LSformElement_password.php b/trunk/includes/class/class.LSformElement_password.php index cb33351f..4d710e88 100644 --- a/trunk/includes/class/class.LSformElement_password.php +++ b/trunk/includes/class/class.LSformElement_password.php @@ -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 = "\n"; - } - - $id = "LSformElement_password_".$this -> name."_".$numberId; - $return['html'] = "\n"; - $return['html'] .= $autogenerate_html; - $id = "LSformElement_password_view_btn_".$this -> name."_".$numberId; - $return['html'] .= "\n"; - if (!$this -> attr_html -> attribute -> ldapObject-> isNew()) { - $id = "LSformElement_password_verify_btn_".$this -> name."_".$numberId; - $return['html'] .= "\"".('Vérifier\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; } diff --git a/trunk/includes/js/LSdefault.js b/trunk/includes/js/LSdefault.js index d5aa5cca..9edbe29b 100644 --- a/trunk/includes/js/LSdefault.js +++ b/trunk/includes/js/LSdefault.js @@ -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(); } }); diff --git a/trunk/includes/js/LSformElement_password.js b/trunk/includes/js/LSformElement_password.js index dd7dd583..e82d8d23 100644 --- a/trunk/includes/js/LSformElement_password.js +++ b/trunk/includes/js/LSformElement_password.js @@ -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() { diff --git a/trunk/index_ajax.php b/trunk/index_ajax.php index 9eacdad9..44f8557d 100644 --- a/trunk/index_ajax.php +++ b/trunk/index_ajax.php @@ -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 { diff --git a/trunk/templates/default/LSformElement_password.tpl b/trunk/templates/default/LSformElement_password.tpl new file mode 100644 index 00000000..5b53d8c3 --- /dev/null +++ b/trunk/templates/default/LSformElement_password.tpl @@ -0,0 +1,3 @@ + diff --git a/trunk/templates/default/LSformElement_password_field.tpl b/trunk/templates/default/LSformElement_password_field.tpl new file mode 100644 index 00000000..dd80297c --- /dev/null +++ b/trunk/templates/default/LSformElement_password_field.tpl @@ -0,0 +1,5 @@ +{if $freeze} +******** +{else} + +{/if}