Subversion Repositories SmartDukaan

Rev

Rev 35841 | Rev 36644 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 35841 Rev 36642
Line 434... Line 434...
434
                    });
434
                    });
435
 
435
 
436
                return false;
436
                return false;
437
            }
437
            }
438
        });
438
        });
439
    var leadId = null;
439
    window.leadId = null;
440
    var row = null;
440
    var row = null;
441
    $(document).on('click', ".editLead", function () {
441
    $(document).on('click', ".editLead", function () {
442
        $('#editLeadData').modal('show');
442
        $('#editLeadData').modal('show');
443
 
443
 
444
        $("#remark").val("");
444
        $("#remark").val("");
Line 554... Line 554...
554
                leadActivityData.source = editSource;
554
                leadActivityData.source = editSource;
555
            }
555
            }
556
 
556
 
557
 
557
 
558
            if (editStatus == "followUp") {
558
            if (editStatus == "followUp") {
559
                leadActivityData['scheldule'] = getDatesFromPicker('input[name="editScheduleTime"]').startDate
-
 
560
                leadActivityData['communicationType'] = communicationType
559
                leadActivityData['communicationType'] = communicationType
-
 
560
                leadActivityData['scheldule'] = getDatesFromPicker('input[name="editScheduleTime"]').startDate
561
 
561
 
-
 
562
                if (communicationType == 'VISIT') {
-
 
563
                    var beatVal = $('#beatDate').val();
-
 
564
                    if (beatVal) {
-
 
565
                        leadActivityData['beatSelection'] = beatVal;
-
 
566
                    }
-
 
567
                }
562
            }
568
            }
563
 
569
 
564
            console.log(leadActivityData);
570
            console.log(leadActivityData);
565
            if (confirm("Are you sure you want to add lead!") == true) {
571
            if (confirm("Are you sure you want to add lead!") == true) {
566
                doPostAjaxRequestWithJsonHandler(context + "/editLead", JSON.stringify(leadActivityData), function (response) {
572
                doPostAjaxRequestWithJsonHandler(context + "/editLead", JSON.stringify(leadActivityData), function (response) {
Line 811... Line 817...
811
 
817
 
812
 
818
 
813
function editStatusAction() {
819
function editStatusAction() {
814
    var val = $('#editStatus').val();
820
    var val = $('#editStatus').val();
815
    if (val == "followUp") {
821
    if (val == "followUp") {
-
 
822
        // Show communication type and schedule date
-
 
823
        $("#communicationTypeSection").show();
816
        $("#editScheduleTime").show();
824
        $("#editScheduleTime").show();
-
 
825
        $("#beatDateSelection").hide();
-
 
826
 
-
 
827
        // Reset communication type and assignTo
-
 
828
        $('#communicationType').val('');
-
 
829
        $('#assignTo').val('');
-
 
830
        $('#assignTo option').show();
-
 
831
 
-
 
832
        // Check if lead has approved geolocation to decide VISIT option
-
 
833
        doAjaxRequestHandler(context + "/lead-geo/check/" + leadId, "GET", function (response) {
-
 
834
            var hasGeo = response.response.hasApprovedGeo;
-
 
835
            var commDropdown = $('#communicationType');
-
 
836
            commDropdown.empty();
-
 
837
            commDropdown.append('<option value="" disabled selected>Communication Type</option>');
-
 
838
            commDropdown.append('<option value="TELEPHONIC">TELEPHONIC</option>');
-
 
839
            if (hasGeo) {
-
 
840
                commDropdown.append('<option value="VISIT">VISIT</option>');
-
 
841
            }
-
 
842
        });
817
    } else {
843
    } else {
-
 
844
        $("#communicationTypeSection").hide();
818
        $("#editScheduleTime").hide();
845
        $("#editScheduleTime").hide();
-
 
846
        $("#beatDateSelection").hide();
-
 
847
        $('#assignTo option').show();
819
    }
848
    }
820
 
849
 
821
}
850
}
822
 
851
 
823
function loadLeadSearchInfo(search_text) {
852
function loadLeadSearchInfo(search_text) {
Line 894... Line 923...
894
            loadLead("main-content");
923
            loadLead("main-content");
895
        }
924
        }
896
    );
925
    );
897
});
926
});
898
 
927
 
-
 
928
// ==================== GEO LOCATION HANDLERS ====================
-
 
929
 
-
 
930
// Communication type change: filter assignTo based on type
-
 
931
$(document).on('change', '#communicationType', function () {
-
 
932
    var val = $(this).val();
-
 
933
    var assignDropdown = $('#assignTo');
-
 
934
 
-
 
935
    // Reset beat
-
 
936
    $('#beatDate').val('');
-
 
937
    $('#beatBadges').empty();
-
 
938
    $("#beatDateSelection").hide();
-
 
939
 
-
 
940
    if (val == 'VISIT') {
-
 
941
        // Filter assignTo to sales users only (no BGC)
-
 
942
        if (typeof salesUserIds !== 'undefined') {
-
 
943
            assignDropdown.find('option').each(function () {
-
 
944
                var optVal = parseInt($(this).val());
-
 
945
                if (optVal && salesUserIds.indexOf(optVal) === -1) {
-
 
946
                    $(this).hide();
-
 
947
                } else {
-
 
948
                    $(this).show();
-
 
949
                }
-
 
950
            });
-
 
951
        }
-
 
952
        // If assignTo already selected, fetch beats immediately
-
 
953
        if (assignDropdown.val()) {
-
 
954
            fetchBeatDates();
-
 
955
        }
-
 
956
    } else {
-
 
957
        // TELEPHONIC — show all users
-
 
958
        assignDropdown.find('option').show();
-
 
959
    }
-
 
960
});
-
 
961
 
-
 
962
// Fetch beats when communicationType or assignTo changes
-
 
963
$(document).on('change', '#communicationType, #assignTo', function () {
-
 
964
    var commType = $('#communicationType').val();
-
 
965
    var salesAuthId = $('#assignTo').val();
-
 
966
    if (commType === 'VISIT' && salesAuthId && leadId) {
-
 
967
        fetchBeatDates();
-
 
968
    } else if (commType !== 'VISIT') {
-
 
969
        $("#beatDateSelection").hide();
-
 
970
    }
-
 
971
});
-
 
972
 
-
 
973
function fetchBeatDates() {
-
 
974
    var salesAuthId = $('#assignTo').val();
-
 
975
    var scheduleDate = $('input[name="editScheduleTime"]').val();
-
 
976
    if (!salesAuthId || !leadId) return;
-
 
977
 
-
 
978
    var badgesDiv = $('#beatBadges');
-
 
979
    badgesDiv.html('<span style="color:#999; font-size:12px;">Loading beats...</span>');
-
 
980
    $("#beatDateSelection").show();
-
 
981
    $('#beatDate').val('');
-
 
982
 
-
 
983
    var url = context + "/lead-geo/beat-dates?leadId=" + leadId + "&salesAuthId=" + salesAuthId;
-
 
984
    if (scheduleDate) {
-
 
985
        url += "&scheduleDate=" + encodeURIComponent(scheduleDate);
-
 
986
    }
-
 
987
 
-
 
988
    $.ajax({
-
 
989
        url: url,
-
 
990
        method: 'GET',
-
 
991
        success: function (response) {
-
 
992
            var data = response.response || response;
-
 
993
            badgesDiv.empty();
-
 
994
            if (data && data.beats && data.beats.length > 0) {
-
 
995
                var beats = data.beats.slice(0, 3); // show max 3
-
 
996
                for (var i = 0; i < beats.length; i++) {
-
 
997
                    var beat = beats[i];
-
 
998
                    var badge = $('<span class="beat-badge" style="' +
-
 
999
                        'display:inline-block; background:#337ab7; color:#fff; padding:6px 12px; ' +
-
 
1000
                        'margin:4px 6px 4px 0; border-radius:16px; cursor:pointer; font-size:12px; ' +
-
 
1001
                        'border:2px solid #337ab7; transition:all 0.2s;">' +
-
 
1002
                        beat.planDate + ' &middot; ' + beat.beatName + ' (' + beat.stops + ' stops)' +
-
 
1003
                        '</span>');
-
 
1004
                    badge.data('value', beat.planDate + '|' + beat.beatName + '|' + beat.planGroupId);
-
 
1005
                    badgesDiv.append(badge);
-
 
1006
                }
-
 
1007
            } else {
-
 
1008
                badgesDiv.html('<span style="color:#999; font-size:12px;">No beats available for this person</span>');
-
 
1009
            }
-
 
1010
        },
-
 
1011
        error: function () {
-
 
1012
            badgesDiv.html('<span style="color:#d9534f; font-size:12px;">Error loading beats</span>');
-
 
1013
        }
-
 
1014
    });
-
 
1015
}
-
 
1016
 
-
 
1017
// Click on beat badge to select it
-
 
1018
$(document).on('click', '.beat-badge', function () {
-
 
1019
    // Deselect others
-
 
1020
    $('.beat-badge').css({'background': '#337ab7', 'border-color': '#337ab7'});
-
 
1021
    // Select this one
-
 
1022
    $(this).css({'background': '#1a5276', 'border-color': '#f39c12', 'border-width': '2px'});
-
 
1023
    $('#beatDate').val($(this).data('value'));
-
 
1024
});
-
 
1025
 
-
 
1026
// Generate Geo Link for lead
-
 
1027
$(document).on('click', '.generateGeoLink', function (e) {
-
 
1028
    e.stopPropagation();
-
 
1029
    var lid = $(this).data('leadid');
-
 
1030
    doAjaxRequestHandler(context + "/lead-geo/generate-link?leadId=" + lid, "GET", function (response) {
-
 
1031
        var url = response.response;
-
 
1032
        if (navigator.clipboard) {
-
 
1033
            navigator.clipboard.writeText(url).then(function () {
-
 
1034
                alert("Link copied to clipboard:\n" + url);
-
 
1035
            });
-
 
1036
        } else {
-
 
1037
            prompt("Share this link with the prospect:", url);
-
 
1038
        }
-
 
1039
    });
-
 
1040
});
-
 
1041
 
-
 
1042
// Geo Review navigation
-
 
1043
$(document).on('click', '.geo-review', function () {
-
 
1044
    doGetAjaxRequestHandler(context + "/lead-geo/pending-reviews", function (response) {
-
 
1045
        $('#main-content').html(response);
-
 
1046
    });
-
 
1047
});
-
 
1048
 
-
 
1049
// Visit Approvals navigation
-
 
1050
$(document).on('click', '.visit-approvals', function () {
-
 
1051
    doGetAjaxRequestHandler(context + "/visit-approvals", function (response) {
-
 
1052
        $('#main-content').html(response);
-
 
1053
    });
-
 
1054
});
-
 
1055
 
-
 
1056
// Approve geolocation from lead table
-
 
1057
$(document).on('click', '.approve-geo', function (e) {
-
 
1058
    e.stopPropagation();
-
 
1059
    var lid = $(this).data('leadid');
-
 
1060
    if (!confirm('Approve geolocation for Lead #' + lid + '?')) return;
-
 
1061
 
-
 
1062
    var btn = $(this);
-
 
1063
    var cell = btn.closest('td');
-
 
1064
 
-
 
1065
    doPostAjaxRequestWithParamsHandler(
-
 
1066
        context + '/lead-geo/review',
-
 
1067
        {leadId: lid, status: 'APPROVED', remark: ''},
-
 
1068
        function (response) {
-
 
1069
            cell.html('<span class="label label-success">Verified</span>');
-
 
1070
        }
-
 
1071
    );
-
 
1072
});
-
 
1073
 
-
 
1074
// Reject geolocation from lead table
-
 
1075
$(document).on('click', '.reject-geo', function (e) {
-
 
1076
    e.stopPropagation();
-
 
1077
    var lid = $(this).data('leadid');
-
 
1078
    var reason = prompt('Reason for rejection:');
-
 
1079
    if (reason === null) return;
-
 
1080
 
-
 
1081
    var btn = $(this);
-
 
1082
    var cell = btn.closest('td');
-
 
1083
 
-
 
1084
    doPostAjaxRequestWithParamsHandler(
-
 
1085
        context + '/lead-geo/review',
-
 
1086
        {leadId: lid, status: 'REJECTED', remark: reason},
-
 
1087
        function (response) {
-
 
1088
            cell.html('<button class="btn btn-xs btn-warning generateGeoLink" data-leadid="' + lid + '">Rejected - Resend</button>');
-
 
1089
        }
-
 
1090
    );
-
 
1091
});
-
 
1092