Skip to content

Commit

Permalink
better render method and remove 'data-method' => 'post' from delete
Browse files Browse the repository at this point in the history
  • Loading branch information
cornernote committed Jul 7, 2015
1 parent 59c8ee8 commit cf54e9f
Show file tree
Hide file tree
Showing 18 changed files with 46 additions and 187 deletions.
30 changes: 7 additions & 23 deletions docs/layouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ class ExampleLayout extends \cornernote\dashboard\Layout
];
}

public function getRegionOpts()
public function getRegions()
{
return [
'column-1' => 'Column 1',
'column-2' => 'Column 2',
];
}

public function regionPanels($dashboardPanels)
public function regionPanels($dashboardPanels, $view = 'view')
{
$regionPanels = [
'column-1' => [],
Expand All @@ -58,32 +58,16 @@ class ExampleLayout extends \cornernote\dashboard\Layout
'id' => 'dashboard-panel-' . $dashboardPanel->id,
'class' => 'dashboard-panel',
],
'content' => $dashboardPanel->panel->renderView(),
'content' => $dashboardPanel->panel->render($view),
];
}
return $regionPanels;
}

public function renderView()
public function render($view, $params = [])
{
return \Yii::$app->view->render($this->viewPath . '/view', [
'layout' => $this,
]);
}

public function renderUpdate()
{
return \Yii::$app->view->render($this->viewPath . '/update', [
'layout' => $this,
]);
}

public function renderForm($form)
{
return \Yii::$app->view->render($this->viewPath . '/form', [
'layout' => $this,
'form' => $form,
]);
$params['layout'] = $this;
return \Yii::$app->view->render($this->viewPath . '/view', $params);
}

}
Expand Down Expand Up @@ -131,7 +115,7 @@ Place the following code into `app/views/dashboard/layouts/example/update.php`:
* @var $this \yii\web\View
*/

$regionPanels = $layout->regionPanels($layout->dashboard->getDashboardPanels()->all());
$regionPanels = $layout->regionPanels($layout->dashboard->getDashboardPanels()->all(), 'update');

echo '<div class="row">';
foreach ($regionPanels as $region => $items) {
Expand Down
24 changes: 3 additions & 21 deletions docs/panels.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,10 @@ class ExamplePanel extends \cornernote\dashboard\Panel
];
}

public function renderView()
public function render($view, $params = [])
{
return \Yii::$app->view->render($this->viewPath . '/view', [
'panel' => $this,
]);
}

public function renderUpdate()
{
return \Yii::$app->view->render($this->viewPath . '/update', [
'panel' => $this,
]);
}

public function renderForm($form)
{
return \Yii::$app->view->render($this->viewPath . '/form', [
'panel' => $this,
'form' => $form,
]);
$params['panel'] = $this;
return \Yii::$app->view->render($this->viewPath . '/view', $params);
}

}
Expand Down Expand Up @@ -92,7 +76,6 @@ Place the following code into `app/views/dashboard/panels/example/view.php`:
['dashboard-panel/delete', 'id' => $panel->dashboardPanel->id],
[
'data-confirm' => 'Are you sure to delete this dashboard panel?',
'data-method' => 'post',
'data-toggle' => 'tooltip',
'title' => 'Delete Dashboard Panel',
]
Expand Down Expand Up @@ -126,7 +109,6 @@ Place the following code into `app/views/dashboard/panels/example/update.php`:
]) ?>
<?= \yii\helpers\Html::a('<span class="glyphicon glyphicon-trash small"></span>', ['dashboard-panel/delete', 'id' => $panel->dashboardPanel->id], [
'data-confirm' => Yii::t('dashboard', 'Are you sure to delete this dashboard panel?'),
'data-method' => 'post',
'data-toggle' => 'tooltip',
'title' => Yii::t('dashboard', 'Delete Dashboard Panel'),
]) ?>
Expand Down
26 changes: 6 additions & 20 deletions src/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,41 +55,27 @@ public function getOptions()
/**
* @return array
*/
public function getRegionOpts()
public function getRegions()
{
return [];
}

/**
* @param DashboardPanel[] $dashboardPanels
* @param string $view
* @return array
*/
public function regionPanels($dashboardPanels)
public function regionPanels($dashboardPanels, $view)
{
return [];
}

/**
* @param string $view
* @param array $params
* @return string
*/
public function renderView()
{
return '';
}

/**
* @return string
*/
public function renderUpdate()
{
return '';
}

/**
* @param ActiveForm $form
* @return string
*/
public function renderForm($form)
public function render($view, $params = [])
{
return '';
}
Expand Down
21 changes: 3 additions & 18 deletions src/Panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,11 @@ public function getOptions()
}

/**
* @param string $view
* @param array $params
* @return string
*/
public function renderView()
{
return '';
}

/**
* @return string
*/
public function renderUpdate()
{
return '';
}

