Commit dac1c9032ba15a907cbe2f57490b4366721327b6

Authored by Anastasia
1 parent 0dee61fa

add button in admin

backend/controllers/PackageController.php
@@ -18,7 +18,9 @@ @@ -18,7 +18,9 @@
18 use common\models\Package; 18 use common\models\Package;
19 use yii\filters\AccessControl; 19 use yii\filters\AccessControl;
20 use yii\filters\VerbFilter; 20 use yii\filters\VerbFilter;
  21 + use yii\helpers\Url;
21 use yii\web\Controller; 22 use yii\web\Controller;
  23 + use yii\web\JsExpression;
22 use yii\web\NotFoundHttpException; 24 use yii\web\NotFoundHttpException;
23 25
24 class PackageController extends Controller implements ControllerInterface 26 class PackageController extends Controller implements ControllerInterface
@@ -139,6 +141,37 @@ @@ -139,6 +141,37 @@
139 protected static function fieldsConfig() 141 protected static function fieldsConfig()
140 { 142 {
141 return [ 143 return [
  144 + 'tinyMceConfig' => [
  145 + 'language' => 'ru',
  146 + 'clientOptions' => [
  147 + 'file_browser_callback' => new JsExpression(
  148 + "function(field_name, url, type, win) {
  149 +window.open('" . Url::to(
  150 + [
  151 + 'imagemanager/manager',
  152 + 'view-mode' => 'iframe',
  153 + 'select-type' => 'tinymce',
  154 + ]
  155 + ) . "&tag_name='+field_name,'','width=800,height=540 ,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no');
  156 +}"
  157 + ),
  158 + 'plugins' => [
  159 + "advlist autolink lists link charmap print preview anchor",
  160 + "searchreplace visualblocks code fullscreen",
  161 + "insertdatetime media table contextmenu paste image",
  162 + ],
  163 + 'toolbar' => "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | code | button",
  164 + 'setup' => new JsExpression('function (editor) {
  165 + editor.addButton("button", {
  166 + text: "Записаться на прием",
  167 + icon: false,
  168 + onclick: function () {
  169 + editor.insertContent("[[button]]");
  170 + }
  171 + });
  172 + }')
  173 + ],
  174 + ],
142 'model' => Package::className(), 175 'model' => Package::className(),
143 'hasAlias' => true, 176 'hasAlias' => true,
144 'languageFields' => [ 177 'languageFields' => [
backend/controllers/ServiceController.php
@@ -18,9 +18,11 @@ @@ -18,9 +18,11 @@
18 use common\models\Service; 18 use common\models\Service;
19 use yii\filters\AccessControl; 19 use yii\filters\AccessControl;
20 use yii\filters\VerbFilter; 20 use yii\filters\VerbFilter;
  21 + use yii\helpers\Url;
21 use yii\web\Controller; 22 use yii\web\Controller;
  23 + use yii\web\JsExpression;
22 use yii\web\NotFoundHttpException; 24 use yii\web\NotFoundHttpException;
23 - 25 +
24 class ServiceController extends Controller implements ControllerInterface 26 class ServiceController extends Controller implements ControllerInterface
25 { 27 {
26 public function behaviors() 28 public function behaviors()
@@ -43,7 +45,7 @@ @@ -43,7 +45,7 @@
43 ], 45 ],
44 ]; 46 ];
45 } 47 }
46 - 48 +
47 public function actions() 49 public function actions()
48 { 50 {
49 return [ 51 return [
@@ -53,7 +55,7 @@ @@ -53,7 +55,7 @@
53 'title' => [ 55 'title' => [
54 'type' => Index::ACTION_COL, 56 'type' => Index::ACTION_COL,
55 ], 57 ],
56 - 'parent' => [ 58 + 'parent' => [
57 'type' => Index::RELATION_COL, 59 'type' => Index::RELATION_COL,
58 'columnConfig' => [ 60 'columnConfig' => [
59 'relationField' => 'title', 61 'relationField' => 'title',
@@ -65,7 +67,7 @@ @@ -65,7 +67,7 @@
65 'sort' => [ 67 'sort' => [
66 'type' => Index::POSITION_COL, 68 'type' => Index::POSITION_COL,
67 ], 69 ],
68 - 'status' => [ 70 + 'status' => [
69 'type' => Index::STATUS_COL, 71 'type' => Index::STATUS_COL,
70 ], 72 ],
71 ], 73 ],
@@ -105,35 +107,35 @@ @@ -105,35 +107,35 @@
105 ], 107 ],
106 ]; 108 ];
107 } 109 }
108 - 110 +
109 public function findModel($id) 111 public function findModel($id)
110 { 112 {
111 $model = Service::find() 113 $model = Service::find()
112 - ->with('languages')  
113 - ->where([ 'id' => $id ])  
114 - ->one(); 114 + ->with('languages')
  115 + ->where([ 'id' => $id ])
  116 + ->one();
115 if ($model !== null) { 117 if ($model !== null) {
116 return $model; 118 return $model;
117 } else { 119 } else {
118 throw new NotFoundHttpException('The requested page does not exist.'); 120 throw new NotFoundHttpException('The requested page does not exist.');
119 } 121 }
120 } 122 }
121 - 123 +
122 public function newModel() 124 public function newModel()
123 { 125 {
124 return new Service(); 126 return new Service();
125 } 127 }
126 - 128 +
127 public function deleteModel($id) 129 public function deleteModel($id)
128 { 130 {
129 $page = Service::find() 131 $page = Service::find()
130 - ->with('languages.alias')  
131 - ->where(  
132 - [  
133 - 'id' => $id,  
134 - ]  
135 - )  
136 - ->one(); 132 + ->with('languages.alias')
  133 + ->where(
  134 + [
  135 + 'id' => $id,
  136 + ]
  137 + )
  138 + ->one();
137 $langs = call_user_func( 139 $langs = call_user_func(
138 [ 140 [
139 $page, 141 $page,
@@ -145,20 +147,58 @@ @@ -145,20 +147,58 @@
145 $lang->alias->delete(); 147 $lang->alias->delete();
146 } 148 }
147 } 149 }
148 - 150 +
149 return $page->delete(); 151 return $page->delete();
150 } 152 }
151 - 153 +
152 protected static function fieldsConfig() 154 protected static function fieldsConfig()
153 { 155 {
154 return [ 156 return [
  157 + 'tinyMceConfig' => [
  158 + 'language' => 'ru',
  159 + 'clientOptions' => [
  160 + 'file_browser_callback' => new JsExpression(
  161 + "function(field_name, url, type, win) {
  162 +window.open('" . Url::to(
  163 + [
  164 + 'imagemanager/manager',
  165 + 'view-mode' => 'iframe',
  166 + 'select-type' => 'tinymce',
  167 + ]
  168 + ) . "&tag_name='+field_name,'','width=800,height=540 ,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no');
  169 +}"
  170 + ),
  171 + 'plugins' => [
  172 + "advlist autolink lists link charmap print preview anchor",
  173 + "searchreplace visualblocks code fullscreen",
  174 + "insertdatetime media table contextmenu paste image",
  175 + ],
  176 + 'toolbar' => "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | code | prices | button",
  177 + 'setup' => new JsExpression('function (editor) {
  178 + editor.addButton("prices", {
  179 + text: "Цена",
  180 + icon: false,
  181 + onclick: function () {
  182 + editor.insertContent("[[prices]]");
  183 + }
  184 + });
  185 + editor.addButton("button", {
  186 + text: "Записаться на прием",
  187 + icon: false,
  188 + onclick: function () {
  189 + editor.insertContent("[[button]]");
  190 + }
  191 + });
  192 + }')
  193 + ],
  194 + ],
155 'model' => Service::className(), 195 'model' => Service::className(),
156 'hasAlias' => true, 196 'hasAlias' => true,
157 'languageFields' => [ 197 'languageFields' => [
158 [ 198 [
159 - 'name' => 'title',  
160 - 'type' => Form::STRING,  
161 - 'decorate' => true 199 + 'name' => 'title',
  200 + 'type' => Form::STRING,
  201 + 'decorate' => true,
162 ], 202 ],
163 [ 203 [
164 'name' => 'body', 204 'name' => 'body',
@@ -168,7 +208,7 @@ @@ -168,7 +208,7 @@
168 'fields' => [ 208 'fields' => [
169 [ 209 [
170 'name' => 'image_id', 210 'name' => 'image_id',
171 - 'type' => Form::IMAGE 211 + 'type' => Form::IMAGE,
172 ], 212 ],
173 [ 213 [
174 'name' => 'parent_id', 214 'name' => 'parent_id',
frontend/controllers/PackageController.php
@@ -9,14 +9,14 @@ @@ -9,14 +9,14 @@
9 namespace frontend\controllers; 9 namespace frontend\controllers;
10 10
11 use common\models\Package; 11 use common\models\Package;
12 - use yii\data\ActiveDataProvider;  
13 use yii\web\Controller; 12 use yii\web\Controller;
14 13
15 class PackageController extends Controller 14 class PackageController extends Controller
16 { 15 {
17 public function actionView($id){ 16 public function actionView($id){
18 $package = Package::find()->with('language')->where(['id' => $id])->one(); 17 $package = Package::find()->with('language')->where(['id' => $id])->one();
19 - 18 + $package->body = str_replace('[[button]]', '<span class="btn_ modal-link" data-form="callback">'.\Yii::t('app','Make an appointment').'</span>', $package->body);
  19 +
20 return $this->render('view', [ 20 return $this->render('view', [
21 'package' => $package 21 'package' => $package
22 ]); 22 ]);
frontend/controllers/ServiceController.php
@@ -118,6 +118,7 @@ @@ -118,6 +118,7 @@
118 118
119 119
120 $model->body = str_replace('[[prices]]', $this->renderPartial('_prices', ['prices' => $model->prices]), $model->body); 120 $model->body = str_replace('[[prices]]', $this->renderPartial('_prices', ['prices' => $model->prices]), $model->body);
  121 + $model->body = str_replace('[[button]]', '<span class="btn_ modal-link" data-form="callback">'.\Yii::t('app','Make an appointment').'</span>', $model->body);
121 return $this->render('view', [ 122 return $this->render('view', [
122 'model' => $model, 123 'model' => $model,
123 'others'=> $others, 124 'others'=> $others,