Subversion Repositories SmartDukaan

Rev

Rev 37248 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 37248 Rev 37494
Line 71... Line 71...
71
 
71
 
72
        $('#dayViewDate').val(fmt(today));
72
        $('#dayViewDate').val(fmt(today));
73
        loadDayView();
73
        loadDayView();
74
    })();
74
    })();
75
 
75
 
-
 
76
    // Fragment is re-injected with .html(), which re-runs this script; clear the
-
 
77
    // namespace first so handlers replace rather than stack (one click would
-
 
78
    // otherwise fire N identical requests and be rejected as duplicates).
-
 
79
    $(document).off('.bpdayview');
76
    $(document).on('click', '#dayViewLoad', function () {
80
    $(document).on('click.bpdayview', '#dayViewLoad', function () {
77
        loadDayView();
81
        loadDayView();
78
    });
82
    });
79
 
83
 
80
    function loadDayView() {
84
    function loadDayView() {
81
        var d = $('#dayViewDate').val();
85
        var d = $('#dayViewDate').val();
Line 146... Line 150...
146
        });
150
        });
147
        $('#dayViewRows').html(html);
151
        $('#dayViewRows').html(html);
148
    }
152
    }
149
 
153
 
150
    // View -> open user's calendar inside the dashboard in a modal iframe (pre-selected)
154
    // View -> open user's calendar inside the dashboard in a modal iframe (pre-selected)
151
    $(document).on('click', '.view-user-calendar', function () {
155
    $(document).on('click.bpdayview', '.view-user-calendar', function () {
152
        var userId = $(this).data('userid');
156
        var userId = $(this).data('userid');
153
        var userName = $(this).data('username') || '';
157
        var userName = $(this).data('username') || '';
154
        var url = context + '/beatPlanWindow?autoUserId=' + userId
158
        var url = context + '/beatPlanWindow?autoUserId=' + userId
155
                + '&autoUserName=' + encodeURIComponent(userName);
159
                + '&autoUserName=' + encodeURIComponent(userName);
156
        $('#userCalendarTitle').text('Calendar - ' + userName);
160
        $('#userCalendarTitle').text('Calendar - ' + userName);
157
        $('#userCalendarFrame').attr('src', url);
161
        $('#userCalendarFrame').attr('src', url);
158
        $('#userCalendarModal').modal('show');
162
        $('#userCalendarModal').modal('show');
159
    });
163
    });
160
 
164
 
161
    // Edit a beat on a specific date — opens beatPlanWindow in edit mode for that run
165
    // Edit a beat on a specific date — opens beatPlanWindow in edit mode for that run
162
    $(document).on('click', '.edit-beat-on-date', function () {
166
    $(document).on('click.bpdayview', '.edit-beat-on-date', function () {
163
        var userId = $(this).data('userid');
167
        var userId = $(this).data('userid');
164
        var userName = $(this).data('username') || '';
168
        var userName = $(this).data('username') || '';
165
        var beatId = $(this).data('beatid');
169
        var beatId = $(this).data('beatid');
166
        var date = $(this).data('date');
170
        var date = $(this).data('date');
167
        var url = context + '/beatPlanWindow?autoUserId=' + userId
171
        var url = context + '/beatPlanWindow?autoUserId=' + userId
Line 173... Line 177...
173
    });
177
    });
174
 
178
 
175
    // ---------- ASSIGN VISIT ----------
179
    // ---------- ASSIGN VISIT ----------
176
    var avContext = {authUserId: null, userName: '', date: '', beatId: null, allParties: [], agendaOptions: []};
180
    var avContext = {authUserId: null, userName: '', date: '', beatId: null, allParties: [], agendaOptions: []};
177
 
181
 
