ztabularinputmanager problem

Hi All & zac, hopefully you read this post.

I have problem when trying to use your extension. My case is that I have Transaction as master and TransactionDetail as details.

Here is code for DetailsManager:




<?php


class DetailsManager extends TabularInputManager {


    protected $class = 'TransactionDetail';


    public function getItems() {

        if (is_array($this->_items))

            return ($this->_items);

        else

            return array(

                'n0' => new TransactionDetail,

            );

    }


    public function deleteOldItems($model, $itemsPk) {

        $criteria = new CDbCriteria;

        $criteria->addNotInCondition('id', $itemsPk);

        $criteria->addCondition("transactionFk= {$model->primaryKey}");


        TransactionDetail::model()->deleteAll($criteria);

    }


    public static function load($model) {

        $return = new DetailsManager;

        foreach ($model->transactionDetails as $item)

            $return->_items[$item->primaryKey] = $item;

        return $return;

    }


    public function setUnsafeAttribute($item, $model) {

        $item->transactionFk = $model->primaryKey;

    }


}


?>

and this is my actionCreate




     public function actionCreate() {

        $model = new Transaction;

        $model->date = date('Y-m-d');

        $model->status = Category::ACTIVE;

        $model->operatorFk = Yii::app()->user->id;


        $details = new DetailsManager();


        // Uncomment the following line if AJAX validation is needed

        // $this->performAjaxValidation($model);


        if (isset($_POST['Transaction'])) {

            $model->attributes = $_POST['Transaction'];

            $details->manage($_POST['TransactionDetails']);

            if (!isset($_POST['noValidate'])) {

                $valid = $model->validate();

                $valid = $details->validate($model) && $valid;


                if ($valid) {

                    $model->save();

                    $details->save($model);

                    $this->redirect(array('view', 'id' => $model->id));

                }

            }

        }


        $this->render('create', array(

            'model' => $model,

            'details' => $details,

        ));

    }



finally my view




        <table id="students">

            <thead>

                <tr>

                    <th>Produk</th>

                    <th>Kode bets</th>

                    <th>Jumlah</th>

                    <th>

                        <?php echo CHtml::link('add', '', array('onClick' => 'addDetail($(this))', 'class' => 'add')); ?>

                    </th>

                </tr>

            </thead>

            <tbody>

                <?php foreach ($details->items as $id => $model): ?> 

                    <?php $this->renderPartial('_formDetail', array('id'=>$id, 'model'=>$model, 'form'=>$form));?>

                <?php endforeach; ?>

            </tbody>

        </table>

    </div>


    <div class="row submit">

        <?php echo CHtml::submitButton($model->isNewRecord ? 'Tambah' : 'Simpan', array('class' => 'myButton')); ?>

    </div>


    <?php $this->endWidget(); ?>


</div><!-- form -->


<script type="text/javascript">

    // initializiation of counters for new elements

    var lastDetail=<?php echo $details->lastNew ?>;

 

    // the subviews rendered with placeholders

    var trDetail=new String(<?php echo CJSON::encode($this->renderPartial('_formDetail', array('id' => 'idRep', 'model' => new TransactionDetail, 'form' => $form), true)); ?>);

 

 

    function addDetail(button)

    {

        lastDetail++;

        button.parents('table').children('tbody').append(trStudent.replace(/idRep/g,'n'+lastDetail));

    }

 

 

    function deleteDetail(button)

    {

        button.parents('tr').detach();

    }

 

</script>




Problems are

  1. javascript seems not working

  2. error in saving related to manage

Any hints?

Thank you for your support.

Cheers,

Daniel

NOTE: moved to proper sub-forum (Extensions instead of Yii 1.0.x)