| 35548 |
aman |
1 |
$(function () {
|
|
|
2 |
$(document).on('click', ".lead", function () {
|
|
|
3 |
loadLead("main-content");
|
|
|
4 |
});
|
| 29598 |
tejbeer |
5 |
|
| 35548 |
aman |
6 |
$(document).on('click', ".team-commitment", function () {
|
|
|
7 |
loadTeamCommitment("main-content");
|
|
|
8 |
});
|
| 30439 |
tejbeer |
9 |
|
|
|
10 |
|
| 35548 |
aman |
11 |
$(document).on('click', ".partner-health", function () {
|
|
|
12 |
loadPartnerHealth("main-content");
|
|
|
13 |
});
|
| 29598 |
tejbeer |
14 |
|
| 37651 |
vikas |
15 |
// Sidebar "Import Meta Leads". The menu row's action_class becomes the anchor's css class,
|
|
|
16 |
// which is how every other menu entry in this app is wired.
|
|
|
17 |
$(document).on('click', ".meta-lead-import", function () {
|
|
|
18 |
doGetAjaxRequestHandler(context + "/lms/meta-import", function (response) {
|
|
|
19 |
$('#main-content').html(response);
|
|
|
20 |
});
|
|
|
21 |
});
|
|
|
22 |
|
|
|
23 |
// Lead id -> LMS record. Delegated because the lead lists are re-rendered by ajax, and the
|
|
|
24 |
// record itself is a fragment that replaces #main-content, same as every other screen here.
|
|
|
25 |
$(document).on('click', ".lms-open-record", function (e) {
|
|
|
26 |
e.preventDefault();
|
|
|
27 |
e.stopPropagation();
|
|
|
28 |
var leadId = $(this).data('leadid');
|
|
|
29 |
if (!leadId) { return; }
|
|
|
30 |
doGetAjaxRequestHandler(context + "/leadRecord?leadId=" + leadId, function (response) {
|
|
|
31 |
$('#main-content').html(response);
|
|
|
32 |
});
|
|
|
33 |
});
|
|
|
34 |
|
| 35548 |
aman |
35 |
$(document).on('click', ".lead-detail", function () {
|
|
|
36 |
loadLeadDetail("main-content");
|
|
|
37 |
});
|
| 30439 |
tejbeer |
38 |
|
| 31370 |
tejbeer |
39 |
|
| 35548 |
aman |
40 |
$(document).on('click', ".submitCommitment",
|
|
|
41 |
function () {
|
|
|
42 |
var startDateTime = getDatesFromPicker('input[name="commitmentDate"]').startDate;
|
|
|
43 |
doGetAjaxRequestHandler(context + "/getTeamCommitment?date="
|
|
|
44 |
+ startDateTime, function (response) {
|
|
|
45 |
$('.teamcommitmentcontainer').html(response);
|
| 31370 |
tejbeer |
46 |
|
| 35548 |
aman |
47 |
});
|
|
|
48 |
});
|
| 30439 |
tejbeer |
49 |
|
|
|
50 |
|
| 35548 |
aman |
51 |
$(document).on('click', ".submitDateWiseLead", function () {
|
| 30439 |
tejbeer |
52 |
|
| 35769 |
amit |
53 |
var startDate = $("#startDate").val();
|
|
|
54 |
var endDate = $("#endDate").val();
|
| 35548 |
aman |
55 |
var status = $("#statusFilter").val();
|
|
|
56 |
var color = $("#colorFilter").val();
|
| 31370 |
tejbeer |
57 |
|
| 35548 |
aman |
58 |
if (color == null) {
|
|
|
59 |
color = "";
|
|
|
60 |
}
|
| 31370 |
tejbeer |
61 |
|
| 35769 |
amit |
62 |
if (startDate && endDate) {
|
|
|
63 |
var start = new Date(startDate);
|
|
|
64 |
var end = new Date(endDate);
|
|
|
65 |
if (end < start) {
|
|
|
66 |
alert("End date must be after start date");
|
|
|
67 |
return;
|
|
|
68 |
}
|
|
|
69 |
}
|
| 31370 |
tejbeer |
70 |
|
| 35769 |
amit |
71 |
doGetAjaxRequestHandler(context + "/getOpenLead?leadStatus=" + status + "&color=" + color + "&startDate=" + startDate + "&endDate=" + endDate, function (response) {
|
| 35548 |
aman |
72 |
$('#' + 'main-content').html(response);
|
|
|
73 |
});
|
| 29598 |
tejbeer |
74 |
|
|
|
75 |
|
| 35548 |
aman |
76 |
})
|
|
|
77 |
;$(document).on('click', ".downloadDateWiseLead", function () {
|
| 29598 |
tejbeer |
78 |
|
| 35769 |
amit |
79 |
var startDate = $("#startDate").val();
|
|
|
80 |
var endDate = $("#endDate").val();
|
| 35548 |
aman |
81 |
var status = $("#statusFilter").val();
|
|
|
82 |
var color = $("#colorFilter").val();
|
| 29598 |
tejbeer |
83 |
|
| 35548 |
aman |
84 |
if (color == null) {
|
|
|
85 |
color = "";
|
|
|
86 |
}
|
| 29598 |
tejbeer |
87 |
|
| 35769 |
amit |
88 |
if (startDate && endDate) {
|
|
|
89 |
var start = new Date(startDate);
|
|
|
90 |
var end = new Date(endDate);
|
|
|
91 |
if (end < start) {
|
|
|
92 |
alert("End date must be after start date");
|
|
|
93 |
return;
|
|
|
94 |
}
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
let endPoint = `${context}/downloadDateWiseLead?leadStatus=${status}&color=${color}&startDate=${startDate}&endDate=${endDate}`;
|
| 35548 |
aman |
98 |
window.location.href = endPoint;
|
| 31249 |
tejbeer |
99 |
|
| 35548 |
aman |
100 |
});
|
| 34650 |
aman.kumar |
101 |
|
| 37046 |
aman |
102 |
// Lead-table Search boxes (top DataTables box + bottom mirror below the table/pagination) =
|
|
|
103 |
// GLOBAL partner search: matches ANY lead by name / mobile / outlet / city across ALL statuses
|
|
|
104 |
// and ALL dates (this year, last year, anytime) - not just the loaded date-scoped rows. It
|
|
|
105 |
// searches AS YOU TYPE (debounced) so old partners surface without needing to press Enter;
|
|
|
106 |
// Enter still triggers an immediate search. Results render into #global-search-results above
|
|
|
107 |
// the date-scoped table; the view auto-scrolls there so a search from the bottom box is visible
|
|
|
108 |
// without the user having to scroll back up manually.
|
|
|
109 |
var LEAD_SEARCH_BOXES = "#lead-table_filter input, #lead-table-bottom-filter";
|
| 37021 |
aman |
110 |
var leadGlobalSearchTimer = null;
|
|
|
111 |
|
| 37048 |
ranu |
112 |
function clearInjectedGlobalRows() {
|
|
|
113 |
if ($.fn.dataTable.isDataTable('#lead-table')) {
|
|
|
114 |
$('#lead-table').DataTable()
|
|
|
115 |
.rows('.global-search-row')
|
|
|
116 |
.remove()
|
|
|
117 |
.draw(false);
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
|
| 37050 |
ranu |
121 |
// Exposed so handlers outside the $(function () { ... }) scope (e.g. #vrSendBtn) can
|
|
|
122 |
// refresh the search view after they mutate a lead.
|
|
|
123 |
window.runGlobalLeadSearch = function (term) {
|
|
|
124 |
runGlobalLeadSearch(term);
|
|
|
125 |
};
|
|
|
126 |
|
| 37021 |
aman |
127 |
function runGlobalLeadSearch(term) {
|
|
|
128 |
term = $.trim(term || "");
|
|
|
129 |
if (term.length < 2) {
|
|
|
130 |
$('#global-search-results').html("");
|
| 37048 |
ranu |
131 |
clearInjectedGlobalRows();
|
| 37021 |
aman |
132 |
return;
|
|
|
133 |
}
|
|
|
134 |
var safeTerm = $('<div>').text(term).html();
|
|
|
135 |
doGetAjaxRequestHandler(context + "/globalLeadSearch?searchTerm=" + encodeURIComponent(term),
|
|
|
136 |
function (response) {
|
|
|
137 |
$('#global-search-results').html(
|
|
|
138 |
'<h4 style="margin:15px 0 8px;">Search results — all partners, any date '
|
|
|
139 |
+ '<small class="text-muted">(matching "' + safeTerm + '")</small></h4>' + response);
|
| 37046 |
aman |
140 |
var resultsEl = document.getElementById('global-search-results');
|
|
|
141 |
if (resultsEl) {
|
|
|
142 |
resultsEl.scrollIntoView({behavior: 'smooth', block: 'start'});
|
|
|
143 |
}
|
| 37048 |
ranu |
144 |
|
|
|
145 |
// Mirror the hits into the main #lead-table so the same row is findable there too.
|
|
|
146 |
// Rows carry class .global-search-row so we can clear them on the next search.
|
|
|
147 |
clearInjectedGlobalRows();
|
|
|
148 |
var $hiddenRows = $('#global-search-main-rows tbody tr');
|
|
|
149 |
if ($hiddenRows.length && $.fn.dataTable.isDataTable('#lead-table')) {
|
|
|
150 |
var dt = $('#lead-table').DataTable();
|
| 37050 |
ranu |
151 |
// Collect lead ids already in the main table (from the initial date-scoped
|
|
|
152 |
// render) so we don't inject a duplicate row for the same lead.
|
|
|
153 |
var existingIds = {};
|
|
|
154 |
dt.rows().nodes().to$().each(function () {
|
|
|
155 |
var id = $(this).attr('data');
|
|
|
156 |
if (id) existingIds[id] = true;
|
|
|
157 |
});
|
| 37048 |
ranu |
158 |
$hiddenRows.each(function () {
|
| 37050 |
ranu |
159 |
var id = $(this).attr('data');
|
|
|
160 |
if (id && existingIds[id]) return;
|
| 37048 |
ranu |
161 |
dt.row.add(this);
|
|
|
162 |
});
|
|
|
163 |
dt.draw(false);
|
|
|
164 |
}
|
| 37021 |
aman |
165 |
});
|
|
|
166 |
}
|
|
|
167 |
|
| 37046 |
aman |
168 |
$(document).on('keydown', LEAD_SEARCH_BOXES, function (e) {
|
| 36984 |
aman |
169 |
if (e.which === 13) {
|
|
|
170 |
e.preventDefault();
|
| 37021 |
aman |
171 |
clearTimeout(leadGlobalSearchTimer);
|
|
|
172 |
runGlobalLeadSearch($(this).val());
|
| 36984 |
aman |
173 |
}
|
|
|
174 |
});
|
| 34650 |
aman.kumar |
175 |
|
| 37046 |
aman |
176 |
$(document).on('input', LEAD_SEARCH_BOXES, function () {
|
| 37021 |
aman |
177 |
var term = $(this).val();
|
|
|
178 |
clearTimeout(leadGlobalSearchTimer);
|
|
|
179 |
leadGlobalSearchTimer = setTimeout(function () {
|
|
|
180 |
runGlobalLeadSearch(term);
|
|
|
181 |
}, 350);
|
| 36984 |
aman |
182 |
});
|
|
|
183 |
|
| 37046 |
aman |
184 |
// Bottom box isn't a native DataTables filter element, so mirror it into the DataTable's own
|
|
|
185 |
// search + keep both boxes showing the same value regardless of which one the user typed into.
|
|
|
186 |
$(document).on('keyup input', '#lead-table-bottom-filter', function () {
|
|
|
187 |
var term = $(this).val();
|
|
|
188 |
$('#lead-table_filter input').val(term);
|
|
|
189 |
if ($.fn.dataTable.isDataTable('#lead-table')) {
|
|
|
190 |
$('#lead-table').DataTable().search(term).draw();
|
|
|
191 |
}
|
|
|
192 |
});
|
| 36984 |
aman |
193 |
|
| 37046 |
aman |
194 |
$(document).on('keyup input', '#lead-table_filter input', function () {
|
|
|
195 |
$('#lead-table-bottom-filter').val($(this).val());
|
|
|
196 |
});
|
|
|
197 |
|
|
|
198 |
|
| 35548 |
aman |
199 |
$(document).on('click', ".visit-request-plan", function () {
|
| 34650 |
aman.kumar |
200 |
|
| 35548 |
aman |
201 |
doGetAjaxRequestHandler(context + "/visitPlan", function (response) {
|
|
|
202 |
$('#' + 'main-content').html(response);
|
|
|
203 |
});
|
| 34650 |
aman.kumar |
204 |
|
| 35548 |
aman |
205 |
});
|
| 34650 |
aman.kumar |
206 |
|
| 35548 |
aman |
207 |
$(document).on('click', ".visitPlan", function () {
|
| 25980 |
tejbeer |
208 |
|
| 35548 |
aman |
209 |
let dateWisePlan = $("#dateVisitSearch").val();
|
| 31249 |
tejbeer |
210 |
|
| 35548 |
aman |
211 |
doGetAjaxRequestHandler(context + "/visit/getVisitPlan?date=" + dateWisePlan, function (response) {
|
|
|
212 |
$('#' + 'main-content').html(response);
|
|
|
213 |
});
|
| 31249 |
tejbeer |
214 |
|
| 35548 |
aman |
215 |
});
|
| 31249 |
tejbeer |
216 |
|
| 35548 |
aman |
217 |
$(document).on('click', ".lead-close", function () {
|
|
|
218 |
loadClosedLead("main-content");
|
|
|
219 |
});
|
| 31249 |
tejbeer |
220 |
|
| 35548 |
aman |
221 |
$(document).on('click', "#lead-close-paginated .next",
|
|
|
222 |
function () {
|
| 31249 |
tejbeer |
223 |
|
| 35548 |
aman |
224 |
var searchText = $("#authUser").val();
|
|
|
225 |
// var searchTxt=$("#scheme-search-text").val();
|
|
|
226 |
console.log(searchText);
|
|
|
227 |
if (typeof (searchText) == "undefined" || !searchText) {
|
|
|
228 |
searchText = "";
|
|
|
229 |
}
|
| 31249 |
tejbeer |
230 |
|
| 35548 |
aman |
231 |
if ((searchText)) {
|
|
|
232 |
var params = {};
|
|
|
233 |
params['searchTerm'] = searchText;
|
|
|
234 |
loadPaginatedNextItems('/searchLeadPaginated', params,
|
|
|
235 |
'lead-close-paginated', 'close-lead-table',
|
|
|
236 |
'lead-close-container');
|
|
|
237 |
} else {
|
| 31249 |
tejbeer |
238 |
|
| 35548 |
aman |
239 |
loadPaginatedNextItems('/getPaginatedClosedLeads', null,
|
|
|
240 |
'lead-close-paginated', 'close-lead-table',
|
|
|
241 |
'lead-close-container');
|
|
|
242 |
}
|
|
|
243 |
$(this).blur();
|
|
|
244 |
});
|
| 31249 |
tejbeer |
245 |
|
| 35548 |
aman |
246 |
$(document).on('click', "#lead-close-paginated .previous",
|
|
|
247 |
function () {
|
|
|
248 |
var searchText = $("#authUser").val();
|
|
|
249 |
// var searchTxt=$("#scheme-search-text").val();
|
|
|
250 |
console.log(searchText);
|
|
|
251 |
if (typeof (searchText) == "undefined" || !searchText) {
|
|
|
252 |
searchText = "";
|
|
|
253 |
}
|
| 25988 |
tejbeer |
254 |
|
| 35548 |
aman |
255 |
if ((searchText)) {
|
|
|
256 |
var params = {};
|
|
|
257 |
params['searchTerm'] = searchText;
|
|
|
258 |
loadPaginatedPreviousItems('/searchLeadPaginated', params,
|
|
|
259 |
'lead-close-paginated', 'close-lead-table',
|
|
|
260 |
'lead-close-container');
|
|
|
261 |
} else {
|
|
|
262 |
loadPaginatedPreviousItems('/getPaginatedClosedLeads',
|
|
|
263 |
null, 'lead-close-paginated', 'close-lead-table',
|
|
|
264 |
'lead-close-container');
|
|
|
265 |
}
|
|
|
266 |
$(this).blur();
|
|
|
267 |
});
|
| 25988 |
tejbeer |
268 |
|
| 35548 |
aman |
269 |
$(document).on('click', "#close-lead-search-button", function () {
|
|
|
270 |
var searchText = $("#authUser").val();
|
|
|
271 |
if (typeof (searchText) == "undefined" || !searchText) {
|
|
|
272 |
searchText = "";
|
|
|
273 |
}
|
|
|
274 |
loadLeadSearchInfo(searchText);
|
|
|
275 |
});
|
| 25988 |
tejbeer |
276 |
|
| 35548 |
aman |
277 |
$(document).on("keyup", "#authUser", function (e) {
|
|
|
278 |
var keyCode = e.keyCode || e.which;
|
|
|
279 |
if (keyCode == 13) {
|
|
|
280 |
$("#close-lead-search-button").click();
|
|
|
281 |
}
|
|
|
282 |
});
|
|
|
283 |
$(document).on('click', ".view",
|
|
|
284 |
function () {
|
|
|
285 |
var id = $(this).data('requestid');
|
|
|
286 |
console.log(id);
|
|
|
287 |
doGetAjaxRequestHandler(context + "/getLeadActivity?leadId="
|
|
|
288 |
+ id, function (response) {
|
| 25988 |
tejbeer |
289 |
|
| 35548 |
aman |
290 |
console.log(response)
|
| 25988 |
tejbeer |
291 |
|
| 35548 |
aman |
292 |
$('#fetchLeadActivityData .modal-content').html(response);
|
| 25988 |
tejbeer |
293 |
|
| 35548 |
aman |
294 |
});
|
|
|
295 |
});
|
| 25988 |
tejbeer |
296 |
|
| 35548 |
aman |
297 |
$(document).on('click', ".newLead", function () {
|
|
|
298 |
$('#newEntryLeadModal').modal('show');
|
|
|
299 |
$("#scheduleTime").hide();
|
|
|
300 |
});
|
| 25988 |
tejbeer |
301 |
|
| 35548 |
aman |
302 |
$(document).on('click', ".show-lead", function () {
|
|
|
303 |
var status = $("#statusFilter").val();
|
|
|
304 |
doGetAjaxRequestHandler(context + "/getOpenLead?leadStatus=" + status, function (response) {
|
|
|
305 |
$('#' + 'main-content').html(response);
|
|
|
306 |
});
|
|
|
307 |
});
|
| 25980 |
tejbeer |
308 |
|
| 31370 |
tejbeer |
309 |
|
| 35548 |
aman |
310 |
$(document).on('click', ".show-colowise-lead", function () {
|
|
|
311 |
var status = $("#statusFilter").val();
|
|
|
312 |
var color = $("#colorFilter").val();
|
|
|
313 |
doGetAjaxRequestHandler(context + "/getOpenLead?leadStatus=" + status + "&color=" + color, function (response) {
|
|
|
314 |
$('#' + 'main-content').html(response);
|
|
|
315 |
});
|
|
|
316 |
});
|
| 25980 |
tejbeer |
317 |
|
| 35548 |
aman |
318 |
$(document).on('click', "#uploadIvoryLead", function () {
|
| 25980 |
tejbeer |
319 |
|
| 35548 |
aman |
320 |
window.location.href = context + "/downloadIvoryLead";
|
|
|
321 |
});
|
| 25980 |
tejbeer |
322 |
|
| 35548 |
aman |
323 |
$(document).on('click', ".submitLeadGenerate", function () {
|
| 27609 |
tejbeer |
324 |
|
| 35548 |
aman |
325 |
console.log("hello");
|
|
|
326 |
if (confirm('Confirm upload ?')) {
|
|
|
327 |
var fileSelector = $(this)[0];
|
|
|
328 |
if (fileSelector != undefined) {
|
|
|
329 |
var url = `${context}/csvFileAndSetLead`;
|
|
|
330 |
console.log(url);
|
|
|
331 |
var file = $(".fileLeadGenerate")[0].files[0];
|
|
|
332 |
let fileInput = $(this);
|
|
|
333 |
console.log("file" + file);
|
|
|
334 |
console.log("fileInput" + fileInput);
|
|
|
335 |
doAjaxUploadRequestHandler(
|
|
|
336 |
url,
|
|
|
337 |
'POST',
|
|
|
338 |
file, function (response) {
|
| 27642 |
tejbeer |
339 |
|
| 35548 |
aman |
340 |
console.log("reponse" + response);
|
| 31370 |
tejbeer |
341 |
|
| 35548 |
aman |
342 |
if (response == true) {
|
|
|
343 |
alert("successfully uploaded");
|
| 31370 |
tejbeer |
344 |
|
|
|
345 |
|
| 35548 |
aman |
346 |
}
|
|
|
347 |
});
|
| 29598 |
tejbeer |
348 |
|
| 35548 |
aman |
349 |
}
|
|
|
350 |
} else {
|
|
|
351 |
// Do nothing!
|
|
|
352 |
}
|
|
|
353 |
});
|
| 27642 |
tejbeer |
354 |
|
|
|
355 |
|
| 35548 |
aman |
356 |
$(document).on('click', ".lead-request",
|
|
|
357 |
function () {
|
| 29598 |
tejbeer |
358 |
|
| 35548 |
aman |
359 |
var firstName = $('input[name="firstName"]').val();
|
|
|
360 |
var lastName = $('input[name="lastName"]').val();
|
|
|
361 |
var mobile = $('input[name="mobile"]').val();
|
|
|
362 |
var address = $('input[name="address"]').val();
|
|
|
363 |
var status = $("#status").val();
|
|
|
364 |
var city = $('input[name="city"]').val();
|
|
|
365 |
var state = $("#state").val();
|
|
|
366 |
var remark = $("#createRemark").val();
|
|
|
367 |
var assignTo = $("#createAssignTo").val();
|
|
|
368 |
var source = $("#leadSource").val();
|
|
|
369 |
var communicationType = $("#communicationTye").val();
|
| 29427 |
manish |
370 |
|
| 35548 |
aman |
371 |
var conversionprobability = $("#conversionprobabilit").val();
|
| 29598 |
tejbeer |
372 |
|
|
|
373 |
|
| 35548 |
aman |
374 |
var outletName = $('input[name="leadoutletName"]').val();
|
|
|
375 |
var counterSize = $('input[name="leadcounterSize"]').val();
|
|
|
376 |
var table = document.getElementById('brandtable');
|
|
|
377 |
var brandValueJson = [];
|
|
|
378 |
var leadBrands;
|
| 29598 |
tejbeer |
379 |
|
| 35548 |
aman |
380 |
console.log(conversionprobability)
|
| 29598 |
tejbeer |
381 |
|
|
|
382 |
|
| 35548 |
aman |
383 |
if (firstName === "" && lastName === "" && mobile === ""
|
|
|
384 |
&& address === "" && status === "" && city === ""
|
|
|
385 |
&& state === "" && remark === "" && source === "") {
|
|
|
386 |
alert("Field can't be empty");
|
|
|
387 |
return;
|
|
|
388 |
}
|
| 29598 |
tejbeer |
389 |
|
| 25980 |
tejbeer |
390 |
|
| 35548 |
aman |
391 |
if (firstName === "") {
|
|
|
392 |
alert("First Name is required");
|
|
|
393 |
return;
|
|
|
394 |
}
|
|
|
395 |
if (lastName === "") {
|
|
|
396 |
alert("Last Name is required");
|
|
|
397 |
return;
|
|
|
398 |
}
|
|
|
399 |
if (mobile === "") {
|
|
|
400 |
alert("Mobile is required");
|
|
|
401 |
return;
|
|
|
402 |
}
|
|
|
403 |
if (status === "") {
|
|
|
404 |
alert("Status is required");
|
|
|
405 |
return;
|
|
|
406 |
}
|
|
|
407 |
if (address === "") {
|
|
|
408 |
alert("address is required");
|
|
|
409 |
return;
|
|
|
410 |
}
|
|
|
411 |
if (city === "") {
|
|
|
412 |
alert("city is required");
|
|
|
413 |
return;
|
|
|
414 |
}
|
| 32471 |
tejbeer |
415 |
|
| 35548 |
aman |
416 |
if (state === "") {
|
|
|
417 |
alert("state is required");
|
|
|
418 |
return;
|
|
|
419 |
}
|
|
|
420 |
if (source === "") {
|
|
|
421 |
alert("Source is required")
|
|
|
422 |
return;
|
|
|
423 |
}
|
| 32471 |
tejbeer |
424 |
|
| 35548 |
aman |
425 |
if (remark === "") {
|
|
|
426 |
alert("Remark is required");
|
|
|
427 |
return;
|
|
|
428 |
}
|
| 32471 |
tejbeer |
429 |
|
| 35548 |
aman |
430 |
if (conversionprobability === "") {
|
|
|
431 |
alert("Conversion Probability is required");
|
|
|
432 |
return;
|
|
|
433 |
}
|
|
|
434 |
if (status == "followUp" || status == "pending" || status == "finalized") {
|
|
|
435 |
if (outletName === "") {
|
|
|
436 |
alert("Outlet Name is required");
|
|
|
437 |
return;
|
|
|
438 |
}
|
| 25980 |
tejbeer |
439 |
|
| 35548 |
aman |
440 |
if (counterSize === "") {
|
|
|
441 |
alert("Counter Size is required");
|
|
|
442 |
return;
|
|
|
443 |
}
|
| 32464 |
tejbeer |
444 |
|
| 35548 |
aman |
445 |
if (localStorage.getItem("frontph") == "undefined" && localStorage.getItem("frontph") == null) {
|
|
|
446 |
alert("Front Document is required");
|
|
|
447 |
return;
|
|
|
448 |
}
|
| 32464 |
tejbeer |
449 |
|
| 35548 |
aman |
450 |
if (localStorage.getItem("internalMarketh") == "undefined" || localStorage.getItem("internalMarketh") == null) {
|
|
|
451 |
alert("Front With Market Document is required");
|
|
|
452 |
return;
|
|
|
453 |
}
|
| 25980 |
tejbeer |
454 |
|
| 35548 |
aman |
455 |
if (localStorage.getItem("leftShoth") == "undefined" || localStorage.getItem("leftShoth") == null) {
|
|
|
456 |
alert("Internal Left Shot Document is required");
|
|
|
457 |
return;
|
|
|
458 |
}
|
| 32464 |
tejbeer |
459 |
|
| 35548 |
aman |
460 |
if (localStorage.getItem("leftWallh") == "undefined" || localStorage.getItem("leftWallh") == null) {
|
|
|
461 |
alert("Internal Left Wall Document is required");
|
|
|
462 |
return;
|
|
|
463 |
}
|
| 25980 |
tejbeer |
464 |
|
|
|
465 |
|
| 35548 |
aman |
466 |
if (localStorage.getItem("rightWallh") == "undefined" || localStorage.getItem("rightWallh") == null) {
|
|
|
467 |
alert("Internal Right Wall Document is required");
|
|
|
468 |
return;
|
|
|
469 |
}
|
| 25980 |
tejbeer |
470 |
|
| 32464 |
tejbeer |
471 |
|
| 35548 |
aman |
472 |
for (i = 1; i < table.rows.length; i++) {
|
| 32464 |
tejbeer |
473 |
|
| 35548 |
aman |
474 |
var objCells = table.rows[i].cells;
|
| 32464 |
tejbeer |
475 |
|
| 35548 |
aman |
476 |
leadBrands = {
|
|
|
477 |
brand: objCells[0].innerText,
|
|
|
478 |
value: objCells[1].getElementsByTagName('input')[0].value
|
|
|
479 |
}
|
|
|
480 |
brandValueJson.push(leadBrands);
|
|
|
481 |
}
|
| 32464 |
tejbeer |
482 |
|
|
|
483 |
|
| 35548 |
aman |
484 |
}
|
| 32464 |
tejbeer |
485 |
|
|
|
486 |
|
| 35548 |
aman |
487 |
var leaddetailData = {}
|
|
|
488 |
leaddetailData['firstName'] = firstName;
|
|
|
489 |
leaddetailData['lastName'] = lastName
|
|
|
490 |
leaddetailData['mobile'] = mobile
|
|
|
491 |
leaddetailData['address'] = address
|
|
|
492 |
leaddetailData['city'] = city
|
|
|
493 |
leaddetailData['state'] = state
|
|
|
494 |
leaddetailData['status'] = status
|
|
|
495 |
leaddetailData['remark'] = remark
|
|
|
496 |
leaddetailData['assignTo'] = assignTo
|
|
|
497 |
leaddetailData['source'] = source
|
|
|
498 |
leaddetailData['colorCheck'] = conversionprobability
|
| 32464 |
tejbeer |
499 |
|
|
|
500 |
|
| 35548 |
aman |
501 |
if (status == "followUp") {
|
|
|
502 |
leaddetailData['schelduleTimestamp'] = getDatesFromPicker('#scheduleTime').startDate;
|
| 32464 |
tejbeer |
503 |
|
| 35548 |
aman |
504 |
leaddetailData['communicationType'] = communicationType
|
|
|
505 |
}
|
| 32464 |
tejbeer |
506 |
|
|
|
507 |
|
| 35548 |
aman |
508 |
leaddetailData['outletName'] = outletName;
|
| 32464 |
tejbeer |
509 |
|
| 35548 |
aman |
510 |
leaddetailData['counterSize'] = counterSize;
|
| 32464 |
tejbeer |
511 |
|
|
|
512 |
|
| 35548 |
aman |
513 |
leaddetailData['leadBrands'] = brandValueJson;
|
| 32464 |
tejbeer |
514 |
|
| 35548 |
aman |
515 |
console.log(localStorage.getItem("frontp"));
|
| 32464 |
tejbeer |
516 |
|
|
|
517 |
|
| 35548 |
aman |
518 |
leaddetailData['frontp'] = localStorage
|
|
|
519 |
.getItem("frontph");
|
| 31249 |
tejbeer |
520 |
|
| 32464 |
tejbeer |
521 |
|
| 35548 |
aman |
522 |
leaddetailData['frontWithMarket'] = localStorage
|
|
|
523 |
.getItem("internalMarketh");
|
| 32464 |
tejbeer |
524 |
|
|
|
525 |
|
| 35548 |
aman |
526 |
leaddetailData['internalLongShot'] = localStorage
|
|
|
527 |
.getItem("leftShoth");
|
| 32464 |
tejbeer |
528 |
|
|
|
529 |
|
| 35548 |
aman |
530 |
leaddetailData['internalLeftWall'] = localStorage
|
|
|
531 |
.getItem("leftWallh");
|
| 32464 |
tejbeer |
532 |
|
|
|
533 |
|
| 35548 |
aman |
534 |
leaddetailData['internalRightWall'] = localStorage
|
|
|
535 |
.getItem("rightWallh");
|
| 32464 |
tejbeer |
536 |
|
| 35548 |
aman |
537 |
console.log(leaddetailData);
|
| 32464 |
tejbeer |
538 |
|
| 35548 |
aman |
539 |
if (confirm("Are you sure you want to add lead!") == true) {
|
|
|
540 |
doPostAjaxRequestWithJsonHandler(context + "/createLead",
|
|
|
541 |
JSON.stringify(leaddetailData), function (response) {
|
|
|
542 |
if (response == 'true') {
|
|
|
543 |
alert("successfully Add");
|
|
|
544 |
$('#newEntryLeadModal').modal('hide');
|
|
|
545 |
$('.modal-backdrop').remove();
|
|
|
546 |
loadLead("main-content");
|
|
|
547 |
} else {
|
|
|
548 |
alert(response);
|
|
|
549 |
}
|
|
|
550 |
});
|
| 32464 |
tejbeer |
551 |
|
| 35548 |
aman |
552 |
return false;
|
|
|
553 |
}
|
|
|
554 |
});
|
| 36642 |
ranu |
555 |
window.leadId = null;
|
| 35548 |
aman |
556 |
var row = null;
|
| 37003 |
ranu |
557 |
// Turn Assign To into a search-select. We attempt initialisation at 3 points to be
|
|
|
558 |
// robust against ordering / DOM-timing issues:
|
|
|
559 |
// 1. Immediately at load time (element is in DOM per lead.vm)
|
|
|
560 |
// 2. On the modal's shown.bs.modal event (post-transition)
|
|
|
561 |
// 3. As a fallback in the click handler with a small delay
|
|
|
562 |
function initAssignToSelect2() {
|
|
|
563 |
if (!$.fn.select2) {
|
|
|
564 |
console.warn('[lead.js] select2 not loaded — falling back to native <select>');
|
|
|
565 |
return;
|
|
|
566 |
}
|
|
|
567 |
var $assign = $('#assignTo');
|
|
|
568 |
if ($assign.length === 0) return;
|
|
|
569 |
if ($assign.hasClass('select2-hidden-accessible')) return; // already applied
|
|
|
570 |
$assign.select2({
|
|
|
571 |
placeholder: 'Assign To',
|
|
|
572 |
allowClear: true,
|
|
|
573 |
width: '100%',
|
|
|
574 |
dropdownParent: $('#editLeadData'),
|
|
|
575 |
// Hide disabled options — VISIT/TELEPHONIC filter uses .prop('disabled', true).
|
|
|
576 |
matcher: function (params, data) {
|
|
|
577 |
if (data.element && $(data.element).prop('disabled')) return null;
|
|
|
578 |
if (!params.term || $.trim(params.term) === '') return data;
|
|
|
579 |
if (data.text && data.text.toLowerCase().indexOf(params.term.toLowerCase()) > -1) return data;
|
|
|
580 |
return null;
|
|
|
581 |
}
|
|
|
582 |
});
|
|
|
583 |
console.log('[lead.js] select2 applied to #assignTo');
|
|
|
584 |
}
|
|
|
585 |
|
|
|
586 |
initAssignToSelect2();
|
|
|
587 |
$(document).on('shown.bs.modal', '#editLeadData', initAssignToSelect2);
|
|
|
588 |
|
| 35548 |
aman |
589 |
$(document).on('click', ".editLead", function () {
|
|
|
590 |
$('#editLeadData').modal('show');
|
| 37003 |
ranu |
591 |
// Belt-and-braces: also try after the modal transition completes.
|
|
|
592 |
setTimeout(initAssignToSelect2, 300);
|
| 32464 |
tejbeer |
593 |
|
| 35548 |
aman |
594 |
$("#remark").val("");
|
| 37003 |
ranu |
595 |
$("#assignTo").val("").trigger('change');
|
| 35548 |
aman |
596 |
$("#editStatus").val("");
|
|
|
597 |
$("#reason").val("");
|
|
|
598 |
$("#editCity").val("");
|
|
|
599 |
$("#editState").val("");
|
| 35769 |
amit |
600 |
$("#editSource").val("");
|
| 35548 |
aman |
601 |
$("#editScheduleTime").hide();
|
| 32464 |
tejbeer |
602 |
|
|
|
603 |
|
| 35548 |
aman |
604 |
localStorage.removeItem("frontph");
|
|
|
605 |
localStorage.removeItem("leftShoth");
|
|
|
606 |
localStorage.removeItem("rightWallh");
|
|
|
607 |
localStorage.removeItem("leftWallh");
|
|
|
608 |
localStorage.removeItem("internalMarketh");
|
| 32464 |
tejbeer |
609 |
|
| 35548 |
aman |
610 |
row = $(this).closest("tr");
|
|
|
611 |
leadId = $(this).data('leadid');
|
| 32464 |
tejbeer |
612 |
|
| 35548 |
aman |
613 |
doAjaxRequestHandler(
|
|
|
614 |
context + "/getLeadDetailByLeadId?leadId=" + leadId,
|
|
|
615 |
"GET",
|
|
|
616 |
function (response) {
|
| 32464 |
tejbeer |
617 |
|
| 35548 |
aman |
618 |
var data = response.response;
|
|
|
619 |
if (!data) return;
|
|
|
620 |
console.log(data);
|
|
|
621 |
$("#editCity").val(data.city);
|
|
|
622 |
$("#editState").val(data.state);
|
|
|
623 |
$("input[name='outletName']").val(data.outletName);
|
|
|
624 |
$("input[name='counterSize']").val(data.counterSize);
|
|
|
625 |
}
|
|
|
626 |
);
|
|
|
627 |
});
|
| 32464 |
tejbeer |
628 |
|
|
|
629 |
|
| 35548 |
aman |
630 |
$(document).on('click', ".lead-edit-request",
|
|
|
631 |
function () {
|
| 32464 |
tejbeer |
632 |
|
| 36761 |
ranu |
633 |
// Gate the assign/status submit on approved geo. Modal stays open so the
|
|
|
634 |
// user can still work the other sub-forms (lead detail, etc.).
|
|
|
635 |
var clickedBtn = $(this);
|
| 36789 |
ranu |
636 |
// notInterested is a close-out — no geo / no beat / no assignee
|
|
|
637 |
// needed. Skip the geo gate and submit straight through with just
|
|
|
638 |
// the activity (status + reason + remark).
|
|
|
639 |
var currentStatus = $('#editStatus').val();
|
|
|
640 |
if (currentStatus === 'notInterested') {
|
|
|
641 |
submitLeadEdit();
|
|
|
642 |
return;
|
|
|
643 |
}
|
| 36792 |
ranu |
644 |
// Non-sales assignees (BGC / other internal hand-offs) don't need
|
|
|
645 |
// geo or a beat-day — the lead just routes to their queue. Skip the
|
|
|
646 |
// geo gate and submit straight through, same as the legacy flow.
|
|
|
647 |
var assigneeId = parseInt($('#assignTo').val(), 10);
|
|
|
648 |
var isSalesAssignee = !isNaN(assigneeId)
|
|
|
649 |
&& typeof salesUserIds !== 'undefined'
|
|
|
650 |
&& salesUserIds.indexOf(assigneeId) !== -1;
|
|
|
651 |
if (!isSalesAssignee) {
|
|
|
652 |
submitLeadEdit();
|
|
|
653 |
return;
|
|
|
654 |
}
|
| 36761 |
ranu |
655 |
if (clickedBtn.data('geoChecking')) return;
|
|
|
656 |
clickedBtn.data('geoChecking', true);
|
|
|
657 |
doAjaxRequestHandler(
|
|
|
658 |
context + "/lead-geo/check/" + leadId,
|
|
|
659 |
"GET",
|
|
|
660 |
function (response) {
|
|
|
661 |
clickedBtn.removeData('geoChecking');
|
|
|
662 |
var hasGeo = response && response.response && response.response.hasApprovedGeo;
|
|
|
663 |
if (!hasGeo) {
|
|
|
664 |
alert('Live geo-location for this lead has not been approved yet. Please approve the geo-location before assigning / updating status.');
|
|
|
665 |
return;
|
|
|
666 |
}
|
|
|
667 |
submitLeadEdit();
|
|
|
668 |
}
|
|
|
669 |
);
|
|
|
670 |
});
|
| 25980 |
tejbeer |
671 |
|
| 36761 |
ranu |
672 |
function submitLeadEdit() {
|
|
|
673 |
|
| 35548 |
aman |
674 |
console.log(row);
|
|
|
675 |
var remark = $('input[name="remark"]').val();
|
|
|
676 |
var assignTo = $("#assignTo").val();
|
|
|
677 |
var editStatus = $("#editStatus").val();
|
|
|
678 |
var city = $('input[name="editCity"]').val();
|
|
|
679 |
var state = $("#editState").val();
|
|
|
680 |
var reason = $("#reason").val();
|
| 25980 |
tejbeer |
681 |
|
| 35769 |
amit |
682 |
var startDate = $("#startDate").val();
|
|
|
683 |
var endDate = $("#endDate").val();
|
| 35548 |
aman |
684 |
var leadStatus = $("#statusFilter").val();
|
|
|
685 |
var color = $("#colorFilter").val();
|
|
|
686 |
var communicationType = $("#communicationType").val();
|
| 29640 |
tejbeer |
687 |
|
| 35548 |
aman |
688 |
var conversionprobability = $("#conversionprobability").val();
|
| 35769 |
amit |
689 |
var editSource = $("#editSource").val();
|
| 29640 |
tejbeer |
690 |
|
| 35548 |
aman |
691 |
console.log(conversionprobability)
|
| 29640 |
tejbeer |
692 |
|
| 31473 |
tejbeer |
693 |
|
| 35769 |
amit |
694 |
console.log(startDate)
|
| 35548 |
aman |
695 |
console.log(leadStatus)
|
| 31370 |
tejbeer |
696 |
|
| 35548 |
aman |
697 |
console.log(color)
|
|
|
698 |
console.log(reason)
|
| 31370 |
tejbeer |
699 |
|
| 35548 |
aman |
700 |
if (remark === "" && assignTo === "" && editStatus === "") {
|
|
|
701 |
alert("All fields is required");
|
|
|
702 |
return;
|
|
|
703 |
}
|
| 31370 |
tejbeer |
704 |
|
| 36789 |
ranu |
705 |
// For notInterested (close-out) the lead doesn't need an assignee
|
|
|
706 |
// — it's just a status + reason + remark write. Only enforce
|
|
|
707 |
// assignTo for the other statuses where scheduling matters.
|
|
|
708 |
if (assignTo === "" && editStatus !== "notInterested") {
|
| 35548 |
aman |
709 |
alert("assignTo is required");
|
|
|
710 |
return;
|
|
|
711 |
}
|
| 31409 |
tejbeer |
712 |
|
| 35548 |
aman |
713 |
if (remark === "") {
|
|
|
714 |
alert("Remark is required");
|
|
|
715 |
return;
|
|
|
716 |
}
|
| 31370 |
tejbeer |
717 |
|
|
|
718 |
|
| 35548 |
aman |
719 |
if (editStatus === "") {
|
|
|
720 |
alert("status is required");
|
|
|
721 |
return;
|
|
|
722 |
}
|
| 31370 |
tejbeer |
723 |
|
| 35548 |
aman |
724 |
if (editStatus === "notInterested") {
|
| 36789 |
ranu |
725 |
if (reason == null || reason === "") {
|
| 35548 |
aman |
726 |
alert("Reason is required");
|
|
|
727 |
return;
|
|
|
728 |
}
|
|
|
729 |
}
|
|
|
730 |
var leadActivityData = {}
|
|
|
731 |
leadActivityData['id'] = leadId;
|
|
|
732 |
leadActivityData['remark'] = remark;
|
|
|
733 |
leadActivityData['assignTo'] = assignTo
|
|
|
734 |
leadActivityData['status'] = editStatus
|
|
|
735 |
leadActivityData['reason'] = reason
|
| 36741 |
ranu |
736 |
leadActivityData['colorCheck'] = (conversionprobability === "true" || conversionprobability === true)
|
| 35548 |
aman |
737 |
if (city && city.trim() !== "") {
|
|
|
738 |
leadActivityData.city = city;
|
|
|
739 |
}
|
| 25980 |
tejbeer |
740 |
|
| 35548 |
aman |
741 |
if (state && state.trim() !== "") {
|
|
|
742 |
leadActivityData.state = state;
|
|
|
743 |
}
|
| 29473 |
manish |
744 |
|
| 35769 |
amit |
745 |
if (editSource && editSource.trim() !== "") {
|
|
|
746 |
leadActivityData.source = editSource;
|
|
|
747 |
}
|
| 29598 |
tejbeer |
748 |
|
| 35769 |
amit |
749 |
|
| 35548 |
aman |
750 |
if (editStatus == "followUp") {
|
| 36642 |
ranu |
751 |
leadActivityData['communicationType'] = communicationType
|
| 36792 |
ranu |
752 |
var assigneeIdForBeat = parseInt(assignTo, 10);
|
|
|
753 |
var isSalesAssigneeForBeat = !isNaN(assigneeIdForBeat)
|
|
|
754 |
&& typeof salesUserIds !== 'undefined'
|
|
|
755 |
&& salesUserIds.indexOf(assigneeIdForBeat) !== -1;
|
| 36741 |
ranu |
756 |
var beatVal = $('#beatDate').val();
|
| 36792 |
ranu |
757 |
// Beat-day gate only applies to sales assignees. Non-sales
|
|
|
758 |
// (BGC / other) hand-offs are just routed to the user's queue
|
|
|
759 |
// without a beat attachment — same as the legacy flow.
|
|
|
760 |
if (isSalesAssigneeForBeat) {
|
|
|
761 |
if (!beatVal) {
|
|
|
762 |
var hasBadges = $('#beatBadges .beat-badge').length > 0;
|
|
|
763 |
if (!hasBadges) {
|
|
|
764 |
alert('No upcoming beat is available for this assignee. Cannot schedule the lead until they have a beat.');
|
|
|
765 |
} else {
|
|
|
766 |
alert('Please select a beat date for the assignee before submitting.');
|
|
|
767 |
}
|
|
|
768 |
return;
|
| 36761 |
ranu |
769 |
}
|
| 36792 |
ranu |
770 |
var beatDate = beatVal.split('|')[0];
|
|
|
771 |
leadActivityData['scheldule'] = beatDate + 'T12:00:00';
|
|
|
772 |
leadActivityData['beatSelection'] = beatVal;
|
| 37064 |
ranu |
773 |
} else {
|
|
|
774 |
// Non-sales assignee: no beat-day panel. Fall back to the manual
|
|
|
775 |
// #editScheduleTime picker so the user's chosen date/time is still
|
|
|
776 |
// persisted on lead_activity.schedule_timestamp.
|
|
|
777 |
try {
|
|
|
778 |
var picker = $('#editScheduleTime').data('daterangepicker');
|
|
|
779 |
if (picker && picker.startDate) {
|
|
|
780 |
leadActivityData['scheldule'] = picker.startDate.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
|
|
|
781 |
}
|
|
|
782 |
} catch (e) {
|
|
|
783 |
// no picker attached / no date — leave scheldule unset
|
|
|
784 |
}
|
| 36642 |
ranu |
785 |
}
|
| 35548 |
aman |
786 |
}
|
| 29598 |
tejbeer |
787 |
|
| 35548 |
aman |
788 |
console.log(leadActivityData);
|
|
|
789 |
if (confirm("Are you sure you want to add lead!") == true) {
|
|
|
790 |
doPostAjaxRequestWithJsonHandler(context + "/editLead", JSON.stringify(leadActivityData), function (response) {
|
|
|
791 |
console.log(response);
|
|
|
792 |
$('#editLeadData').modal('hide');
|
|
|
793 |
$('.modal-backdrop').remove();
|
| 37050 |
ranu |
794 |
// Inline row replace only works when the row's column layout matches the
|
|
|
795 |
// main #lead-table (that's what edit-lead.vm renders for). The upper
|
|
|
796 |
// search-results table has fewer columns, so let the search re-run
|
|
|
797 |
// repaint it cleanly instead.
|
|
|
798 |
if (row && !row.closest('#global-search-results').length) {
|
|
|
799 |
row.html(response);
|
|
|
800 |
}
|
|
|
801 |
var activeTerm = $.trim($('#lead-table_filter input').val() || $('#lead-table-bottom-filter').val() || "");
|
|
|
802 |
if (activeTerm.length >= 2 && $('#global-search-results').children().length) {
|
|
|
803 |
runGlobalLeadSearch(activeTerm);
|
|
|
804 |
}
|
| 35548 |
aman |
805 |
});
|
|
|
806 |
}
|
| 29598 |
tejbeer |
807 |
|
| 36761 |
ranu |
808 |
}
|
| 32477 |
tejbeer |
809 |
|
|
|
810 |
|
| 35548 |
aman |
811 |
$(document).on('click', ".show-partner-health",
|
|
|
812 |
function () {
|
| 29598 |
tejbeer |
813 |
|
| 35548 |
aman |
814 |
var email = $("#authUserFilter").val();
|
| 25980 |
tejbeer |
815 |
|
| 35548 |
aman |
816 |
console.log(email)
|
|
|
817 |
doGetAjaxRequestHandler(context + "/partnerHealth?email="
|
|
|
818 |
+ email, function (response) {
|
|
|
819 |
console.log(response)
|
|
|
820 |
$('#' + 'main-content').html(response);
|
| 25980 |
tejbeer |
821 |
|
| 35548 |
aman |
822 |
});
|
|
|
823 |
});
|
| 25980 |
tejbeer |
824 |
|
|
|
825 |
|
| 35548 |
aman |
826 |
$(document).on('click', ".lead-detail-entry",
|
|
|
827 |
function () {
|
| 28200 |
tejbeer |
828 |
|
| 35548 |
aman |
829 |
console.log("hello");
|
|
|
830 |
var outletName = $('input[name="outletName"]').val();
|
|
|
831 |
var counterSize = $('input[name="counterSize"]').val();
|
|
|
832 |
var table = document.getElementById('editbrandtable');
|
|
|
833 |
var brandValueJson = [];
|
|
|
834 |
var leadBrands;
|
| 25980 |
tejbeer |
835 |
|
| 35548 |
aman |
836 |
if (outletName === "") {
|
|
|
837 |
alert("Outlet Name is required");
|
|
|
838 |
return;
|
|
|
839 |
}
|
| 29598 |
tejbeer |
840 |
|
| 35548 |
aman |
841 |
if (counterSize === "") {
|
|
|
842 |
alert("Counter Size is required");
|
|
|
843 |
return;
|
|
|
844 |
}
|
| 32471 |
tejbeer |
845 |
|
| 35548 |
aman |
846 |
if (localStorage.getItem("frontph") == "undefined" && localStorage.getItem("frontph") == null) {
|
|
|
847 |
alert("Front Document is required");
|
|
|
848 |
return;
|
|
|
849 |
}
|
| 31249 |
tejbeer |
850 |
|
| 35548 |
aman |
851 |
if (localStorage.getItem("internalMarketh") == "undefined" || localStorage.getItem("internalMarketh") == null) {
|
|
|
852 |
alert("Front With Market Document is required");
|
|
|
853 |
return;
|
|
|
854 |
}
|
| 25980 |
tejbeer |
855 |
|
| 35548 |
aman |
856 |
if (localStorage.getItem("leftShoth") == "undefined" || localStorage.getItem("leftShoth") == null) {
|
|
|
857 |
alert("Internal Left Shot Document is required");
|
|
|
858 |
return;
|
|
|
859 |
}
|
| 27605 |
tejbeer |
860 |
|
| 35548 |
aman |
861 |
if (localStorage.getItem("leftWallh") == "undefined" || localStorage.getItem("leftWallh") == null) {
|
|
|
862 |
alert("Internal Left Wall Document is required");
|
|
|
863 |
return;
|
|
|
864 |
}
|
| 27605 |
tejbeer |
865 |
|
| 30185 |
tejbeer |
866 |
|
| 35548 |
aman |
867 |
if (localStorage.getItem("rightWallh") == "undefined" || localStorage.getItem("rightWallh") == null) {
|
|
|
868 |
alert("Internal Right Wall Document is required");
|
|
|
869 |
return;
|
|
|
870 |
}
|
| 30185 |
tejbeer |
871 |
|
|
|
872 |
|
| 35548 |
aman |
873 |
for (i = 1; i < table.rows.length; i++) {
|
| 30185 |
tejbeer |
874 |
|
| 35548 |
aman |
875 |
var objCells = table.rows[i].cells;
|
| 30185 |
tejbeer |
876 |
|
| 35548 |
aman |
877 |
leadBrands = {
|
|
|
878 |
brand: objCells[0].innerText,
|
|
|
879 |
value: objCells[1].getElementsByTagName('input')[0].value
|
|
|
880 |
}
|
|
|
881 |
brandValueJson.push(leadBrands);
|
|
|
882 |
}
|
| 30185 |
tejbeer |
883 |
|
| 30416 |
tejbeer |
884 |
|
| 35548 |
aman |
885 |
var leadDetailObject = {};
|
| 31402 |
tejbeer |
886 |
|
| 35548 |
aman |
887 |
leadDetailObject['leadId'] = leadId;
|
| 30416 |
tejbeer |
888 |
|
|
|
889 |
|
| 35548 |
aman |
890 |
leadDetailObject['outletName'] = outletName;
|
| 31370 |
tejbeer |
891 |
|
| 35548 |
aman |
892 |
leadDetailObject['counterSize'] = counterSize;
|
| 31370 |
tejbeer |
893 |
|
| 35548 |
aman |
894 |
leadDetailObject['leadBrands'] = brandValueJson;
|
| 31370 |
tejbeer |
895 |
|
| 31402 |
tejbeer |
896 |
|
| 35548 |
aman |
897 |
console.log(localStorage.getItem("frontp"));
|
| 31402 |
tejbeer |
898 |
|
|
|
899 |
|
| 35548 |
aman |
900 |
leadDetailObject['frontp'] = localStorage
|
|
|
901 |
.getItem("frontph");
|
| 31402 |
tejbeer |
902 |
|
|
|
903 |
|
| 35548 |
aman |
904 |
leadDetailObject['frontWithMarket'] = localStorage
|
|
|
905 |
.getItem("internalMarketh");
|
| 31370 |
tejbeer |
906 |
|
|
|
907 |
|
| 35548 |
aman |
908 |
leadDetailObject['internalLongShot'] = localStorage
|
|
|
909 |
.getItem("leftShoth");
|
| 31370 |
tejbeer |
910 |
|
|
|
911 |
|
| 35548 |
aman |
912 |
leadDetailObject['internalLeftWall'] = localStorage
|
|
|
913 |
.getItem("leftWallh");
|
| 31370 |
tejbeer |
914 |
|
|
|
915 |
|
| 35548 |
aman |
916 |
leadDetailObject['internalRightWall'] = localStorage
|
|
|
917 |
.getItem("rightWallh");
|
| 31370 |
tejbeer |
918 |
|
| 35548 |
aman |
919 |
console.log(leadDetailObject);
|
| 31370 |
tejbeer |
920 |
|
| 35548 |
aman |
921 |
if (confirm("Are you sure you want to add lead detail!") == true) {
|
|
|
922 |
doPostAjaxRequestWithJsonHandler(context + "/leadDetail", JSON.stringify(leadDetailObject), function (response) {
|
|
|
923 |
console.log(response);
|
|
|
924 |
if (response == 'true') {
|
|
|
925 |
alert("Submit Successfully");
|
|
|
926 |
}
|
| 31370 |
tejbeer |
927 |
|
| 35548 |
aman |
928 |
});
|
|
|
929 |
}
|
| 31370 |
tejbeer |
930 |
|
| 35548 |
aman |
931 |
});
|
| 31370 |
tejbeer |
932 |
|
|
|
933 |
|
| 35548 |
aman |
934 |
$(document).on('change', '.frontp',
|
|
|
935 |
function () {
|
| 31370 |
tejbeer |
936 |
|
| 35548 |
aman |
937 |
if (confirm('Document has been selected, Do you want to upload ?')) {
|
| 31370 |
tejbeer |
938 |
|
| 35548 |
aman |
939 |
var documentId = uploadImage(this, "frontph");
|
| 31370 |
tejbeer |
940 |
|
|
|
941 |
|
| 35548 |
aman |
942 |
} else {
|
| 31370 |
tejbeer |
943 |
|
| 35548 |
aman |
944 |
}
|
|
|
945 |
});
|
| 31456 |
tejbeer |
946 |
|
| 35548 |
aman |
947 |
$(document).on('change', '.internalMarket',
|
|
|
948 |
function () {
|
| 31456 |
tejbeer |
949 |
|
| 35548 |
aman |
950 |
if (confirm('Document has been selected, Do you want to upload ?')) {
|
| 31456 |
tejbeer |
951 |
|
| 35548 |
aman |
952 |
var documentId = uploadImage(this, "internalMarketh");
|
| 31456 |
tejbeer |
953 |
|
| 35548 |
aman |
954 |
} else {
|
| 31456 |
tejbeer |
955 |
|
| 35548 |
aman |
956 |
}
|
|
|
957 |
});
|
| 31370 |
tejbeer |
958 |
|
| 35548 |
aman |
959 |
$(document).on('change', '.leftShot',
|
| 31370 |
tejbeer |
960 |
|
| 35548 |
aman |
961 |
function () {
|
|
|
962 |
if (confirm('Document has been selected, Do you want to upload ?')) {
|
|
|
963 |
var documentId = uploadImage(this, "leftShoth");
|
|
|
964 |
} else {
|
| 31370 |
tejbeer |
965 |
|
| 35548 |
aman |
966 |
}
|
|
|
967 |
});
|
| 31370 |
tejbeer |
968 |
|
| 35548 |
aman |
969 |
$(document).on('change', '.leftWall',
|
|
|
970 |
function () {
|
|
|
971 |
if (confirm('Document has been selected, Do you want to upload ?')) {
|
|
|
972 |
var documentId = uploadImage(this, "leftWallh");
|
|
|
973 |
} else {
|
| 31370 |
tejbeer |
974 |
|
| 35548 |
aman |
975 |
}
|
|
|
976 |
});
|
| 31370 |
tejbeer |
977 |
|
| 35548 |
aman |
978 |
$(document).on('change', '.rightWall',
|
|
|
979 |
function () {
|
|
|
980 |
if (confirm('Document has been selected, Do you want to upload ?')) {
|
|
|
981 |
var documentId = uploadImage(this, "rightWallh");
|
|
|
982 |
} else {
|
|
|
983 |
}
|
|
|
984 |
});
|
| 31370 |
tejbeer |
985 |
|
|
|
986 |
|
| 25980 |
tejbeer |
987 |
});
|
|
|
988 |
|
| 31404 |
tejbeer |
989 |
function uploadImage(fileSelector, attrName) {
|
| 35548 |
aman |
990 |
var documentId;
|
|
|
991 |
if (fileSelector != undefined
|
|
|
992 |
&& fileSelector.files[0] != undefined) {
|
|
|
993 |
var url = context
|
|
|
994 |
+ '/document-upload';
|
| 31370 |
tejbeer |
995 |
|
| 35548 |
aman |
996 |
console.log(url);
|
|
|
997 |
var file = fileSelector.files[0];
|
| 31370 |
tejbeer |
998 |
|
| 35548 |
aman |
999 |
console.log(file)
|
|
|
1000 |
doAjaxUploadRequestHandler(
|
|
|
1001 |
url,
|
|
|
1002 |
'POST',
|
|
|
1003 |
file,
|
|
|
1004 |
function (response) {
|
|
|
1005 |
console.log(response)
|
|
|
1006 |
documentId = response.response.document_id;
|
|
|
1007 |
console
|
|
|
1008 |
.log("documentId : "
|
|
|
1009 |
+ documentId);
|
| 31370 |
tejbeer |
1010 |
|
|
|
1011 |
|
| 35548 |
aman |
1012 |
localStorage
|
|
|
1013 |
.setItem(
|
|
|
1014 |
attrName,
|
|
|
1015 |
documentId);
|
| 31402 |
tejbeer |
1016 |
|
| 35548 |
aman |
1017 |
});
|
|
|
1018 |
return documentId;
|
|
|
1019 |
}
|
| 31370 |
tejbeer |
1020 |
|
|
|
1021 |
}
|
|
|
1022 |
|
|
|
1023 |
|
| 25980 |
tejbeer |
1024 |
function loadLead(domId) {
|
| 35548 |
aman |
1025 |
doGetAjaxRequestHandler(context + "/getOpenLead", function (response) {
|
|
|
1026 |
$('#' + domId).html(response);
|
|
|
1027 |
});
|
| 25980 |
tejbeer |
1028 |
}
|
|
|
1029 |
|
| 25988 |
tejbeer |
1030 |
function loadClosedLead(domId, searchTerm) {
|
| 35548 |
aman |
1031 |
doGetAjaxRequestHandler(context + "/getClosedLead", function (response) {
|
|
|
1032 |
$('#' + domId).html(response);
|
|
|
1033 |
})
|
| 25988 |
tejbeer |
1034 |
}
|
|
|
1035 |
|
| 25980 |
tejbeer |
1036 |
function statusAction() {
|
| 35548 |
aman |
1037 |
var val = $('#status').val();
|
|
|
1038 |
if (val == "followUp") {
|
|
|
1039 |
$("#scheduleTime").show();
|
|
|
1040 |
} else {
|
|
|
1041 |
$("#scheduleTime").hide();
|
|
|
1042 |
}
|
| 25980 |
tejbeer |
1043 |
|
|
|
1044 |
}
|
| 27605 |
tejbeer |
1045 |
|
|
|
1046 |
|
|
|
1047 |
function editStatusAction() {
|
| 35548 |
aman |
1048 |
var val = $('#editStatus').val();
|
|
|
1049 |
if (val == "followUp") {
|
| 36642 |
ranu |
1050 |
// Show communication type and schedule date
|
|
|
1051 |
$("#communicationTypeSection").show();
|
| 35548 |
aman |
1052 |
$("#editScheduleTime").show();
|
| 36642 |
ranu |
1053 |
$("#beatDateSelection").hide();
|
|
|
1054 |
|
| 36761 |
ranu |
1055 |
// Reset communication type only; preserve the assignee the user picked.
|
| 36642 |
ranu |
1056 |
$('#communicationType').val('');
|
| 37003 |
ranu |
1057 |
$('#assignTo option').prop('disabled', false);
|
| 36642 |
ranu |
1058 |
|
|
|
1059 |
// Check if lead has approved geolocation to decide VISIT option
|
|
|
1060 |
doAjaxRequestHandler(context + "/lead-geo/check/" + leadId, "GET", function (response) {
|
|
|
1061 |
var hasGeo = response.response.hasApprovedGeo;
|
|
|
1062 |
var commDropdown = $('#communicationType');
|
|
|
1063 |
commDropdown.empty();
|
|
|
1064 |
commDropdown.append('<option value="" disabled selected>Communication Type</option>');
|
|
|
1065 |
commDropdown.append('<option value="TELEPHONIC">TELEPHONIC</option>');
|
|
|
1066 |
if (hasGeo) {
|
|
|
1067 |
commDropdown.append('<option value="VISIT">VISIT</option>');
|
|
|
1068 |
}
|
|
|
1069 |
});
|
| 35548 |
aman |
1070 |
} else {
|
| 36642 |
ranu |
1071 |
$("#communicationTypeSection").hide();
|
| 35548 |
aman |
1072 |
$("#editScheduleTime").hide();
|
| 36642 |
ranu |
1073 |
$("#beatDateSelection").hide();
|
| 37003 |
ranu |
1074 |
$('#assignTo option').prop('disabled', false);
|
| 35548 |
aman |
1075 |
}
|
| 27605 |
tejbeer |
1076 |
|
|
|
1077 |
}
|
|
|
1078 |
|
| 25988 |
tejbeer |
1079 |
function loadLeadSearchInfo(search_text) {
|
| 35548 |
aman |
1080 |
loadSearchLead("main-content", search_text);
|
| 25988 |
tejbeer |
1081 |
}
|
|
|
1082 |
|
| 30185 |
tejbeer |
1083 |
function loadTeamCommitment(domId) {
|
| 35548 |
aman |
1084 |
doGetAjaxRequestHandler(context + "/teamCommitment",
|
|
|
1085 |
function (response) {
|
|
|
1086 |
$('#' + domId).html(response);
|
|
|
1087 |
});
|
| 30185 |
tejbeer |
1088 |
}
|
|
|
1089 |
|
| 31370 |
tejbeer |
1090 |
function loadLeadDetail(domId) {
|
| 35548 |
aman |
1091 |
doGetAjaxRequestHandler(context + "/getLeadDetail",
|
|
|
1092 |
function (response) {
|
|
|
1093 |
$('#' + domId).html(response);
|
|
|
1094 |
});
|
| 31370 |
tejbeer |
1095 |
}
|
|
|
1096 |
|
| 30416 |
tejbeer |
1097 |
function loadPartnerHealth(domId) {
|
| 35548 |
aman |
1098 |
doGetAjaxRequestHandler(context + "/partnerHealth",
|
|
|
1099 |
function (response) {
|
|
|
1100 |
$('#' + domId).html(response);
|
|
|
1101 |
});
|
| 30416 |
tejbeer |
1102 |
}
|
|
|
1103 |
|
| 25988 |
tejbeer |
1104 |
function loadSearchLead(domId, search_text) {
|
| 35548 |
aman |
1105 |
doGetAjaxRequestHandler(context + "/searchLeads?searchTerm=" + search_text,
|
|
|
1106 |
function (response) {
|
|
|
1107 |
$('#' + domId).html(response);
|
|
|
1108 |
});
|
| 25988 |
tejbeer |
1109 |
}
|
| 33917 |
ranu |
1110 |
|
|
|
1111 |
$(document).on('click', ".arr-button-mk",
|
| 35548 |
aman |
1112 |
function () {
|
|
|
1113 |
var startDate = $('.arr-start_date').val();
|
|
|
1114 |
doGetAjaxRequestHandler(context + "/rbmTodayArr?startDate=" + startDate, function (response) {
|
|
|
1115 |
$('#main-content').html(response);
|
| 33917 |
ranu |
1116 |
|
| 35548 |
aman |
1117 |
});
|
|
|
1118 |
});
|
| 33917 |
ranu |
1119 |
|
|
|
1120 |
$(document).on('click', ".rbm-today-arr",
|
| 35548 |
aman |
1121 |
function () {
|
|
|
1122 |
doGetAjaxRequestHandler(context + "/rbmTodayArr", function (response) {
|
|
|
1123 |
$('#main-content').html(response);
|
| 33917 |
ranu |
1124 |
|
| 35548 |
aman |
1125 |
});
|
|
|
1126 |
});
|
|
|
1127 |
$(document).on('click', '.reassign', function () {
|
|
|
1128 |
$('#bulkReassignFile').val(null);
|
|
|
1129 |
$('#bulkReassignFile').click();
|
|
|
1130 |
});
|
|
|
1131 |
|
|
|
1132 |
$(document).on('change', '#bulkReassignFile', function () {
|
|
|
1133 |
|
|
|
1134 |
if (!confirm("Confirm bulk reassign upload?")) {
|
|
|
1135 |
return;
|
|
|
1136 |
}
|
|
|
1137 |
|
|
|
1138 |
var file = this.files[0];
|
|
|
1139 |
if (!file) {
|
|
|
1140 |
alert("No file selected");
|
|
|
1141 |
return;
|
|
|
1142 |
}
|
|
|
1143 |
|
|
|
1144 |
doAjaxUploadRequestHandler(
|
|
|
1145 |
context + "/upload-assign-id",
|
|
|
1146 |
'POST',
|
|
|
1147 |
file,
|
|
|
1148 |
function (response) {
|
|
|
1149 |
alert("Bulk reassignment completed");
|
|
|
1150 |
loadLead("main-content");
|
|
|
1151 |
}
|
|
|
1152 |
);
|
|
|
1153 |
});
|
|
|
1154 |
|
| 36642 |
ranu |
1155 |
// ==================== GEO LOCATION HANDLERS ====================
|
|
|
1156 |
|
|
|
1157 |
// Communication type change: filter assignTo based on type
|
|
|
1158 |
$(document).on('change', '#communicationType', function () {
|
|
|
1159 |
var val = $(this).val();
|
|
|
1160 |
var assignDropdown = $('#assignTo');
|
|
|
1161 |
|
| 36741 |
ranu |
1162 |
// Reset beat + restore manual date input
|
| 36642 |
ranu |
1163 |
$('#beatDate').val('');
|
|
|
1164 |
$('#beatBadges').empty();
|
|
|
1165 |
$("#beatDateSelection").hide();
|
| 36741 |
ranu |
1166 |
$("#editScheduleTime").show();
|
| 36642 |
ranu |
1167 |
|
|
|
1168 |
if (val == 'VISIT') {
|
| 37003 |
ranu |
1169 |
// Filter assignTo to sales users only (no BGC). Uses .prop('disabled', ...)
|
|
|
1170 |
// instead of .hide()/.show() because select2 doesn't respect hidden <option>s
|
|
|
1171 |
// in its dropdown UI. Disabled options are filtered out by our matcher above.
|
| 36642 |
ranu |
1172 |
if (typeof salesUserIds !== 'undefined') {
|
|
|
1173 |
assignDropdown.find('option').each(function () {
|
|
|
1174 |
var optVal = parseInt($(this).val());
|
|
|
1175 |
if (optVal && salesUserIds.indexOf(optVal) === -1) {
|
| 37003 |
ranu |
1176 |
$(this).prop('disabled', true);
|
| 36642 |
ranu |
1177 |
} else {
|
| 37003 |
ranu |
1178 |
$(this).prop('disabled', false);
|
| 36642 |
ranu |
1179 |
}
|
|
|
1180 |
});
|
|
|
1181 |
}
|
|
|
1182 |
} else {
|
| 37003 |
ranu |
1183 |
// TELEPHONIC — enable all users
|
|
|
1184 |
assignDropdown.find('option').prop('disabled', false);
|
| 36642 |
ranu |
1185 |
}
|
| 37003 |
ranu |
1186 |
// Nudge select2 to re-render its dropdown with the new enabled/disabled state.
|
|
|
1187 |
if ($.fn.select2 && assignDropdown.hasClass('select2-hidden-accessible')) {
|
|
|
1188 |
assignDropdown.trigger('change.select2');
|
|
|
1189 |
}
|
| 36741 |
ranu |
1190 |
// Both VISIT and TELEPHONIC offer beat-day slots when an assignee is set
|
|
|
1191 |
// (TELEPHONIC just uses the beat date as the call slot; backend won't
|
|
|
1192 |
// attach a LeadRoute for it). Non-sales assignees simply get an empty list.
|
|
|
1193 |
if (val && assignDropdown.val()) {
|
|
|
1194 |
fetchBeatDates();
|
|
|
1195 |
}
|
| 36642 |
ranu |
1196 |
});
|
|
|
1197 |
|
| 36741 |
ranu |
1198 |
// Fetch beats when assignTo changes (works for both VISIT and TELEPHONIC)
|
|
|
1199 |
$(document).on('change', '#assignTo', function () {
|
| 36642 |
ranu |
1200 |
var commType = $('#communicationType').val();
|
|
|
1201 |
var salesAuthId = $('#assignTo').val();
|
| 36741 |
ranu |
1202 |
if (commType && salesAuthId && leadId) {
|
| 36642 |
ranu |
1203 |
fetchBeatDates();
|
| 36741 |
ranu |
1204 |
} else if (!commType) {
|
| 36642 |
ranu |
1205 |
$("#beatDateSelection").hide();
|
|
|
1206 |
}
|
|
|
1207 |
});
|
|
|
1208 |
|
|
|
1209 |
function fetchBeatDates() {
|
|
|
1210 |
var salesAuthId = $('#assignTo').val();
|
|
|
1211 |
if (!salesAuthId || !leadId) return;
|
|
|
1212 |
|
| 36792 |
ranu |
1213 |
// Beat slots only make sense for sales assignees. BGC / other internal
|
|
|
1214 |
// hand-offs skip the entire beat panel (and the visit-request CTA that
|
|
|
1215 |
// sits inside it). Mirrors the server-side carve-out in /editLead.
|
|
|
1216 |
var assigneeIntId = parseInt(salesAuthId, 10);
|
|
|
1217 |
var isSalesAssigneeFetch = !isNaN(assigneeIntId)
|
|
|
1218 |
&& typeof salesUserIds !== 'undefined'
|
|
|
1219 |
&& salesUserIds.indexOf(assigneeIntId) !== -1;
|
|
|
1220 |
if (!isSalesAssigneeFetch) {
|
|
|
1221 |
$('#beatBadges').empty();
|
|
|
1222 |
$('#beatDate').val('');
|
|
|
1223 |
$('#beatDateSelection').hide();
|
|
|
1224 |
return;
|
|
|
1225 |
}
|
|
|
1226 |
|
| 36642 |
ranu |
1227 |
var badgesDiv = $('#beatBadges');
|
|
|
1228 |
badgesDiv.html('<span style="color:#999; font-size:12px;">Loading beats...</span>');
|
|
|
1229 |
$("#beatDateSelection").show();
|
|
|
1230 |
$('#beatDate').val('');
|
|
|
1231 |
|
|
|
1232 |
var url = context + "/lead-geo/beat-dates?leadId=" + leadId + "&salesAuthId=" + salesAuthId;
|
|
|
1233 |
|
|
|
1234 |
$.ajax({
|
|
|
1235 |
url: url,
|
|
|
1236 |
method: 'GET',
|
|
|
1237 |
success: function (response) {
|
|
|
1238 |
var data = response.response || response;
|
|
|
1239 |
badgesDiv.empty();
|
| 36644 |
ranu |
1240 |
|
| 36741 |
ranu |
1241 |
// Stores within radius of the lead — show count + top 3 inline.
|
|
|
1242 |
var radius = (data && data.radiusKm) ? data.radiusKm : 30;
|
|
|
1243 |
var stores = (data && data.nearestStores) || [];
|
|
|
1244 |
if (stores.length > 0) {
|
|
|
1245 |
var preview = stores.slice(0, 3).map(function (s) {
|
|
|
1246 |
return '<strong>' + s.code + ' - ' + s.name + '</strong> (' + s.distanceKm + ' km)';
|
|
|
1247 |
}).join(', ');
|
|
|
1248 |
var more = stores.length > 3 ? ' +' + (stores.length - 3) + ' more' : '';
|
| 36644 |
ranu |
1249 |
badgesDiv.append('<div style="font-size:12px; color:#333; margin-bottom:6px;">' +
|
| 36741 |
ranu |
1250 |
stores.length + ' partner store(s) within ' + radius + ' km of this lead: ' +
|
|
|
1251 |
preview + more + '</div>');
|
| 36644 |
ranu |
1252 |
}
|
|
|
1253 |
|
| 36741 |
ranu |
1254 |
// All upcoming beat-dates for the assignee that touch any nearby store.
|
| 36642 |
ranu |
1255 |
if (data && data.beats && data.beats.length > 0) {
|
| 36644 |
ranu |
1256 |
badgesDiv.append('<div style="font-weight:bold; font-size:11px; color:#666; margin-bottom:4px;">Available Slots (near this lead):</div>');
|
| 36741 |
ranu |
1257 |
var beats = data.beats;
|
| 36642 |
ranu |
1258 |
for (var i = 0; i < beats.length; i++) {
|
|
|
1259 |
var beat = beats[i];
|
| 36644 |
ranu |
1260 |
var nearTxt = beat.nearStore ? ' · near ' + beat.nearStore : '';
|
| 36642 |
ranu |
1261 |
var badge = $('<span class="beat-badge" style="' +
|
|
|
1262 |
'display:inline-block; background:#337ab7; color:#fff; padding:6px 12px; ' +
|
|
|
1263 |
'margin:4px 6px 4px 0; border-radius:16px; cursor:pointer; font-size:12px; ' +
|
|
|
1264 |
'border:2px solid #337ab7; transition:all 0.2s;">' +
|
| 36644 |
ranu |
1265 |
beat.planDate + ' · ' + beat.beatName + ' (' + beat.stops + ' stops)' + nearTxt +
|
| 36642 |
ranu |
1266 |
'</span>');
|
|
|
1267 |
badge.data('value', beat.planDate + '|' + beat.beatName + '|' + beat.planGroupId);
|
|
|
1268 |
badgesDiv.append(badge);
|
|
|
1269 |
}
|
|
|
1270 |
} else {
|
| 36787 |
ranu |
1271 |
// No beat-days available for this assignee. Surface a CTA so the
|
|
|
1272 |
// user can fire a visit request to the assignee's hierarchy instead
|
|
|
1273 |
// of being stuck. The pre-existing 'beats > 0' branch above is
|
|
|
1274 |
// untouched — this only fires for the empty-beats case.
|
|
|
1275 |
var nearestId = (stores.length > 0 && stores[0].storeId) ? stores[0].storeId : '';
|
|
|
1276 |
badgesDiv.append(
|
|
|
1277 |
'<div style="background:#fff8e1; border:1px solid #f0e0a0; border-radius:6px; padding:8px 10px; margin-top:4px;">'
|
|
|
1278 |
+ '<div style="font-size:12px; color:#7c5a00; margin-bottom:6px;">'
|
|
|
1279 |
+ 'No upcoming beat is available for this assignee.'
|
|
|
1280 |
+ '</div>'
|
|
|
1281 |
+ '<div style="display:flex; gap:8px; align-items:center;">'
|
|
|
1282 |
+ '<label style="font-size:11px; color:#666; margin:0;">Preferred date (optional):</label>'
|
|
|
1283 |
+ '<input type="date" id="vrPreferredDate" class="input-sm" style="font-size:12px; padding:3px 6px;">'
|
|
|
1284 |
+ '<button type="button" id="vrSendBtn" class="btn btn-warning btn-sm" '
|
|
|
1285 |
+ 'data-nearest="' + nearestId + '" style="font-size:12px;">Send Visit Request</button>'
|
|
|
1286 |
+ '</div>'
|
|
|
1287 |
+ '<div style="font-size:11px; color:#888; margin-top:6px;">'
|
|
|
1288 |
+ 'The request goes to the assignee\'s reporting head (and up). Once they approve and pick a beat-day, the lead lands on that beat.'
|
|
|
1289 |
+ '</div>'
|
|
|
1290 |
+ '</div>');
|
| 36642 |
ranu |
1291 |
}
|
|
|
1292 |
},
|
|
|
1293 |
error: function () {
|
|
|
1294 |
badgesDiv.html('<span style="color:#d9534f; font-size:12px;">Error loading beats</span>');
|
|
|
1295 |
}
|
|
|
1296 |
});
|
|
|
1297 |
}
|
|
|
1298 |
|
| 36787 |
ranu |
1299 |
// Send Visit Request when no beats are available for the chosen assignee.
|
|
|
1300 |
// Posts to /visitRequest/create. Existing beat-pick + Submit flow is unchanged.
|
|
|
1301 |
$(document).on('click', '#vrSendBtn', function () {
|
|
|
1302 |
var $btn = $(this);
|
|
|
1303 |
var assigneeAuthId = parseInt($('#assignTo').val());
|
|
|
1304 |
var commType = $('#communicationType').val() || null;
|
|
|
1305 |
var nearestStoreId = parseInt($btn.data('nearest'));
|
|
|
1306 |
var preferred = $('#vrPreferredDate').val() || null;
|
| 37050 |
ranu |
1307 |
var selectedStatus = $('#editStatus').val() || null;
|
| 36787 |
ranu |
1308 |
if (!leadId || !assigneeAuthId) {
|
|
|
1309 |
alert('Pick an assignee first.');
|
|
|
1310 |
return;
|
|
|
1311 |
}
|
|
|
1312 |
$btn.prop('disabled', true).text('Sending...');
|
|
|
1313 |
var payload = {
|
|
|
1314 |
leadId: leadId,
|
|
|
1315 |
assigneeAuthId: assigneeAuthId,
|
|
|
1316 |
communicationType: commType,
|
|
|
1317 |
reason: 'No upcoming beats for assignee'
|
|
|
1318 |
};
|
|
|
1319 |
if (!isNaN(nearestStoreId) && nearestStoreId > 0) payload.nearestStoreId = nearestStoreId;
|
|
|
1320 |
if (preferred) payload.requestedDate = preferred;
|
| 37050 |
ranu |
1321 |
// Ship the picked status too — server (VisitRequestController.create) reads
|
|
|
1322 |
// it via parseLeadStatus and updates lead.status through reassignLeadAndLog.
|
|
|
1323 |
// Without it, the visit request is raised but the lead status never moves
|
|
|
1324 |
// off its previous value (e.g. stays notInterested while user picked followUp).
|
|
|
1325 |
if (selectedStatus) payload.status = selectedStatus;
|
| 36787 |
ranu |
1326 |
|
|
|
1327 |
doPostAjaxRequestWithJsonHandler(context + '/visitRequest/create', JSON.stringify(payload),
|
|
|
1328 |
function (response) {
|
|
|
1329 |
$btn.prop('disabled', false).text('Send Visit Request');
|
|
|
1330 |
var data = (response && response.response) || response || {};
|
|
|
1331 |
if (data && data.id) {
|
|
|
1332 |
alert('Visit request sent. The assignee\'s manager has been notified.');
|
|
|
1333 |
$('#editLeadData').modal('hide');
|
|
|
1334 |
$('.modal-backdrop').remove();
|
| 37050 |
ranu |
1335 |
// Repaint the affected rows so the new status is visible without
|
|
|
1336 |
// a manual refresh. If a global search is active, re-run it (this
|
|
|
1337 |
// also refreshes the injected rows in #lead-table).
|
|
|
1338 |
var activeTerm = $.trim($('#lead-table_filter input').val() || $('#lead-table-bottom-filter').val() || "");
|
|
|
1339 |
if (activeTerm.length >= 2 && $('#global-search-results').children().length && typeof window.runGlobalLeadSearch === 'function') {
|
|
|
1340 |
window.runGlobalLeadSearch(activeTerm);
|
|
|
1341 |
}
|
| 36787 |
ranu |
1342 |
} else {
|
|
|
1343 |
var msg = (data && data.message) || (data && data.error) || 'Could not send request.';
|
|
|
1344 |
alert(msg);
|
|
|
1345 |
}
|
|
|
1346 |
});
|
|
|
1347 |
});
|
|
|
1348 |
|
| 36741 |
ranu |
1349 |
// Click on beat badge to select it. A picked beat becomes the schedule
|
|
|
1350 |
// source — the manual date input is hidden (not needed when scheduling by beat).
|
| 36642 |
ranu |
1351 |
$(document).on('click', '.beat-badge', function () {
|
|
|
1352 |
$('.beat-badge').css({'background': '#337ab7', 'border-color': '#337ab7'});
|
|
|
1353 |
$(this).css({'background': '#1a5276', 'border-color': '#f39c12', 'border-width': '2px'});
|
|
|
1354 |
$('#beatDate').val($(this).data('value'));
|
| 36741 |
ranu |
1355 |
$("#editScheduleTime").hide();
|
| 36642 |
ranu |
1356 |
});
|
|
|
1357 |
|
|
|
1358 |
// Generate Geo Link for lead
|
|
|
1359 |
$(document).on('click', '.generateGeoLink', function (e) {
|
|
|
1360 |
e.stopPropagation();
|
|
|
1361 |
var lid = $(this).data('leadid');
|
|
|
1362 |
doAjaxRequestHandler(context + "/lead-geo/generate-link?leadId=" + lid, "GET", function (response) {
|
|
|
1363 |
var url = response.response;
|
|
|
1364 |
if (navigator.clipboard) {
|
|
|
1365 |
navigator.clipboard.writeText(url).then(function () {
|
|
|
1366 |
alert("Link copied to clipboard:\n" + url);
|
|
|
1367 |
});
|
|
|
1368 |
} else {
|
|
|
1369 |
prompt("Share this link with the prospect:", url);
|
|
|
1370 |
}
|
|
|
1371 |
});
|
|
|
1372 |
});
|
|
|
1373 |
|
| 36868 |
ranu |
1374 |
// Manual geo verification — for cases where the prospect refused to tap the
|
|
|
1375 |
// verification link. Team-member confirms lat/lng over phone (or pastes a
|
|
|
1376 |
// Maps URL the prospect shared) and writes it APPROVED directly.
|
|
|
1377 |
function ensureManualVerifyModal() {
|
|
|
1378 |
if ($('#manualVerifyGeoModal').length) return;
|
|
|
1379 |
var html =
|
|
|
1380 |
'<div id="manualVerifyGeoModal" class="modal" role="dialog" tabindex="-1">' +
|
|
|
1381 |
' <div class="modal-dialog modal-lg">' +
|
|
|
1382 |
' <div class="modal-content">' +
|
|
|
1383 |
' <div class="modal-header">' +
|
|
|
1384 |
' <button type="button" class="close" data-dismiss="modal">×</button>' +
|
|
|
1385 |
' <h4 class="modal-title">Verify Lead Location Manually</h4>' +
|
|
|
1386 |
' </div>' +
|
|
|
1387 |
' <div class="modal-body" style="max-height:75vh;overflow-y:auto;">' +
|
|
|
1388 |
' <input type="hidden" id="manualVerifyLeadId">' +
|
|
|
1389 |
' <div class="form-group">' +
|
|
|
1390 |
' <label>Address <small class="text-muted">(include city, state, pincode for best result)</small></label>' +
|
|
|
1391 |
' <div class="input-group">' +
|
|
|
1392 |
' <input type="text" class="form-control" id="manualVerifyAddress" placeholder="e.g. Shop 12, Sector 18, Noida, UP, 201301">' +
|
|
|
1393 |
' <span class="input-group-btn">' +
|
|
|
1394 |
' <button type="button" class="btn btn-default" id="manualVerifyGeocodeBtn">Find on map</button>' +
|
|
|
1395 |
' </span>' +
|
|
|
1396 |
' </div>' +
|
|
|
1397 |
' </div>' +
|
|
|
1398 |
' <div class="form-group">' +
|
|
|
1399 |
' <label>Latitude, Longitude</label>' +
|
|
|
1400 |
' <div class="input-group">' +
|
|
|
1401 |
' <input type="text" class="form-control" id="manualVerifyLatLng" placeholder="28.6139,77.2090">' +
|
|
|
1402 |
' <span class="input-group-btn">' +
|
|
|
1403 |
' <button type="button" class="btn btn-default" id="manualVerifyPreviewBtn">Show on map</button>' +
|
|
|
1404 |
' </span>' +
|
|
|
1405 |
' </div>' +
|
|
|
1406 |
' <small class="text-muted">You can also paste a Google Maps URL containing coords.</small>' +
|
|
|
1407 |
' </div>' +
|
|
|
1408 |
' <div class="form-group" id="manualVerifyMapWrap" style="display:none;">' +
|
|
|
1409 |
' <label>Map preview <small class="text-muted">(confirm the pin is right)</small></label>' +
|
|
|
1410 |
' <div style="border:1px solid #ddd;border-radius:3px;overflow:hidden;">' +
|
|
|
1411 |
' <iframe id="manualVerifyMapFrame" width="100%" height="260" frameborder="0" style="border:0;" allowfullscreen></iframe>' +
|
|
|
1412 |
' </div>' +
|
|
|
1413 |
' <small><a href="#" id="manualVerifyOpenMap" target="_blank">Open in Google Maps</a></small>' +
|
|
|
1414 |
' </div>' +
|
|
|
1415 |
' <div class="form-group">' +
|
|
|
1416 |
' <label>Store-board photo <span class="text-danger">*</span> <small class="text-muted">(required — proves the verification)</small></label>' +
|
|
|
1417 |
' <input type="file" id="manualVerifyPhoto" accept="image/jpeg,image/png" required>' +
|
|
|
1418 |
' <div id="manualVerifyPhotoPreview" style="margin-top:6px;display:none;">' +
|
|
|
1419 |
' <img id="manualVerifyPhotoImg" src="" style="max-height:120px;border:1px solid #ddd;border-radius:3px;padding:2px;">' +
|
|
|
1420 |
' </div>' +
|
|
|
1421 |
' </div>' +
|
|
|
1422 |
' <div class="form-group">' +
|
|
|
1423 |
' <label>Remark <small class="text-muted">(optional)</small></label>' +
|
|
|
1424 |
' <input type="text" class="form-control" id="manualVerifyRemark" placeholder="e.g. Confirmed on call with prospect">' +
|
|
|
1425 |
' </div>' +
|
|
|
1426 |
' <div id="manualVerifyErr" class="text-danger" style="display:none;"></div>' +
|
|
|
1427 |
' </div>' +
|
|
|
1428 |
' <div class="modal-footer">' +
|
|
|
1429 |
' <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>' +
|
|
|
1430 |
' <button type="button" class="btn btn-success" id="manualVerifySaveBtn">Save & Verify</button>' +
|
|
|
1431 |
' </div>' +
|
|
|
1432 |
' </div>' +
|
|
|
1433 |
' </div>' +
|
|
|
1434 |
'</div>';
|
|
|
1435 |
$('body').append(html);
|
|
|
1436 |
}
|
|
|
1437 |
|
|
|
1438 |
function manualVerifyShowMap(lat, lng) {
|
|
|
1439 |
var src = 'https://www.google.com/maps?q=' + lat + ',' + lng + '&z=17&output=embed';
|
|
|
1440 |
$('#manualVerifyMapFrame').attr('src', src);
|
|
|
1441 |
$('#manualVerifyOpenMap').attr('href', 'https://www.google.com/maps?q=' + lat + ',' + lng);
|
|
|
1442 |
$('#manualVerifyMapWrap').show();
|
|
|
1443 |
}
|
|
|
1444 |
|
|
|
1445 |
// Parses raw "lat,lng" or a Google Maps URL containing the coords.
|
|
|
1446 |
// Maps formats covered: /@lat,lng, /maps?q=lat,lng, ?ll=lat,lng, ?destination=lat,lng.
|
|
|
1447 |
function parseLatLngInput(raw) {
|
|
|
1448 |
if (!raw) return null;
|
|
|
1449 |
var s = String(raw).trim();
|
|
|
1450 |
// Strip any leading "lat:" / "lng:" tokens
|
|
|
1451 |
var direct = s.match(/(-?\d{1,3}\.\d+)\s*,\s*(-?\d{1,3}\.\d+)/);
|
|
|
1452 |
if (direct) return {lat: parseFloat(direct[1]), lng: parseFloat(direct[2])};
|
|
|
1453 |
return null;
|
|
|
1454 |
}
|
|
|
1455 |
|
|
|
1456 |
$(document).on('click', '.verifyGeoManual', function (e) {
|
|
|
1457 |
e.stopPropagation();
|
|
|
1458 |
var lid = $(this).data('leadid');
|
|
|
1459 |
ensureManualVerifyModal();
|
|
|
1460 |
$('#manualVerifyLeadId').val(lid);
|
|
|
1461 |
$('#manualVerifyAddress').val('');
|
|
|
1462 |
$('#manualVerifyLatLng').val('');
|
|
|
1463 |
$('#manualVerifyRemark').val('');
|
|
|
1464 |
$('#manualVerifyErr').hide().text('');
|
|
|
1465 |
$('#manualVerifyMapWrap').hide();
|
|
|
1466 |
$('#manualVerifyMapFrame').attr('src', '');
|
|
|
1467 |
$('#manualVerifyPhoto').val('');
|
|
|
1468 |
$('#manualVerifyPhotoImg').attr('src', '');
|
|
|
1469 |
$('#manualVerifyPhotoPreview').hide();
|
|
|
1470 |
$('#manualVerifyGeoModal').modal('show');
|
|
|
1471 |
});
|
|
|
1472 |
|
|
|
1473 |
// Local thumbnail preview as soon as the user picks a file (no upload yet —
|
|
|
1474 |
// upload happens on Save so we don't orphan documents on cancel).
|
|
|
1475 |
$(document).on('change', '#manualVerifyPhoto', function () {
|
|
|
1476 |
var f = this.files && this.files[0];
|
|
|
1477 |
if (!f) {
|
|
|
1478 |
$('#manualVerifyPhotoPreview').hide();
|
|
|
1479 |
return;
|
|
|
1480 |
}
|
|
|
1481 |
var reader = new FileReader();
|
|
|
1482 |
reader.onload = function (ev) {
|
|
|
1483 |
$('#manualVerifyPhotoImg').attr('src', ev.target.result);
|
|
|
1484 |
$('#manualVerifyPhotoPreview').show();
|
|
|
1485 |
};
|
|
|
1486 |
reader.readAsDataURL(f);
|
|
|
1487 |
});
|
|
|
1488 |
|
|
|
1489 |
// Address -> coords via server (uses existing GeocodingService).
|
|
|
1490 |
// On success, fills the lat/lng box and renders the map preview.
|
|
|
1491 |
$(document).on('click', '#manualVerifyGeocodeBtn', function () {
|
|
|
1492 |
var addr = ($('#manualVerifyAddress').val() || '').trim();
|
|
|
1493 |
if (!addr) {
|
|
|
1494 |
$('#manualVerifyErr').text('Enter an address first.').show();
|
|
|
1495 |
return;
|
|
|
1496 |
}
|
|
|
1497 |
$('#manualVerifyErr').hide();
|
|
|
1498 |
var btn = $(this);
|
|
|
1499 |
btn.prop('disabled', true).text('Finding...');
|
|
|
1500 |
$.ajax({
|
|
|
1501 |
url: context + '/lead-geo/geocode-address',
|
|
|
1502 |
type: 'POST',
|
|
|
1503 |
data: {address: addr},
|
|
|
1504 |
success: function (resp) {
|
|
|
1505 |
btn.prop('disabled', false).text('Find on map');
|
|
|
1506 |
var r = resp && resp.response ? resp.response : resp;
|
|
|
1507 |
if (!r || !r.success) {
|
|
|
1508 |
$('#manualVerifyErr').text((r && r.message) || 'Could not geocode that address.').show();
|
|
|
1509 |
return;
|
|
|
1510 |
}
|
|
|
1511 |
$('#manualVerifyLatLng').val(r.latitude + ',' + r.longitude);
|
|
|
1512 |
manualVerifyShowMap(r.latitude, r.longitude);
|
|
|
1513 |
},
|
|
|
1514 |
error: function () {
|
|
|
1515 |
btn.prop('disabled', false).text('Find on map');
|
|
|
1516 |
$('#manualVerifyErr').text('Geocode request failed. Try again.').show();
|
|
|
1517 |
}
|
|
|
1518 |
});
|
|
|
1519 |
});
|
|
|
1520 |
|
|
|
1521 |
// "Show on map" — re-render the iframe from whatever is in the lat/lng input.
|
|
|
1522 |
// Useful after the user nudges the coords manually.
|
|
|
1523 |
$(document).on('click', '#manualVerifyPreviewBtn', function () {
|
|
|
1524 |
var parsed = parseLatLngInput($('#manualVerifyLatLng').val());
|
|
|
1525 |
if (!parsed) {
|
|
|
1526 |
$('#manualVerifyErr').text('Enter latitude,longitude first.').show();
|
|
|
1527 |
return;
|
|
|
1528 |
}
|
|
|
1529 |
$('#manualVerifyErr').hide();
|
|
|
1530 |
manualVerifyShowMap(parsed.lat, parsed.lng);
|
|
|
1531 |
});
|
|
|
1532 |
|
|
|
1533 |
$(document).on('click', '#manualVerifySaveBtn', function () {
|
|
|
1534 |
var lid = $('#manualVerifyLeadId').val();
|
|
|
1535 |
var raw = $('#manualVerifyLatLng').val();
|
|
|
1536 |
var remark = $('#manualVerifyRemark').val() || '';
|
|
|
1537 |
var parsed = parseLatLngInput(raw);
|
|
|
1538 |
if (!parsed) {
|
|
|
1539 |
$('#manualVerifyErr').text('Could not read latitude/longitude. Paste like 28.6139,77.2090').show();
|
|
|
1540 |
return;
|
|
|
1541 |
}
|
|
|
1542 |
if (parsed.lat < -90 || parsed.lat > 90 || parsed.lng < -180 || parsed.lng > 180
|
|
|
1543 |
|| (parsed.lat === 0 && parsed.lng === 0)) {
|
|
|
1544 |
$('#manualVerifyErr').text('Latitude/longitude out of range.').show();
|
|
|
1545 |
return;
|
|
|
1546 |
}
|
|
|
1547 |
var fileInput = document.getElementById('manualVerifyPhoto');
|
|
|
1548 |
var pickedFile = fileInput && fileInput.files && fileInput.files[0];
|
|
|
1549 |
if (!pickedFile) {
|
|
|
1550 |
$('#manualVerifyErr').text('Please attach a store-board photo to verify.').show();
|
|
|
1551 |
return;
|
|
|
1552 |
}
|
|
|
1553 |
$('#manualVerifyErr').hide();
|
|
|
1554 |
var btn = $('#manualVerifySaveBtn');
|
|
|
1555 |
btn.prop('disabled', true).text('Verifying...');
|
|
|
1556 |
|
|
|
1557 |
function callVerify(docId) {
|
|
|
1558 |
$.ajax({
|
|
|
1559 |
url: context + '/lead-geo/manual-verify',
|
|
|
1560 |
type: 'POST',
|
|
|
1561 |
data: {
|
|
|
1562 |
leadId: lid,
|
|
|
1563 |
latitude: parsed.lat,
|
|
|
1564 |
longitude: parsed.lng,
|
|
|
1565 |
remark: remark,
|
|
|
1566 |
imageDocumentId: docId || 0
|
|
|
1567 |
},
|
|
|
1568 |
success: function () {
|
|
|
1569 |
btn.prop('disabled', false).text('Save & Verify');
|
|
|
1570 |
$('#manualVerifyGeoModal').modal('hide');
|
|
|
1571 |
// Replace the cell of this lead row with the Verified badge so
|
|
|
1572 |
// the user sees the result without reloading the whole list.
|
|
|
1573 |
var $cell = $('.verifyGeoManual[data-leadid="' + lid + '"]').closest('td');
|
|
|
1574 |
if ($cell.length) {
|
|
|
1575 |
var photoBtn = docId > 0
|
|
|
1576 |
? ' <a href="' + context + '/open-attachment?documentId=' + docId + '" target="_blank" class="btn btn-xs btn-default" style="margin-bottom:2px;">View Photo</a>'
|
|
|
1577 |
: '';
|
|
|
1578 |
$cell.html(
|
|
|
1579 |
'<div class="btn-group-vertical" style="width:100%">' +
|
|
|
1580 |
' <span class="label label-success" style="margin-bottom:4px;">Verified</span>' +
|
|
|
1581 |
' <a href="https://www.google.com/maps?q=' + parsed.lat + ',' + parsed.lng + '" target="_blank" class="btn btn-xs btn-default" style="margin-bottom:2px;">View Map</a>' +
|
|
|
1582 |
photoBtn +
|
|
|
1583 |
' <button class="btn btn-xs btn-danger reject-geo" data-leadid="' + lid + '">Revoke</button>' +
|
|
|
1584 |
'</div>'
|
|
|
1585 |
);
|
|
|
1586 |
}
|
|
|
1587 |
},
|
|
|
1588 |
error: function (xhr) {
|
|
|
1589 |
btn.prop('disabled', false).text('Save & Verify');
|
|
|
1590 |
var msg = 'Failed to verify. Please try again.';
|
|
|
1591 |
try {
|
|
|
1592 |
var j = xhr.responseJSON || JSON.parse(xhr.responseText || '{}');
|
|
|
1593 |
if (j && j.response) msg = j.response;
|
|
|
1594 |
else if (j && j.message) msg = j.message;
|
|
|
1595 |
} catch (e) {
|
|
|
1596 |
}
|
|
|
1597 |
$('#manualVerifyErr').text(msg).show();
|
|
|
1598 |
}
|
|
|
1599 |
});
|
|
|
1600 |
}
|
|
|
1601 |
|
|
|
1602 |
// Upload first, then verify with the returned document id. Photo is
|
|
|
1603 |
// required (gate at the top of the handler), so we always go through this.
|
|
|
1604 |
btn.text('Uploading photo...');
|
|
|
1605 |
var formData = new FormData();
|
|
|
1606 |
formData.append('file', pickedFile, pickedFile.name || 'store-photo.jpg');
|
|
|
1607 |
$.ajax({
|
|
|
1608 |
url: context + '/lead-geo/upload-image',
|
|
|
1609 |
type: 'POST',
|
|
|
1610 |
data: formData,
|
|
|
1611 |
processData: false,
|
|
|
1612 |
contentType: false,
|
|
|
1613 |
success: function (resp) {
|
|
|
1614 |
var r = resp && resp.response ? resp.response : resp;
|
|
|
1615 |
var docId = r && (r.document_id || r.documentId || r.id);
|
|
|
1616 |
if (!docId) {
|
|
|
1617 |
btn.prop('disabled', false).text('Save & Verify');
|
|
|
1618 |
$('#manualVerifyErr').text('Photo upload failed. Try again or remove the photo.').show();
|
|
|
1619 |
return;
|
|
|
1620 |
}
|
|
|
1621 |
btn.text('Verifying...');
|
|
|
1622 |
callVerify(docId);
|
|
|
1623 |
},
|
|
|
1624 |
error: function () {
|
|
|
1625 |
btn.prop('disabled', false).text('Save & Verify');
|
|
|
1626 |
$('#manualVerifyErr').text('Photo upload failed. Try again or remove the photo.').show();
|
|
|
1627 |
}
|
|
|
1628 |
});
|
|
|
1629 |
});
|
|
|
1630 |
|
| 36642 |
ranu |
1631 |
// Geo Review navigation
|
|
|
1632 |
$(document).on('click', '.geo-review', function () {
|
|
|
1633 |
doGetAjaxRequestHandler(context + "/lead-geo/pending-reviews", function (response) {
|
|
|
1634 |
$('#main-content').html(response);
|
|
|
1635 |
});
|
|
|
1636 |
});
|
|
|
1637 |
|
|
|
1638 |
// Visit Approvals navigation
|
|
|
1639 |
$(document).on('click', '.visit-approvals', function () {
|
|
|
1640 |
doGetAjaxRequestHandler(context + "/visit-approvals", function (response) {
|
|
|
1641 |
$('#main-content').html(response);
|
|
|
1642 |
});
|
|
|
1643 |
});
|
|
|
1644 |
|
| 36650 |
ranu |
1645 |
// Beat Day View — load inline into dashboard
|
|
|
1646 |
$(document).on('click', '.beat-plan-dayview', function (e) {
|
|
|
1647 |
e.preventDefault();
|
|
|
1648 |
doGetAjaxRequestHandler(context + '/beatPlan/dayView', function (response) {
|
|
|
1649 |
$('#main-content').html(response);
|
|
|
1650 |
});
|
|
|
1651 |
});
|
|
|
1652 |
|
| 36655 |
ranu |
1653 |
// Base Location manager — load inline into dashboard
|
|
|
1654 |
$(document).on('click', '.base-location', function (e) {
|
|
|
1655 |
e.preventDefault();
|
|
|
1656 |
doGetAjaxRequestHandler(context + '/beatPlan/baseLocationPage', function (response) {
|
|
|
1657 |
$('#main-content').html(response);
|
|
|
1658 |
});
|
|
|
1659 |
});
|
|
|
1660 |
|
| 37187 |
amit |
1661 |
// Agenda Config — standalone full page (allow-list gated server-side),
|
|
|
1662 |
// so navigate instead of loading into #main-content.
|
|
|
1663 |
$(document).on('click', '.agenda-config', function (e) {
|
|
|
1664 |
e.preventDefault();
|
|
|
1665 |
window.location.href = context + '/agenda-config';
|
|
|
1666 |
});
|
|
|
1667 |
|
| 36740 |
ranu |
1668 |
// Deferred Partners — load inline into dashboard
|
|
|
1669 |
$(document).on('click', '.beat-plan-deferred', function (e) {
|
|
|
1670 |
e.preventDefault();
|
|
|
1671 |
doGetAjaxRequestHandler(context + '/beatPlan/deferredView', function (response) {
|
|
|
1672 |
$('#main-content').html(response);
|
|
|
1673 |
});
|
|
|
1674 |
});
|
|
|
1675 |
|
| 36642 |
ranu |
1676 |
// Approve geolocation from lead table
|
|
|
1677 |
$(document).on('click', '.approve-geo', function (e) {
|
|
|
1678 |
e.stopPropagation();
|
|
|
1679 |
var lid = $(this).data('leadid');
|
|
|
1680 |
if (!confirm('Approve geolocation for Lead #' + lid + '?')) return;
|
|
|
1681 |
|
|
|
1682 |
var btn = $(this);
|
|
|
1683 |
var cell = btn.closest('td');
|
|
|
1684 |
|
|
|
1685 |
doPostAjaxRequestWithParamsHandler(
|
|
|
1686 |
context + '/lead-geo/review',
|
|
|
1687 |
{leadId: lid, status: 'APPROVED', remark: ''},
|
|
|
1688 |
function (response) {
|
|
|
1689 |
cell.html('<span class="label label-success">Verified</span>');
|
|
|
1690 |
}
|
|
|
1691 |
);
|
|
|
1692 |
});
|
|
|
1693 |
|
|
|
1694 |
// Reject geolocation from lead table
|
|
|
1695 |
$(document).on('click', '.reject-geo', function (e) {
|
|
|
1696 |
e.stopPropagation();
|
|
|
1697 |
var lid = $(this).data('leadid');
|
|
|
1698 |
var reason = prompt('Reason for rejection:');
|
|
|
1699 |
if (reason === null) return;
|
|
|
1700 |
|
|
|
1701 |
var btn = $(this);
|
|
|
1702 |
var cell = btn.closest('td');
|
|
|
1703 |
|
|
|
1704 |
doPostAjaxRequestWithParamsHandler(
|
|
|
1705 |
context + '/lead-geo/review',
|
|
|
1706 |
{leadId: lid, status: 'REJECTED', remark: reason},
|
|
|
1707 |
function (response) {
|
|
|
1708 |
cell.html('<button class="btn btn-xs btn-warning generateGeoLink" data-leadid="' + lid + '">Rejected - Resend</button>');
|
|
|
1709 |
}
|
|
|
1710 |
);
|
|
|
1711 |
});
|
|
|
1712 |
|