Commit e4b2a65220e0a280a17568bb81084d745b7ba522
Merge remote-tracking branch 'origin/master'
Showing
5 changed files
with
48 additions
and
20 deletions
 
Show diff stats
backend/web/js/fieldWidget.js
common/models/UserInfo.php
| ... | ... | @@ -88,10 +88,6 @@ | 
| 88 | 88 | 'country', | 
| 89 | 89 | 'image', | 
| 90 | 90 | 'poster', | 
| 91 | - 'social_vk', | |
| 92 | - 'social_fb', | |
| 93 | - 'social_in', | |
| 94 | - 'social_t', | |
| 95 | 91 | ], | 
| 96 | 92 | 'string', | 
| 97 | 93 | ], | 
| ... | ... | @@ -158,6 +154,34 @@ | 
| 158 | 154 | 'integer', | 
| 159 | 155 | 'min' => 0, | 
| 160 | 156 | ], | 
| 157 | + [ | |
| 158 | + [ | |
| 159 | + 'social_vk', | |
| 160 | + ], | |
| 161 | + 'match', | |
| 162 | + 'pattern' => '/^(?:https?:\/\/)?(?:www\.)?vk\.com\/[\S]+\/?$/', | |
| 163 | + ], | |
| 164 | + [ | |
| 165 | + [ | |
| 166 | + 'social_fb', | |
| 167 | + ], | |
| 168 | + 'match', | |
| 169 | + 'pattern' => '/^(?:https?:\/\/)?(?:www\.)?facebook\.com\/[\S]+\/?$/', | |
| 170 | + ], | |
| 171 | + [ | |
| 172 | + [ | |
| 173 | + 'social_in', | |
| 174 | + ], | |
| 175 | + 'match', | |
| 176 | + 'pattern' => '/^(?:https?:\/\/)?(?:www\.)?linkedin\.com\/(?:pub|in)\/[\S]+\/?$/', | |
| 177 | + ], | |
| 178 | + [ | |
| 179 | + [ | |
| 180 | + 'social_t', | |
| 181 | + ], | |
| 182 | + 'match', | |
| 183 | + 'pattern' => '/^(?:https?:\/\/)?(?:www\.)?twitter\.com\/[\S]+\/?$/', | |
| 184 | + ], | |
| 161 | 185 | ]; | 
| 162 | 186 | } | 
| 163 | 187 | ... | ... | 
common/widgets/views/site_field.php
| ... | ... | @@ -19,7 +19,7 @@ use yii\helpers\Html; | 
| 19 | 19 | <?= Html::beginTag('div',['class'=>'form-group','id'=>isset($model[$i]['parent_key']) ? $model[$i]['parent_key'] : 0 ])?> | 
| 20 | 20 | <div class="input-blocks"> | 
| 21 | 21 | <label for="cont-site-<?= ++$label ?>">Сайт</label> | 
| 22 | - <input id="cont-site-<?= $label ?>" type="text" placeholder="" class="form-control custom-input-2" value="<?= isset($model[$t]['value']) ? $model[$t]['value'] : '' ?>" name="Fields[site][<?=$row?>][0][site]" /> | |
| 22 | + <input id="cont-site-<?= $label ?>" type="url" placeholder="http://" class="form-control custom-input-2" value="<?= isset($model[$t]['value']) ? $model[$t]['value'] : '' ?>" name="Fields[site][<?=$row?>][0][site]" /> | |
| 23 | 23 | </div> | 
| 24 | 24 | <span data-id="<?= isset($model[$i]['parent_key']) ? $model[$i]['parent_key'] : 0 ?>" title="удалить" class="glyphicon glyphicon-trash delete-field-item"></span> | 
| 25 | 25 | <?= Html::endTag('div')?> | 
| ... | ... | @@ -41,7 +41,7 @@ use yii\helpers\Html; | 
| 41 | 41 | |
| 42 | 42 | '<div class="input-blocks">'+ | 
| 43 | 43 | '<label for="cont-site-' + ++start_label_<?=$this->context->id?> +'">Сайт</label>'+ | 
| 44 | - '<input id="cont-site-' + start_label_<?=$this->context->id?> +'" type="text" placeholder="" class="form-control custom-input-2" value="" name="Fields[site]['+ start_i_<?=$this->context->id?>++ +'][0][site]" />'+ | |
| 44 | + '<input id="cont-site-' + start_label_<?=$this->context->id?> +'" type="url" placeholder="http://" class="form-control custom-input-2" value="" name="Fields[site]['+ start_i_<?=$this->context->id?>++ +'][0][site]" />'+ | |
| 45 | 45 | '</div>'+ | 
| 46 | 46 | '<span title="удалить" class="glyphicon glyphicon-trash delete-field-item"></span>'+ | 
| 47 | 47 | '<div>'; | ... | ... | 
frontend/controllers/AccountsController.php
| ... | ... | @@ -183,7 +183,9 @@ | 
| 183 | 183 | $user_info = new UserInfo([ 'user_id' => \Yii::$app->user->getId() ]); | 
| 184 | 184 | } | 
| 185 | 185 | if(!empty( \Yii::$app->request->post() )) { | 
| 186 | - Fields::saveFieldData(Yii::$app->request->post('Fields'), \Yii::$app->user->identity->id, User::className(), 'ru'); | |
| 186 | + if(!empty(Yii::$app->request->post('Fields'))) { | |
| 187 | + Fields::saveFieldData(Yii::$app->request->post('Fields'), \Yii::$app->user->identity->id, User::className(), 'ru'); | |
| 188 | + } | |
| 187 | 189 | $user_info->load(\Yii::$app->request->post()); | 
| 188 | 190 | $user_info->save(); | 
| 189 | 191 | } | ... | ... | 
frontend/web/js/fieldWidget.js
| 1 | -$(document).ready(function(){ | |
| 2 | - $('body').on('click', '.delete-field-item', function(){ | |
| 1 | +$(function(){ | |
| 2 | + $(document).on('click', '.delete-field-item', function(){ | |
| 3 | + var container = $(this).parents('.field_list').first(); | |
| 3 | 4 | $(this).parent('.form-group').remove(); | 
| 4 | - | |
| 5 | + var count = $(container).find('.form-group').length; | |
| 6 | + if(count <= 1) { | |
| 7 | + $(container).find('.delete-field-item').addClass('hidden'); | |
| 8 | + } | |
| 5 | 9 | }); | 
| 6 | -}); | |
| 10 | + $(document).on('click', '[class*=add_field_w]', function() { | |
| 11 | + var container = $(this).siblings('.field_list').first(); | |
| 12 | + var count = $(container).find('.form-group').length; | |
| 13 | + if(count > 1) { | |
| 14 | + $(container).find('.delete-field-item').removeClass('hidden'); | |
| 15 | + } | |
| 16 | + }); | |
| 17 | +}); | |
| 7 | 18 | \ No newline at end of file | ... | ... |