178
    $(document).on('click', '.assign-visit-btn', function () {
182
    $(document).on('click.bpdayview', '.assign-visit-btn', function () {
179
        avContext.authUserId = $(this).data('userid');
183
        avContext.authUserId = $(this).data('userid');
180
        avContext.userName = $(this).data('username') || '';
184
        avContext.userName = $(this).data('username') || '';
181
        avContext.date = $(this).data('date');
185
        avContext.date = $(this).data('date');
182
        avContext.beatId = $(this).data('beatid');
186
        avContext.beatId = $(this).data('beatid');
183
        avContext.allParties = [];
187
        avContext.allParties = [];
Line 257... Line 261...
257
        if (chips) html += '<div>' + chips + '</div>';
261
        if (chips) html += '<div>' + chips + '</div>';
258
        return html;
262
        return html;
259
    }
263
    }
260
 
264
 
261
    // Close a MANUAL agenda instance from its chip.
265
    // Close a MANUAL agenda instance from its chip.
262
    $(document).on('click', '.av-agenda-close', function (e) {
266
    $(document).on('click.bpdayview', '.av-agenda-close', function (e) {
263
        e.preventDefault();
267
        e.preventDefault();
264
        var chip = $(this).closest('span');
268
        var chip = $(this).closest('span');
265
        var iid = $(this).data('instanceid');
269
        var iid = $(this).data('instanceid');
266
        var remark = prompt('Closing remark (optional):');
270
        var remark = prompt('Closing remark (optional):');
267
        if (remark === null) return; // cancelled
271
        if (remark === null) return; // cancelled
Line 355... Line 359...
355
        initRowMultiselects();
359
        initRowMultiselects();
356
        updateAvSelectedCount();
360
        updateAvSelectedCount();
357
    }
361
    }
358
 
362
 
359
    // Search filter
363
    // Search filter
360
    $(document).on('input', '#avSearch', function () {
364
    $(document).on('input.bpdayview', '#avSearch', function () {
361
        var q = $(this).val().toLowerCase().trim();
365
        var q = $(this).val().toLowerCase().trim();
362
        if (!q) {
366
        if (!q) {
363
            renderAvParties(avContext.allParties);
367
            renderAvParties(avContext.allParties);
364
            return;
368
            return;
365
        }
369
        }
Line 370... Line 374...
370
        });
374
        });
371
        renderAvParties(filtered);
375
        renderAvParties(filtered);
372
    });
376
    });
373
 
377
 
374
    // Select all toggle
378
    // Select all toggle
375
    $(document).on('change', '#avSelectAll', function () {
379
    $(document).on('change.bpdayview', '#avSelectAll', function () {
376
        $('.av-party-chk').prop('checked', this.checked);
380
        $('.av-party-chk').prop('checked', this.checked);
377
        updateAvSelectedCount();
381
        updateAvSelectedCount();
378
    });
382
    });
379
 
383
 
380
    $(document).on('change', '.av-party-chk', updateAvSelectedCount);
384
    $(document).on('change.bpdayview', '.av-party-chk', updateAvSelectedCount);
381
 
385
 
382
    function updateAvSelectedCount() {
386
    function updateAvSelectedCount() {
383
        var n = $('.av-party-chk:checked').length;
387
        var n = $('.av-party-chk:checked').length;
384
        $('#avSelectedCount').text(n + ' selected');
388
        $('#avSelectedCount').text(n + ' selected');
385
        $('#avSubmit').prop('disabled', n === 0);
389
        $('#avSubmit').prop('disabled', n === 0);
Line 387... Line 391...
387
 
391
 
388
    // Apply the default agendas (multi-select) to all currently-selected rows.
392
    // Apply the default agendas (multi-select) to all currently-selected rows.
389
    // MERGES with each row's existing selections so in-beat rows keep prior agendas.
393
    // MERGES with each row's existing selections so in-beat rows keep prior agendas.
390
    // After updating <select>.val(), call multiselect('refresh') so the checkbox
394
    // After updating <select>.val(), call multiselect('refresh') so the checkbox
391
    // UI re-syncs with the underlying option state.
395
    // UI re-syncs with the underlying option state.
392
    $(document).on('click', '#avApplyAgenda', function () {
396
    $(document).on('click.bpdayview', '#avApplyAgenda', function () {
393
        var defValues = $('#avDefaultAgenda').val() || [];
397
        var defValues = $('#avDefaultAgenda').val() || [];
394
        if (defValues.length === 0) {
398
        if (defValues.length === 0) {
395
            alert('Pick at least one agenda above first');
399
            alert('Pick at least one agenda above first');
396
            return;
400
            return;
397
        }
401
        }
Line 410... Line 414...
410
            }
414
            }
411
        });
415
        });
412
    });
416
    });
413
 
417
 
414
    // Submit
418
    // Submit
