HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux Bradford-Sitios 6.14.0-1017-azure #17~24.04.1-Ubuntu SMP Mon Dec 1 20:10:50 UTC 2025 x86_64
User: www-data (33)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/plan-b.bradford/storage/framework/views/c67f77c145c521efc2cf44eedd09653fb4c09352.php
<script nonce="<?php echo e(app('csp_nonce')); ?>">
 const student_region_id =
        <?php echo e(old('student_region') > 0 ? old('student_region') : ($form_data->student_region_id > 0 ? $form_data->student_region_id : 0)); ?>;
    const student_commune_id =
        <?php echo e(old('student_commune') > 0 ? old('student_commune') : ($form_data->student_commune_id > 0 ? $form_data->student_commune_id : 0)); ?>;

    // Función para filtrar las comunas basadas en la región seleccionada
    function filterCommunesStudent(regionId) {
        $('#student_commune').empty(); // Limpia las opciones actuales
        // Agrega la opción predeterminada
        $('#student_commune').append('<option value="">Seleccione comuna...</option>');
        // Recorre todas las comunas y muestra solo las de la región seleccionada
        let selected = '';
        <?php $__currentLoopData = $communes_data; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            if (<?php echo e($key->region_id); ?> == regionId) {
                selected = <?php echo e($key->id); ?> == student_commune_id ? 'selected' : '';
                $('#student_commune').append(
                    `<option value="<?php echo e($key->id); ?>" ${selected} ><?php echo e($key->commune); ?> - <?php echo e($key->code); ?></option>`
                );
                console.log(
                    `<option value="<?php echo e($key->id); ?>" ${selected} ><?php echo e($key->commune); ?> - <?php echo e($key->code); ?></option>`
                )
            }
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        // Recarga select2 después de modificar las opciones
        $('#student_commune').select2();
    }


    $(document).ready(function() {
        // Inicializa select2
        $('#student_region').select2();
        $('#student_commune').select2();
        $('#student_commune').empty().append(
                '<option value="">Seleccione región para desbloquear...</option>')
            .select2();

        if (student_region_id > 0) {
            filterCommunesStudent(student_region_id)
        }
    });


    // Cambia las opciones visibles de comuna según la región seleccionada
    $('#student_region').change(function() {
        let regionId = $(this).val();

        // Si se selecciona una región válida
        if (regionId > 0) {
            filterCommunesStudent(regionId);
            $('#student_commune').focus();
            validateField($('#student_commune').val(), 'student_commune', 'select', true,
                'Seleccione comuna...');
        } else {
            // Si no se selecciona una región válida, muestra solo la opción predeterminada
            $('#student_commune').empty().append(
                    '<option value="">Seleccione región para desbloquear...</option>')
                .select2();
            validateField($('#student_commune').val(), 'student_commune', 'select', false,
                'Seleccione comuna...');
        }
    });



    // Validación en tiempo real para estudiantes
    $('input[name^="student"]').keyup(function() {
        let id = $(this).attr('id');
        let type = $(this).data('type');
        let required = $(this).data('required');
        if (type === 'email') {
            isValid = validateEmail($(this).val(), id, 'Ingrese un Correo Válido') && isValid;
        } else {
            isValid = validateField($(this).val(), id, type, required) && isValid;
        }
    });



    $('select[name^="student"]').change(function() {
        let id = $(this).attr('id');
        let type = $(this).data('type');
        let required = $(this).data('required');
        validateField($(this).val(), id, type, required, 'Seleccione una opción');
        if(id == 'student_course'){
            $("#btn-add-service").click();
        }
    });
</script>


<script nonce="<?php echo e(app('csp_nonce')); ?>">
    // ESTUDIANTE
    if ($('#table_list_students')) {
        $('#table_list_students').DataTable({
            responsive: true,
            "bLengthChange": false,
            "info": false,
            "searching": false, // Ocultar búsqueda
            "paging": false, // Ocultar paginación
            "pageLength": 15, // Mostrar 15 registros por defecto
            "language": {
                "url": `<?php echo e(asset(ASSETS_JS)); ?>/Spanish.json`
            },
            order: [
                [0, 'asc']
            ],
        });
    }


    $("#search_students").click(function() {
        $("#modal-students").modal({
            backdrop: 'static',
            keyboard: false
        }).modal('show');
    });

    $("modal-students").on('hidden.bs.modal', function() {
        // $("#status_contract_id").val('');
        // $("#btn_finished_cancel").attr('hidden', false);
        // $("#btn_finished").attr('disabled', false);
    });

    $("#form_select_student").submit(function(e) {
        e.preventDefault();
        let select_student = $('input[name="select_student"]:checked').val();
        if (!select_student) {
            toastr.error('Debes seleccionar un estudiante para continuar.', 'Error de Validación');
            return false;
        }
        $("#modal-students").modal('hide');
        cargando('Asignando Estudiante...');
        $.ajax({
            url: "<?php echo e(route('contract-assign-student')); ?>",
            type: "POST",
            data: {
                id: select_student,
                contract: <?php echo e($form_data->id); ?>,
                parent: <?php echo e($form_data->financial_parent_id); ?>,
                _token: "<?php echo e(csrf_token()); ?>"
            },
            dataType: 'json',
            success: function(resp) {
                setTimeout(function() {
                    console.log(resp);
                    swal.close();
                    if (resp.type == 'error') {
                        toastr["error"](`${resp.msg}`, "ERROR DE VALIDACIÓN");
                        return;
                    }

                    toastr[`${resp.type}`]('Estudiante asignado correctamente',
                        'Gestión de Contrato');

                    // Asignar los valores recibidos a los campos correspondientes
                    $('#student_rut').val(resp.data.rut)
                    $('#student_first_name').val(resp.data.first_name);
                    $('#student_second_name').val(resp.data.second_name);
                    $('#student_last_name').val(resp.data.last_name);
                    $('#student_second_last_name').val(resp.data.second_last_name);
                    $('#student_birth_date').val(resp.data.birth_date);

                    // Seleccionar el valor correspondiente en los select
                    $('#student_course').val(resp.data.course_id).trigger('change');
                    $('#student_course_letter').val(resp.data.course_letter_id).trigger(
                        'change');
                    $('#student_country').val(resp.data.country_id).trigger('change');
                    $('#student_gender').val(resp.data.gender_id).trigger('change');
                    $('#student_region').val(resp.data.region_id).trigger('change');
                    $('#student_commune').val(resp.data.commune_id).trigger('change');

                    // Asignar el valor de la dirección
                    $('#student_address').val(resp.data.address);

                    // Habilitar los campos que estaban deshabilitados (excepto el RUT)
                    $('#student_first_name, #student_second_name, #student_last_name, #student_second_last_name, #student_birth_date, #student_course, #student_course_letter, #student_country, #student_gender, #student_region, #student_commune, #student_address')
                        .prop('disabled', false);

                }, 800);
            },
            error: function(error) {
                swal.close();
                toastr["error"](`Ocurrió un error. Recargue e intente nuevamente`,
                    "ERROR INTERNO")
                console.log(JSON.stringify(error))
            }
        });
    });
</script><?php /**PATH /var/www/plan-b.bradford/resources/views/admin/contracts/sections_contract_edit/student_contract_js.blade.php ENDPATH**/ ?>