From 1b0b689c3d9e6b10f6e5099052604f1c95424663 Mon Sep 17 00:00:00 2001 From: stes Date: Fri, 28 Jul 2017 11:23:48 +0300 Subject: [PATCH] stock map --- migrations/m170721_133313_create_city_table.php | 1 + models/City.php | 23 ++++++++++++++++++++--- views/city/_form.php | 45 ++++++++++++++++++++++++++++++++++++++++++++- views/city/_form_language.php | 9 +++++++-- web/js/stock.js | 4 ++++ 5 files changed, 76 insertions(+), 6 deletions(-) diff --git a/migrations/m170721_133313_create_city_table.php b/migrations/m170721_133313_create_city_table.php index 84685c0..6f5a21c 100755 --- a/migrations/m170721_133313_create_city_table.php +++ b/migrations/m170721_133313_create_city_table.php @@ -17,6 +17,7 @@ class m170721_133313_create_city_table extends Migration 'sort' => $this->integer(), 'status' => $this->boolean() ->defaultValue(true), + 'coords' => $this->string(), ]); } diff --git a/models/City.php b/models/City.php index 63cabca..adea0a2 100644 --- a/models/City.php +++ b/models/City.php @@ -7,7 +7,8 @@ use artbox\core\behaviors\LanguageBehavior; use yii\db\ActiveRecord; use yii\web\Request; - + use yii\helpers\Json; + /** * This is the model class for table "city". * @@ -18,9 +19,8 @@ * @property Language[] $languages * @property CityLang[] $modelLangs * @property Shop[] $shops - * * @method bool saveWithLangs() - * @method bool loadWithLangs( Request $request) + * @method bool loadWithLangs( Request $request ) * @method void generateLangs() */ class City extends ActiveRecord @@ -56,6 +56,13 @@ [ 'status' ], 'boolean', ], + [ + [ + 'coords', + 'coordsArr', + ], + 'safe', + ], ]; } @@ -96,4 +103,14 @@ { return $this->hasMany(Shop::className(), [ 'city_id' => 'id' ]); } + + public function setCoordsArr($value) + { + $this->coords = Json::encode($value); + } + + public function getCoordsArr() + { + return Json::decode($this->coords); + } } diff --git a/views/city/_form.php b/views/city/_form.php index 299ee28..b1a021c 100644 --- a/views/city/_form.php +++ b/views/city/_form.php @@ -8,6 +8,8 @@ /* @var $model artbox\stock\models\City */ /* @var $form yii\widgets\ActiveForm */ /* @var $modelLangs artbox\stock\models\CityLang */ + + //\artbox\stock\assets\StockAsset::register($this); ?>
@@ -20,7 +22,24 @@ 'form' => $form, ] ) ?> - + field($model, 'coordsArr[lat]') + ->textInput( + [ + 'value' => ( isset($model->coordsArr[ 'lat' ]) ) ? $model->coordsArr[ 'lat' ] : '', + 'id' => 'lat', + 'size' => 10, + ] + ) + ->label(false); ?> + field($model, 'coordsArr[lng]') + ->textInput( + [ + 'value' => ( isset($model->coordsArr[ 'lng' ]) ) ? $model->coordsArr[ 'lng' ] : '', + 'id' => 'lng', + 'size' => 10, + ] + ) + ->label(false); ?> field($model, 'sort') ->textInput() ?> @@ -37,3 +56,27 @@
+ diff --git a/views/city/_form_language.php b/views/city/_form_language.php index 4addcd5..5074e82 100755 --- a/views/city/_form_language.php +++ b/views/city/_form_language.php @@ -7,7 +7,7 @@ use yii\widgets\ActiveForm; /** - * @var CityLang $model_lang + * @var CityLang $model_lang * @var Language $language * @var ActiveForm $form * @var View $this @@ -15,7 +15,12 @@ ?> field($model_lang, '[' . $language->id . ']title') - ->textInput([ 'maxlength' => true ]); + ->textInput( + [ + 'maxlength' => true, + 'id' => 'city_title', + ] + ); echo $attributeField; ?> diff --git a/web/js/stock.js b/web/js/stock.js index a694af8..5ce33b9 100644 --- a/web/js/stock.js +++ b/web/js/stock.js @@ -36,6 +36,10 @@ $(function() { } }); }); + + + + var lat, lng; if ($("#lat").val() !== "" && $("#lng").val() !== ""){ lat = $("#lat").val(); -- libgit2 0.21.4