Subversion Repositories SmartDukaan

Rev

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

Rev 37048 Rev 37050
Line 96... Line 96...
96
                .remove()
96
                .remove()
97
                .draw(false);
97
                .draw(false);
98
        }
98
        }
99
    }
99
    }
100
 
100
 
-
 
101
    // Exposed so handlers outside the $(function () { ... }) scope (e.g. #vrSendBtn) can
-
 
102
    // refresh the search view after they mutate a lead.
-
 
103
    window.runGlobalLeadSearch = function (term) {
-
 
104
        runGlobalLeadSearch(term);
-
 
105
    };
-
 
106
 
101
    function runGlobalLeadSearch(term) {
107
    function runGlobalLeadSearch(term) {
102
        term = $.trim(term || "");
108
        term = $.trim(term || "");
103
        if (term.length < 2) {
109
        if (term.length < 2) {
104
            $('#global-search-results').html("");
110
            $('#global-search-results').html("");
105
            clearInjectedGlobalRows();
111
            clearInjectedGlobalRows();
Line 120... Line 126...
120
                // Rows carry class .global-search-row so we can clear them on the next search.
126
                // Rows carry class .global-search-row so we can clear them on the next search.
121
                clearInjectedGlobalRows();
127
                clearInjectedGlobalRows();
122
                var $hiddenRows = $('#global-search-main-rows tbody tr');
128
                var $hiddenRows = $('#global-search-main-rows tbody tr');
123
                if ($hiddenRows.length && $.fn.dataTable.isDataTable('#lead-table')) {
129
                if ($hiddenRows.length && $.fn.dataTable.isDataTable('#lead-table')) {
124
                    var dt = $('#lead-table').DataTable();
130
                    var dt = $('#lead-table').DataTable();
-
 
131
                    // Collect lead ids already in the main table (from the initial date-scoped
-
 
132
                    // render) so we don't inject a duplicate row for the same lead.
-
 
133
                    var existingIds = {};
-
 
134
                    dt.rows().nodes().to$().each(function () {
-
 
135
                        var id = $(this).attr('data');
-
 
136
                        if (id) existingIds[id] = true;
-
 
137
                    });
125
                    $hiddenRows.each(function () {
138
                    $hiddenRows.each(function () {
-
 
139
                        var id = $(this).attr('data');
-
 
140
                        if (id && existingIds[id]) return;
126
                        dt.row.add(this);
141
                        dt.row.add(this);
127
                    });
142
                    });
128
                    dt.draw(false);
143
                    dt.draw(false);
129
                }
144
                }
130
            });
145
            });
Line 742... Line 757...
742
            if (confirm("Are you sure you want to add lead!") == true) {
757
            if (confirm("Are you sure you want to add lead!") == true) {
743
                doPostAjaxRequestWithJsonHandler(context + "/editLead", JSON.stringify(leadActivityData), function (response) {
758
                doPostAjaxRequestWithJsonHandler(context + "/editLead", JSON.stringify(leadActivityData), function (response) {
744
                    console.log(response);
759
                    console.log(response);
745
                    $('#editLeadData').modal('hide');
760
                    $('#editLeadData').modal('hide');
746
                    $('.modal-backdrop').remove();
761
                    $('.modal-backdrop').remove();
-
 
762
                    // Inline row replace only works when the row's column layout matches the
-
 
763
                    // main #lead-table (that's what edit-lead.vm renders for). The upper
-
 
764
                    // search-results table has fewer columns, so let the search re-run
-
 
765
                    // repaint it cleanly instead.
-
 
766
                    if (row && !row.closest('#global-search-results').length) {
747
                    row.html(response);
767
                        row.html(response);
-
 
768
                    }
-
 
769
                    var activeTerm = $.trim($('#lead-table_filter input').val() || $('#lead-table-bottom-filter').val() || "");
-
 
770
                    if (activeTerm.length >= 2 && $('#global-search-results').children().length) {
-
 
771
                        runGlobalLeadSearch(activeTerm);
-
 
772
                    }
748
                });
773
                });
749
            }
774
            }
750
 
775
 
751
    }
