Commit dac1c9032ba15a907cbe2f57490b4366721327b6

Authored by Anastasia
1 parent 0dee61fa

add button in admin

backend/controllers/PackageController.php
... ... @@ -18,7 +18,9 @@
18 18 use common\models\Package;
19 19 use yii\filters\AccessControl;
20 20 use yii\filters\VerbFilter;
  21 + use yii\helpers\Url;
21 22 use yii\web\Controller;
  23 + use yii\web\JsExpression;
22 24 use yii\web\NotFoundHttpException;
23 25  
24 26 class PackageController extends Controller implements ControllerInterface
... ... @@ -139,6 +141,37 @@
139 141 protected static function fieldsConfig()
140 142 {
141 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 175 'model' => Package::className(),
143 176 'hasAlias' => true,
144 177 'languageFields' => [
... ...
backend/controllers/ServiceController.php
... ... @@ -18,9 +18,11 @@
18 18 use common\models\Service;
19 19 use yii\filters\AccessControl;
20 20 use yii\filters\VerbFilter;
  21 + use yii\helpers\Url;
21 22 use yii\web\Controller;
  23 + use yii\web\JsExpression;
22 24 use yii\web\NotFoundHttpException;
23   -
  25 +
24 26 class ServiceController extends Controller implements ControllerInterface
25 27 {
26 28 public function behaviors()
... ... @@ -43,7 +45,7 @@
43 45 ],
44 46 ];
45 47 }
46   -
  48 +
47 49 public function actions()
48 50 {
49 51 return [
... ... @@ -53,7 +55,7 @@
53 55 'title' => [
54 56 'type' => Index::ACTION_COL,
55 57 ],
56   - 'parent' => [
  58 + 'parent' => [
57 59 'type' => Index::RELATION_COL,
58 60 'columnConfig' => [
59 61 'relationField' => 'title',
... ... @@ -65,7 +67,7 @@
65 67 'sort' => [
66 68 'type' => Index::POSITION_COL,
67 69 ],
68   - 'status' => [
  70 + 'status' => [
69 71 'type' => Index::STATUS_COL,
70 72 ],
71 73 ],
... ... @@ -105,35 +107,35 @@
105 107 ],
106 108 ];
107 109 }
108   -
  110 +
109 111 public function findModel($id)
110 112 {
111 113 $model = Service::find()
112   - ->with('languages')
113   - ->where([ 'id' => $id ])
114   - ->one();
  114 + ->with('languages')
  115 + ->where([ 'id' => $id ])
  116 + ->one();
115 117 if ($model !== null) {
116 118 return $model;
117 119 } else {
118 120 throw new NotFoundHttpException('The requested page does not exist.');
119 121 }
120 122 }
121   -
  123 +
122 124 public function newModel()
123 125 {
124 126 return new Service();
125 127 }
126   -
  128 +
127 129 public function deleteModel($id)
128 130 {
129 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 139 $langs = call_user_func(
138 140 [
139 141 $page,
... ... @@ -145,20 +147,58 @@
145 147 $lang->alias->delete();
146 148 }
147 149 }
148   -
  150 +
149 151 return $page->delete();
150 152 }
151   -
  153 +
152 154 protected static function fieldsConfig()
153 155 {
154 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 195 'model' => Service::className(),
156 196 'hasAlias' => true,
157 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 204 'name' => 'body',
... ... @@ -168,7 +208,7 @@
168 208 'fields' => [
169 209 [
170 210 'name' => 'image_id',
171   - 'type' => Form::IMAGE
  211 + 'type' => Form::IMAGE,
172 212 ],
173 213 [
174 214 'name' => 'parent_id',
... ...
frontend/controllers/PackageController.php
... ... @@ -9,14 +9,14 @@
9 9 namespace frontend\controllers;
10 10  
11 11 use common\models\Package;
12   - use yii\data\ActiveDataProvider;
13 12 use yii\web\Controller;
14 13  
15 14 class PackageController extends Controller
16 15 {
17 16 public function actionView($id){
18 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 20 return $this->render('view', [
21 21 'package' => $package
22 22 ]);
... ...
frontend/controllers/ServiceController.php
... ... @@ -118,6 +118,7 @@
118 118  
119 119  
120 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 122 return $this->render('view', [
122 123 'model' => $model,
123 124 'others'=> $others,
... ...