From 5980693fc1ae24d03163e0abc6f93d8b7c7331ff Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Thu, 12 Feb 2009 10:04:50 +0000 Subject: [PATCH] =?UTF-8?q?-=20LSform=20:=20=09->=20Ajout=20de=20la=20poss?= =?UTF-8?q?ibilit=C3=A9=20de=20d=C3=A9sactiver=20l'envoi=20d'un=20formulai?= =?UTF-8?q?re=20par=20Ajax=20=09->=20D=C3=A9sactivation=20automatique=20de?= =?UTF-8?q?=20l'envoi=20d'un=20formulaire=20par=20Ajax=20lorsqu'un=20=09?= =?UTF-8?q?=09=20champs=20input=20de=20type=20file=20poss=C3=A8de=20une=20?= =?UTF-8?q?valeur.=20=09->=20Les=20onglets=20vides=20sont=20d=C3=A9sormais?= =?UTF-8?q?=20cach=C3=A9s.=20-=20Vues=20create=20et=20modify=20:=20Ajout?= =?UTF-8?q?=20du=20support=20de=20retour=20non-ajax=20dans=20le=20cas=20d'?= =?UTF-8?q?une=20=09erreur=20de=20validation=20du=20formulaire.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LSobjects/config.LSobjects.LSeepeople.php | 1 + trunk/create.php | 17 +++-- trunk/includes/class/class.LSldapObject.php | 3 + trunk/includes/js/LSform.js | 76 ++++++++++++++----- trunk/modify.php | 15 ++-- 5 files changed, 81 insertions(+), 31 deletions(-) diff --git a/trunk/conf/LSobjects/config.LSobjects.LSeepeople.php b/trunk/conf/LSobjects/config.LSobjects.LSeepeople.php index 8d2a5e52..04d1d017 100644 --- a/trunk/conf/LSobjects/config.LSobjects.LSeepeople.php +++ b/trunk/conf/LSobjects/config.LSobjects.LSeepeople.php @@ -68,6 +68,7 @@ $GLOBALS['LSobjects']['LSeepeople'] = array ( // LSform 'LSform' => array ( + 'ajaxSubmit' => 1, // Layout 'layout' => array ( 'Civilite' => array( diff --git a/trunk/create.php b/trunk/create.php index babe40d4..d8ce82ad 100644 --- a/trunk/create.php +++ b/trunk/create.php @@ -64,12 +64,17 @@ if(LSsession :: startLSsession()) { } } else { - LSsession :: displayAjaxReturn ( - array( - 'LSformErrors' => $form -> getErrors() - ) - ); - exit(); + if (isset($_REQUEST['ajax'])) { + LSsession :: displayAjaxReturn ( + array( + 'LSformErrors' => $form -> getErrors() + ) + ); + exit(); + } + else { + LSsession :: displayTemplate(); + } } } else if (isset($_REQUEST['ajax']) && $form -> definedError()) { diff --git a/trunk/includes/class/class.LSldapObject.php b/trunk/includes/class/class.LSldapObject.php index 7c85f061..084bdeef 100644 --- a/trunk/includes/class/class.LSldapObject.php +++ b/trunk/includes/class/class.LSldapObject.php @@ -210,6 +210,9 @@ class LSldapObject { } } } + LSsession :: addJSconfigParam('LSform_'.$idForm,array( + 'ajaxSubmit' => ((isset($this -> config['LSform']['ajaxSubmit']))?$this -> config['LSform']['ajaxSubmit']:1) + )); return $LSform; } diff --git a/trunk/includes/js/LSform.js b/trunk/includes/js/LSform.js index 71c63cac..e2841ca4 100644 --- a/trunk/includes/js/LSform.js +++ b/trunk/includes/js/LSform.js @@ -14,6 +14,7 @@ var LSform = new Class({ }, initializeLSform: function(el) { + this.params={}; if (this.idform) { if (typeof(el) == 'undefined') { el = document; @@ -21,19 +22,17 @@ var LSform = new Class({ el.getElements('ul.LSform').each(function(ul) { this._elements[ul.id] = new LSformElement(this,ul.id,ul); }, this); + this.params=varLSdefault.LSjsConfig['LSform_'+this.idform]; + if (!$type(this.params)) { + this.params={}; + } + this._ajaxSubmit=this.params.ajaxSubmit; + LSdebug(this.params); } LSforms = $$('form.LSform'); if ($type(LSforms[0])) { this.LSform = LSforms[0]; - this.LSformAjaxInput = new Element('input'); - this.LSformAjaxInput.setProperties ({ - type: 'hidden', - name: 'ajax', - value: '1' - }); - this.LSformAjaxInput.injectInside(this.LSform); - this.LSform.addEvent('submit',this.ajaxSubmit.bindWithEvent(this)); } }, @@ -45,6 +44,18 @@ var LSform = new Class({ var LIs = $$('li.LSform_layout'); LIs.each(function(li) { + var Layout = this.getLayout(li); + if ($type(Layout)) { + if ($type(Layout.getElement('dt.LSform-errors'))) { + LSdebug('add'); + li.addClass('LSform_layout_errors'); + } + else { + if (!$type(Layout.getElement('dt'))) { + li.setStyle('display','none'); + } + } + } li.getFirst('a').addEvent('click',this.onTabBtnClick.bindWithEvent(this,li)); },this); @@ -159,18 +170,43 @@ var LSform = new Class({ }, ajaxSubmit: function(event) { - event = new Event(event); - event.stop(); - - this.resetErrors(); - - this.LSform.set('send',{ - data: this.LSform, - onSuccess: this.onAjaxSubmitComplete.bind(this), - url: this.LSform.get('action'), - imgload: varLSdefault.loadingImgDisplay($('LSform_title'),'inside') - }); - this.LSform.send(); + this.checkUploadFileDefined(); + + if (this._ajaxSubmit) { + event = new Event(event); + event.stop(); + + this.LSformAjaxInput = new Element('input'); + this.LSformAjaxInput.setProperties ({ + type: 'hidden', + name: 'ajax', + value: '1' + }); + this.LSformAjaxInput.injectInside(this.LSform); + + this.resetErrors(); + + this.LSform.set('send',{ + data: this.LSform, + onSuccess: this.onAjaxSubmitComplete.bind(this), + url: this.LSform.get('action'), + imgload: varLSdefault.loadingImgDisplay($('LSform_title'),'inside') + }); + this.LSform.send(); + } + else { + if($type(this.LSformAjaxInput)) { + this.LSformAjaxInput.dispose(); + } + } + }, + + checkUploadFileDefined: function() { + this.LSform.getElements('input[type=file]').each(function(ipt) { + if (ipt.files.length!=0) { + this._ajaxSubmit=0; + } + }, this); }, onAjaxSubmitComplete: function(responseText, responseXML) { diff --git a/trunk/modify.php b/trunk/modify.php index cc95d6ca..d7b45328 100644 --- a/trunk/modify.php +++ b/trunk/modify.php @@ -74,11 +74,16 @@ if(LSsession :: startLSsession()) { } } else { - LSsession :: displayAjaxReturn ( - array( - 'LSformErrors' => $form -> getErrors() - ) - ); + if (isset($_REQUEST['ajax'])) { + LSsession :: displayAjaxReturn ( + array( + 'LSformErrors' => $form -> getErrors() + ) + ); + } + else { + LSsession :: displayTemplate(); + } } } else if (isset($_REQUEST['ajax']) && $form -> definedError()) {