776
    }
752
 
777
 
Line 1245... Line 1270...
1245
    var $btn = $(this);
1270
    var $btn = $(this);
1246
    var assigneeAuthId = parseInt($('#assignTo').val());
1271
    var assigneeAuthId = parseInt($('#assignTo').val());
1247
    var commType = $('#communicationType').val() || null;
1272
    var commType = $('#communicationType').val() || null;
1248
    var nearestStoreId = parseInt($btn.data('nearest'));
1273
    var nearestStoreId = parseInt($btn.data('nearest'));
1249
    var preferred = $('#vrPreferredDate').val() || null;
1274
    var preferred = $('#vrPreferredDate').val() || null;
-
 
1275
    var selectedStatus = $('#editStatus').val() || null;
1250
    if (!leadId || !assigneeAuthId) {
1276
    if (!leadId || !assigneeAuthId) {
1251
        alert('Pick an assignee first.');
1277
        alert('Pick an assignee first.');
1252
        return;
1278
        return;
1253
    }
1279
    }
1254
    $btn.prop('disabled', true).text('Sending...');
1280
    $btn.prop('disabled', true).text('Sending...');
Line 1258... Line 1284...
1258
        communicationType: commType,
1284
        communicationType: commType,
1259
        reason: 'No upcoming beats for assignee'
1285
        reason: 'No upcoming beats for assignee'
1260
    };
1286
    };
1261
    if (!isNaN(nearestStoreId) && nearestStoreId > 0) payload.nearestStoreId = nearestStoreId;
1287
    if (!isNaN(nearestStoreId) && nearestStoreId > 0) payload.nearestStoreId = nearestStoreId;
1262
    if (preferred) payload.requestedDate = preferred;
1288
    if (preferred) payload.requestedDate = preferred;
-
 
1289
    // Ship the picked status too — server (VisitRequestController.create) reads
-
 
1290
    // it via parseLeadStatus and updates lead.status through reassignLeadAndLog.
-
 
1291
    // Without it, the visit request is raised but the lead status never moves
-
 
1292
    // off its previous value (e.g. stays notInterested while user picked followUp).
-
 
1293
    if (selectedStatus) payload.status = selectedStatus;
1263
 
1294
 
1264
    doPostAjaxRequestWithJsonHandler(context + '/visitRequest/create', JSON.stringify(payload),
1295
    doPostAjaxRequestWithJsonHandler(context + '/visitRequest/create', JSON.stringify(payload),
1265
        function (response) {
1296
        function (response) {
1266
            $btn.prop('disabled', false).text('Send Visit Request');
1297
            $btn.prop('disabled', false).text('Send Visit Request');
1267
            var data = (response && response.response) || response || {};
1298
            var data = (response && response.response) || response || {};
1268
            if (data && data.id) {
1299
            if (data && data.id) {
1269
                alert('Visit request sent. The assignee\'s manager has been notified.');
1300
                alert('Visit request sent. The assignee\'s manager has been notified.');
1270
                $('#editLeadData').modal('hide');
1301
                $('#editLeadData').modal('hide');
1271
                $('.modal-backdrop').remove();
1302
                $('.modal-backdrop').remove();
-
 
1303
                // Repaint the affected rows so the new status is visible without
-
 
1304
                // a manual refresh. If a global search is active, re-run it (this
-
 
1305
                // also refreshes the injected rows in #lead-table).
-
 
1306
                var activeTerm = $.trim($('#lead-table_filter input').val() || $('#lead-table-bottom-filter').val() || "");
-
 
1307
                if (activeTerm.length >= 2 && $('#global-search-results').children().length && typeof window.runGlobalLeadSearch === 'function') {
-
 
1308
                    window.runGlobalLeadSearch(activeTerm);
-
 
1309
                }
1272
            } else {
1310
            } else {
1273
                var msg = (data && data.message) || (data && data.error) || 'Could not send request.';
1311
                var msg = (data && data.message) || (data && data.error) || 'Could not send request.';
1274
                alert(msg);
1312
                alert(msg);
1275
            }
1313
            }
1276
        });
1314
        });