JSON Editor is a good way if you know alle the Widget-Attributes. However most of my users and customers don’t know all attributes.
So i added a form. This form has to be in the widget Folder with the same name as the widget + "Form". So "BasicWidget" -> "BasicWidgetForm".
The Form is dynamically updating when you choose a different Widget.
I can upload an Screencast if someone is interested.
Here is the code:
../views/widget/_form.php (You need to enable JQuery ) line 0:
<script type="text/javascript">
$(document).ready(function() {
$("#formBox").load("<?php echo $this->createUrl("GetForm"); ?>?form=" +
$("#Widget_alias :selected").val() + "&id=<?php echo $model->id ?>" );
$("select").change(function () {
$("#formBox").load("<?php echo $this->createUrl("GetForm"); ?>?form=" +
$("#Widget_alias :selected").val() + "&id=<?php echo $model->id ?>" );
});
});
</script>
Somewhere in the form-container:
<div id="formBox">
</div>
WidgetController
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id) {
$model = $this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Widget'])) {
$model->attributes = $_POST['Widget'];
if ($_POST['Form'])
$model->properties = json_encode($_POST['Form']);
$criteria = new CDbCriteria();
$criteria->params = array(
':controllerId' => $model->controllerId,
':actionName' => $model->actionName,
':containerId' => $model->containerId,
':rank' => $model->rank,
);
$criteria->condition = 'actionName = :actionName AND containerId = :containerId AND controllerId = :controllerId AND rank = :rank';
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('update', array(
'model' => $model
), false, true);
}
And add this function to WidgetController:
public function actionGetForm($id) {
if($id){
$properties = json_decode($this->loadModel($id)->properties);
}
$form = $_GET['form'] . "Form";
if ($this->getViewFile($form)) {
$this->renderPartial($form,array('properties'=> $properties));
} else {
return true;
}
}
Then you can add form to your Widget
Exampe BasicWidgetForm
<fieldset class="no-border">
<label for="Form[events_headline]">Überschrift</label>
<input name="Form[events_headline]" id="name" type="text" class="text" maxlength="" value="<?php echo $properties->events_headline ?>">
</fieldset>
Hopefully you get an idea. I think it is pretty useful.
Best regards,
Peili