- LSform :

-> Ajout de la possibilité de désactiver l'envoi d'un formulaire par Ajax
	-> Désactivation automatique de l'envoi d'un formulaire par Ajax lorsqu'un
		 champs input de type file possède une valeur.
	-> Les onglets vides sont désormais cachés.
- Vues create et modify : Ajout du support de retour non-ajax dans le cas d'une
	erreur de validation du formulaire.
This commit is contained in:
Benjamin Renard 2009-02-12 10:04:50 +00:00
parent e885ccd5ac
commit 5980693fc1
5 changed files with 81 additions and 31 deletions

View file

@ -68,6 +68,7 @@ $GLOBALS['LSobjects']['LSeepeople'] = array (
// LSform // LSform
'LSform' => array ( 'LSform' => array (
'ajaxSubmit' => 1,
// Layout // Layout
'layout' => array ( 'layout' => array (
'Civilite' => array( 'Civilite' => array(

View file

@ -64,12 +64,17 @@ if(LSsession :: startLSsession()) {
} }
} }
else { else {
LSsession :: displayAjaxReturn ( if (isset($_REQUEST['ajax'])) {
array( LSsession :: displayAjaxReturn (
'LSformErrors' => $form -> getErrors() array(
) 'LSformErrors' => $form -> getErrors()
); )
exit(); );
exit();
}
else {
LSsession :: displayTemplate();
}
} }
} }
else if (isset($_REQUEST['ajax']) && $form -> definedError()) { else if (isset($_REQUEST['ajax']) && $form -> definedError()) {

View file

@ -210,6 +210,9 @@ class LSldapObject {
} }
} }
} }
LSsession :: addJSconfigParam('LSform_'.$idForm,array(
'ajaxSubmit' => ((isset($this -> config['LSform']['ajaxSubmit']))?$this -> config['LSform']['ajaxSubmit']:1)
));
return $LSform; return $LSform;
} }

View file

@ -14,6 +14,7 @@ var LSform = new Class({
}, },
initializeLSform: function(el) { initializeLSform: function(el) {
this.params={};
if (this.idform) { if (this.idform) {
if (typeof(el) == 'undefined') { if (typeof(el) == 'undefined') {
el = document; el = document;
@ -21,19 +22,17 @@ var LSform = new Class({
el.getElements('ul.LSform').each(function(ul) { el.getElements('ul.LSform').each(function(ul) {
this._elements[ul.id] = new LSformElement(this,ul.id,ul); this._elements[ul.id] = new LSformElement(this,ul.id,ul);
}, this); }, 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'); LSforms = $$('form.LSform');
if ($type(LSforms[0])) { if ($type(LSforms[0])) {
this.LSform = 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)); this.LSform.addEvent('submit',this.ajaxSubmit.bindWithEvent(this));
} }
}, },
@ -45,6 +44,18 @@ var LSform = new Class({
var LIs = $$('li.LSform_layout'); var LIs = $$('li.LSform_layout');
LIs.each(function(li) { 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)); li.getFirst('a').addEvent('click',this.onTabBtnClick.bindWithEvent(this,li));
},this); },this);
@ -159,18 +170,43 @@ var LSform = new Class({
}, },
ajaxSubmit: function(event) { ajaxSubmit: function(event) {
event = new Event(event); this.checkUploadFileDefined();
event.stop();
if (this._ajaxSubmit) {
this.resetErrors(); event = new Event(event);
event.stop();
this.LSform.set('send',{
data: this.LSform, this.LSformAjaxInput = new Element('input');
onSuccess: this.onAjaxSubmitComplete.bind(this), this.LSformAjaxInput.setProperties ({
url: this.LSform.get('action'), type: 'hidden',
imgload: varLSdefault.loadingImgDisplay($('LSform_title'),'inside') name: 'ajax',
}); value: '1'
this.LSform.send(); });
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) { onAjaxSubmitComplete: function(responseText, responseXML) {

View file

@ -74,11 +74,16 @@ if(LSsession :: startLSsession()) {
} }
} }
else { else {
LSsession :: displayAjaxReturn ( if (isset($_REQUEST['ajax'])) {
array( LSsession :: displayAjaxReturn (
'LSformErrors' => $form -> getErrors() array(
) 'LSformErrors' => $form -> getErrors()
); )
);
}
else {
LSsession :: displayTemplate();
}
} }
} }
else if (isset($_REQUEST['ajax']) && $form -> definedError()) { else if (isset($_REQUEST['ajax']) && $form -> definedError()) {