LSform : Added data entry form in create mode
[ldapsaisie.git] / public_html / includes / js / LSform.js
index 20c11f0..f4adfff 100644 (file)
@@ -27,7 +27,28 @@ var LSform = new Class({
           this.params={};
         }
         this._ajaxSubmit=this.params.ajaxSubmit;
+
+        this.warnBox = new LSinfosBox({
+          name: 'LSformWarnBox',
+          fxDuration: 600,
+          closeBtn: 1,
+          autoClose: 0
+        });
+
+        if ($type(this.params.warnings)) {
+          this.warnTxt = '<ul>';
+          this.params.warnings.each(function(w) {
+            this.warnTxt +='<li>'+w+'</li>';
+          },this);
+          this.warnTxt += '</ul>';
+          this.warnBox.display(this.warnTxt);
+        }
         LSdebug(this.params);
+
+        this.listAvailableDataEntryForm=$('LSform_listAvailableDataEntryForm');
+        if ($type(this.listAvailableDataEntryForm)) {
+          this.listAvailableDataEntryForm.addEvent('change',this.onListAvailableDataEntryFormChange.bind(this));
+        }
       }
       
       LSforms = $$('form.LSform');
@@ -244,8 +265,10 @@ var LSform = new Class({
           dd.injectAfter(this.getParent());
         },ul);
         
-        var dt = ul.getParent().getPrevious('dt');
-        dt.addClass('LSform-errors');
+        var dt = ul.getParent('dd.LSform').getPrevious('dt');
+        if ($type(dt)) {
+          dt.addClass('LSform-errors');
+        }
         
         var layout = ul.getParent('div.LSform_layout_active');
         if ($type(layout)) {
@@ -255,6 +278,23 @@ var LSform = new Class({
           }
         }
       }
+      else {
+        this.tmp=name+" :</br><ul>";
+        errors = new Array(errors);
+        errors.each(function(error){
+          this.tmp += "<li>"+error+"</li>";
+        },this);
+        this.tmp +="</ul>";
+        this.warnBox.display(this.tmp);
+      }
+    },
+
+    onListAvailableDataEntryFormChange: function() {
+      var url=window.location.pathname+"?LSobject="+this.objecttype
+      if (this.listAvailableDataEntryForm.value!="") {
+        url+="&LSform_dataEntryForm="+this.listAvailableDataEntryForm.value;
+      }
+      document.location=url;
     }
 });
 window.addEvent(window.ie ? 'load' : 'domready', function() {