]> git.andy128k.dev Git - ipf.git/commitdiff
Small fixes
authoravl <alex.litovchenko@gmail.com>
Thu, 11 Sep 2008 07:07:20 +0000 (10:07 +0300)
committeravl <alex.litovchenko@gmail.com>
Thu, 11 Sep 2008 07:07:20 +0000 (10:07 +0300)
ipf/admin/model.php
ipf/admin/modelinline.php
ipf/admin/templates/admin/change.html

index 3bffff06250f8d1cd01e209f839529e42c73e59c..07f52e215b85e2d291abc8719dacadd98180c06d 100644 (file)
@@ -47,6 +47,12 @@ class IPF_Admin_Model{
         }
     }
     
+    protected function saveInlines($obj){
+        foreach($this->inlineInstances as $inlineInstance){
+            $inlineInstance->save($obj);
+        }
+    }
+    
     protected function _setupEditForm($form){
         $this->_setupForm($form);
         $this->setInlines($this->instance);
@@ -65,11 +71,10 @@ class IPF_Admin_Model{
     public function inlines(){return null;}
     
     public function isValidInlines(){
-        if ($this->inlineInstances==null)
-            return true;
         foreach($this->inlineInstances as &$il){
-            if ($il->isValid()===false)
-                return false;
+            if ($il->isValid()===false){
+                //return false;
+            }
         }
         return true;
     }
@@ -154,7 +159,7 @@ class IPF_Admin_Model{
     }
 
     protected function _getAddTemplate(){
-        return 'admin/change.html';
+        return 'admin/add.html';
     }
 
     protected function _getChangeTemplate(){
@@ -193,6 +198,7 @@ class IPF_Admin_Model{
             $this->_setupEditForm($form);
             if ( ($form->isValid()) && ($this->isValidInlines()) ) {
                 $item = $form->save();
+                $this->saveInlines($item);
                 AdminLog::logAction($request, $item, AdminLog::CHANGE);
                 $url = IPF_HTTP_URL_urlForView('IPF_Admin_Views_ListItems', array($lapp, $lmodel));
                 return new IPF_HTTP_Response_Redirect($url);
@@ -213,7 +219,7 @@ class IPF_Admin_Model{
             'perms'=>$this->getPerms($request),
             'lmodel'=>$lmodel,
         );
-        return IPF_Shortcuts::RenderToResponse($this->_getAddTemplate(), $context, $request);
+        return IPF_Shortcuts::RenderToResponse($this->_getChangeTemplate(), $context, $request);
     }
 
     public function DeleteItem($request, $lapp, $lmodel, $o){
index 7951b83f0753153a007f6cc7e3202b6dee7b32e8..b7b32c9da156b631118717fe6e18dc5a9485973b 100644 (file)
@@ -5,16 +5,14 @@ abstract class IPF_Admin_ModelInline{
     var $model = null;
     var $parentModel = null;
     var $formset = null;
-    var $parentInstance = null;
-    
-    function __construct(&$parentModel,$parentInstance=null){
+
+    function __construct($parentModel,$data){
         $this->parentModel = $parentModel;
-        $this->parentInstance = $parentInstance;
         
         $modelName = $this->getModelName();
         $this->model = new $modelName();
         
-        $this->createFormSet();
+        $this->createFormSet($data);
     }
 
     abstract function getModelName();
@@ -50,11 +48,13 @@ abstract class IPF_Admin_ModelInline{
         throw new IPF_Exception('Cannot get fkLocal for '.$this->getModelName());
     }
 
-    function createFormSet(){
+    function createFormSet(&$data){
         $this->formset = array();
         for($i=0; $i<$this->getAddNum(); $i++ ){
             $form = IPF_Shortcuts::GetFormForModel($this->model, null, array('exclude'=>array($this->getFkName(),$this->getFkLocal())));
-            $form->prefix = "add-$i";
+            $form->fields = array_merge(array(new IPF_Form_Field_Boolean(array('label'=>'Del','name'=>'delete_', 'widget_attrs'=>array('disabled'=>'disabled')))),$form->fields);
+            $form->prefix = 'add_'.get_class($this->model).'_'.$i;
+            $form->data = $data;
             if ($i==0)
                 $form->isFirst = true;
             else
@@ -63,4 +63,8 @@ abstract class IPF_Admin_ModelInline{
             $this->formset[] = $form;
         }
     }
+    
+    function save(){
+        
+    }
 }
\ No newline at end of file
index 2877aac9dbb4bafb13fe4dfa633cf0a03929f67d..52613997ca00056d6ce073be79c3ccc880132570 100644 (file)
@@ -22,7 +22,7 @@
     {if $formset.isFirst}
     <tr>
     {foreach $formset.fields as $fieldname=>$field}
-    <th>{$formset.field($fieldname).labelTag()|safe}</th>
+    <th{if $formset.field($fieldname).label=='Del'} style="width:20px;"{/if}>{$formset.field($fieldname).label}</th>
     {/foreach}
     </tr>
     {/if}