- LSform :
authorBenjamin Renard <brenard@easter-eggs.com>
Thu, 12 Feb 2009 10:04:50 +0000 (10:04 +0000)
committerBenjamin Renard <brenard@easter-eggs.com>
Thu, 12 Feb 2009 10:04:50 +0000 (10:04 +0000)
-> 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.

trunk/conf/LSobjects/config.LSobjects.LSeepeople.php
trunk/create.php
trunk/includes/class/class.LSldapObject.php
trunk/includes/js/LSform.js
trunk/modify.php

index 8d2a5e5..04d1d01 100644 (file)
@@ -68,6 +68,7 @@ $GLOBALS['LSobjects']['LSeepeople'] = array (
   
   // LSform
   'LSform' => array (
+    'ajaxSubmit' => 1,
     // Layout
     'layout' => array (
       'Civilite' => array(
index babe40d..d8ce82a 100644 (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()) {
index 7c85f06..084bdee 100644 (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;
   }
   
index 71c63ca..e2841ca 100644 (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) {
index cc95d6c..d7b4532 100644 (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()) {