Commit 0cf90b500c4ee06d11c9a741095a15fef6c7d31b
1 parent
22d79652
add modal form by ajax for check-price form
Showing
8 changed files
with
96 additions
and
235 deletions
Show diff stats
1 | +<?php | |
2 | +/** | |
3 | + * Created by PhpStorm. | |
4 | + * User: Cibermag | |
5 | + * Date: 28.09.2015 | |
6 | + * Time: 11:40 | |
7 | + */ | |
8 | + | |
9 | +namespace backend\assets; | |
10 | + | |
11 | +use yii\web\AssetBundle; | |
12 | + | |
13 | +class CheckPriceAsset extends AssetBundle { | |
14 | + public $basePath = '@webroot'; | |
15 | + public $baseUrl = '@web'; | |
16 | + public $css = [ | |
17 | + 'css/site.css', | |
18 | + ]; | |
19 | + public $js = [ | |
20 | + 'js/check-price.js', | |
21 | + ]; | |
22 | + public $depends = [ | |
23 | + 'yii\web\YiiAsset', | |
24 | + 'yii\bootstrap\BootstrapAsset', | |
25 | + ]; | |
26 | +} | |
0 | 27 | \ No newline at end of file | ... | ... |
backend/controllers/CheckPriceController.php
... | ... | @@ -62,7 +62,7 @@ class CheckPriceController extends BaseController |
62 | 62 | public function actionIndex() |
63 | 63 | { |
64 | 64 | if(Yii::$app->request->isAjax){ |
65 | - CustomVarDamp::dumpAndDie(1); | |
65 | + CustomVarDamp::dumpAndDie('Ajax!!!'); | |
66 | 66 | } |
67 | 67 | |
68 | 68 | //$query = (new Query())->select('*')->from('{{%importer_files}}')->where(['not', ['time_end' => null]])->orderBy(['upload_time' => SORT_DESC]); |
... | ... | @@ -81,18 +81,18 @@ class CheckPriceController extends BaseController |
81 | 81 | } |
82 | 82 | |
83 | 83 | |
84 | - public function actionView ($id) | |
84 | + public function actionView ($id, $date_update) | |
85 | 85 | { |
86 | - // @todo переписать запрос - нужно условие на равенство даты, а также вьюшка должна быть модальным окном вызываемой по аджаксу | |
87 | - $query = Details::find()->where(['IMPORT_ID' => $id])->orderBy(['timestamp' => SORT_DESC]); | |
86 | + | |
87 | + $query = Details::find()->where(['IMPORT_ID' => $id, 'timestamp' => $date_update])->limit(20); | |
88 | 88 | |
89 | 89 | $provider = new ActiveDataProvider([ |
90 | 90 | 'query' => $query, |
91 | - 'pagination' => [ | |
92 | - 'pageSize' => 16, | |
93 | - ], | |
91 | + 'pagination' => false, | |
92 | + 'sort' => false, | |
94 | 93 | ]); |
95 | - return $this->render('view', | |
94 | + | |
95 | + return $this->renderAjax('view', | |
96 | 96 | ['dataProvider' => $provider]); |
97 | 97 | } |
98 | 98 | ... | ... |
backend/controllers/Check_priceController.php deleted
1 | -<?php | |
2 | -namespace backend\controllers; | |
3 | - | |
4 | -use Yii; | |
5 | -use yii\bootstrap\Modal; | |
6 | -use yii\data\ActiveDataProvider; | |
7 | -use yii\filters\AccessControl; | |
8 | -use backend\components\base\BaseController; | |
9 | -use yii\filters\VerbFilter; | |
10 | -use backend\models\UploadFileParsingForm; | |
11 | -use yii\web\UploadedFile; | |
12 | -use yii\data\ArrayDataProvider; | |
13 | -use yii\multiparser\DynamicFormHelper; | |
14 | -use backend\components\parsers\CustomParserConfigurator; | |
15 | -use backend\models\Details; | |
16 | -use backend\models\ImporterFiles; | |
17 | -use backend\models\Importer; | |
18 | -use yii\base\ErrorException; | |
19 | -use yii\db\Query; | |
20 | - | |
21 | -use common\components\CustomVarDamp; | |
22 | - | |
23 | -/** | |
24 | - * Parser controller | |
25 | - */ | |
26 | -class Check_priceController extends BaseController | |
27 | -{ | |
28 | - public $layout = "/column"; | |
29 | - | |
30 | - /** | |
31 | - * @inheritdoc | |
32 | - */ | |
33 | - public function behaviors() | |
34 | - { | |
35 | - return [ | |
36 | - 'access' => [ | |
37 | - 'class' => AccessControl::className(), | |
38 | - 'rules' => [ | |
39 | - [ | |
40 | - 'actions' => ['index', 'view'], | |
41 | - 'allow' => true, | |
42 | - 'roles' => ['@'], | |
43 | - ], | |
44 | - ], | |
45 | - ], | |
46 | -// 'verbs' => [ | |
47 | -// 'class' => VerbFilter::className(), | |
48 | -// 'actions' => [ | |
49 | -// 'logout' => ['post'], | |
50 | -// ], | |
51 | -// ], | |
52 | - ]; | |
53 | - } | |
54 | - | |
55 | - /** | |
56 | - * @inheritdoc | |
57 | - */ | |
58 | - public function actions() | |
59 | - { | |
60 | - return [ | |
61 | - 'error' => [ | |
62 | - 'class' => 'yii\web\ErrorAction', | |
63 | - ], | |
64 | - ]; | |
65 | - } | |
66 | - | |
67 | - | |
68 | - public function actionIndex() | |
69 | - { | |
70 | - | |
71 | - if(Yii::$app->request->isAjax){ | |
72 | - CustomVarDamp::dumpAndDie(1); | |
73 | - } | |
74 | - | |
75 | - //$query = (new Query())->select('*')->from('{{%importer_files}}')->where(['not', ['time_end' => null]])->orderBy(['upload_time' => SORT_DESC]); | |
76 | - $query = Importer::find()->where(['active' => true])->orderBy(['price_date_update' => SORT_DESC]); | |
77 | - | |
78 | - $provider = new ActiveDataProvider([ | |
79 | - 'query' => $query, | |
80 | - 'pagination' => [ | |
81 | - 'pageSize' => 10, | |
82 | - ], | |
83 | - ]); | |
84 | - return $this->render('index', | |
85 | - [ | |
86 | - 'dataProvider' => $provider, | |
87 | - ]); | |
88 | - } | |
89 | - | |
90 | - | |
91 | - public function actionView ($id) | |
92 | - { | |
93 | - | |
94 | - | |
95 | - | |
96 | - | |
97 | - $query = Details::find()->where(['IMPORT_ID' => $id])->orderBy(['timestamp' => SORT_DESC]); | |
98 | - | |
99 | - $provider = new ActiveDataProvider([ | |
100 | - 'query' => $query, | |
101 | - 'pagination' => [ | |
102 | - 'pageSize' => 16, | |
103 | - ], | |
104 | - ]); | |
105 | - return $this->render('view', | |
106 | - ['dataProvider' => $provider]); | |
107 | - } | |
108 | -} |
backend/views/check-price/index.php
... | ... | @@ -4,6 +4,9 @@ use yii\grid\GridView; |
4 | 4 | use yii\grid\SerialColumn; |
5 | 5 | use yii\grid\ActionColumn; |
6 | 6 | use yii\widgets\Pjax; |
7 | +use yii\bootstrap\Modal; | |
8 | +use yii\helpers\Url; | |
9 | +use backend\assets\CheckPriceAsset; | |
7 | 10 | |
8 | 11 | |
9 | 12 | /* @var $this yii\web\View */ |
... | ... | @@ -12,47 +15,68 @@ use yii\widgets\Pjax; |
12 | 15 | |
13 | 16 | $this->title = 'Проверка прайсов'; |
14 | 17 | $this->params['breadcrumbs'][] = $this->title; |
18 | +// зарегистрируем скрипт для обработки загрузки модального окна | |
19 | +CheckPriceAsset::register($this); | |
15 | 20 | ?> |
16 | 21 | <div class="catalog-index"> |
17 | 22 | |
18 | 23 | <h1><?= Html::encode($this->title) ?></h1> |
19 | 24 | |
20 | 25 | |
21 | - <?= GridView::widget( ['dataProvider' => $dataProvider, | |
22 | - 'columns' => [['class' => SerialColumn::className()], | |
23 | - [ | |
24 | - 'class' => ActionColumn::className(), | |
25 | - 'template'=>'{view}', | |
26 | - 'contentOptions' => function ($model, $key, $index, $column){ | |
27 | - return ['data' => ['id' => $model->id, 'date' => $model->price_date_update]]; | |
28 | - } | |
26 | + <?= GridView::widget(['dataProvider' => $dataProvider, | |
27 | + 'columns' => [ | |
28 | + ['class' => SerialColumn::className()], | |
29 | + | |
30 | + ['content' => function ($model) { | |
31 | + $url = Url::to(['view', 'id' => $model->id, 'date_update' => $model->price_date_update]); | |
32 | + return Html::a('<span class="glyphicon glyphicon-remove"> Просмотреть </span>', '#', [ | |
33 | + 'title' => Yii::t('yii', 'Просмотреть прайс'), | |
34 | + 'class' => 'modalButton', | |
35 | + 'value' => $url, | |
36 | + ]); | |
37 | + }, | |
29 | 38 | ], |
39 | + | |
30 | 40 | [ |
31 | - 'label' =>'Поставщик', | |
41 | + 'label' => 'Поставщик', | |
32 | 42 | 'value' => function ($data) { |
33 | - return '№ ' .$data->id . ' ' . $data->name; | |
43 | + return '№ ' . $data->id . ' ' . $data->name; | |
34 | 44 | }, |
35 | 45 | ], |
36 | - ['label' =>'Дата обновления', | |
37 | - 'attribute' => 'price_date_update' ], | |
38 | - ['label' => 'Кол-во дней', | |
39 | - 'value' => function ($data) { | |
40 | - $date1 = new DateTime("now"); | |
41 | - $date2 = new DateTime( $data->price_date_update ); | |
42 | - $quo_days = $date2->diff($date1)->format('%R%a'); | |
43 | - // уберем первый символ - там знак "+" | |
44 | - $quo_days = substr( $quo_days, 1, strlen($quo_days) ); | |
45 | - $quo_days = (int) $quo_days; | |
46 | - | |
47 | - if($quo_days > 15) | |
48 | - $quo_days = '>15'; | |
49 | - | |
50 | - return $quo_days; | |
51 | - } | |
52 | - ], | |
53 | - ]] );?> | |
54 | 46 | |
47 | + ['label' => 'Дата обновления', | |
48 | + 'attribute' => 'price_date_update'], | |
49 | + | |
50 | + ['label' => 'Кол-во дней', | |
51 | + 'value' => function ($data) { | |
52 | + $date1 = new DateTime("now"); | |
53 | + $date2 = new DateTime($data->price_date_update); | |
54 | + $quo_days = $date2->diff($date1)->format('%R%a'); | |
55 | + // уберем первый символ - там знак "+" | |
56 | + $quo_days = substr($quo_days, 1, strlen($quo_days)); | |
57 | + $quo_days = (int)$quo_days; | |
58 | + | |
59 | + if ($quo_days > 15) | |
60 | + $quo_days = '>15'; | |
61 | + | |
62 | + return $quo_days; | |
63 | + } | |
64 | + ], | |
65 | + ] | |
66 | + ]); ?> | |
67 | + | |
68 | + <?php | |
69 | + // сюда будем всавлять контент модального окна | |
70 | + Modal::begin([ | |
71 | + // 'header'=>'<h4>Прайс</h4>', | |
72 | + 'id' => 'modal', | |
73 | + 'size' => 'modal-lg', | |
74 | + ]); | |
75 | + | |
76 | + echo "<div id='modalContent'></div>"; | |
55 | 77 | |
78 | + Modal::end(); | |
79 | + ?> | |
56 | 80 | |
57 | 81 | |
58 | 82 | </div> |
59 | 83 | \ No newline at end of file | ... | ... |
backend/views/check_price/index.php deleted
1 | -<?php | |
2 | -use yii\helpers\Html; | |
3 | -use yii\grid\GridView; | |
4 | -use yii\grid\SerialColumn; | |
5 | -use yii\grid\ActionColumn; | |
6 | -use yii\widgets\Pjax; | |
7 | - | |
8 | - | |
9 | -/* @var $this yii\web\View */ | |
10 | -/* @var $searchModel backend\models\CatalogSearch */ | |
11 | -/* @var $dataProvider yii\data\ActiveDataProvider */ | |
12 | - | |
13 | -$this->title = 'Проверка прайсов'; | |
14 | -$this->params['breadcrumbs'][] = $this->title; | |
15 | -?> | |
16 | -<div class="catalog-index"> | |
17 | - | |
18 | - <h1><?= Html::encode($this->title) ?></h1> | |
19 | - | |
20 | - | |
21 | - <?= GridView::widget( ['dataProvider' => $dataProvider, | |
22 | - 'columns' => [['class' => SerialColumn::className()], | |
23 | - [ | |
24 | - 'class' => ActionColumn::className(), | |
25 | - 'template'=>'{view}', | |
26 | - 'contentOptions' => function ($model, $key, $index, $column){ | |
27 | - return ['data' => ['id' => $model->id, 'date' => $model->price_date_update]]; | |
28 | - } | |
29 | - ], | |
30 | - [ | |
31 | - 'label' =>'Поставщик', | |
32 | - 'value' => function ($data) { | |
33 | - return '№ ' .$data->id . ' ' . $data->name; | |
34 | - }, | |
35 | - ], | |
36 | - ['label' =>'Дата обновления', | |
37 | - 'attribute' => 'price_date_update' ], | |
38 | - ['label' => 'Кол-во дней', | |
39 | - 'value' => function ($data) { | |
40 | - $date1 = new DateTime("now"); | |
41 | - $date2 = new DateTime( $data->price_date_update ); | |
42 | - $quo_days = $date2->diff($date1)->format('%R%a'); | |
43 | - // уберем первый символ - там знак "+" | |
44 | - $quo_days = substr( $quo_days, 1, strlen($quo_days) ); | |
45 | - $quo_days = (int) $quo_days; | |
46 | - | |
47 | - if($quo_days > 15) | |
48 | - $quo_days = '>15'; | |
49 | - | |
50 | - return $quo_days; | |
51 | - } | |
52 | - ], | |
53 | - ]] );?> | |
54 | - | |
55 | - | |
56 | - | |
57 | - | |
58 | -</div> | |
59 | 0 | \ No newline at end of file |
backend/views/check_price/view.php deleted
1 | -<?php | |
2 | -use yii\helpers\Html; | |
3 | -use yii\grid\GridView; | |
4 | -use yii\grid\SerialColumn; | |
5 | -use yii\bootstrap\Modal; | |
6 | - | |
7 | - | |
8 | -/* @var $this yii\web\View */ | |
9 | -/* @var $searchModel backend\models\CatalogSearch */ | |
10 | -/* @var $dataProvider yii\data\ActiveDataProvider */ | |
11 | - | |
12 | -$this->title = 'Проверка прайсов'; | |
13 | -$this->params['breadcrumbs'][] = $this->title; | |
14 | - | |
15 | -?> | |
16 | -<div class="catalog-index"> | |
17 | - | |
18 | - <h1><?= Html::encode($this->title) ?></h1> | |
19 | - | |
20 | - <?= GridView::widget( ['dataProvider' => $dataProvider, | |
21 | - | |
22 | - ] ); | |
23 | - | |
24 | - | |
25 | - ?> | |
26 | - | |
27 | - | |
28 | - | |
29 | -</div> | |
30 | -<?php | |
31 | - | |
32 | -?> | |
33 | 0 | \ No newline at end of file |
backend/views/parser/server-files.php