- LSform :

-> Envoie des données via une requête Ajax
- Correction des templates et des procédures modify et create pour l'utilisation
	de l'envoie des données via Ajax.
This commit is contained in:
Benjamin Renard 2008-11-09 23:24:46 +00:00
parent 14bb86529f
commit 102cf0ea31
7 changed files with 170 additions and 29 deletions

View file

@ -52,10 +52,36 @@ if($LSsession -> startLSsession()) {
if (!$GLOBALS['LSerror']->errorsDefined()) {
$GLOBALS['LSsession'] -> addInfo(_("L'objet a bien été ajouté."));
}
if ((!LSdebugDefined()) && !$GLOBALS['LSerror']->errorsDefined()) {
$GLOBALS['LSsession'] -> redirect('view.php?LSobject='.$LSobject.'&dn='.$object -> getDn());
if (isset($_REQUEST['ajax'])) {
$GLOBALS['LSsession'] -> displayAjaxReturn (
array(
'LSformRedirect' => 'view.php?LSobject='.$LSobject.'&dn='.$object -> getDn()
)
);
exit();
}
else {
if ((!LSdebugDefined()) && !$GLOBALS['LSerror']->errorsDefined()) {
$GLOBALS['LSsession'] -> redirect('view.php?LSobject='.$LSobject.'&dn='.$object -> getDn());
}
}
}
else {
$GLOBALS['LSsession'] -> displayAjaxReturn (
array(
'LSformErrors' => $form -> getErrors()
)
);
exit();
}
}
else if (isset($_REQUEST['ajax']) && $form -> definedError()) {
$GLOBALS['LSsession'] -> displayAjaxReturn (
array(
'LSformErrors' => $form -> getErrors()
)
);
exit();
}
// Définition du Titre de la page
$GLOBALS['Smarty'] -> assign('pagetitle',_('Nouveau').' : '.$object -> getLabel());
@ -78,7 +104,6 @@ if($LSsession -> startLSsession()) {
else {
$GLOBALS['LSsession'] -> setTemplate('login.tpl');
}
// Affichage des retours d'erreurs
$GLOBALS['LSsession'] -> displayTemplate();
?>

View file

@ -38,6 +38,10 @@ li.LSform_layout_current {
background-color: #433F3A;
}
li.LSform_layout_errors {
background-color: #f59a67;
}
h2.LSform_layout_active {
display: none;
}

View file

@ -38,6 +38,10 @@ li.LSform_layout_current {
background-color: #0072B8;
}
li.LSform_layout_errors {
background-color: #f59a67;
}
h2.LSform_layout_active {
display: none;
}

View file

@ -23,6 +23,20 @@ var LSform = new Class({
this._elements[ul.id] = new LSformElement(this,ul.id,ul);
}, this);
}
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));
}
},
initializeLSformLayout: function(el) {
@ -125,6 +139,74 @@ var LSform = new Class({
},this);
}
return retVal;
},
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();
},
onAjaxSubmitComplete: function(responseText, responseXML) {
var data = JSON.decode(responseText);
if ( varLSdefault.checkAjaxReturn(data) ) {
if ($type(data.LSformRedirect)) {
if (!$type(data.LSdebug)) {
(function(addr){document.location = addr;}).delay(1000,this,data.LSformRedirect);
}
}
else if ($type(data.LSformErrors) == 'object') {
data.LSformErrors = new Hash(data.LSformErrors);
data.LSformErrors.each(this.addError,this);
}
}
},
resetErrors: function() {
$$('dd.LSform-errors').each(function(dd) {
dd.destroy();
});
$$('dt.LSform-errors').each(function(dt) {
dt.removeClass('LSform-errors');
});
$$('li.LSform_layout_errors').each(function(li) {
li.removeClass('LSform_layout_errors');
});
},
addError: function(errors,name) {
var ul = $(name);
if ($type(ul)) {
errors = new Array(errors);
errors.each(function(txt){
var dd = new Element('dd');
dd.addClass('LSform');
dd.addClass('LSform-errors');
dd.set('html',txt);
dd.injectAfter(this.getParent());
},ul);
var dt = ul.getParent().getPrevious('dt');
dt.addClass('LSform-errors');
var layout = ul.getParent('div.LSform_layout_active');
if ($type(layout)) {
var li = document.getElement('li.LSform_layout[title='+layout.title+']');
if($type(li)) {
li.addClass('LSform_layout_errors');
}
}
}
}
});
window.addEvent(window.ie ? 'load' : 'domready', function() {

View file

@ -59,33 +59,59 @@ if($LSsession -> startLSsession()) {
else {
$GLOBALS['LSsession'] -> addInfo(_("L'objet a bien été modifié."));
}
if ((!LSdebugDefined()) && !$GLOBALS['LSerror']->errorsDefined()) {
$GLOBALS['LSsession'] -> redirect('view.php?LSobject='.$LSobject.'&dn='.$object -> getDn());
if (isset($_REQUEST['ajax'])) {
$GLOBALS['LSsession'] -> displayAjaxReturn (
array(
'LSformRedirect' => 'view.php?LSobject='.$LSobject.'&dn='.$object -> getDn()
)
);
}
else {
if ((!LSdebugDefined()) && !$GLOBALS['LSerror']->errorsDefined()) {
$GLOBALS['LSsession'] -> redirect('view.php?LSobject='.$LSobject.'&dn='.$object -> getDn());
}
else {
$GLOBALS['LSsession'] -> displayTemplate();
}
}
}
else {
$GLOBALS['LSsession'] -> displayAjaxReturn (
array(
'LSformErrors' => $form -> getErrors()
)
);
}
}
$LSview_actions[] = array(
'label' => _('Voir'),
'url' =>'view.php?LSobject='.$LSobject.'&dn='.$object -> getDn(),
'action' => 'view'
);
if ($GLOBALS['LSsession'] -> canRemove($LSobject,$object -> getDn())) {
$LSview_actions[] = array(
'label' => _('Supprimer'),
'url' => 'remove.php?LSobject='.$LSobject.'&dn='.$object -> getDn(),
'action' => 'delete'
else if (isset($_REQUEST['ajax']) && $form -> definedError()) {
$GLOBALS['LSsession'] -> displayAjaxReturn (
array(
'LSformErrors' => $form -> getErrors()
)
);
}
else {
$LSview_actions[] = array(
'label' => _('Voir'),
'url' =>'view.php?LSobject='.$LSobject.'&dn='.$object -> getDn(),
'action' => 'view'
);
$GLOBALS['LSsession'] -> addJSscript('LSsmoothbox.js');
$GLOBALS['LSsession'] -> addCssFile('LSsmoothbox.css');
$GLOBALS['Smarty'] -> assign('LSview_actions',$LSview_actions);
$GLOBALS['LSsession'] -> setTemplate('modify.tpl');
$form -> display();
if ($GLOBALS['LSsession'] -> canRemove($LSobject,$object -> getDn())) {
$LSview_actions[] = array(
'label' => _('Supprimer'),
'url' => 'remove.php?LSobject='.$LSobject.'&dn='.$object -> getDn(),
'action' => 'delete'
);
}
$GLOBALS['LSsession'] -> addJSscript('LSsmoothbox.js');
$GLOBALS['LSsession'] -> addCssFile('LSsmoothbox.css');
$GLOBALS['Smarty'] -> assign('LSview_actions',$LSview_actions);
$GLOBALS['LSsession'] -> setTemplate('modify.tpl');
$form -> display();
$GLOBALS['LSsession'] -> displayTemplate();
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1011);
@ -106,8 +132,8 @@ if($LSsession -> startLSsession()) {
}
else {
$GLOBALS['LSsession'] -> setTemplate('login.tpl');
$GLOBALS['LSsession'] -> displayTemplate();
}
// Affichage des retours d'erreurs
$GLOBALS['LSsession'] -> displayTemplate();
?>

View file

@ -1,5 +1,5 @@
{include file='top.tpl'}
{if $pagetitle != ''}<h1>{$pagetitle}</h1>{/if}
{if $pagetitle != ''}<h1 id='LSform_title'>{$pagetitle}</h1>{/if}
{include file='LSform.tpl'}
{include file='bottom.tpl'}

View file

@ -1,5 +1,5 @@
{include file='top.tpl'}
{if $pagetitle != ''}<h1>{$pagetitle}</h1>{/if}
{if $pagetitle != ''}<h1 id='LSform_title'>{$pagetitle}</h1>{/if}
{if $LSview_actions != ''}
<ul class='LSview-actions'>
{foreach from=$LSview_actions item=item}