Skip to content

Commit cf54e9f

Browse files
committed
better render method and remove 'data-method' => 'post' from delete
1 parent 59c8ee8 commit cf54e9f

File tree

18 files changed

+46
-187
lines changed

18 files changed

+46
-187
lines changed

docs/layouts.md

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ class ExampleLayout extends \cornernote\dashboard\Layout
3737
];
3838
}
3939

40-
public function getRegionOpts()
40+
public function getRegions()
4141
{
4242
return [
4343
'column-1' => 'Column 1',
4444
'column-2' => 'Column 2',
4545
];
4646
}
4747

48-
public function regionPanels($dashboardPanels)
48+
public function regionPanels($dashboardPanels, $view = 'view')
4949
{
5050
$regionPanels = [
5151
'column-1' => [],
@@ -58,32 +58,16 @@ class ExampleLayout extends \cornernote\dashboard\Layout
5858
'id' => 'dashboard-panel-' . $dashboardPanel->id,
5959
'class' => 'dashboard-panel',
6060
],
61-
'content' => $dashboardPanel->panel->renderView(),
61+
'content' => $dashboardPanel->panel->render($view),
6262
];
6363
}
6464
return $regionPanels;
6565
}
6666

67-
public function renderView()
67+
public function render($view, $params = [])
6868
{
69-
return \Yii::$app->view->render($this->viewPath . '/view', [
70-
'layout' => $this,
71-
]);
72-
}
73-
74-
public function renderUpdate()
75-
{
76-
return \Yii::$app->view->render($this->viewPath . '/update', [
77-
'layout' => $this,
78-
]);
79-
}
80-
81-
public function renderForm($form)
82-
{
83-
return \Yii::$app->view->render($this->viewPath . '/form', [
84-
'layout' => $this,
85-
'form' => $form,
86-
]);
69+
$params['layout'] = $this;
70+
return \Yii::$app->view->render($this->viewPath . '/view', $params);
8771
}
8872

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

134-
$regionPanels = $layout->regionPanels($layout->dashboard->getDashboardPanels()->all());
118+
$regionPanels = $layout->regionPanels($layout->dashboard->getDashboardPanels()->all(), 'update');
135119

136120
echo '<div class="row">';
137121
foreach ($regionPanels as $region => $items) {

docs/panels.md

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,10 @@ class ExamplePanel extends \cornernote\dashboard\Panel
3737
];
3838
}
3939

40-
public function renderView()
40+
public function render($view, $params = [])
4141
{
42-
return \Yii::$app->view->render($this->viewPath . '/view', [
43-
'panel' => $this,
44-
]);
45-
}
46-
47-
public function renderUpdate()
48-
{
49-
return \Yii::$app->view->render($this->viewPath . '/update', [
50-
'panel' => $this,
51-
]);
52-
}
53-
54-
public function renderForm($form)
55-
{
56-
return \Yii::$app->view->render($this->viewPath . '/form', [
57-
'panel' => $this,
58-
'form' => $form,
59-
]);
42+
$params['panel'] = $this;
43+
return \Yii::$app->view->render($this->viewPath . '/view', $params);
6044
}
6145

6246
}
@@ -92,7 +76,6 @@ Place the following code into `app/views/dashboard/panels/example/view.php`:
9276
['dashboard-panel/delete', 'id' => $panel->dashboardPanel->id],
9377
[
9478
'data-confirm' => 'Are you sure to delete this dashboard panel?',
95-
'data-method' => 'post',
9679
'data-toggle' => 'tooltip',
9780
'title' => 'Delete Dashboard Panel',
9881
]
@@ -126,7 +109,6 @@ Place the following code into `app/views/dashboard/panels/example/update.php`:
126109
]) ?>
127110
<?= \yii\helpers\Html::a('<span class="glyphicon glyphicon-trash small"></span>', ['dashboard-panel/delete', 'id' => $panel->dashboardPanel->id], [
128111
'data-confirm' => Yii::t('dashboard', 'Are you sure to delete this dashboard panel?'),
129-
'data-method' => 'post',
130112
'data-toggle' => 'tooltip',
131113
'title' => Yii::t('dashboard', 'Delete Dashboard Panel'),
132114
]) ?>

src/Layout.php

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,41 +55,27 @@ public function getOptions()
5555
/**
5656
* @return array
5757
*/
58-
public function getRegionOpts()
58+
public function getRegions()
5959
{
6060
return [];
6161
}
6262

6363
/**
6464
* @param DashboardPanel[] $dashboardPanels
65+
* @param string $view
6566
* @return array
6667
*/
67-
public function regionPanels($dashboardPanels)
68+
public function regionPanels($dashboardPanels, $view)
6869
{
6970
return [];
7071
}
7172

7273
/**
74+
* @param string $view
75+
* @param array $params
7376
* @return string
7477
*/
75-
public function renderView()
76-
{
77-
return '';
78-
}
79-
80-
/**
81-
* @return string
82-
*/
83-
public function renderUpdate()
84-
{
85-
return '';
86-
}
87-
88-
/**
89-
* @param ActiveForm $form
90-
* @return string
91-
*/
92-
public function renderForm($form)
78+
public function render($view, $params = [])
9379
{
9480
return '';
9581
}

src/Panel.php

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,11 @@ public function getOptions()
5252
}
5353

5454
/**
55+
* @param string $view
56+
* @param array $params
5557
* @return string
5658
*/
57-
public function renderView()
58-
{
59-
return '';
60-
}
61-
62-
/**
63-
* @return string
64-
*/
65-
public function renderUpdate()
66-
{
67-
return '';
68-
}
69-
70-
/**
71-
* @param ActiveForm $form
72-
* @return string
73-
*/
74-
public function renderForm($form)
59+
public function render($view, $params = [])
7560
{
7661
return '';
7762
}

