Subversion Repositories SmartDukaan

Rev

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

Rev 36984 Rev 37003
Line 460... Line 460...
460
                return false;
460
                return false;
461
            }
461
            }
462
        });
462
        });
463
    window.leadId = null;
463
    window.leadId = null;
464
    var row = null;
464
    var row = null;
-
 
465
    // Turn Assign To into a search-select. We attempt initialisation at 3 points to be
-
 
466
    // robust against ordering / DOM-timing issues:
-
 
467
    //   1. Immediately at load time (element is in DOM per lead.vm)
-
 
468
    //   2. On the modal's shown.bs.modal event (post-transition)
-
 
469
    //   3. As a fallback in the click handler with a small delay
-
 
470
    function initAssignToSelect2() {
-
 
471
        if (!$.fn.select2) {
-
 
472
            console.warn('[lead.js] select2 not loaded — falling back to native <select>');
-
 
473
            return;
-
 
474
        }
-
 
475
        var $assign = $('#assignTo');
-
 
476
        if ($assign.length === 0) return;
-
 
477
        if ($assign.hasClass('select2-hidden-accessible')) return; // already applied
-
 
478
        $assign.select2({
-
 
479
            placeholder: 'Assign To',
-
 
480
            allowClear: true,
-
 
481
            width: '100%',
-
 
482
            dropdownParent: $('#editLeadData'),
-
 
483
            // Hide disabled options — VISIT/TELEPHONIC filter uses .prop('disabled', true).
-
 
484
            matcher: function (params, data) {
-
 
485
                if (data.element && $(data.element).prop('disabled')) return null;
-
 
486
                if (!params.term || $.trim(params.term) === '') return data;
-
 
487
                if (data.text && data.text.toLowerCase().indexOf(params.term.toLowerCase()) > -1) return data;
-
 
488
                return null;
-
 
489
            }
-
 
490
        });
-
 
491
        console.log('[lead.js] select2 applied to #assignTo');
-
 
492
    }
-
 
493
 
-
 
494
    initAssignToSelect2();
-
 
495
    $(document).on('shown.bs.modal', '#editLeadData', initAssignToSelect2);
-
 
496
 
465
    $(document).on('click', ".editLead", function () {
497
    $(document).on('click', ".editLead", function () {
466
        $('#editLeadData').modal('show');
498
        $('#editLeadData').modal('show');
-
 
499
        // Belt-and-braces: also try after the modal transition completes.
-
 
500
        setTimeout(initAssignToSelect2, 300);
467
 
501
 
468
        $("#remark").val("");
502
        $("#remark").val("");
469
        $("#assignTo").val("");
503
        $("#assignTo").val("").trigger('change');
470
        $("#editStatus").val("");
504
        $("#editStatus").val("");
471
        $("#reason").val("");
505
        $("#reason").val("");
472
        $("#editCity").val("");
506
        $("#editCity").val("");
473
        $("#editState").val("");
507
        $("#editState").val("");
474
        $("#editSource").val("");
508
        $("#editSource").val("");
Line 904... Line 938...
904
        $("#editScheduleTime").show();
938
        $("#editScheduleTime").show();
905
        $("#beatDateSelection").hide();
939
        $("#beatDateSelection").hide();
906
 
940
 
907
        // Reset communication type only; preserve the assignee the user picked.
941
        // Reset communication type only; preserve the assignee the user picked.
908
        $('#communicationType').val('');
942
        $('#communicationType').val('');
909
        $('#assignTo option').show();
943
        $('#assignTo option').prop('disabled', false);
910
 
944
 
911
        // Check if lead has approved geolocation to decide VISIT option
945
        // Check if lead has approved geolocation to decide VISIT option
912
        doAjaxRequestHandler(context + "/lead-geo/check/" + leadId, "GET", function (response) {
946
        doAjaxRequestHandler(context + "/lead-geo/check/" + leadId, "GET", function (response) {
913
            var hasGeo = response.response.hasApprovedGeo;
947
            var hasGeo = response.response.hasApprovedGeo;
914
            var commDropdown = $('#communicationType');
948
            var commDropdown = $('#communicationType');
Line 921... Line 955...
921
        });
955
        });
922
    } else {
956
    } else {
923
        $("#communicationTypeSection").hide();
957
        $("#communicationTypeSection").hide();
924
        $("#editScheduleTime").hide();
958
        $("#editScheduleTime").hide();
925
        $("#beatDateSelection").hide();
959
        $("#beatDateSelection").hide();
926
        $('#assignTo option').show();
960
        $('#assignTo option').prop('disabled', false);
927
    }
961
    }
928
 
962
 
929
}
963
}
930
 
964
 
931
function loadLeadSearchInfo(search_text) {
965
function loadLeadSearchInfo(search_text) {
Line 1016... Line 1050...
1016
    $('#beatBadges').empty();
1050
    $('#beatBadges').empty();
1017
    $("#beatDateSelection").hide();
1051
    $("#beatDateSelection").hide();
1018
    $("#editScheduleTime").show();
1052
    $("#editScheduleTime").show();
1019
 
1053
 
1020
    if (val == 'VISIT') {
1054
    if (val == 'VISIT') {
1021
        // Filter assignTo to sales users only (no BGC)
1055
        // Filter assignTo to sales users only (no BGC). Uses .prop('disabled', ...)
-
 
1056
        // instead of .hide()/.show() because select2 doesn't respect hidden <option>s
-
 
1057
        // in its dropdown UI. Disabled options are filtered out by our matcher above.
1022
        if (typeof salesUserIds !== 'undefined') {
1058
        if (typeof salesUserIds !== 'undefined') {
1023
            assignDropdown.find('option').each(function () {
1059
            assignDropdown.find('option').each(function () {
1024
                var optVal = parseInt($(this).val());
1060
                var optVal = parseInt($(this).val());
1025
                if (optVal && salesUserIds.indexOf(optVal) === -1) {
1061
                if (optVal && salesUserIds.indexOf(optVal) === -1) {
1026
                    $(this).hide();
1062
                    $(this).prop('disabled', true);
1027
                } else {
1063
                } else {
1028
                    $(this).show();
1064
                    $(this).prop('disabled', false);
1029
                }
1065
                }
1030
            });
1066
            });
1031
        }
1067
        }
1032
    } else {
1068
    } else {
1033
        // TELEPHONIC — show all users
1069
        // TELEPHONIC — enable all users
1034
        assignDropdown.find('option').show();
1070
        assignDropdown.find('option').prop('disabled', false);
-
 
1071
    }
-
 
1072
    // Nudge select2 to re-render its dropdown with the new enabled/disabled state.
-
 
1073
    if ($.fn.select2 && assignDropdown.hasClass('select2-hidden-accessible')) {
-
 
1074
        assignDropdown.trigger('change.select2');
1035
    }
1075
    }
1036
    // Both VISIT and TELEPHONIC offer beat-day slots when an assignee is set
1076
    // Both VISIT and TELEPHONIC offer beat-day slots when an assignee is set
1037
    // (TELEPHONIC just uses the beat date as the call slot; backend won't
1077
    // (TELEPHONIC just uses the beat date as the call slot; backend won't
1038
    // attach a LeadRoute for it). Non-sales assignees simply get an empty list.
1078
    // attach a LeadRoute for it). Non-sales assignees simply get an empty list.
1039
    if (val && assignDropdown.val()) {
1079
    if (val && assignDropdown.val()) {