_vacancy_form.php 11.8 KB
<?php
    /**
     * @var Vacancy          $vacancy
     * @var Employment[]     $employment
     * @var string[]         $currencies
     * @var Specialization[] $specializations
     * @var User             $user
     */
    use common\components\Request;
    use common\models\Employment;
    use common\models\Specialization;
    use common\models\Vacancy;
    use common\widgets\FieldEditor;
    use kartik\select2\Select2;
    use mihaildev\ckeditor\CKEditor;
    use yii\helpers\Html;
    use yii\web\JsExpression;
    use yii\widgets\ActiveForm;
    use common\models\User;

    $this->title = 'Вакансии';
    $this->params[ 'breadcrumbs' ][] = $this->title;
?>
<div class="login-left-column-title"><?= $this->title ?></div>
<div class="login-left-column-title-two style">Редактирование:</div>
<?php
    $form = ActiveForm::begin();
?>

<div class="input-blocks-wrapper">
    <div class="input-blocks">
        <?= $form->field($vacancy, 'name')
                 ->textInput([ 'class' => 'custom-input-2' ]); ?>
    </div>
</div>


<div class="input-blocks-wrapper">
    <div class="input-blocks">
        <?= $form->field($vacancy, 'user_name')
                 ->textInput([ 'class' => 'custom-input-2' ]); ?>
        <?php
            if(!empty( $user->firstname ) && !empty( $user->lastname )) {
                echo Html::tag('span', 'Вы', [
                        'class'      => 'admin-hint-vacancy-contact form_auto_data',
                        'data-value' => $user->firstname . ' ' . $user->lastname,
                        'title'      => 'Вставить данные с Вашего личного кабинета',
                    ]);
            }
        ?>
    </div>
</div>
<div class="input-blocks-wrapper">
    <div class="input-blocks">
        <?= $form->field($vacancy, 'phone')
                 ->textInput([ 'class' => 'custom-input-2' ]); ?>
        <?php
            if(!empty($user->getPhones()[1]['phone'])) {
                echo Html::tag('span', 'Вы', [
                    'class'      => 'admin-hint-vacancy-contact form_auto_data',
                    'data-value' => $user->getPhones()[1]['phone'],
                    'title'      => 'Вставить данные с Вашего личного кабинета',
                ]);
            }
        ?>
    </div>
</div>

<div class="input-blocks-wrapper hint-link hint-link-fx">
    <div class="input-blocks">
        <?= $form->field($vacancy, 'city')
                 ->hint('Город, в котором предлагается работа', ['tag' => 'span'])
                 ->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; }'),
                     ],
                 ]); ?>
        <?php
            if(!empty( $user->userInfo->city )) {
                echo Html::tag('span', 'Ваш', [
                        'class'      => 'admin-hint-vacancy-contact form_auto_data',
                        'data-value' => $user->userInfo->city,
                        'title'      => 'Вставить данные с Вашего личного кабинета',
                    ]);
            }
        ?>
    </div>
</div>

<div class="input-blocks-wrapper">
    <div class="input-blocks admin-currency-first">
        <?= $form->field($vacancy, 'salary', [
            'template' => "{label}<br /><span class='admn-input-txt'>от</span>{input}\n{hint}\n{error}",
            'options'  => [ 'class' => 'form-inline' ],
        ])
                 ->label('Заработная плата')
                 ->textInput([
                     'class' => 'custom-input-2 custom-input-2-date',
                     'type'  => 'number',
                     'min'   => 0,
                 ]); ?>
    </div>
    <div class="input-blocks admin-currency-second">
        <?= $form->field($vacancy, 'salary_currency', [
            'template' => "{input}\n{hint}\n{error}",
        ])
                 ->label(false)
                 ->dropDownList($currencies) ?>
    </div>
</div>


