| 36662 |
ranu |
1 |
<section class="wrapper">
|
|
|
2 |
<div class="row">
|
|
|
3 |
<div class="col-lg-12">
|
|
|
4 |
<h3 class="page-header"><i class="icon_calendar"></i> Scheduled Beats - Day View</h3>
|
|
|
5 |
<ol class="breadcrumb">
|
|
|
6 |
<li><i class="fa fa-home"></i><a href="${rc.contextPath}/dashboard">Home</a></li>
|
|
|
7 |
<li><i class="icon_group"></i> Partner Acquisition</li>
|
|
|
8 |
<li><i class="icon_calendar"></i> Beat Day View</li>
|
|
|
9 |
</ol>
|
|
|
10 |
</div>
|
|
|
11 |
</div>
|
|
|
12 |
|
|
|
13 |
<div class="row" style="margin-bottom:10px;">
|
|
|
14 |
<div class="col-lg-12" style="display:flex; gap:10px; align-items:center; flex-wrap:wrap;">
|
| 36821 |
ranu |
15 |
<label style="margin:0;">Category:</label>
|
|
|
16 |
<select id="dayViewCategory" class="form-control input-sm" style="width:140px;">
|
|
|
17 |
<option value="$categoryId">Sales</option>
|
|
|
18 |
</select>
|
|
|
19 |
<label style="margin:0;">Level:</label>
|
|
|
20 |
<select id="dayViewLevel" class="form-control input-sm" style="width:140px;">
|
|
|
21 |
<option value="">All Levels</option>
|
|
|
22 |
#foreach($lvl in $escalationTypes)
|
|
|
23 |
<option value="$lvl">$lvl</option>
|
|
|
24 |
#end
|
|
|
25 |
</select>
|
| 36761 |
ranu |
26 |
<label style="margin:0;">Date:</label>
|
|
|
27 |
<input type="date" id="dayViewDate" class="form-control input-sm" style="width:160px;">
|
| 36662 |
ranu |
28 |
<button class="btn btn-primary btn-sm" id="dayViewLoad">Load</button>
|
|
|
29 |
<span id="dayViewSummary" style="color:#777; font-size:12px; margin-left:10px;"></span>
|
|
|
30 |
</div>
|
|
|
31 |
</div>
|
|
|
32 |
|
|
|
33 |
<div class="row">
|
|
|
34 |
<div class="col-lg-12">
|
|
|
35 |
<div class="table-responsive">
|
|
|
36 |
<table class="table table-bordered table-striped table-hover" id="dayViewTable">
|
|
|
37 |
<thead>
|
|
|
38 |
<tr>
|
|
|
39 |
<th>User</th>
|
|
|
40 |
<th>Date</th>
|
|
|
41 |
<th>Beat</th>
|
|
|
42 |
<th>Day</th>
|
|
|
43 |
<th>Partners</th>
|
|
|
44 |
<th>Leads</th>
|
|
|
45 |
<th>Total Visits</th>
|
|
|
46 |
<th>Action</th>
|
|
|
47 |
</tr>
|
|
|
48 |
</thead>
|
|
|
49 |
<tbody id="dayViewRows">
|
|
|
50 |
<tr>
|
|
|
51 |
<td colspan="8" style="text-align:center; color:#999;">Pick a date range and click Load.</td>
|
|
|
52 |
</tr>
|
|
|
53 |
</tbody>
|
|
|
54 |
</table>
|
|
|
55 |
</div>
|
|
|
56 |
</div>
|
|
|
57 |
</div>
|
|
|
58 |
</section>
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
<script>
|
| 36962 |
vikas |
62 |
// Edit-beat / assign-visit in the Beat Planner are L2-and-above only.
|
|
|
63 |
var CAN_EDIT_BEAT = $canEditBeat;
|
| 36662 |
ranu |
64 |
(function () {
|
| 36761 |
ranu |
65 |
// Default: today only. Other dates → use the per-user calendar from the row's View button.
|
| 36662 |
ranu |
66 |
var today = new Date();
|
|
|
67 |
|
|
|
68 |
function fmt(d) {
|
|
|
69 |
return d.getFullYear() + '-' + ('0' + (d.getMonth() + 1)).slice(-2) + '-' + ('0' + d.getDate()).slice(-2);
|
|
|
70 |
}
|
|
|
71 |
|
| 36761 |
ranu |
72 |
$('#dayViewDate').val(fmt(today));
|
| 36662 |
ranu |
73 |
loadDayView();
|
|
|
74 |
})();
|
|
|
75 |
|
|
|
76 |
$(document).on('click', '#dayViewLoad', function () {
|
|
|
77 |
loadDayView();
|
|
|
78 |
});
|
|
|
79 |
|
|
|
80 |
function loadDayView() {
|
| 36761 |
ranu |
81 |
var d = $('#dayViewDate').val();
|
|
|
82 |
if (!d) {
|
|
|
83 |
alert('Pick a date');
|
| 36662 |
ranu |
84 |
return;
|
|
|
85 |
}
|
|
|
86 |
$('#dayViewRows').html('<tr><td colspan="8" style="text-align:center;">Loading...</td></tr>');
|
|
|
87 |
$('#dayViewSummary').text('');
|
| 36821 |
ranu |
88 |
var params = {startDate: d, endDate: d};
|
|
|
89 |
var cat = $('#dayViewCategory').val();
|
|
|
90 |
var lvl = $('#dayViewLevel').val();
|
|
|
91 |
if (cat) params.categoryId = cat;
|
|
|
92 |
if (lvl) params.escalationType = lvl;
|
|
|
93 |
$.get(context + '/beatPlan/scheduledList', params).done(function (r) {
|
| 36662 |
ranu |
94 |
var data = r.response || r;
|
|
|
95 |
renderDayViewRows(data.rows || []);
|
| 36761 |
ranu |
96 |
$('#dayViewSummary').text((data.rows || []).length + ' beats scheduled on ' + data.startDate);
|
| 36662 |
ranu |
97 |
}).fail(function (xhr) {
|
|
|
98 |
$('#dayViewRows').html('<tr><td colspan="8" style="color:#d9534f; text-align:center;">Error: ' + (xhr.responseText || xhr.statusText) + '</td></tr>');
|
|
|
99 |
});
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
function renderDayViewRows(rows) {
|
|
|
103 |
if (!rows || rows.length === 0) {
|
|
|
104 |
$('#dayViewRows').html('<tr><td colspan="8" style="text-align:center; color:#999;">No beats scheduled in this range.</td></tr>');
|
|
|
105 |
return;
|
|
|
106 |
}
|
| 36716 |
ranu |
107 |
// Assign Visit is only valid for TODAY's run — future/past dates hide the button.
|
|
|
108 |
var todayStr = (function () {
|
|
|
109 |
var d = new Date();
|
|
|
110 |
var mm = ('0' + (d.getMonth() + 1)).slice(-2);
|
|
|
111 |
var dd = ('0' + d.getDate()).slice(-2);
|
|
|
112 |
return d.getFullYear() + '-' + mm + '-' + dd;
|
|
|
113 |
})();
|
| 36662 |
ranu |
114 |
var html = '';
|
|
|
115 |
rows.forEach(function (r) {
|
| 36716 |
ranu |
116 |
var isToday = r.scheduleDate === todayStr;
|
| 36662 |
ranu |
117 |
html += '<tr>'
|
|
|
118 |
+ '<td>' + r.userName + '</td>'
|
|
|
119 |
+ '<td><span class="label label-primary">' + r.scheduleDate + '</span></td>'
|
|
|
120 |
+ '<td><span style="display:inline-block;width:10px;height:10px;border-radius:2px;background:' + (r.beatColor || '#3498db') + ';margin-right:6px;"></span>' + r.beatName + '</td>'
|
|
|
121 |
+ '<td>' + r.dayNumber + '</td>'
|
|
|
122 |
+ '<td>' + r.partnerCount + '</td>'
|
|
|
123 |
+ '<td>' + (r.leadCount > 0 ? '<span class="label label-warning">' + r.leadCount + '</span>' : '0') + '</td>'
|
|
|
124 |
+ '<td><strong>' + r.visitCount + '</strong></td>'
|
|
|
125 |
+ '<td>'
|
|
|
126 |
+ '<button class="btn btn-xs btn-info view-user-calendar" data-userid="' + r.authUserId + '" data-username="' + r.userName + '">View Calendar</button> '
|
| 36962 |
vikas |
127 |
+ (CAN_EDIT_BEAT
|
|
|
128 |
? '<button class="btn btn-xs btn-warning edit-beat-on-date" '
|
|
|
129 |
+ 'data-userid="' + r.authUserId + '" data-username="' + r.userName + '" '
|
|
|
130 |
+ 'data-beatid="' + r.beatId + '" data-date="' + r.scheduleDate + '">Edit</button>'
|
|
|
131 |
+ (isToday
|
|
|
132 |
? ' <button class="btn btn-xs btn-success assign-visit-btn"'
|
|
|
133 |
+ ' data-userid="' + r.authUserId + '" data-username="' + r.userName + '"'
|
|
|
134 |
+ ' data-beatid="' + r.beatId + '"'
|
|
|
135 |
+ ' data-date="' + r.scheduleDate + '">Assign Visit</button>'
|
|
|
136 |
: '')
|
| 36716 |
ranu |
137 |
: '')
|
| 36662 |
ranu |
138 |
+ '</td>'
|
|
|
139 |
+ '</tr>';
|
|
|
140 |
});
|
|
|
141 |
$('#dayViewRows').html(html);
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
// View -> open user's calendar inside the dashboard in a modal iframe (pre-selected)
|
|
|
145 |
$(document).on('click', '.view-user-calendar', function () {
|
|
|
146 |
var userId = $(this).data('userid');
|
|
|
147 |
var userName = $(this).data('username') || '';
|
|
|
148 |
var url = context + '/beatPlanWindow?autoUserId=' + userId
|
|
|
149 |
+ '&autoUserName=' + encodeURIComponent(userName);
|
|
|
150 |
$('#userCalendarTitle').text('Calendar - ' + userName);
|
|
|
151 |
$('#userCalendarFrame').attr('src', url);
|
|
|
152 |
$('#userCalendarModal').modal('show');
|
|
|
153 |
});
|
|
|
154 |
|
|
|
155 |
// Edit a beat on a specific date — opens beatPlanWindow in edit mode for that run
|
|
|
156 |
$(document).on('click', '.edit-beat-on-date', function () {
|
|
|
157 |
var userId = $(this).data('userid');
|
|
|
158 |
var userName = $(this).data('username') || '';
|
|
|
159 |
var beatId = $(this).data('beatid');
|
|
|
160 |
var date = $(this).data('date');
|
|
|
161 |
var url = context + '/beatPlanWindow?autoUserId=' + userId
|
|
|
162 |
+ '&autoUserName=' + encodeURIComponent(userName)
|
|
|
163 |
+ '&editBeatId=' + beatId + '&editDate=' + date;
|
|
|
164 |
$('#userCalendarTitle').text('Edit Beat - ' + userName + ' on ' + date);
|
|
|
165 |
$('#userCalendarFrame').attr('src', url);
|
|
|
166 |
$('#userCalendarModal').modal('show');
|
|
|
167 |
});
|
| 36663 |
ranu |
168 |
|
|
|
169 |
// ---------- ASSIGN VISIT ----------
|
| 36716 |
ranu |
170 |
var avContext = {authUserId: null, userName: '', date: '', beatId: null, allParties: [], agendaOptions: []};
|
| 36663 |
ranu |
171 |
|
|
|
172 |
$(document).on('click', '.assign-visit-btn', function () {
|
|
|
173 |
avContext.authUserId = $(this).data('userid');
|
|
|
174 |
avContext.userName = $(this).data('username') || '';
|
|
|
175 |
avContext.date = $(this).data('date');
|
| 36716 |
ranu |
176 |
avContext.beatId = $(this).data('beatid');
|
| 36663 |
ranu |
177 |
avContext.allParties = [];
|
|
|
178 |
|
| 36716 |
ranu |
179 |
$('#avTitle').text('Assign Visit - ' + avContext.userName + ' on ' + avContext.date);
|
| 36663 |
ranu |
180 |
$('#avSearch').val('');
|
| 36716 |
ranu |
181 |
// The default-agenda multiselect is rebuilt (and re-initialized) below in rebuildDefaultAgenda
|
| 36663 |
ranu |
182 |
$('#avPartyList').html('<div style="padding:20px; color:#999; text-align:center;">Loading parties...</div>');
|
|
|
183 |
$('#avMsg').text('');
|
|
|
184 |
$('#avSelectedCount').text('0 selected');
|
|
|
185 |
$('#avSubmit').prop('disabled', true);
|
|
|
186 |
$('#assignVisitModal').modal('show');
|
|
|
187 |
|
| 36716 |
ranu |
188 |
$.get(context + '/beatPlan/assignVisit/parties', {
|
|
|
189 |
authUserId: avContext.authUserId,
|
|
|
190 |
date: avContext.date,
|
|
|
191 |
beatId: avContext.beatId
|
|
|
192 |
}).done(function (r) {
|
|
|
193 |
var data = r.response || r;
|
|
|
194 |
// Drop parties already in the beat — they're handled by the beat plan itself,
|
|
|
195 |
// Assign Visit is purely for adding extra (non-beat) visits.
|
|
|
196 |
avContext.allParties = (data.parties || []).filter(function (p) {
|
|
|
197 |
return !p.inBeat;
|
|
|
198 |
});
|
|
|
199 |
avContext.agendaOptions = data.agendaOptions || [];
|
|
|
200 |
if (!data.dtrUserId) {
|
|
|
201 |
$('#avPartyList').html('<div style="padding:20px; color:#c62828; text-align:center;">' +
|
|
|
202 |
'This user has no dtr.users record (cannot create visit tasks).</div>');
|
|
|
203 |
return;
|
|
|
204 |
}
|
|
|
205 |
rebuildDefaultAgenda();
|
|
|
206 |
renderAvParties(avContext.allParties);
|
|
|
207 |
}).fail(function (xhr) {
|
|
|
208 |
$('#avPartyList').html('<div style="padding:20px; color:#c62828; text-align:center;">' +
|
|
|
209 |
'Error loading parties: ' + (xhr.responseText || xhr.statusText) + '</div>');
|
|
|
210 |
});
|
| 36663 |
ranu |
211 |
});
|
|
|
212 |
|
| 36716 |
ranu |
213 |
// Per-row agenda markup. Initialized as bootstrap-multiselect dropdown
|
|
|
214 |
// (project standard — same as today-offer.vm, lead.vm, etc.) after render.
|
|
|
215 |
// In-beat parties are filtered out of the list entirely, so only non-beat
|
|
|
216 |
// (extra-visit) parties show up here. existingAgendas[] is pre-selected for
|
|
|
217 |
// parties that already have a saved visit today (so editing existing ones works).
|
|
|
218 |
function agendaSelectHtml(p) {
|
|
|
219 |
var preset = {};
|
|
|
220 |
(p.existingAgendas || []).forEach(function (a) {
|
|
|
221 |
preset[a] = true;
|
|
|
222 |
});
|
|
|
223 |
var html = '<select multiple class="av-party-agenda"'
|
|
|
224 |
+ ' data-fofoid="' + p.fofoStoreId + '">';
|
|
|
225 |
avContext.agendaOptions.forEach(function (opt) {
|
|
|
226 |
html += '<option value="' + opt + '"' + (preset[opt] ? ' selected' : '') + '>' + opt + '</option>';
|
|
|
227 |
});
|
|
|
228 |
html += '</select>';
|
|
|
229 |
return html;
|
|
|
230 |
}
|
|
|
231 |
|
|
|
232 |
var AGENDA_MULTISELECT_OPTS = {
|
|
|
233 |
includeSelectAllOption: false,
|
|
|
234 |
maxHeight: 220,
|
|
|
235 |
buttonWidth: '240px',
|
|
|
236 |
numberDisplayed: 2,
|
|
|
237 |
nonSelectedText: 'Pick agenda(s)',
|
|
|
238 |
nSelectedText: ' agendas',
|
|
|
239 |
allSelectedText: 'All agendas',
|
|
|
240 |
enableFiltering: true,
|
|
|
241 |
enableCaseInsensitiveFiltering: true
|
|
|
242 |
};
|
|
|
243 |
|
|
|
244 |
function rebuildDefaultAgenda() {
|
|
|
245 |
var $sel = $('#avDefaultAgenda');
|
|
|
246 |
// Destroy any prior instance before re-initing (re-open of the modal)
|
|
|
247 |
try {
|
|
|
248 |
$sel.multiselect('destroy');
|
|
|
249 |
} catch (e) {
|
|
|
250 |
}
|
|
|
251 |
var html = '';
|
|
|
252 |
avContext.agendaOptions.forEach(function (opt) {
|
|
|
253 |
html += '<option value="' + opt + '">' + opt + '</option>';
|
|
|
254 |
});
|
|
|
255 |
$sel.html(html);
|
|
|
256 |
// Build opts as a variable — inline {...} object literal after $.extend()
|
|
|
257 |
// confused Velocity's parser ("Encountered { ... was expecting ...").
|
|
|
258 |
var defaultOpts = $.extend({}, AGENDA_MULTISELECT_OPTS);
|
|
|
259 |
defaultOpts.nonSelectedText = 'Pick agenda(s) to apply';
|
|
|
260 |
$sel.multiselect(defaultOpts);
|
|
|
261 |
}
|
|
|
262 |
|
|
|
263 |
function initRowMultiselects() {
|
|
|
264 |
$('.av-party-agenda').each(function () {
|
|
|
265 |
var $sel = $(this);
|
|
|
266 |
try {
|
|
|
267 |
$sel.multiselect('destroy');
|
|
|
268 |
} catch (e) {
|
|
|
269 |
}
|
|
|
270 |
$sel.multiselect(AGENDA_MULTISELECT_OPTS);
|
|
|
271 |
});
|
|
|
272 |
}
|
|
|
273 |
|
| 36663 |
ranu |
274 |
function renderAvParties(list) {
|
|
|
275 |
if (!list || list.length === 0) {
|
|
|
276 |
$('#avPartyList').html('<div style="padding:20px; color:#999; text-align:center;">No parties found.</div>');
|
|
|
277 |
return;
|
|
|
278 |
}
|
|
|
279 |
var html = '<table class="table table-condensed table-hover" style="margin-bottom:0; font-size:13px;">';
|
|
|
280 |
html += '<thead><tr>'
|
|
|
281 |
+ '<th style="width:30px;"><input type="checkbox" id="avSelectAll" title="Select all"></th>'
|
|
|
282 |
+ '<th>Code</th><th>Outlet</th><th>City</th>'
|
| 36716 |
ranu |
283 |
+ '<th style="width:260px;">Agenda</th>'
|
|
|
284 |
+ '<th style="width:260px;">Description</th>'
|
| 36663 |
ranu |
285 |
+ '</tr></thead><tbody>';
|
|
|
286 |
list.forEach(function (p) {
|
|
|
287 |
var safeName = (p.outletName || '').replace(/"/g, '"');
|
| 36716 |
ranu |
288 |
var existingDesc = (p.existingDescription || '').replace(/"/g, '"');
|
| 36663 |
ranu |
289 |
html += '<tr>'
|
|
|
290 |
+ '<td><input type="checkbox" class="av-party-chk" '
|
|
|
291 |
+ 'data-fofoid="' + p.fofoStoreId + '" '
|
|
|
292 |
+ 'data-name="' + safeName + '" '
|
|
|
293 |
+ 'data-lat="' + (p.latitude || '') + '" '
|
|
|
294 |
+ 'data-lng="' + (p.longitude || '') + '"></td>'
|
|
|
295 |
+ '<td>' + (p.code || '') + '</td>'
|
|
|
296 |
+ '<td>' + (p.outletName || '') + '</td>'
|
|
|
297 |
+ '<td>' + (p.city || '') + '</td>'
|
| 36716 |
ranu |
298 |
+ '<td>' + agendaSelectHtml(p) + '</td>'
|
|
|
299 |
+ '<td><textarea class="form-control input-sm av-party-desc"'
|
|
|
300 |
+ ' data-fofoid="' + p.fofoStoreId + '"'
|
|
|
301 |
+ ' rows="2" placeholder="Optional notes..."'
|
|
|
302 |
+ ' style="resize:vertical; min-height:34px;">' + existingDesc + '</textarea></td>'
|
| 36663 |
ranu |
303 |
+ '</tr>';
|
|
|
304 |
});
|
|
|
305 |
html += '</tbody></table>';
|
|
|
306 |
$('#avPartyList').html(html);
|
| 36716 |
ranu |
307 |
initRowMultiselects();
|
| 36663 |
ranu |
308 |
updateAvSelectedCount();
|
|
|
309 |
}
|
|
|
310 |
|
|
|
311 |
// Search filter
|
|
|
312 |
$(document).on('input', '#avSearch', function () {
|
|
|
313 |
var q = $(this).val().toLowerCase().trim();
|
|
|
314 |
if (!q) {
|
|
|
315 |
renderAvParties(avContext.allParties);
|
|
|
316 |
return;
|
|
|
317 |
}
|
|
|
318 |
var filtered = avContext.allParties.filter(function (p) {
|
|
|
319 |
return (p.code || '').toLowerCase().indexOf(q) !== -1
|
|
|
320 |
|| (p.outletName || '').toLowerCase().indexOf(q) !== -1
|
|
|
321 |
|| (p.city || '').toLowerCase().indexOf(q) !== -1;
|
|
|
322 |
});
|
|
|
323 |
renderAvParties(filtered);
|
|
|
324 |
});
|
|
|
325 |
|
|
|
326 |
// Select all toggle
|
|
|
327 |
$(document).on('change', '#avSelectAll', function () {
|
|
|
328 |
$('.av-party-chk').prop('checked', this.checked);
|
|
|
329 |
updateAvSelectedCount();
|
|
|
330 |
});
|
|
|
331 |
|
|
|
332 |
$(document).on('change', '.av-party-chk', updateAvSelectedCount);
|
|
|
333 |
|
|
|
334 |
function updateAvSelectedCount() {
|
|
|
335 |
var n = $('.av-party-chk:checked').length;
|
|
|
336 |
$('#avSelectedCount').text(n + ' selected');
|
|
|
337 |
$('#avSubmit').prop('disabled', n === 0);
|
|
|
338 |
}
|
|
|
339 |
|
| 36716 |
ranu |
340 |
// Apply the default agendas (multi-select) to all currently-selected rows.
|
|
|
341 |
// MERGES with each row's existing selections so in-beat rows keep prior agendas.
|
|
|
342 |
// After updating <select>.val(), call multiselect('refresh') so the checkbox
|
|
|
343 |
// UI re-syncs with the underlying option state.
|
| 36663 |
ranu |
344 |
$(document).on('click', '#avApplyAgenda', function () {
|
| 36716 |
ranu |
345 |
var defValues = $('#avDefaultAgenda').val() || [];
|
|
|
346 |
if (defValues.length === 0) {
|
|
|
347 |
alert('Pick at least one agenda above first');
|
| 36663 |
ranu |
348 |
return;
|
|
|
349 |
}
|
|
|
350 |
$('.av-party-chk:checked').each(function () {
|
|
|
351 |
var fid = $(this).data('fofoid');
|
| 36716 |
ranu |
352 |
var $sel = $('.av-party-agenda[data-fofoid="' + fid + '"]');
|
|
|
353 |
var existing = $sel.val() || [];
|
|
|
354 |
var merged = existing.slice();
|
|
|
355 |
defValues.forEach(function (v) {
|
|
|
356 |
if (merged.indexOf(v) === -1) merged.push(v);
|
|
|
357 |
});
|
|
|
358 |
$sel.val(merged);
|
|
|
359 |
try {
|
|
|
360 |
$sel.multiselect('refresh');
|
|
|
361 |
} catch (e) {
|
|
|
362 |
}
|
| 36663 |
ranu |
363 |
});
|
|
|
364 |
});
|
|
|
365 |
|
|
|
366 |
// Submit
|
|
|
367 |
$(document).on('click', '#avSubmit', function () {
|
|
|
368 |
var picks = [];
|
|
|
369 |
var missing = 0;
|
|
|
370 |
$('.av-party-chk:checked').each(function () {
|
|
|
371 |
var fid = parseInt($(this).data('fofoid'));
|
| 36716 |
ranu |
372 |
var agendas = $('.av-party-agenda[data-fofoid="' + fid + '"]').val() || [];
|
|
|
373 |
var description = ($('.av-party-desc[data-fofoid="' + fid + '"]').val() || '').trim();
|
|
|
374 |
if (agendas.length === 0) missing++;
|
| 36663 |
ranu |
375 |
picks.push({
|
|
|
376 |
fofoStoreId: fid,
|
|
|
377 |
outletName: $(this).data('name'),
|
|
|
378 |
latitude: $(this).data('lat') ? String($(this).data('lat')) : null,
|
|
|
379 |
longitude: $(this).data('lng') ? String($(this).data('lng')) : null,
|
| 36716 |
ranu |
380 |
agendas: agendas,
|
|
|
381 |
description: description
|
| 36663 |
ranu |
382 |
});
|
|
|
383 |
});
|
|
|
384 |
if (picks.length === 0) return;
|
|
|
385 |
if (missing > 0) {
|
|
|
386 |
if (!confirm(missing + ' selected row(s) have no agenda. Submit anyway with default "Visit"?')) return;
|
|
|
387 |
}
|
|
|
388 |
|
|
|
389 |
var btn = $(this);
|
|
|
390 |
btn.prop('disabled', true).text('Assigning...');
|
|
|
391 |
$('#avMsg').text('');
|
|
|
392 |
|
|
|
393 |
$.ajax({
|
|
|
394 |
url: context + '/beatPlan/assignVisit/submit',
|
|
|
395 |
type: 'POST',
|
|
|
396 |
contentType: 'application/json',
|
|
|
397 |
data: JSON.stringify({
|
|
|
398 |
authUserId: avContext.authUserId,
|
|
|
399 |
planDate: avContext.date,
|
|
|
400 |
parties: picks
|
|
|
401 |
}),
|
|
|
402 |
success: function (r) {
|
|
|
403 |
var d = r.response || r;
|
| 36716 |
ranu |
404 |
$('#avMsg').html('<span style="color:#2e7d32;">' + (d.message || 'Saved') + '</span>');
|
|
|
405 |
btn.prop('disabled', false).text('Save Assignments');
|
| 36663 |
ranu |
406 |
setTimeout(function () {
|
|
|
407 |
$('#assignVisitModal').modal('hide');
|
| 36716 |
ranu |
408 |
}, 1500);
|
| 36663 |
ranu |
409 |
},
|
|
|
410 |
error: function (xhr) {
|
|
|
411 |
var msg = 'Failed';
|
|
|
412 |
try {
|
|
|
413 |
msg = (JSON.parse(xhr.responseText).response.message) || msg;
|
|
|
414 |
} catch (e) {
|
|
|
415 |
}
|
|
|
416 |
$('#avMsg').html('<span style="color:#c62828;">' + msg + '</span>');
|
| 36716 |
ranu |
417 |
btn.prop('disabled', false).text('Save Assignments');
|
| 36663 |
ranu |
418 |
}
|
|
|
419 |
});
|
|
|
420 |
});
|
| 36662 |
ranu |
421 |
</script>
|
|
|
422 |
|
| 36663 |
ranu |
423 |
<!-- Assign Visit Modal -->
|
|
|
424 |
<div class="modal fade" id="assignVisitModal" tabindex="-1" style="overflow-y:auto;">
|
|
|
425 |
<div class="modal-dialog" style="width:90%; max-width:900px; margin-top:30px;">
|
|
|
426 |
<div class="modal-content">
|
|
|
427 |
<div class="modal-header">
|
|
|
428 |
<button type="button" class="close" data-dismiss="modal">×</button>
|
|
|
429 |
<h4 class="modal-title" id="avTitle">Assign Visit</h4>
|
|
|
430 |
</div>
|
|
|
431 |
<div class="modal-body">
|
| 36716 |
ranu |
432 |
<div style="display:flex; gap:10px; align-items:flex-start; margin-bottom:10px;">
|
|
|
433 |
<div style="flex:1;">
|
|
|
434 |
<label style="font-size:11px; color:#666; font-weight:normal; margin-bottom:2px;">
|
|
|
435 |
Agenda - applies to selected rows
|
|
|
436 |
</label>
|
|
|
437 |
<select id="avDefaultAgenda" multiple></select>
|
|
|
438 |
</div>
|
| 36663 |
ranu |
439 |
<button type="button" class="btn btn-default btn-sm" id="avApplyAgenda"
|
| 36716 |
ranu |
440 |
style="margin-top:18px;"
|
|
|
441 |
title="Add the picked agendas into all selected rows (merges with existing)">
|
| 36663 |
ranu |
442 |
Apply to Selected
|
|
|
443 |
</button>
|
|
|
444 |
</div>
|
|
|
445 |
<div style="display:flex; gap:10px; align-items:center; margin-bottom:10px;">
|
|
|
446 |
<input type="text" id="avSearch" class="form-control input-sm"
|
|
|
447 |
placeholder="Search by code, outlet name or city..." style="flex:1;">
|
|
|
448 |
<span id="avSelectedCount" style="font-size:12px; color:#666;">0 selected</span>
|
|
|
449 |
</div>
|
|
|
450 |
<div id="avPartyList"
|
|
|
451 |
style="max-height:50vh; overflow-y:auto; border:1px solid #e5e5e5; border-radius:4px;"></div>
|
|
|
452 |
<div id="avMsg" style="margin-top:10px; font-size:12px;"></div>
|
|
|
453 |
</div>
|
|
|
454 |
<div class="modal-footer">
|
|
|
455 |
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
|
| 36716 |
ranu |
456 |
<button type="button" class="btn btn-success" id="avSubmit" disabled>Save Assignments</button>
|
| 36663 |
ranu |
457 |
</div>
|
|
|
458 |
</div>
|
|
|
459 |
</div>
|
|
|
460 |
</div>
|
|
|
461 |
|
| 36662 |
ranu |
462 |
<!-- Calendar modal (iframe loads /beatPlanWindow with auto-selected user) -->
|
|
|
463 |
<div class="modal fade" id="userCalendarModal" tabindex="-1" style="overflow-y:auto;">
|
|
|
464 |
<div class="modal-dialog" style="width:95%; max-width:1300px; margin-top:20px;">
|
|
|
465 |
<div class="modal-content">
|
|
|
466 |
<div class="modal-header">
|
|
|
467 |
<button type="button" class="close" data-dismiss="modal"
|
|
|
468 |
onclick="$('#userCalendarFrame').attr('src','');">×
|
|
|
469 |
</button>
|
|
|
470 |
<h4 class="modal-title" id="userCalendarTitle">Calendar</h4>
|
|
|
471 |
</div>
|
|
|
472 |
<div class="modal-body" style="padding:0;">
|
|
|
473 |
<iframe id="userCalendarFrame" style="width:100%; height:80vh; border:none;"></iframe>
|
|
|
474 |
</div>
|
|
|
475 |
</div>
|
|
|
476 |
</div>
|
|
|
477 |
</div>
|