- 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' => array (
'ajaxSubmit' => 1,
// Layout
'layout' => array (
'Civilite' => array(

View file

@ -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()) {

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;
}

View file

@ -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) {

View file

@ -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()) {