<div class="input-blocks-wrapper admin-menu-list">
    <div class="input-blocks" style="width: 100%; margin-bottom: 5px">
        <label>Специализации</label>
        <div class="required"></div>
    </div>

    <div class="style">
        <ul class="content-menu-first">
            <?php foreach($specializations as $specialization): ?>
                <li data-img="<?= $specialization->image ?>">
                    <span data-menu-bg="<?= $specialization->background ?>" style="background: <?= $specialization->background ?>"></span><a href="#"><?= $specialization->specialization_name ?></a>
                    <ul>
                        <?php foreach($specialization->children as $child_first): ?>

                            <?php if($child_first instanceof Specialization): ?>
                                <li>
                                    <a href="#"><?= $child_first->specialization_name ?></a>
                                    <ul>
                                        <?php foreach($child_first->children as $child_second): ?>
                                            <?php if($child_first instanceof Specialization): ?>
                                                <li>
                                                    <a href="#" title="<?= $child_second->specialization_name ?>">
                                                        <?= $form->field($vacancy, "specializationInput[{$child_second->specialization_id}]", [
                                                            'template' => '{input}{label}{hint}{error}',
                                                        ])
                                                                 ->label('<span></span>' . $child_second->specialization_name)
                                                                 ->checkbox([
                                                                     'value'   => $child_second->specialization_id,
                                                                     'label'   => NULL,
                                                                     'uncheck' => NULL,
                                                                     'class'   => 'custom-check',
                                                                 ], false) ?>
                                                    </a>
                                                </li>
                                            <?php endif; ?>
                                        <?php endforeach; ?>
                                    </ul>
                                </li>
                            <?php endif; ?>
                        <?php endforeach; ?>

                    </ul>
                </li>
            <?php endforeach; ?>
        </ul>
    </div>

    <div class="style admn-menu-err">
        <div class="help-block">Необходимо выбрать хотя бы одну «специализацию».</div>
    </div>
</div>

<div class="admin-specialization-selected style">
    <ul></ul>
</div>

<div class="input-blocks-wrapper admin-vacancy-check admin-vacancy-check-fx-marg" style="margin-top: 19px">
    <div class="input-blocks">
        <?= $form->field($vacancy, 'employmentInput')
                 ->checkboxList($employment, [
                     'item' => function($index, $label, $name, $checked, $value) {
                         $return = '<div class="admin-who-check-payment">';
                         $return .= '<input class="custom-check" id="select_admin_payment' . $value . '" type="checkbox" name="' . $name . '" value="' . $value . '" ' . ( $checked ? "checked" : "" ) . ' >';
                         $return .= '<label for="select_admin_payment' . $value . '" >';
                         $return .= '<span></span>' . ucwords($label);
                         $return .= '</label>';
                         $return .= '</div>';
                         return $return;
                     },
                 ]) ?>
    </div>
</div>

<div class="skills-admin-wrapper style">
    <div class="input-blocks-wrapper skills-programs">
        <div class="input-blocks">
            <?= FieldEditor::widget([
                'template' => 'requirements',
                'item_id'  => $vacancy->vacancy_id,
                'model'    => 'common\models\Vacancy',
                'language' => 'ru',
            ]); ?>
        </div>
    </div>
</div>

<div class="input-blocks-wrapper full-blocks admin-editor-bl">
    <div class="input-blocks">
        <?= $form->field($vacancy, 'description')
                 ->widget(CKEditor::className()) ?>
    </div>
</div>

<div class="admin-save-btn skills-save-btn admin-add-remove-wr style">
    <?= Html::submitButton($vacancy->isNewRecord ? Yii::t('app', 'add') : 'Обновить', [ 'class' => 'input-blocks-wrapper button' ]) ?>
    <div class="admin-remove-note">
        <?php
            if(!$vacancy->isNewRecord) {
                echo Html::a(Yii::t('app', 'delete'), [
                    'accounts/vacancy-delete',
                    'id' => $vacancy->vacancy_id,
                ], [
                    'title'        => Yii::t('app', 'delete'),
                    'aria-label'   => Yii::t('app', 'delete'),
                    'data-confirm' =>  Yii::t('app', 'delete_confirm'),
                    'data-method'  => 'post',
                    'data-pjax'    => 0,
                ]);
            }
        ?>
    </div>
    <div class="admin-back-note">
        <?= Html::a('вернуться', Request::getIsLocal(\Yii::$app->request->referrer) ? \Yii::$app->request->referrer : [ 'accounts/vacancy' ]) ?>
    </div>
</div>


<?php
    $form->end();
?>
<script>
    $(
        function()
        {
            $('.input-blocks.admin-currency-second select').change(
                function()
                {
                    $(this).blur()
                }
            );
            $(document).on(
                'click', '.form_auto_data', function()
                {
                    var value = $(this).data('value');
                    var container = $(this).parents('.input-blocks').first();
                    var select = $(container).find('select[data-krajee-select2]').first();
                    if(select.length >= 1)
                    {
                        $(select)
                        .append('<option value="' + value + '" selected>' + value + '</option>');
                        var id = $(select).attr('id');
                        $(container).find('#select2-' + id + '-container').attr('title', value);
                        $(container).find('#select2-' + id + '-container').text(value);
                    } else
                    {
                        $(container).find('input, textarea').val(value);
                    }
                }
            );
        }
    );
</script>