Commit f6a2a0d555dfe014a471b8202e64519adbe5f98d
1 parent
65bb8189
test
Showing
8 changed files
with
96 additions
and
51 deletions
Show diff stats
backend/web/js/fieldWidget.js
| ... | ... | @@ -6,14 +6,4 @@ $(document).ready(function(){ |
| 6 | 6 | }); |
| 7 | 7 | |
| 8 | 8 | |
| 9 | - | |
| 10 | - $('.add_field').click(function(){ | |
| 11 | - var block = $('.fields_video_result'); | |
| 12 | - var sub_block = '<div class="form-group">'+ | |
| 13 | - '<input type="text" class="form-control" value="" name="Fields[video]['+ start_i++ +'][value]">'+ | |
| 14 | - '<span data-id="none" title="удалить" class="glyphicon glyphicon-trash delete-field-item"></span>'+ | |
| 15 | - '<div>'; | |
| 16 | - block.append(sub_block); | |
| 17 | - | |
| 18 | - }); | |
| 19 | 9 | }); |
| 20 | 10 | \ No newline at end of file | ... | ... |
common/config/main-local.php
| ... | ... | @@ -3,9 +3,9 @@ return [ |
| 3 | 3 | 'components' => [ |
| 4 | 4 | 'db' => [ |
| 5 | 5 | 'class' => 'yii\db\Connection', |
| 6 | - 'dsn' => 'pgsql:host=195.248.225.149;port=5432;dbname=mfp', | |
| 7 | - 'username' => 'test33', | |
| 8 | - 'password' => 'E4q2N7i9', | |
| 6 | + 'dsn' => 'pgsql:host=127.0.0.1;port=5432;dbname=mfp_local', | |
| 7 | + 'username' => 'postges', | |
| 8 | + 'password' => '', | |
| 9 | 9 | 'schemaMap' => [ |
| 10 | 10 | 'pgsql'=> [ |
| 11 | 11 | 'class'=>'yii\db\pgsql\Schema', | ... | ... |
common/models/UserInfo.php
| ... | ... | @@ -63,7 +63,7 @@ class UserInfo extends \yii\db\ActiveRecord |
| 63 | 63 | return [ |
| 64 | 64 | [['user_id', 'view_count', 'contract', 'estimate', 'purchase', 'delivery'], 'integer'], |
| 65 | 65 | [['date_visit'], 'safe'], |
| 66 | - [['experience', 'soft', 'guarantee', 'about', 'city', 'country', 'image', 'poster'], 'string'], | |
| 66 | + [['experience', 'soft', 'guarantee', 'about', 'city', 'country', 'image', 'poster', 'social_vk', 'social_fb', 'social_in', 'social_t'], 'string'], | |
| 67 | 67 | [['prepayment'], 'number'], |
| 68 | 68 | |
| 69 | 69 | [['rank', 'location'], 'string', 'max' => 50], | ... | ... |
common/widgets/views/phone_field.php
| 1 | 1 | <?php |
| 2 | -use yii\helpers\Html; | |
| 2 | + use yii\helpers\Html; | |
| 3 | 3 | ?> |
| 4 | 4 | <fieldset> |
| 5 | 5 | |
| 6 | - <legend>Образование</legend> | |
| 6 | + <legend>Телефон</legend> | |
| 7 | 7 | |
| 8 | - <p class="btn btn-success add_field">Добавить поле</p> | |
| 8 | + <p class="btn btn-success add_field_<?=$this->context->id?>">Добавить поле</p> | |
| 9 | 9 | |
| 10 | 10 | |
| 11 | 11 | <?php $t = 0; for($i=1; $i <= count($model); $i++): |
| ... | ... | @@ -14,8 +14,8 @@ use yii\helpers\Html; |
| 14 | 14 | ?> |
| 15 | 15 | |
| 16 | 16 | <?= Html::beginTag('div',['class'=>'form-group','id'=>isset($model[$i]['parent_key']) ? $model[$i]['parent_key'] : 0 ])?> |
| 17 | - <input type="text" placeholder="Телефон" class="form-control" value="<?= isset($model[$t]['value']) ? $model[$t]['value'] : '' ?>" name="Fields[phone][<?=$row?>][0][phone]" /> | |
| 18 | - <span data-id="<?= isset($model[$i]['parent_key']) ? $model[$i]['parent_key'] : 0 ?>" title="удалить" class="glyphicon glyphicon-trash delete-field-item"></span> | |
| 17 | + <input type="text" placeholder="Телефон" class="form-control" value="<?= isset($model[$t]['value']) ? $model[$t]['value'] : '' ?>" name="Fields[phone][<?=$row?>][0][phone]" /> | |
| 18 | + <span data-id="<?= isset($model[$i]['parent_key']) ? $model[$i]['parent_key'] : 0 ?>" title="удалить" class="glyphicon glyphicon-trash delete-field-item"></span> | |
| 19 | 19 | <?= Html::endTag('div')?> |
| 20 | 20 | <?php $i = ++ $t; ?> |
| 21 | 21 | <?php endfor; ?> |
| ... | ... | @@ -24,15 +24,16 @@ use yii\helpers\Html; |
| 24 | 24 | |
| 25 | 25 | </fieldset> |
| 26 | 26 | <script> |
| 27 | + var start_i_<?=$this->context->id?> = <?=$i?>; | |
| 27 | 28 | $( document ).ready(function(){ |
| 28 | - var start_i = <?=$i?>; | |
| 29 | - $('.add_field').click(function(){ | |
| 29 | + $('.add_field_<?=$this->context->id?>').click(function(){ | |
| 30 | 30 | var block = $(this).parent('fieldset'); |
| 31 | 31 | var block_id = $(this).parent('fieldset'); |
| 32 | 32 | var sub_block = '<div class="form-group" >'+ |
| 33 | - '<input type="text" placeholder="Телефон" class="form-control" value="" name="Fields[phone]['+ start_i++ +'][0][phone]" />'+ | |
| 33 | + '<input type="text" placeholder="Телефон" class="form-control" value="" name="Fields[phone]['+ start_i_<?=$this->context->id?>++ +'][0][phone]" />'+ | |
| 34 | 34 | '<span title="удалить" class="glyphicon glyphicon-trash delete-field-item"></span>'+ |
| 35 | 35 | '<div>'; |
| 36 | + console.log(block); | |
| 36 | 37 | block.append(sub_block); |
| 37 | 38 | |
| 38 | 39 | }); | ... | ... |
| 1 | +<?php | |
| 2 | +use yii\helpers\Html; | |
| 3 | +?> | |
| 4 | +<fieldset> | |
| 5 | + | |
| 6 | + <legend>Сайт</legend> | |
| 7 | + | |
| 8 | + <p class="btn btn-success add_field_<?=$this->context->id?>">Добавить поле</p> | |
| 9 | + | |
| 10 | + | |
| 11 | + <?php $t = 0; for($i=1; $i <= count($model); $i++): | |
| 12 | + $row = $i; | |
| 13 | + | |
| 14 | + ?> | |
| 15 | + | |
| 16 | + <?= Html::beginTag('div',['class'=>'form-group','id'=>isset($model[$i]['parent_key']) ? $model[$i]['parent_key'] : 0 ])?> | |
| 17 | + <input type="text" placeholder="www.example.com" class="form-control" value="<?= isset($model[$t]['value']) ? $model[$t]['value'] : '' ?>" name="Fields[site][<?=$row?>][0][site]" /> | |
| 18 | + <span data-id="<?= isset($model[$i]['parent_key']) ? $model[$i]['parent_key'] : 0 ?>" title="удалить" class="glyphicon glyphicon-trash delete-field-item"></span> | |
| 19 | + <?= Html::endTag('div')?> | |
| 20 | + <?php $i = ++ $t; ?> | |
| 21 | + <?php endfor; ?> | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | +</fieldset> | |
| 26 | +<script> | |
| 27 | + var start_i_<?=$this->context->id?> = <?=$i?>; | |
| 28 | + $( document ).ready(function(){ | |
| 29 | + $('.add_field_<?=$this->context->id?>').click(function(){ | |
| 30 | + var block = $(this).parent('fieldset'); | |
| 31 | + var block_id = $(this).parent('fieldset'); | |
| 32 | + var sub_block = '<div class="form-group" >'+ | |
| 33 | + '<input type="text" placeholder="Телефон" class="form-control" value="" name="Fields[site]['+ start_i_<?=$this->context->id?>++ +'][0][site]" />'+ | |
| 34 | + '<span title="удалить" class="glyphicon glyphicon-trash delete-field-item"></span>'+ | |
| 35 | + '<div>'; | |
| 36 | + console.log(block); | |
| 37 | + block.append(sub_block); | |
| 38 | + | |
| 39 | + }); | |
| 40 | + }); | |
| 41 | +</script> | |
| 42 | + | |
| 43 | + | ... | ... |
frontend/controllers/AccountsController.php
| ... | ... | @@ -150,13 +150,16 @@ class AccountsController extends Controller |
| 150 | 150 | |
| 151 | 151 | public function actionContacts() |
| 152 | 152 | { |
| 153 | - if(!empty(\Yii::$app->request->post())) { | |
| 154 | - Fields::saveFieldData( Yii::$app->request->post('Fields'), \Yii::$app->user->identity->id, User::className(),'ru'); | |
| 155 | - } | |
| 156 | 153 | $user_info = UserInfo::find()->where(['user_id' => \Yii::$app->user->getId()])->one(); |
| 157 | 154 | if(empty($user_info)) { |
| 158 | 155 | $user_info = new UserInfo(['user_id' => \Yii::$app->user->getId()]); |
| 159 | 156 | } |
| 157 | + if(!empty(\Yii::$app->request->post())) { | |
| 158 | + Fields::saveFieldData( Yii::$app->request->post('Fields'), \Yii::$app->user->identity->id, User::className(),'ru'); | |
| 159 | + $user_info->load(\Yii::$app->request->post()); | |
| 160 | + $user_info->save(); | |
| 161 | + $user_info; | |
| 162 | + } | |
| 160 | 163 | return $this->render('contacts', ['user_info' => $user_info]); |
| 161 | 164 | } |
| 162 | 165 | ... | ... |
frontend/views/accounts/contacts.php
| 1 | 1 | <?php |
| 2 | -use common\models\Option; | |
| 3 | -use yii\helpers\Html; | |
| 4 | -use yii\widgets\ActiveForm; | |
| 5 | -use \common\widgets\MultiLangForm; | |
| 2 | + /** | |
| 3 | + * @var UserInfo $user_info | |
| 4 | + */ | |
| 5 | + use common\models\UserInfo; | |
| 6 | + use common\widgets\FieldEditor; | |
| 7 | + use yii\helpers\Html; | |
| 8 | + use yii\widgets\ActiveForm; | |
| 6 | 9 | |
| 7 | 10 | $this->title = 'Мой профиль'; |
| 8 | 11 | $this->params['breadcrumbs'][] = $this->title; |
| 9 | 12 | $user = \Yii::$app->user->identity; |
| 10 | 13 | ?> |
| 11 | 14 | |
| 12 | -<h1><?= $this->title ?></h1> | |
| 15 | +<h1><?= $this->title ?></h1> | |
| 16 | +<p>Будут видны всем</p> | |
| 13 | 17 | <?php |
| 14 | -$form = ActiveForm::begin(); | |
| 18 | + $form = ActiveForm::begin (); | |
| 15 | 19 | ?> |
| 16 | -<?= \common\widgets\FieldEditor::widget([ | |
| 17 | - 'template'=>'phone', | |
| 18 | - 'item_id'=> $user->id, | |
| 19 | - 'model'=>'common\models\User', | |
| 20 | - 'language'=>'ru' | |
| 21 | -]); ?> | |
| 20 | +<?= FieldEditor::widget ( | |
| 21 | + [ | |
| 22 | + 'template' => 'phone', 'item_id' => $user->id, 'model' => 'common\models\User', 'language' => 'ru', | |
| 23 | + ] | |
| 24 | +); ?> | |
| 25 | +<?= $form->field ($user_info, 'social_vk') | |
| 26 | + ->label ('Vk.com') | |
| 27 | + ->textInput () ?> | |
| 28 | +<?= $form->field ($user_info, 'social_fb') | |
| 29 | + ->label ('FaceBook.com') | |
| 30 | + ->textInput () ?> | |
| 31 | +<?= $form->field ($user_info, 'social_in') | |
| 32 | + ->label ('LinkedIn.com') | |
| 33 | + ->textInput () ?> | |
| 34 | +<?= $form->field ($user_info, 'social_t') | |
| 35 | + ->label ('Twitter.com') | |
| 36 | + ->textInput () ?> | |
| 37 | +<?= FieldEditor::widget ( | |
| 38 | + [ | |
| 39 | + 'template' => 'site', 'item_id' => $user->id, 'model' => 'common\models\User', 'language' => 'ru', | |
| 40 | + ] | |
| 41 | +); ?> | |
| 22 | 42 | <?php |
| 23 | - echo Html::submitButton('submit'); | |
| 24 | - $form->end(); | |
| 43 | + echo Html::submitButton ('submit'); | |
| 44 | + $form->end (); | |
| 25 | 45 | ?> |
| 26 | 46 | |
| 27 | 47 | ... | ... |
frontend/web/js/fieldWidget.js
| 1 | 1 | $(document).ready(function(){ |
| 2 | 2 | $('body').on('click', '.delete-field-item', function(){ |
| 3 | - console.log('sfddf'); | |
| 4 | 3 | $(this).parent('.form-group').remove(); |
| 5 | 4 | |
| 6 | 5 | }); |
| 7 | - | |
| 8 | - | |
| 9 | - $('.add_field').click(function(){ | |
| 10 | - var block = $('.fields_video_result'); | |
| 11 | - var sub_block = '<div class="form-group">'+ | |
| 12 | - '<input type="text" class="form-control" value="" name="Fields[video]['+ start_i++ +'][value]">'+ | |
| 13 | - '<span data-id="none" title="удалить" class="glyphicon glyphicon-trash delete-field-item"></span>'+ | |
| 14 | - '<div>'; | |
| 15 | - block.append(sub_block); | |
| 16 | - | |
| 17 | - }); | |
| 18 | 6 | }); | ... | ... |