/**
* @param ActiveForm $form
* @return string
*/
public function renderForm($form)
public function render($view, $params = [])
{
return '';
}
Expand Down
34 changes: 6 additions & 28 deletions src/layouts/DefaultLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static function getColumnOpts()
/**
* @return array
*/
public function getRegionOpts()
public function getRegions()
{
$regions = [];
for ($i = 1; $i <= $this->columns; $i++) {
Expand All @@ -64,32 +64,10 @@ public function getRegionOpts()
/**
* @inheritdoc
*/
public function renderView()
public function render($view = 'view', $params = [])
{
return Yii::$app->view->render($this->viewPath . '/view', [
'layout' => $this,
]);
}

/**
* @inheritdoc
*/
public function renderUpdate()
{
return Yii::$app->view->render($this->viewPath . '/update', [
'layout' => $this,
]);
}

/**
* @inheritdoc
*/
public function renderForm($form)
{
return Yii::$app->view->render($this->viewPath . '/form', [
'layout' => $this,
'form' => $form,
]);
$params['layout'] = $this;
return Yii::$app->view->render($this->viewPath . '/' . $view, $params);
}

/**
Expand All @@ -105,7 +83,7 @@ public function getOptions()
/**
* @inheritdoc
*/
public function regionPanels($dashboardPanels)
public function regionPanels($dashboardPanels, $view)
{
$regionPanels = [];
for ($column = 1; $column <= $this->columns; $column++) {
Expand All @@ -119,7 +97,7 @@ public function regionPanels($dashboardPanels)
'id' => 'dashboard-panel-' . $dashboardPanel->id,
'class' => 'dashboard-panel',
],
'content' => $dashboardPanel->panel->renderView(),
'content' => $dashboardPanel->panel->render($view),
];
}
return $regionPanels;
Expand Down
28 changes: 3 additions & 25 deletions src/panels/TextPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,10 @@ public function getOptions()
/**
* @inheritdoc
*/
public function renderView()
public function render($view, $params = [])
{
return Yii::$app->view->render($this->viewPath . '/view', [
'panel' => $this,
]);
}

/**
* @inheritdoc
*/
public function renderUpdate()
{
return Yii::$app->view->render($this->viewPath . '/update', [
'panel' => $this,
]);
}

/**
* @inheritdoc
*/
public function renderForm($form)
{
return Yii::$app->view->render($this->viewPath . '/form', [
'panel' => $this,
'form' => $form,
]);
$params['panel'] = $this;
return Yii::$app->view->render($this->viewPath . '/' . $view, $params);
}

}
2 changes: 1 addition & 1 deletion src/views/dashboard-panel/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

<?= $form->field($model, 'panel_class')->dropDownList(array_flip(Module::getInstance()->panels), ['prompt' => '']) ?>

<?= $form->field($model, 'region')->dropDownList($model->dashboard->layout->getRegionOpts(), ['prompt' => '']) ?>
<?= $form->field($model, 'region')->dropDownList($model->dashboard->layout->getRegions(), ['prompt' => '']) ?>

<?= $form->field($model, 'sort')->textInput(['maxlength' => true]) ?>

Expand Down
2 changes: 1 addition & 1 deletion src/views/dashboard-panel/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<?= $form->field($model, 'enabled')->checkbox() ?>

<?= $model->panel->renderForm($form); ?>
<?= $model->panel->render('form', ['form' => $form]); ?>

<?= Html::submitButton('<span class="fa fa-check"></span> ' . Yii::t('dashboard', 'Save'), [
'id' => 'save-' . $model->formName(),
Expand Down
2 changes: 1 addition & 1 deletion src/views/dashboard/layouts/default/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
if (!in_array($columns, array(1, 2, 3, 4, 6))) $columns = 1;
$span = round(12 / $columns);

$regionPanels = $layout->regionPanels($layout->dashboard->getDashboardPanels()->all());
$regionPanels = $layout->regionPanels($layout->dashboard->getDashboardPanels()->all(), 'update');

if (isset($regionPanels['overflow'])) {
$overflow = $regionPanels['overflow'];
Expand Down
2 changes: 1 addition & 1 deletion src/views/dashboard/layouts/default/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
if (!in_array($columns, array(1, 2, 3, 4, 6))) $columns = 1;
$span = round(12 / $columns);

$regionPanels = $layout->regionPanels($layout->dashboard->getDashboardPanels()->enabled()->all());
$regionPanels = $layout->regionPanels($layout->dashboard->getDashboardPanels()->enabled()->all(), 'view');

if (isset($regionPanels['overflow'])) {
$overflow = $regionPanels['overflow'];
Expand Down
2 changes: 1 addition & 1 deletion src/views/dashboard/panels/text/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
]) ?>
<?= Html::a('<span class="glyphicon glyphicon-trash small"></span>', ['dashboard-panel/delete', 'id' => $panel->dashboardPanel->id], [
'data-confirm' => Yii::t('dashboard', 'Are you sure to delete this dashboard panel?'),
'data-method' => 'post',
//'data-method' => 'post',
'data-toggle' => 'tooltip',
'title' => Yii::t('dashboard', 'Delete Dashboard Panel'),
]) ?>
Expand Down
2 changes: 1 addition & 1 deletion src/views/dashboard/panels/text/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
]) ?>
<?= Html::a('<span class="glyphicon glyphicon-trash small"></span>', ['dashboard-panel/delete', 'id' => $panel->dashboardPanel->id], [
'data-confirm' => Yii::t('dashboard', 'Are you sure to delete this dashboard panel?'),
'data-method' => 'post',
//'data-method' => 'post',
'data-toggle' => 'tooltip',
'title' => Yii::t('dashboard', 'Delete Dashboard Panel'),
]) ?>
Expand Down
4 changes: 2 additions & 2 deletions src/views/dashboard/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@

<?= $form->field($model, 'enabled')->checkbox() ?>

<?= $model->layout->renderForm($form); ?>
<?= $model->layout->render('form', ['form' => $form]); ?>

<?= $model->layout->renderUpdate(); ?>
<?= $model->layout->render('update'); ?>

<div class="form-group">
<?= Html::submitButton('<span class="fa fa-check"></span> ' . Yii::t('dashboard', 'Save'), [
Expand Down
2 changes: 1 addition & 1 deletion src/views/dashboard/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@
]); ?>
</h1>

<?= $model->layout->renderView(); ?>
<?= $model->layout->render('view'); ?>

</div>
Loading

0 comments on commit cf54e9f

Please sign in to comment.