Source

jelix-trunk-patches / jForms-dynamic-fill-with-class-datasource.patch

Full commit
# HG changeset patch
# Parent df0663557f5245e72cf079f297c3d1129cdd0c87

diff -r df0663557f52 lib/jelix/core-modules/jelix/controllers/jforms.classic.php
--- a/lib/jelix/core-modules/jelix/controllers/jforms.classic.php	Sun Mar 27 21:55:32 2011 +0200
+++ b/lib/jelix/core-modules/jelix/controllers/jforms.classic.php	Sun Mar 27 23:10:02 2011 +0200
@@ -43,7 +43,7 @@
         if (!$control || ! ($control instanceof jFormsControlDatasource))
             throw new Exception('bad control');
 
-        if (!($control->datasource instanceof jFormsDaoDatasource))
+        if (!($control->datasource instanceof jFormsDaoDatasource || $control->datasource instanceof jIFormsDatasource3))
             throw new Exception('not supported datasource type');
 
         $dependentControls = $control->datasource->getDependentControls();
@@ -85,7 +85,7 @@
         if (!$control || ! ($control instanceof jFormsControlDatasource))
             throw new Exception('bad control');
 
-        if (!($control->datasource instanceof jFormsDaoDatasource))
+        if (!($control->datasource instanceof jFormsDaoDatasource || $control->datasource instanceof jIFormsDatasource3))
             throw new Exception('not supported datasource type');
         $form->setData('_autocomplete', $this->param('__q').'%');
         if($this->param('__getlabelforkey'))
diff -r df0663557f52 lib/jelix/forms/jFormsCompiler_jf_1_1.class.php
--- a/lib/jelix/forms/jFormsCompiler_jf_1_1.class.php	Sun Mar 27 21:55:32 2011 +0200
+++ b/lib/jelix/forms/jFormsCompiler_jf_1_1.class.php	Sun Mar 27 23:10:02 2011 +0200
@@ -315,7 +315,6 @@
             foreach ($control->datasource->attributes() as $name=>$value){
                 $attrs[$name]=(string)$value;
             }
-
             if(isset($attrs['dao'])) {
                 if (isset($attrs['profile']))
                     $profile = ',\''.$attrs['profile'].'\'';
@@ -357,7 +356,8 @@
                 $class = new jSelectorClass($attrs['class']);
                 $source[]='jClasses::inc(\''.$attrs['class'].'\');';
                 $source[]='$datasource = new '.$class->className.'($this->id());';
-                $source[]='if ($datasource instanceof jIFormsDatasource){$ctrl->datasource=$datasource;}';
+                $source[]='if ($datasource instanceof jIFormsDatasource3){'.((isset($attrs['groupby']) && trim($attrs['groupby']) != '')?'$datasource->setGroupBy(\''.trim($attrs['groupby']).'\');':'').'$datasource->setDependentControls(\''.$attrs['criteriafrom'].'\'); $ctrl->datasource=$datasource;}';
+                $source[]='elseif ($datasource instanceof jIFormsDatasource){$ctrl->datasource=$datasource;}';
                 $source[]='else{$ctrl->datasource=new jFormsStaticDatasource();}';
                 if($controltype == 'submit'){
                     $source[]='$ctrl->standalone=false;';
diff -r df0663557f52 lib/jelix/forms/jFormsDatasource.class.php
--- a/lib/jelix/forms/jFormsDatasource.class.php	Sun Mar 27 21:55:32 2011 +0200
+++ b/lib/jelix/forms/jFormsDatasource.class.php	Sun Mar 27 23:10:02 2011 +0200
@@ -70,6 +70,14 @@
 }
 
 
+
+
+interface jIFormsDatasource3 extends jIFormsDatasource2 {
+    public function setDependentControls($controls);
+    
+    public function getDependentControls();
+}
+
 /**
  * A datasource which is based on static values.
  * @package     jelix
diff -r df0663557f52 lib/jelix/plugins/jforms/html/html.jformsbuilder.php
--- a/lib/jelix/plugins/jforms/html/html.jformsbuilder.php	Sun Mar 27 21:55:32 2011 +0200
+++ b/lib/jelix/plugins/jforms/html/html.jformsbuilder.php	Sun Mar 27 23:10:02 2011 +0200
@@ -131,7 +131,7 @@
 
         $this->jsContent .="c = new jFormsJQControlString('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n";
         if ($ctrl instanceof jFormsControlDatasource
-            && $ctrl->datasource instanceof jFormsDaoDatasource) {
+            && ($ctrl->datasource instanceof jFormsDaoDatasource || $ctrl->datasource instanceof jIFormsDatasource3)) {
             $dependentControls = $ctrl->datasource->getDependentControls();
             if ($dependentControls) {
                 $this->jsContent .="c.dependencies = ['".implode("','",$dependentControls)."'];\n";