src/layouts/DefaultLayout.php

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static function getColumnOpts()
5252
/**
5353
* @return array
5454
*/
55-
public function getRegionOpts()
55+
public function getRegions()
5656
{
5757
$regions = [];
5858
for ($i = 1; $i <= $this->columns; $i++) {
@@ -64,32 +64,10 @@ public function getRegionOpts()
6464
/**
6565
* @inheritdoc
6666
*/
67-
public function renderView()
67+
public function render($view = 'view', $params = [])
6868
{
69-
return Yii::$app->view->render($this->viewPath . '/view', [
70-
'layout' => $this,
71-
]);
72-
}
73-
74-
/**
75-
* @inheritdoc
76-
*/
77-
public function renderUpdate()
78-
{
79-
return Yii::$app->view->render($this->viewPath . '/update', [
80-
'layout' => $this,
81-
]);
82-
}
83-
84-
/**
85-
* @inheritdoc
86-
*/
87-
public function renderForm($form)
88-
{
89-
return Yii::$app->view->render($this->viewPath . '/form', [
90-
'layout' => $this,
91-
'form' => $form,
92-
]);
69+
$params['layout'] = $this;
70+
return Yii::$app->view->render($this->viewPath . '/' . $view, $params);
9371
}
9472

9573
/**
@@ -105,7 +83,7 @@ public function getOptions()
10583
/**
10684
* @inheritdoc
10785
*/
108-
public function regionPanels($dashboardPanels)
86+
public function regionPanels($dashboardPanels, $view)
10987
{
11088
$regionPanels = [];
11189
for ($column = 1; $column <= $this->columns; $column++) {
@@ -119,7 +97,7 @@ public function regionPanels($dashboardPanels)
11997
'id' => 'dashboard-panel-' . $dashboardPanel->id,
12098
'class' => 'dashboard-panel',
12199
],
122-
'content' => $dashboardPanel->panel->renderView(),
100+
'content' => $dashboardPanel->panel->render($view),
123101
];
124102
}
125103
return $regionPanels;

src/panels/TextPanel.php

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,10 @@ public function getOptions()
4545
/**
4646
* @inheritdoc
4747
*/
48-
public function renderView()
48+
public function render($view, $params = [])
4949
{
50-
return Yii::$app->view->render($this->viewPath . '/view', [
51-
'panel' => $this,
52-
]);
53-
}
54-
55-
/**
56-
* @inheritdoc
57-
*/
58-
public function renderUpdate()
59-
{
60-
return Yii::$app->view->render($this->viewPath . '/update', [
61-
'panel' => $this,
62-
]);
63-
}
64-
65-
/**
66-
* @inheritdoc
67-
*/
68-
public function renderForm($form)
69-
{
70-
return Yii::$app->view->render($this->viewPath . '/form', [
71-
'panel' => $this,
72-
'form' => $form,
73-
]);
50+
$params['panel'] = $this;
51+
return Yii::$app->view->render($this->viewPath . '/' . $view, $params);
7452
}
7553

7654
}

src/views/dashboard-panel/create.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

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

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

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

src/views/dashboard-panel/update.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

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

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

3333
<?= Html::submitButton('<span class="fa fa-check"></span> ' . Yii::t('dashboard', 'Save'), [
3434
'id' => 'save-' . $model->formName(),

src/views/dashboard/layouts/default/update.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
if (!in_array($columns, array(1, 2, 3, 4, 6))) $columns = 1;
1616
$span = round(12 / $columns);
1717

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

2020
if (isset($regionPanels['overflow'])) {
2121
$overflow = $regionPanels['overflow'];

src/views/dashboard/layouts/default/view.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
if (!in_array($columns, array(1, 2, 3, 4, 6))) $columns = 1;
1515
$span = round(12 / $columns);
1616

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

1919
if (isset($regionPanels['overflow'])) {
2020
$overflow = $regionPanels['overflow'];

src/views/dashboard/panels/text/update.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
]) ?>
2020
<?= Html::a('<span class="glyphicon glyphicon-trash small"></span>', ['dashboard-panel/delete', 'id' => $panel->dashboardPanel->id], [
2121
'data-confirm' => Yii::t('dashboard', 'Are you sure to delete this dashboard panel?'),
22-
'data-method' => 'post',
22+
//'data-method' => 'post',
2323
'data-toggle' => 'tooltip',
2424
'title' => Yii::t('dashboard', 'Delete Dashboard Panel'),
2525
]) ?>

src/views/dashboard/panels/text/view.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
]) ?>
1919
<?= Html::a('<span class="glyphicon glyphicon-trash small"></span>', ['dashboard-panel/delete', 'id' => $panel->dashboardPanel->id], [
2020
'data-confirm' => Yii::t('dashboard', 'Are you sure to delete this dashboard panel?'),
21-
'data-method' => 'post',
21+
//'data-method' => 'post',
2222
'data-toggle' => 'tooltip',
2323
'title' => Yii::t('dashboard', 'Delete Dashboard Panel'),
2424
]) ?>

src/views/dashboard/update.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434

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

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

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

4141
<div class="form-group">
4242
<?= Html::submitButton('<span class="fa fa-check"></span> ' . Yii::t('dashboard', 'Save'), [

src/views/dashboard/view.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@
3838
]); ?>
3939
</h1>
4040

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

4343
</div>

0 commit comments

Comments
 (0)