Commit 998611ceb89c5c8ae1c994f424d8b848fe8bd750

Authored by Administrator
1 parent 5860e30d

add Vitaliy's widgets

common/models/Cities.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace common\models;
  4 +
  5 +use Yii;
  6 +
  7 +/**
  8 + * This is the model class for table "cities".
  9 + *
  10 + * @property integer $id
  11 + * @property string $name
  12 + * @property integer $is_active
  13 + * @property integer $parent
  14 + */
  15 +class Cities extends \yii\db\ActiveRecord
  16 +{
  17 + /**
  18 + * @inheritdoc
  19 + */
  20 + public static function tableName()
  21 + {
  22 + return 'cities';
  23 + }
  24 +
  25 + /**
  26 + * @inheritdoc
  27 + */
  28 + public function rules()
  29 + {
  30 + return [
  31 + [['is_active', 'parent'], 'integer'],
  32 + [['name'], 'string', 'max' => 255],
  33 + ];
  34 + }
  35 +
  36 + /**
  37 + * @inheritdoc
  38 + */
  39 + public function attributeLabels()
  40 + {
  41 + return [
  42 + 'id' => 'ID',
  43 + 'name' => 'Name',
  44 + 'is_active' => 'Is Active',
  45 + 'parent' => 'Parent',
  46 + ];
  47 + }
  48 +}
... ...
frontend/assets/AppAsset.php
... ... @@ -38,7 +38,7 @@ class AppAsset extends AssetBundle
38 38 ];
39 39 public $depends = [
40 40 'yii\web\YiiAsset',
41   - 'backend\assets\FileUploadAsset'
  41 + 'backend\assets\FileUploadAsset',
42 42 ];
43 43 public $jsOptions = array(
44 44 'position' => \yii\web\View::POS_HEAD
... ...
frontend/config/main.php
... ... @@ -47,7 +47,6 @@ return [
47 47 'showScriptName' => false,
48 48 'rules' => [
49 49 'landing/<view:[\w-]+>' => 'landing/view',
50   - 'site/city/<query:[\d]+>' => 'site/city',
51 50 ]
52 51 ],
53 52 ],
... ...
frontend/controllers/SiteController.php
1 1 <?php
2 2 namespace frontend\controllers;
3 3  
  4 +use common\models\Cities;
