Hey all,
i have some trouble with the correct use of CJuiDialog.
I have a page where i edit company data.
Each company has several offices, which i want to make editable (create new office, edit office, delete office) via ajax.
I managed to accomplish the create part with CJuiDialog:
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id'=>'niederlassung_neu',
'options'=>array(
'title'=>'Niederlassung hinzufügen',
'autoOpen'=>false,
),
));
$niederlassung = new Niederlassungen;
$parent_id = Yii::app()->getRequest()->getQuery('id');
echo CHtml::beginForm('','post',array('id'=>'add-nl-form')).'
';
echo CHtml::activeHiddenField($niederlassung, 'vermittler_id', array('value'=>$parent_id)).'
';
echo CHtml::activeLabelEx($niederlassung, 'firma2').'
';
echo CHtml::activeTextField($niederlassung, 'firma2').'
';
// ... some other form fields
echo '<p>'.CHtml::ajaxSubmitButton('Speichern',
CController::createUrl('niederlassungenManager/ajaxCreate'),
array('success'=>'js: function(data) {
$("#nl-list").replaceWith(data);
$("#niederlassung_neu").dialog("close");
}'
)
).'</p>
';
echo CHtml::endForm().'
';
$this->endWidget('zii.widgets.jui.CJuiDialog');
i am calling the dialog with
echo CHtml::imageButton(Yii::app()->request->baseUrl.'/images/icons_16x16/add.png', array(
'onclick'=>'$("#niederlassung_neu").dialog("open"); return false;',
'title'=>'Niederlassung hinzufügen',
));
the model is created and the list of offices is updated afterwards. so far so good.
now comes the tricky part:
i have an edit-button for each office in the list, and i want to open a dialog with the model data, change the data, save and update the list.
i just don’t know how to get the model id of each office into the dialog, so i can fetch the appropriate data to populate the form.
$niederlassung = new Niederlassungen;
$nl_id = ?; // get the office id and load the model data
$niederlassung->loadModel($nl_id);
echo CHtml::beginForm('','post',array('id'=>'add-nl-form')).'
';
echo CHtml::activeHiddenField($niederlassung, 'id', array('value'=>$nl_id));
or do i have to create a CJuiDialog for each office and populate it at page render? that wouldn’t be very elegant, or would it.
any hint is appreciated, thanks.