]> git.andy128k.dev Git - ipf.git/commitdiff
Inline CheckBoxes fix
authoravl <alex.litovchenko@gmail.com>
Sun, 1 Feb 2009 21:41:49 +0000 (23:41 +0200)
committeravl <alex.litovchenko@gmail.com>
Sun, 1 Feb 2009 21:41:49 +0000 (23:41 +0200)
ipf/admin/model.php
ipf/admin/modelinline.php
ipf/form.php
ipf/form/widget/checkboxinput.php
ipf/orm/record.php

index a4b21b80e8c533b07430aee853cb025f850c0a29..5c7d0a7541c4b7ed76e01a4cf635b88f6f123dfe 100644 (file)
@@ -64,7 +64,7 @@ class IPF_Admin_Model{
         return array('view', 'add', 'change', 'delete');
     }
 
-    protected function setInlines($model, &$data){
+    protected function setInlines($model, $data){
         $il = $this->inlines();
         if (is_array($il)){
             foreach($il as $inlineName=>$inlineClassName){
@@ -241,7 +241,7 @@ class IPF_Admin_Model{
             $form = $this->_getAddForm($this->model,null,array('user_fields'=>$this->fields()));
             $this->_setupAddForm($form);
             $data = array();
-            $this->setInlines($this->model, &$data);
+            $this->setInlines($this->model);
         }
 
         $context = array(
@@ -265,7 +265,6 @@ class IPF_Admin_Model{
             $form = $this->_getEditForm($o,&$data,array('user_fields'=>$this->fields()));
             $this->_setupEditForm($form);
             $this->setInlines($o, &$data);
-
             if ( ($form->isValid()) && ($this->isValidInlines()) ) {
                 $item = $form->save();
                 $this->saveInlines($item);
@@ -289,7 +288,7 @@ class IPF_Admin_Model{
             }
             $form = $this->_getEditForm($o,&$data,array('user_fields'=>$this->fields()));
             $this->_setupEditForm($form);
-            $this->setInlines($o, &$data);
+            $this->setInlines($o);
         }
 
         $context = array(
index 7543e816a9f5e469e782841638b2bf7462eb1ba0..d57628614ca0084507b4b1e9cf55f9e05531ff66 100644 (file)
@@ -7,12 +7,11 @@ abstract class IPF_Admin_ModelInline{
     var $parentModel = null;
     var $formset = null;
 
-    function __construct($parentModel,$data){
+    function __construct($parentModel,$data=null){
         $this->parentModel = $parentModel;
 
         $modelName = $this->getModelName();
         $this->model = new $modelName();
-
         $this->createFormSet($data);
     }
 
@@ -55,7 +54,7 @@ abstract class IPF_Admin_ModelInline{
         throw new IPF_Exception(__('Cannot get fkLocal for '.$this->getModelName()));
     }
 
-    function createFormSet(&$data){
+    function createFormSet($data){
 
         $this->formset = array();
 
@@ -71,15 +70,24 @@ abstract class IPF_Admin_ModelInline{
             foreach ($objects as $obj){
                 $prefix = 'edit_'.get_class($this->model).'_'.$obj->id.'_';
                 $d = array();
-                foreach ($obj->getData() as $k=>$v)
-                    $d[$prefix.$k] = $v;
-                foreach ($data as $k=>$v){
-                    if (strpos($k,$prefix)==0)
-                        $d[$k] = $v;
-                }
+
+                               if ($data===null){
+                       foreach ($obj->getData() as $k=>$v){
+                           $d[$prefix.$k] = $v;
+                       }
+                               }
+                               else{
+                       foreach ($data as $k=>$v){
+                           if (strpos($k,$prefix)==0)
+                               $d[$k] = $v;
+                       }
+               }
+
                 $form = $this->_getForm($obj, $d,
                     array('exclude'=>array($this->getFkName(),$this->getFkLocal()))
                 );
+
+
                 $form->prefix = $prefix;
                 $form->fields = array_merge(array(
                     new IPF_Form_Field_Boolean(array('label'=>'Del','name'=>'is_remove')),
@@ -113,7 +121,6 @@ abstract class IPF_Admin_ModelInline{
     }
 
     function save($parent_obj){
-
         if ($this->parentModel->exists()){
             $objects = IPF_ORM_Query::create()
                 ->from(get_class($this->model))
@@ -124,6 +131,7 @@ abstract class IPF_Admin_ModelInline{
                 foreach($this->formset as $form){
                     if ($form->isAdd)
                         continue;
+
                     @list($x1,$x2,$id,$x3) = @split('_',$form->prefix);
                     if ($id==$obj->id){
                         if ($form->cleaned_data[0]==true)
@@ -137,8 +145,8 @@ abstract class IPF_Admin_ModelInline{
                                     if($form->cleaned_data[$fname]=='')
                                         unset($form->cleaned_data[$fname]);
                                 }
-                            }
 
+                            }
                             $obj->synchronizeWithArray($form->cleaned_data);
                             $obj->save();
                         }
index 517135d37baf35da0f056dbea3e76e0230e704a1..b8f6c452ae4688b0902b6b387ab9906c9ae6ccfe 100644 (file)
@@ -59,6 +59,7 @@ class IPF_Form implements Iterator
         $this->cleaned_data = array();
         $this->errors = array();
         $form_methods = get_class_methods($this);
+
         foreach ($this->fields as $name=>$field) {
             $value = $field->widget->valueFromFormData($this->addPrefix($name), &$this->data);
             try {
index d365982aba6d9a8b974edf8fffb1063bf6599f2f..3905ba2059049513943b8f4d512dcbe04b8a7033 100644 (file)
@@ -9,13 +9,13 @@ class IPF_Form_Widget_CheckboxInput extends IPF_Form_Widget_Input
         if ((bool)$value) {
             $extra_attrs['checked'] = 'checked';
         }
+        $extra_attrs['value'] = '1';
         return parent::render($name, '', $extra_attrs);
     }
 
     public function valueFromFormData($name, $data)
     {
-        if (!isset($data[$name]) 
-            or false === $data[$name] or (string)$data[$name] === '0') {
+        if (!isset($data[$name]) or false === $data[$name] or (string)$data[$name] === '0' or (string)$data[$name] === 'off') {
             return false;
         }
         return true;
index a8baf48ba8ad7f829372268e997d065f95d6b507..9eeb8f154ef641ad39b3a5f810169a23d14a2ff7 100644 (file)
@@ -863,21 +863,18 @@ abstract class IPF_ORM_Record extends IPF_ORM_Record_Abstract implements Countab
                 $this->assignIdentifier((array) $value);
                 continue;
             }
-
             if ($deep && $this->getTable()->hasRelation($key)) {
                 $this->get($key)->synchronizeWithArray($value);
             } else if ($this->getTable()->hasField($key)) {
                 $this->set($key, $value);
             }
         }
-
         // eliminate relationships missing in the $array
         foreach ($this->_references as $name => $obj) {
             if ( ! isset($array[$name])) {
                 unset($this->$name);
             }
         }
-
         if ($refresh) {
             $this->refresh();
         }