Back | Home
الـ Path الحالي: /home/picotech/domains/instantly.picotech.app/public_html/public/uploads/.././modules/../js/admin/.
الملفات الموجودة في هذا الـ Path:
.
..
addon.js
customer.js
dashboard.js
faqs.js
front_contact.js
lead.js
pages.js
plan.js
servers.js
settings.js
tax.js
ticket.js

مشاهدة ملف: servers.js

"use strict";
Object.defineProperty(String.prototype, 'capitalize', {
    value: function() {
        return this.charAt(0).toUpperCase() + this.slice(1);
    },
    enumerable: false
});

function format_field_name(field){
    return field.replace('_',' ').capitalize();
}

function generateChunk(inputArray,perChunk){
    return inputArray.reduce((resultArray, item, index) => {
        const chunkIndex = Math.floor(index / perChunk)

        if (!resultArray[chunkIndex]) {
            resultArray[chunkIndex] = [] // start a new chunk
        }

        resultArray[chunkIndex].push(item)

        return resultArray
    }, []);
}


$('#from').select2();
$('#from').on('change',function (e) {
    e.preventDefault();
    $('#custom_fields').html(`<div class="text-center"><i class="fas fa-spinner fa-spin"></i></div>`);
    const server=$(this).val();
    $.ajax({
        method:'GET',
        url:'/admin/server/get/fields',
        data:{sending_server:server},
        success:function (res) {
            let html='';
            const serverFields=generateChunk(res,3)
            for(let i=0;i<serverFields.length;i++){
                let row="<div class='form-row'>";
                let rowFields='';
                $.each(serverFields[i],(index,item)=>{
                    rowFields+=`<div class="form-group col-md-4">
                                <label for="${server+'_'+item}">${format_field_name(item)}</label>
                                <input value="" type="text" name="${item}" class="form-control" id="${server+'_'+item}"
                                       placeholder="Enter ${format_field_name(item)}">
                               </div>`;
                });
               row+=rowFields+"</div>";
                html+=row;
            }

            $('#custom_fields').html(html);
        }
    })
});


$('#servers').DataTable({
    processing: true,
    serverSide: true,
    responsive:true,
    ajax:'/admin/server/all',
    columns: [
        { "data": "title" },
        { "data": "from" },
        { "data": "status" },
        { "data": "created_at" },
        { "data": "action" },
    ]
});

$('#testConnection').on('click',function (e) {
    e.preventDefault();
    const to_mail = $('#recipient_email').val();
    const testEmail = /^[A-Z0-9._%+-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}$/i;
    if (to_mail && testEmail.test(to_mail)){
        $('#to_mail').val(to_mail);
        let preText=$(this).text();
        $(this).addClass('disabled').attr('disabled','true').text('Checking...');
        let that=this;

        $('#serverForm').append("<input id='serverFormPutMethod' name='_method' value='PUT' type='hidden'/>");
        let formData=$('#serverForm').serialize();
        $.ajax({
            method: 'post',
            url:$(this).attr('data-action'),
            data:formData,
            success:function (res) {
                $('#serverTestModal').modal('toggle');
                $(that).removeClass('disabled').removeAttr('disabled').text(preText);
                notify('success', res.message);
                $("#serverFormPutMethod").remove();
            },
            error:function (res) {
                $("#serverFormPutMethod").remove();
                $('#serverTestModal').modal('toggle');
                $(that).removeClass('disabled').removeAttr('disabled').text(preText);
                let errors=res.responseJSON.errors;
                let errorMsg='';
                $.each(errors,function (index,value) {
                    errorMsg+=value[0]+"\n <br>";
                })
                notify('danger', res.message);

            }

        })
        $('#recipient_email_required').addClass('d-none')
    }else {
        $('#recipient_email_required').removeClass('d-none')
    }

});