Back | Home
الـ Path الحالي: /home/picotech/domains/instantly.picotech.app/public_html/public/uploads/./.././js/./customer/././.
الملفات الموجودة في هذا الـ Path:
.
..
campaign.js
campaign_statistic.js
compose.js
contact.js
dashboard.js
domain.js
email_account.js
email_template.js
form.js
group.js
inbox.js
label.js
lead_finder.js
list_builder.js
queue.js
sender.js
sent.js
settings.js
ticket.js

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

"use strict";

$('#campaign').DataTable({
    processing: true,
    serverSide: true,
    responsive:true,
    ajax:'/get/campaigns',
    columns: [
        { "data": "title","name":"campaigns.title" },
        { "data": "start_date" },
        { "data": "end_date" },
        { "data": "start_time" },
        { "data": "end_time" },
        { "data": "status" },
        { "data": "action" },
    ]
});


$.validator.addMethod("phone_number", function (value, element) {
    return new RegExp(/^[0-9\-\+]{9,15}$/).test(value);
}, 'Invalid phone number');



$('#forward_to_dial_code,#contact_dial_code').select2();
$(document).on('click', '.campaign_side_bar', function (e) {
    const type = $(this).attr('data-type');
    $('.campaign_side_bar').removeClass('active');
    $(this).addClass('active');
    $('.campaign_section').hide();
    $('#' + type + '_section').show();
    if (type == 'rate') {
        $('button[type="submit"]').removeClass('disabled').removeClass('d-none');
    } else {
        $('button[type="submit"]').addClass('disabled').addClass('d-none');
    }

});

$(".group, .active_btn").on('click', function (e) {
    var curPos = document.getElementById("to_emails").selectionStart;
    let to_emails = $("#to_emails").val();
    let id = $(this).attr('data-id');
    const pre_btn = $(this).hasClass('active_btn');
    let that = $(this);

    let preData = that.attr('data-value');

    if (!isLoading && !preData) {
        isLoading = true;
        $('.group').addClass('disabled').attr('disabled','disabled');

        $.ajax({
            method: 'get',
            url: '/group/get/numbers',
            data: {id: id},
            success: function (res) {
                if (res.status == 'success') {
                    let insert_text = res.data;
                    let numbersInString='';
                    $.each(insert_text, function (key, data) {
                        if (key != insert_text.length - 1) {
                            data = data.trim() + ', ';
                        } else {
                            data = data.trim();
                        }
                        numbersInString+=data;
                    });

                    if (pre_btn) {
                        that.removeClass('active_btn').addClass('group');
                        $('#to_emails').val($("#to_emails").val().replaceAll(numbersInString, ''));

                    } else {
                        $("#to_emails").val(to_emails.slice(0, curPos) + numbersInString + ', ' + to_emails.slice(curPos));
                        that.addClass('active_btn').removeClass('group');
                    }
                    that.attr('data-value',numbersInString);
                    isLoading = false;
                    $('.group').removeClass('disabled').removeAttr('disabled');
                }
            }
        })
    } else {
        isLoading = true;
        $('.group').addClass('disabled').attr('disabled','disabled');

        if (preData) {
            let insert_text = preData.split(", ");
            let numbersInString='';
            $.each(insert_text, function (key, data) {
                if (key != insert_text.length - 1) {
                    data = data.trim() + ', ';
                } else {
                    data = data.trim();
                }
                numbersInString+=data;
            });

            if (pre_btn) {
                that.removeClass('active_btn').addClass('group');
                $('#to_emails').val($("#to_emails").val().replaceAll(numbersInString, ''));

            } else {
                $("#to_emails").val(to_emails.slice(0, curPos) + numbersInString + ', ' + to_emails.slice(curPos));
                that.addClass('active_btn').removeClass('group');
            }
        }

        isLoading = false;
        $('.group').removeClass('disabled').removeAttr('disabled');
    }
})
$(function () {
    $('#range_5').ionRangeSlider({
        min: 1,
        max: 500,
        type: 'single',
        step: 1,
        postfix: ' ',
        prettify: false,
        hasGrid: true
    })
});
$(function () {
    $('.date_range').daterangepicker({
        autoUpdateInput: true,
        singleDatePicker: true,
        timePicker: false,
        locale: {
            format: 'YYYY/MM/DD'
        }
    });
});

var select2 = $('#campaignFromNumber').select2({
    minimumInputLength: 1,
    tags: true,
    tokenSeparators: [",", " "],
})

$('#template').select2({
    placeholder: "Select an template",
    allowClear: true
}).on('select2:select', function (e) {
    let data = e.params.data;
    const name = $(data.element).attr('data-name');
    const body = $(data.element).attr('data-body');
    const id = $(data.element).attr('data-id');


    $('#custom_tabs_one_tabContent').append(`
                     <div class="tab-pane fade " id="custom_tabs_one_home_tab_${id}" role="tabpanel" aria-labelledby="custom-tabs-one-home-tab">
                            <textarea name="template_body[]" class="form-control" id="email_template_body_${id}" cols="4"  rows="10"></textarea>
                    </div>`);

    $('#email_template_body_'+ id).summernote('destroy');
    $('#email_template_body_'+ id).summernote('pasteHTML',body);


    $('#custom_tabs_one_tab').append(`
                        <li class="nav-item">
                            <a class="nav-link select_template" id="nav_tab_${id}"  data-toggle="pill" href="#custom_tabs_one_home_tab_${id}" role="tab" data-id="${id}" aria-controls="custom-tabs-one-home" aria-selected="true">${name}</a>
                        </li>`);
    $('.select_template').last().trigger('click');
}).on('select2:unselect', function (e){
    let data = e.params.data;
    const id = $(data.element).attr('data-id');

    $('#custom_tabs_one_home_tab_' + id).remove();
    $('#nav_tab_' + id).remove();
});

$(document).on('click', '.select_template', function (e) {
    e.preventDefault();
    const id = $(this).attr('data-id');
    console.log(id)
    $('#template_active_nav').val(id);
});
$('#campaignFromNumber').select2({
    tags: false,
    placeholder: 'Select an from number'
});
function typeInTextarea(newText, el = document.activeElement) {
    const [start, end] = [el.selectionStart, el.selectionEnd];
    el.setRangeText(newText, start, end, 'select');
}
$('.email_template_variable').on('click', function (e) {
    e.preventDefault()
    let text_to_insert = $(this).attr('data-name');
    const id = $('#template_active_nav').val();
    if (id){
        typeInTextarea(text_to_insert,document.getElementById('email_template_body_' + id));
    }
    let newValue = $('#email_template_body_'+ id).val();
    $('#email_template_body_'+ id).summernote('destroy');
    $('#email_template_body_'+ id).summernote('setRangeText', newValue);
    $('#email_template_body_' + id).focus();
});

$(document).on('keyup or click', '#email_template_body', function (e) {
    const character = $(this).val().length;

    var messageValue = $(this).val();
    var div = parseInt(parseInt(messageValue.length - 1) / 160) + 1;
    if (div <= 1) {
        $("#count").text("Characters left: " + (160 - messageValue.length));
    } else $("#count").text("Characters left: " + (160 * div - messageValue.length) + "/" + div);
});