HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/buyercall_new/buyercall/buyercall/assets/scripts/mobile/contact_note.js
$(() => {
    getContactNoteList();
    end_url = location.href.split('/')[5];
    $("#nav-details").attr("href", "/mobile/contact_detail/" + end_url + location.search);
    $("#nav-timeline").attr("href", "/mobile/timeline/" + end_url + location.search);
})

function getContactNoteList() {
    params = new URLSearchParams(location.search);
    username = params.get('username');
    password = params.get('password');
    contact_id = window.location.pathname.split('/')[3];
    $.ajax({
        type: "GET",
        url: "/mobile/contact_notes_list/" + contact_id,
        data: { "username": username, "password": password },
        success: function (result) {

            $("#notesList").html(result.html_content);

            $('.notes-edit-btn').click(function () {
                $(this).closest(".message-wrapper").find('.message p').attr("contenteditable", true);
                $(this).closest(".notes-card").find('.save-note-btn').attr("hidden", false);
            });

            $('.save-note-btn').click(function () {
                para = $(this).closest(".notes-card").find('.message p');
                para.attr("contenteditable", false);
                updateNote(para.text(), para.attr("data-id"));
                $(this).attr("hidden", true);
            });

            $(".rm-note-btn").click(function () {
                note_id = $(this).attr("data-id");
                $("#dlt-note-id").val(note_id);
                $("#removeToModal").modal("show");
            });
        }
    });
}

function createNote(note) {
    params = new URLSearchParams(location.search);
    username = params.get('username');
    password = params.get('password');
    contact_id = window.location.pathname.split('/')[3];
    $.ajax({
        type: "POST",
        url: "/mobile/add_note/" + contact_id,
        data: { "username": username, "password": password, "note": note },
        success: function (result) {
            if (result.status) {
                window.location.reload();
            }
            else{
                $("#addNoteModal").modal("hide");
                $("#error-msg").text(result.error);
                $("#validationError").modal('show');
            }
        }
    });
}

function updateNote(note, note_id) {
    params = new URLSearchParams(location.search);
    username = params.get('username');
    password = params.get('password');
    contact_id = window.location.pathname.split('/')[3];
    $.ajax({
        type: "POST",
        url: "/mobile/edit_note/" + contact_id,
        data: { "username": username, "password": password, "note": note, "note_id": note_id },
        success: function (result) {
            if (result.status) {
                // window.location.reload();
            }
        }
    });
}

function deleteNote(note_id) {
    params = new URLSearchParams(location.search);
    username = params.get('username');
    password = params.get('password');
    $.ajax({
        type: "POST",
        url: "/mobile/delete_note/" + note_id,
        data: { "username": username, "password": password},
        success: function (result) {
            if (result.status) {
                window.location.reload();
            }
        }
    });
}

$("#add-note-button").on("click", () => {
    note = $("#new-note").val();
    createNote(note);
});


$(".btn-dlt").on("click", () => {
    note = $("#dlt-note-id").val();
    deleteNote(note);
});

$("#back-to-contact").on("click", () => {
    if ($(".save-note-btn:visible").length){
        $("#modal-ok-link").attr("href", "/mobile/contact_leads/detail" + location.search);
        $("#backToModal").modal('show');
    }
    else{
        location.href = "/mobile/contact_leads/detail" + location.search;
    }
})