From b16ed95f7aecff5c5edfa4ff9c0570c0240662ba Mon Sep 17 00:00:00 2001 From: Yarik Date: Wed, 10 Feb 2016 15:18:56 +0200 Subject: [PATCH] test --- common/models/Team.php | 6 +++--- console/migrations/m160208_101449_team.php | 2 +- frontend/controllers/SiteController.php | 19 +++++++++++++++++++ frontend/views/accounts/_projects_form.php | 28 ++++++++++++++++++++++------ frontend/views/accounts/_team_form.php | 21 +++++++++++++++++++-- 5 files changed, 64 insertions(+), 12 deletions(-) diff --git a/common/models/Team.php b/common/models/Team.php index 9e8bb58..edd96b7 100644 --- a/common/models/Team.php +++ b/common/models/Team.php @@ -13,7 +13,7 @@ * @property integer $user_id * @property string $firstname * @property string $lastname - * @property string $midlename + * @property string $middlename * @property string $link * @property string $position * @property integer $department_id @@ -85,7 +85,7 @@ [ 'firstname', 'lastname', - 'midlename', + 'middlename', 'link', 'position', 'photo', @@ -107,7 +107,7 @@ 'user_id' => Yii::t('app', 'User ID'), 'firstname' => Yii::t('app', 'Имя'), 'lastname' => Yii::t('app', 'Фамилия'), - 'midlename' => Yii::t('app', 'Отчество'), + 'middlename' => Yii::t('app', 'Отчество'), 'link' => Yii::t('app', 'Ссылка на профиль МФП'), 'position' => Yii::t('app', 'Должность'), 'department_id' => Yii::t('app', 'Отдел компании'), diff --git a/console/migrations/m160208_101449_team.php b/console/migrations/m160208_101449_team.php index d6cc451..fbf7e62 100644 --- a/console/migrations/m160208_101449_team.php +++ b/console/migrations/m160208_101449_team.php @@ -17,7 +17,7 @@ class m160208_101449_team extends Migration 'link' => $this->string(255), 'position' => $this->string(255)->notNull(), 'department_id' => $this->integer()->notNull(), - 'experience_from' => $this->timestamp(), + 'experience_from' => $this->integer(), 'date_add' => $this->timestamp()->notNull(), 'user_add_id' => $this->integer(), 'photo' => $this->string(255), diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php index b391fe1..36231a8 100755 --- a/frontend/controllers/SiteController.php +++ b/frontend/controllers/SiteController.php @@ -2,6 +2,7 @@ namespace frontend\controllers; use common\models\Cities; +use common\models\Country; use common\models\Specialization; use common\models\UserInfo; use Yii; @@ -69,6 +70,24 @@ class SiteController extends Controller return $out; } + public function actionCountry($q = null, $id = null) { + \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; + $out = ['results' => ['id' => '', 'text' => '']]; + if (!is_null($q)) { + $query = new Query; + $query->select('country_name AS id, country_name AS text') + ->from('country') + ->where(['like', 'lower(country_name)', mb_strtolower($q) ]) + ->limit(20); + $command = $query->createCommand(); + $data = $command->queryAll(); + $out['results'] = array_values($data); + } + elseif ($id > 0) { + $out['results'] = ['id' => $id, 'text' => Country::find($id)->country_name]; + } + return $out; + } public function actionFormsModal() { diff --git a/frontend/views/accounts/_projects_form.php b/frontend/views/accounts/_projects_form.php index 4eeaa35..7e80c66 100644 --- a/frontend/views/accounts/_projects_form.php +++ b/frontend/views/accounts/_projects_form.php @@ -1,16 +1,18 @@ title = 'Мой профиль'; @@ -29,15 +31,29 @@ ->textInput() ?> field($project, 'project_pid') - ->dropDownList($projects, ['prompt' => 'Родительский проект']) ?> + ->dropDownList($projects, [ 'prompt' => 'Родительский проект' ]) ?> field($project, 'specializationInput') ->checkboxList($specialization) ?>
Адрес: - field($project, 'city', [ 'template' => "{label}{input}{hint}{error}" ]) - ->textInput() ?> + field($project, 'city') + ->widget(Select2::classname(), [ + 'options' => [ 'placeholder' => 'Выбор города ...' ], + 'pluginOptions' => [ + 'allowClear' => true, + 'minimumInputLength' => 3, + 'ajax' => [ + 'url' => \yii\helpers\Url::to([ 'site/city' ]), + 'dataType' => 'json', + 'data' => new JsExpression('function(params) { return {q:params.term}; }'), + ], + 'escapeMarkup' => new JsExpression('function (markup) { return markup; }'), + 'templateResult' => new JsExpression('function(city) { return city.text; }'), + 'templateSelection' => new JsExpression('function (city) { return city.text; }'), + ], + ]); ?> field($project, 'street', [ 'template' => "{label}{input}{hint}{error}" ]) ->textInput() ?> field($project, 'house', [ 'template' => "{label}{input}{hint}{error}" ]) diff --git a/frontend/views/accounts/_team_form.php b/frontend/views/accounts/_team_form.php index 74c178b..dad351a 100644 --- a/frontend/views/accounts/_team_form.php +++ b/frontend/views/accounts/_team_form.php @@ -6,9 +6,11 @@ */ use common\models\Team; use common\widgets\ImageUploader; + use kartik\select2\Select2; use mihaildev\ckeditor\CKEditor; use yii\helpers\Html; use yii\jui\DatePicker; + use yii\web\JsExpression; use yii\widgets\ActiveForm; $this->title = 'Мой профиль'; @@ -41,8 +43,23 @@ field($team, 'experience_from', [ 'template' => "{label}, с {input} года \n{hint}\n{error}" ]) ->input('number') ?> -field($team, 'country_id') - ->dropDownList($country) ?> +field($team, 'country_id')->widget(Select2::classname(), [ + 'options' => ['placeholder' => 'Выбор страны ...'], + 'pluginOptions' => [ + 'allowClear' => true, + 'minimumInputLength' => 3, + 'ajax' => [ + 'url' => \yii\helpers\Url::to(['site/country']), + 'dataType' => 'json', + 'data' => new JsExpression('function(params) { return {q:params.term}; }') + ], + 'escapeMarkup' => new JsExpression('function (markup) { return markup; }'), + 'templateResult' => new JsExpression('function(country) { return country.text; }'), + 'templateSelection' => new JsExpression('function (country) { return country.text; }'), + ], + ]); +?> $team, -- libgit2 0.21.4