4 5 use common\models\Specialization;
5 6 use common\models\UserInfo;
6 7 use Yii;
... ... @@ -49,21 +50,23 @@ class SiteController extends Controller
49 50  
50 51  
51 52  
52   - public function actionCity($query){
53   - \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
54   - $out = ['results' => ['id' => '', 'text' => '']];
55   - if (!is_null($query)) {
56   - $query = new Query();
57   - $query->select('id, name AS text')
58   - ->from('city')
59   - ->where(['like', 'name', $query])
60   - ->limit(20);
61   - $command = $query->createCommand();
62   - $data = $command->queryAll();
63   - $out['results'] = array_values($data);
64   - }
65   -
66   - return $out;
  53 + public function actionCity($q = null, $id = null) {
  54 + \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
  55 + $out = ['results' => ['id' => '', 'text' => '']];
  56 + if (!is_null($q)) {
  57 + $query = new Query;
  58 + $query->select('id, name AS text')
  59 + ->from('cities')
  60 + ->where(['like', 'name', $q])
  61 + ->limit(20);
  62 + $command = $query->createCommand();
  63 + $data = $command->queryAll();
  64 + $out['results'] = array_values($data);
  65 + }
  66 + elseif ($id > 0) {
  67 + $out['results'] = ['id' => $id, 'text' => Cities::find($id)->name];
  68 + }
  69 + return $out;
67 70 }
68 71  
69 72  
... ...
frontend/models/SignupForm.php
... ... @@ -17,6 +17,7 @@ class SignupForm extends Model
17 17 public $lastname;
18 18 public $verifyCode;
19 19 public $location;
  20 + public $type;
20 21  
21 22 /**
22 23 * @inheritdoc
... ... @@ -39,6 +40,8 @@ class SignupForm extends Model
39 40  
40 41 ['verifyCode', 'captcha'],
41 42  
  43 + ['type', 'integer'],
  44 +
42 45 ['password', 'required'],
43 46 ['password', 'string', 'min' => 6],
44 47 ];
... ...
frontend/views/site/registration.php
... ... @@ -5,7 +5,9 @@
5 5 */
6 6 use yii\captcha\Captcha;
7 7 use yii\widgets\ActiveForm;
8   - $this->registerJsFile('/js/selectize.js');
  8 + use kartik\select2\Select2;
  9 + use yii\web\JsExpression;
  10 +
9 11 ?>
10 12 <div class="section-box content">
11 13 <div class="section-box registration">
... ... @@ -48,18 +50,26 @@
48 50 <div class="who-you-are-title style">Кто Вы</div>
49 51 <div class="who-you-are-form-wr style">
50 52 <div class="who-you-are-form">
51   - <div class="check-radio-wr">
52 53  
53   - <div class="custom-form-buttons">
54   - <input class="custom-radio" id="custom-radio-1" name="group-1" checked="checked" type="radio">
55   - <label for="custom-radio-1"><span></span>Частное лицо copy</label>
56   - </div>
57 54  
58   - <div class="custom-form-buttons">
59   - <input class="custom-radio" id="custom-radio-2" name="group-1" type="radio">
60   - <label for="custom-radio-2"><span></span>Компания</label>
61   - </div>
62   - </div>
  55 +
  56 + <?= $form->field ($model, 'type',['options'=> ['class'=>'check-radio-wr']])
  57 + ->label (false)
  58 + ->radioList (
  59 + [1 => 'Частное лицо', 2 => 'Компания'],
  60 + [
  61 + 'item' => function($index, $label, $name, $checked, $value) {
  62 + $return = '<div class="custom-form-buttons">';
  63 + $return .= '<input class="custom-radio" id="custom-radio-'.$value.'" type="radio" name="' . $name . '" value="' . $value . '" >';
  64 + $return .= '<label for="custom-radio-'.$value.'" ><span></span>' . $label .'</label>';
  65 + $return .= '</div>';
  66 + return $return;
  67 + }
  68 + ]
  69 + );
  70 + ?>
  71 +
  72 +
63 73 <div class="check-radio-wr">
64 74 <div class="custom-form-buttons">
65 75 <input class="custom-check" id="custom-check-1" type="checkbox" checked>
... ... @@ -75,36 +85,36 @@
75 85  
76 86 <div class="input-blocks-wrapper">
77 87 <div class="input-blocks">
78   - <label for="input-txt-4">Имя</label>
79   - <input class="custom-input-2" id="input-txt-4" type="text">
  88 + <?= $form->field($model, 'firstname')->textInput(['class'=>'custom-input-2'])?>
80 89 </div>
81 90 </div>
82 91 <div class="input-blocks-wrapper">
83 92 <div class="input-blocks">
84   - <label for="input-txt-5">Фамилия</label>
85   - <input class="custom-input-2" id="input-txt-5" type="text">
86   - </div>
87   - </div>
88   - <div class="input-blocks-wrapper city" >
89   -
90   - <div class="control-group">
91   - <div id="btnClear" style=""></div>
92   -
93   - <label for="select-beast-w">Город</label>
94   - <select id="select-beast-w" placeholder="">
95   - <option value="">Выберите город</option>
96   - <option value="4">Киев</option>
97   - <option value="1">Одесса</option>
98   - <option value="3">Харьков</option>
99   - <option value="2">Днепр</option>
100   - <option value="6">Чернигов</option>
101   - <option value="8">Черкасы</option>
102   - <option value="9">Черкасы</option>
103   - <option value="5">Черкасы</option>
104   - </select>
  93 + <?= $form->field($model, 'lastname')->textInput(['class'=>'custom-input-2'])?>
105 94 </div>
106 95 </div>
107 96  
  97 + <?=
  98 + $form->field($model, 'location')->widget(Select2::classname(), [
  99 + 'options' => ['placeholder' => 'Search for a city ...'],
  100 + 'pluginOptions' => [
  101 + 'allowClear' => true,
  102 + 'minimumInputLength' => 3,
  103 + 'ajax' => [
  104 + 'url' => \yii\helpers\Url::to(['site/city']),
  105 + 'dataType' => 'json',
  106 + 'data' => new JsExpression('function(params) { return {q:params.term}; }')
  107 + ],
  108 + 'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
  109 + 'templateResult' => new JsExpression('function(city) { return city.text; }'),
  110 + 'templateSelection' => new JsExpression('function (city) { return city.text; }'),
  111 + ],
  112 + ]);
  113 + ?>
  114 +
  115 +
  116 +
  117 +
108 118 <div class="input-blocks-wrapper city-two">
109 119 <div class="input-blocks">
110 120 <label for="input-txt-7">Город не в списке</label>
... ...