employment.php 4.28 KB
<?php
    /**
     * @var Job[] $job
     */
    use common\models\Job;
    use yii\helpers\Html;
    use yii\jui\DatePicker;
    use yii\widgets\ActiveForm;

    $this->title = 'Трудовой стаж';
    $this->params['breadcrumbs'][] = $this->title;
?>
    <h1><?= $this->title ?></h1>
<?php
    $form = ActiveForm::begin ();
    $current = array_shift ($job);
?>
    <div class="current_job_container">
        <p>Текущее место работы:</p>
        <div class="current_job_inputs">
            <?php
                echo $form->field ($current, '[0]name')
                          ->label ('Название')
                          ->textInput ();
                echo $form->field ($current, '[0]link')
                          ->label ('Ссылка на компанию на сайте МФП')
                          ->textInput ();
                echo $form->field ($current, '[0]date_start')
                          ->label ('Дата начала работы')
                          ->widget (DatePicker::className (), ['language' => 'ru', 'dateFormat' => 'dd-MM-yyyy']);
                echo $form->field ($current, '[0]position')
                          ->label ('Должность')
                          ->textInput ();
                echo $form->field ($current, '[0]total_count')
                          ->label ('Количество проектов, в которых принимали участие')
                          ->input ('number');
                echo $form->field ($current, '[0]complete_count')
                          ->label ('из них реализовано')
                          ->input ('number');
            ?>
        </div>
    </div>
    <div class="prev_job_container">
        <p>Предыдущие места работы</p>
        <?php
            foreach ($job as $index => $job_model)
            {
                echo "<div class='prev_job_inputs'>";
                echo $form->field ($job_model, '['. ($index + 1) .']name')
                          ->label ('Название')
                          ->textInput ();
                echo $form->field ($job_model, '['. ($index + 1) .']link')
                          ->label ('Ссылка на компанию на сайте МФП')
                          ->textInput ();
                echo $form->field ($job_model, '['. ($index + 1) .']date_start')
                          ->label ('Дата начала работы')
                          ->widget (DatePicker::className (), ['language' => 'ru', 'dateFormat' => 'dd-MM-yyyy']);
                echo $form->field ($job_model, '['. ($index + 1) .']date_end')
                          ->label ('Дата окончания работы')
                          ->widget (DatePicker::className (), ['language' => 'ru', 'dateFormat' => 'dd-MM-yyyy']);
                echo $form->field ($job_model, '['. ($index + 1) .']position')
                          ->label ('Должность')
                          ->textInput ();
                echo $form->field ($job_model, '['. ($index + 1) .']total_count')
                          ->label ('Количество проектов, в которых принимали участие')
                          ->input ('number');
                echo $form->field ($job_model, '['. ($index + 1) .']complete_count')
                          ->label ('из них реализовано')
                          ->input ('number');
                echo "</div>";
            }
        ?>
    </div>
<?php
    echo Html::button('Добавить место работы', ['id' => 'add_job_button']);
    echo Html::submitButton('Обновить');
    $form->end ();
?>
<script>
    $(function() {
        var regexp = /^[\w]+\[(\d+)\].*$/;
        $(document).on('click', '#add_job_button', function() {
            var inputs = $('.prev_job_inputs').last();
            var name = $(inputs).find('input, textarea').first().attr('name');
            var lastindex = regexp.exec(name)[1];
            $.get('/accounts/get-form', { lastindex: lastindex }, function(data) {
                $('.prev_job_container').append($(data).find('.ajax-loaded').first().html());
                $(data).filter('script').appendTo('body');
            });
        });
    });
</script>