415
    $(document).on('click', '#avSubmit', function () {
419
    $(document).on('click.bpdayview', '#avSubmit', function () {
416
        var picks = [];
420
        var picks = [];
417
        var missing = 0;
421
        var missing = 0;
418
        $('.av-party-chk:checked').each(function () {
422
        $('.av-party-chk:checked').each(function () {
419
            var fid = parseInt($(this).data('fofoid'));
423
            var fid = parseInt($(this).data('fofoid'));
420
            var agendas = $('.av-party-agenda[data-fofoid="' + fid + '"]').val() || [];
424
            var agendas = $('.av-party-agenda[data-fofoid="' + fid + '"]').val() || [];
Line 475... Line 479...
475
    // ---------- ADD LEAD ----------
479
    // ---------- ADD LEAD ----------
476
    // Routes the rep's assigned leads onto this scheduled beat/date. Writes an
480
    // Routes the rep's assigned leads onto this scheduled beat/date. Writes an
477
    // APPROVED lead_route per pick via /beatPlan/leadsForBeat/submit.
481
    // APPROVED lead_route per pick via /beatPlan/leadsForBeat/submit.
478
    var alCtx = {authUserId: null, userName: '', beatId: null, date: '', allLeads: []};
482
    var alCtx = {authUserId: null, userName: '', beatId: null, date: '', allLeads: []};
479
 
483
 
480
    $(document).on('click', '.add-lead-btn', function () {
484
    $(document).on('click.bpdayview', '.add-lead-btn', function () {
481
        alCtx.authUserId = $(this).data('userid');
485
        alCtx.authUserId = $(this).data('userid');
482
        alCtx.userName = $(this).data('username') || '';
486
        alCtx.userName = $(this).data('username') || '';
483
        alCtx.beatId = $(this).data('beatid');
487
        alCtx.beatId = $(this).data('beatid');
484
        alCtx.date = $(this).data('date');
488
        alCtx.date = $(this).data('date');
485
        alCtx.allLeads = [];
489
        alCtx.allLeads = [];
Line 531... Line 535...
531
        html += '</tbody></table>';
535
        html += '</tbody></table>';
532
        $('#alLeadList').html(html);
536
        $('#alLeadList').html(html);
533
        updateAlSelectedCount();
537
        updateAlSelectedCount();
534
    }
538
    }
535
 
539
 
536
    $(document).on('input', '#alSearch', function () {
540
    $(document).on('input.bpdayview', '#alSearch', function () {
537
        var q = $(this).val().toLowerCase().trim();
541
        var q = $(this).val().toLowerCase().trim();
538
        if (!q) {
542
        if (!q) {
539
            renderAlLeads(alCtx.allLeads);
543
            renderAlLeads(alCtx.allLeads);
540
            return;
544
            return;
541
        }
545
        }
Line 546... Line 550...
546
                    || (p.mobile || '').toLowerCase().indexOf(q) !== -1;
550
                    || (p.mobile || '').toLowerCase().indexOf(q) !== -1;
547
        });
551
        });
548
        renderAlLeads(filtered);
552
        renderAlLeads(filtered);
549
    });
553
    });
550
 
554
 
551
    $(document).on('change', '#alSelectAll', function () {
555
    $(document).on('change.bpdayview', '#alSelectAll', function () {
552
        $('.al-lead-chk:not(:disabled)').prop('checked', this.checked);
556
        $('.al-lead-chk:not(:disabled)').prop('checked', this.checked);
553
        updateAlSelectedCount();
557
        updateAlSelectedCount();
554
    });
558
    });
555
 
559
 
556
    $(document).on('change', '.al-lead-chk', updateAlSelectedCount);
560
    $(document).on('change.bpdayview', '.al-lead-chk', updateAlSelectedCount);
557
 
561
 
558
    function updateAlSelectedCount() {
562
    function updateAlSelectedCount() {
559
        var n = $('.al-lead-chk:checked:not(:disabled)').length;
563
        var n = $('.al-lead-chk:checked:not(:disabled)').length;
560
        $('#alSelectedCount').text(n + ' selected');
564
        $('#alSelectedCount').text(n + ' selected');
561
        $('#alSubmit').prop('disabled', n === 0);
565
        $('#alSubmit').prop('disabled', n === 0);
562
    }
566
    }
563
 
567
 
564
    $(document).on('click', '#alSubmit', function () {
568
    $(document).on('click.bpdayview', '#alSubmit', function () {
565
        var ids = [];
569
        var ids = [];
566
        $('.al-lead-chk:checked:not(:disabled)').each(function () {
570
        $('.al-lead-chk:checked:not(:disabled)').each(function () {
567
            ids.push(parseInt($(this).data('lead')));
571
            ids.push(parseInt($(this).data('lead')));
568
        });
572
        });
569
        if (ids.length === 0) return;
573
        if (ids.length === 0) return;