Subversion Repositories SmartDukaan

Rev

Rev 36666 | Rev 36685 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
36645 vikas 1
<section class="wrapper">
2
    <div class="row">
3
        <div class="col-lg-12">
4
            <h3 class="page-header"><i class="icon_document_alt"></i> $username - Visit Details ($reportDate)</h3>
5
            <ol class="breadcrumb">
6
                <li><i class="fa fa-home"></i><a href="${rc.contextPath}/dashboard">Home</a></li>
7
                <li><a href="javascript:void(0);" class="beat-report">Beat Report</a></li>
8
                <li><i class="fa fa-user"></i>$username</li>
9
            </ol>
10
        </div>
11
    </div>
12
    <br>
13
    <div class="row col-lg-12" style="float: right;">
36664 vikas 14
        <div class="col-lg-2">
15
            <label>Level</label>
16
            <select id="user-detail-level" class="form-control" data-selected="$!userLevel">
17
                <option value="">All Levels</option>
18
                #foreach($et in $escalationTypes)
19
                    <option value="$et" #if($et.name() == $userLevel)selected#end>$et</option>
20
                #end
21
            </select>
22
        </div>
36645 vikas 23
        <div class="col-lg-3">
36664 vikas 24
            <label>User</label>
25
            <select id="user-detail-user" class="form-control" data-selected-auth="$!authUserId">
26
                <option value="$!authUserId">$username</option>
27
            </select>
28
        </div>
29
        <div class="col-lg-3">
36645 vikas 30
            <label>Select Date</label>
31
            <div class="input-group">
32
                <input type="date" id="user-detail-date" class="form-control" value="$reportDate" data-userid="$userId">
33
                <span class="input-group-btn">
34
                    <button type="button" class="btn btn-info user-detail-refresh" data-userid="$userId" style="margin-left:10px;">
35
                        <i class="fa fa-refresh"></i> Refresh
36
                    </button>
36664 vikas 37
                    <button type="button" class="btn btn-success live-tracking-btn" data-userid="$userId" data-username="$username" style="margin-left:5px;">
38
                        <i class="fa fa-map-marker"></i> Live Tracking
39
                    </button>
36645 vikas 40
                </span>
41
            </div>
42
        </div>
43
    </div>
44
    <br><br><br>
45
 
46
    <div class="col-lg-12">
47
        <div class="row" style="margin-bottom:15px;">
48
            <div class="col-lg-3">
49
                <div class="panel panel-default" style="text-align:center; padding:10px;">
50
                    <h4 style="margin:0; color:#1abc9c; font-weight:bold;">$visits.size()</h4>
51
                    <small>Total Visits</small>
52
                </div>
53
            </div>
54
            #set($completedCount = 0)
55
            #set($pendingCount = 0)
56
            #set($deferredCount = 0)
57
            #foreach($v in $visits)
58
                #if($v.getMarkType() == "CHECKIN-CHECKOUT" || $v.getMarkType() == "CHECKOUT")
59
                    #set($completedCount = $completedCount + 1)
60
                #elseif($v.getMarkType() == "PENDING" || $v.getMarkType() == "CHECKIN")
61
                    #set($pendingCount = $pendingCount + 1)
62
                #elseif($v.getMarkType() == "DEFERRED")
63
                    #set($deferredCount = $deferredCount + 1)
64
                #end
65
            #end
66
            <div class="col-lg-3">
67
                <div class="panel panel-default" style="text-align:center; padding:10px;">
68
                    <h4 style="margin:0; color:#27ae60; font-weight:bold;">$completedCount</h4>
69
                    <small>Completed</small>
70
                </div>
71
            </div>
72
            <div class="col-lg-3">
73
                <div class="panel panel-default" style="text-align:center; padding:10px;">
74
                    <h4 style="margin:0; color:#e67e22; font-weight:bold;">$pendingCount</h4>
75
                    <small>Pending</small>
76
                </div>
77
            </div>
78
            <div class="col-lg-3">
79
                <div class="panel panel-default" style="text-align:center; padding:10px;">
80
                    <h4 style="margin:0; color:#e74c3c; font-weight:bold;">$deferredCount</h4>
81
                    <small>Deferred</small>
82
                </div>
83
            </div>
84
        </div>
85
 
86
        <table class="table table-border table-condensed table-bordered table-striped" id="userDetailTable" style="width:100%">
87
            <thead>
36656 vikas 88
            <tr >
36645 vikas 89
                <th>#</th>
36666 vikas 90
                <th>Agenda/Partner Name</th>
36645 vikas 91
                <th>Task Type</th>
92
                <th>Status</th>
93
                <th>Address</th>
94
                <th>Check In Time</th>
95
                <th>Check Out Time</th>
36666 vikas 96
                <th>Time Spent at Outlet</th>
36645 vikas 97
                <th>Transit Time</th>
98
                <th>Distance (km)</th>
36666 vikas 99
                <th>Estimated Time</th>
36645 vikas 100
            </tr>
101
            </thead>
102
            <tbody>
36656 vikas 103
            #if($punchIn)
104
                <tr style="background:#d5f5e3;">
105
                    <td>--</td>
106
                    <td><strong>PUNCH IN</strong></td>
107
                    <td>$!punchIn.getTaskType()</td>
108
                    <td><span class="label label-info">PUNCHIN</span> #if($punchIn.getAttachment() && $punchIn.getAttachment() != "")<a href="https://partners.smartdukaan.com/document/$punchIn.getAttachment()" target="_blank" title="View Attachment"><i class="fa fa-paperclip" style="color:#e67e22; margin-left:5px;"></i></a>#end</td>
109
                    <td>$!punchIn.getAddress()</td>
110
                    <td>$!punchIn.getCheckInTime()</td>
111
                    <td>--</td>
112
                    <td>--</td>
113
                    <td>--</td>
114
                    <td>$!punchIn.getTotalDistance()</td>
36666 vikas 115
                    <td>$!punchIn.getEstimatedTime()</td>
36656 vikas 116
                </tr>
117
            #end
36645 vikas 118
            #set($idx = 1)
119
            #foreach($v in $visits)
120
                <tr>
121
                    <td>$idx</td>
122
                    <td>$!v.getTaskName()</td>
123
                    <td>$!v.getTaskType()</td>
124
                    <td>
125
                        #if($v.getMarkType() == "CHECKIN-CHECKOUT" || $v.getMarkType() == "CHECKOUT")
126
                            <span class="label label-success">$v.getMarkType()</span>
127
                        #elseif($v.getMarkType() == "PENDING" || $v.getMarkType() == "CHECKIN")
128
                            <span class="label label-warning">$v.getMarkType()</span>
129
                        #elseif($v.getMarkType() == "DEFERRED")
130
                            <span class="label label-danger">$v.getMarkType()</span>
131
                        #else
132
                            <span class="label label-default">$!v.getMarkType()</span>
133
                        #end
36656 vikas 134
                        <a href="javascript:void(0);" class="beat-history-link" data-userid="$userId" data-taskid="$v.getTaskId()" data-tasktype="$!v.getTaskType()" data-taskname="$!v.getTaskName()" title="View History" style="margin-left:5px;"><i class="fa fa-history" style="color:#3498db; font-size:14px;"></i></a>
135
                        #if($v.getAttachment() && $v.getAttachment() != "")<a href="https://partners.smartdukaan.com/document/$v.getAttachment()" target="_blank" title="View Attachment"><i class="fa fa-paperclip" style="color:#e67e22; margin-left:3px; font-size:14px;"></i></a>#end
36645 vikas 136
                    </td>
137
                    <td>$!v.getAddress()</td>
138
                    <td>$!v.getCheckInTime()</td>
139
                    <td>$!v.getCheckOutTime()</td>
140
                    <td>$!v.getTimeSpent()</td>
141
                    <td>$!v.getTransitTime()</td>
142
                    <td>$!v.getTotalDistance()</td>
36666 vikas 143
                    <td>$!v.getEstimatedTime()</td>
36645 vikas 144
                </tr>
145
                #set($idx = $idx + 1)
146
            #end
36656 vikas 147
            #if($punchOut)
148
                <tr style="background:#fadbd8;">
149
                    <td>--</td>
150
                    <td><strong>PUNCH OUT</strong></td>
151
                    <td>$!punchOut.getTaskType()</td>
152
                    <td><span class="label label-danger">PUNCHOUT</span> #if($punchOut.getAttachment() && $punchOut.getAttachment() != "")<a href="https://partners.smartdukaan.com/document/$punchOut.getAttachment()" target="_blank" title="View Attachment"><i class="fa fa-paperclip" style="color:#e67e22; margin-left:5px;"></i></a>#end</td>
153
                    <td>$!punchOut.getAddress()</td>
154
                    <td>$!punchOut.getCheckInTime()</td>
155
                    <td>--</td>
156
                    <td>--</td>
157
                    <td>--</td>
158
                    <td>$!punchOut.getTotalDistance()</td>
36666 vikas 159
                    <td>$!punchOut.getEstimatedTime()</td>
36656 vikas 160
                </tr>
161
            #end
36645 vikas 162
            </tbody>
36656 vikas 163
            <tfoot>
164
                <tr style="background:#f2f3f4; font-weight:bold;">
165
                    <td colspan="5" style="text-align:right;">Totals</td>
166
                    <td>--</td>
167
                    <td>--</td>
168
                    <td>$totalTimeSpentStr</td>
169
                    <td>$totalTransitStr</td>
170
                    <td>$totalDistanceStr km | Visits: $visitCount | Leads: $leadCount</td>
36666 vikas 171
                    <td></td>
36656 vikas 172
                </tr>
173
            </tfoot>
36645 vikas 174
        </table>
175
    </div>
176
</section>
177
 
36656 vikas 178
<!-- Task History Modal -->
179
<div class="modal fade" id="taskHistoryModal" tabindex="-1" role="dialog">
180
    <div class="modal-dialog modal-lg" role="document" style="width:85%;">
181
        <div class="modal-content">
182
            <div class="modal-header" style="background:#3498db; color:white;">
183
                <button type="button" class="close" data-dismiss="modal" style="color:white;">&times;</button>
184
                <h4 class="modal-title" id="taskHistoryModalTitle">Task History</h4>
185
            </div>
186
            <div class="modal-body" id="taskHistoryModalBody">
187
                <div class="text-center"><i class="fa fa-spinner fa-spin fa-2x"></i> Loading...</div>
188
            </div>
189
            <div class="modal-footer">
190
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
191
            </div>
192
        </div>
193
    </div>
194
</div>
195
 
36664 vikas 196
<!-- Live Tracking Modal -->
197
<div class="modal fade" id="liveTrackingModal" tabindex="-1" role="dialog">
198
    <div class="modal-dialog modal-lg" role="document" style="width:90%;">
199
        <div class="modal-content">
200
            <div class="modal-header" style="background:#27ae60; color:white;">
201
                <button type="button" class="close" data-dismiss="modal" style="color:white;">&times;</button>
202
                <h4 class="modal-title" id="liveTrackingModalTitle"><i class="fa fa-map-marker"></i> Live Tracking</h4>
203
            </div>
204
            <div class="modal-body" style="padding:0;">
205
                <div id="liveTrackingInfo" style="padding:8px 15px; background:#f8f9fa; border-bottom:1px solid #ddd; font-size:13px;"></div>
206
                <div id="liveTrackingMap" style="height:500px; width:100%;"></div>
207
            </div>
208
            <div class="modal-footer">
36682 vikas 209
                <label style="float:left; margin-top:7px; font-weight:normal; font-size:13px;">
210
                    <input type="checkbox" id="autoRefreshToggle" checked style="margin-right:5px;"> Auto-refresh (30s)
211
                </label>
36664 vikas 212
                <button type="button" class="btn btn-primary" id="refreshTrackingBtn"><i class="fa fa-refresh"></i> Refresh</button>
213
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
214
            </div>
215
        </div>
216
    </div>
217
</div>
218
 
36645 vikas 219
<script>
220
    $('#userDetailTable').DataTable({
221
        "scrollX": true,
222
        "bPaginate": true,
223
        "bLengthChange": true,
224
        "bFilter": true,
225
        "bInfo": true,
226
        "bAutoWidth": false
227
    });
36656 vikas 228
 
36664 vikas 229
    (function () {
230
        var level = $('#user-detail-level').data('selected');
231
        var selectedAuth = $('#user-detail-user').data('selected-auth');
232
        if (level && selectedAuth) {
233
            $.ajax({
234
                url: context + "/beatPlan/getAuthUsers", type: "GET", dataType: "json",
235
                data: { categoryId: 4, escalationType: level },
236
                success: function (r) {
237
                    var data = r.response || r;
238
                    var html = '<option value="">Select User</option>';
239
                    data.forEach(function (u) {
240
                        html += '<option value="' + u.id + '"' + (u.id == selectedAuth ? ' selected' : '') + '>' + u.name + '</option>';
241
                    });
242
                    $('#user-detail-user').html(html);
243
                }
244
            });
245
        }
246
    })();
247
 
248
    $(document).off('click.beatdetail').off('click.livetrack');
249
 
250
    $(document).on('click.beatdetail', '.beat-history-link', function () {
36656 vikas 251
        var userId = $(this).data('userid');
252
        var taskId = $(this).data('taskid');
253
        var taskType = $(this).data('tasktype');
254
        var taskName = $(this).data('taskname');
255
 
256
        $('#taskHistoryModalTitle').text('History - ' + taskName);
257
        $('#taskHistoryModalBody').html('<div class="text-center"><i class="fa fa-spinner fa-spin fa-2x"></i> Loading...</div>');
258
        $('#taskHistoryModal').modal('show');
259
 
260
        doGetAjaxRequestHandler(context + "/beat-report/task-history?userId=" + userId + "&taskId=" + taskId + "&taskType=" + encodeURIComponent(taskType),
261
            function (response) {
262
                $('#taskHistoryModalBody').html(response);
263
            });
264
    });
36664 vikas 265
 
266
    var liveTrackingMap = null;
267
    var liveTrackingUserId = null;
268
    var liveTrackingInterval = null;
269
 
270
    function getMarkerColor(markType) {
271
        if (markType === 'CHECKIN-CHECKOUT' || markType === 'CHECKOUT') return '#0F9D58';
272
        if (markType === 'PENDING' || markType === 'CHECKIN') return '#4285F4';
273
        if (markType === 'DEFERRED') return '#DB4437';
274
        if (markType === 'PUNCHIN') return '#1abc9c';
275
        if (markType === 'PUNCHOUT') return '#e74c3c';
276
        return '#F4B400';
277
    }
278
 
279
    function createTrackingMarkerIcon(color, label) {
280
        var svg = '<svg xmlns="http://www.w3.org/2000/svg" width="28" height="40" viewBox="0 0 28 40">' +
281
            '<path d="M14 0C6.268 0 0 6.268 0 14c0 10.5 14 26 14 26s14-15.5 14-26C28 6.268 21.732 0 14 0z" fill="' + color + '"/>' +
282
            '<circle cx="14" cy="14" r="7" fill="white"/>' +
283
            '<text x="14" y="18" text-anchor="middle" font-size="10" font-weight="bold" fill="' + color + '">' + label + '</text></svg>';
284
        return 'data:image/svg+xml;charset=UTF-8,' + encodeURIComponent(svg);
285
    }
286
 
287
    function loadLiveTracking(userId, username) {
288
        var selectedDate = $('#user-detail-date').val();
289
        $.ajax({
290
            url: context + "/beat-report/live-tracking",
291
            type: "GET",
292
            dataType: "json",
293
            data: { userId: userId, date: selectedDate },
294
            success: function (data) {
295
                renderLiveTrackingMap(data, username);
296
            },
297
            error: function () {
298
                $('#liveTrackingInfo').html('<span style="color:red;">Failed to load tracking data.</span>');
299
            }
300
        });
301
    }
302
 
303
    function renderLiveTrackingMap(data, username) {
304
        var visits = data.visits || [];
305
        var pathPoints = data.pathPoints || [];
306
 
307
        if (!liveTrackingMap) {
308
            liveTrackingMap = new google.maps.Map(document.getElementById('liveTrackingMap'), {
309
                zoom: 12,
310
                center: { lat: 20.5937, lng: 78.9629 },
311
                mapTypeControl: true,
312
                streetViewControl: false
313
            });
314
        }
315
 
316
        if (liveTrackingMap._markers) {
317
            liveTrackingMap._markers.forEach(function (m) { m.setMap(null); });
318
        }
319
        if (liveTrackingMap._polyline) {
320
            liveTrackingMap._polyline.setMap(null);
321
        }
36682 vikas 322
        if (liveTrackingMap._visitRoute) {
323
            liveTrackingMap._visitRoute.setMap(null);
324
        }
36664 vikas 325
        if (liveTrackingMap._currentMarker) {
326
            liveTrackingMap._currentMarker.setMap(null);
327
        }
328
        liveTrackingMap._markers = [];
329
 
330
        var bounds = new google.maps.LatLngBounds();
331
        var hasPoints = false;
332
        var visitIdx = 0;
333
 
334
        for (var i = 0; i < visits.length; i++) {
335
            var v = visits[i];
336
            if (!v.lat || !v.lng) continue;
337
            var lat = parseFloat(v.lat);
338
            var lng = parseFloat(v.lng);
339
            if (isNaN(lat) || isNaN(lng) || (lat === 0 && lng === 0)) continue;
340
 
341
            hasPoints = true;
342
            var pos = { lat: lat, lng: lng };
343
            bounds.extend(pos);
344
 
345
            var label = v.markType === 'PUNCHIN' ? 'P' : (v.markType === 'PUNCHOUT' ? 'X' : String(++visitIdx));
346
            var marker = new google.maps.Marker({
347
                position: pos,
348
                map: liveTrackingMap,
349
                icon: {
350
                    url: createTrackingMarkerIcon(getMarkerColor(v.markType), label),
351
                    scaledSize: new google.maps.Size(28, 40),
352
                    anchor: new google.maps.Point(14, 40)
353
                },
354
                title: v.taskName + ' (' + v.markType + ')'
355
            });
356
 
357
            var infoContent = '<div style="font-size:13px; max-width:250px;">' +
358
                '<strong>' + (v.taskName || '') + '</strong><br>' +
359
                '<span class="label" style="background:' + getMarkerColor(v.markType) + '; color:white;">' + v.markType + '</span><br>' +
360
                (v.checkInTime ? '<i class="fa fa-sign-in"></i> ' + v.checkInTime + '<br>' : '') +
361
                (v.checkOutTime ? '<i class="fa fa-sign-out"></i> ' + v.checkOutTime + '<br>' : '') +
362
                (v.address ? '<i class="fa fa-map-marker"></i> ' + v.address : '') +
363
                '</div>';
364
            (function (m, c) {
365
                var iw = new google.maps.InfoWindow({ content: c });
366
                m.addListener('click', function () { iw.open(liveTrackingMap, m); });
367
            })(marker, infoContent);
368
 
369
            liveTrackingMap._markers.push(marker);
370
        }
371
 
36682 vikas 372
        // Draw visit-to-visit route (dashed line with arrows)
373
        var visitCoords = [];
374
        for (var vi = 0; vi < visits.length; vi++) {
375
            var vv = visits[vi];
376
            if (!vv.lat || !vv.lng) continue;
377
            var vLat = parseFloat(vv.lat);
378
            var vLng = parseFloat(vv.lng);
379
            if (isNaN(vLat) || isNaN(vLng) || (vLat === 0 && vLng === 0)) continue;
380
            visitCoords.push({ lat: vLat, lng: vLng });
381
        }
382
        if (visitCoords.length > 1) {
383
            liveTrackingMap._visitRoute = new google.maps.Polyline({
384
                path: visitCoords,
385
                geodesic: true,
386
                strokeColor: '#8e44ad',
387
                strokeOpacity: 0,
388
                strokeWeight: 3,
389
                icons: [{
390
                    icon: { path: 'M 0,-1 0,1', strokeOpacity: 0.6, strokeWeight: 3, scale: 3 },
391
                    offset: '0',
392
                    repeat: '16px'
393
                }, {
394
                    icon: { path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW, strokeOpacity: 0.8, scale: 3 },
395
                    offset: '50%',
396
                    repeat: '200px'
397
                }],
398
                map: liveTrackingMap
399
            });
400
        }
401
 
36664 vikas 402
        if (pathPoints.length > 0) {
403
            var pathCoords = [];
404
            for (var j = 0; j < pathPoints.length; j++) {
405
                var pt = pathPoints[j];
406
                var pLat = parseFloat(pt.lat);
407
                var pLng = parseFloat(pt.lng);
408
                if (isNaN(pLat) || isNaN(pLng) || (pLat === 0 && pLng === 0)) continue;
409
                pathCoords.push({ lat: pLat, lng: pLng });
410
                bounds.extend({ lat: pLat, lng: pLng });
411
                hasPoints = true;
412
            }
413
 
414
            if (pathCoords.length > 0) {
415
                liveTrackingMap._polyline = new google.maps.Polyline({
416
                    path: pathCoords,
417
                    geodesic: true,
418
                    strokeColor: '#3498db',
419
                    strokeOpacity: 0.8,
420
                    strokeWeight: 3,
421
                    map: liveTrackingMap
422
                });
423
 
424
                var lastPoint = pathCoords[pathCoords.length - 1];
425
                liveTrackingMap._currentMarker = new google.maps.Marker({
426
                    position: lastPoint,
427
                    map: liveTrackingMap,
428
                    icon: {
429
                        path: google.maps.SymbolPath.CIRCLE,
430
                        scale: 10,
431
                        fillColor: '#e74c3c',
432
                        fillOpacity: 1,
433
                        strokeColor: '#ffffff',
434
                        strokeWeight: 3
435
                    },
436
                    title: 'Last Known Location',
437
                    zIndex: 999
438
                });
439
 
440
                var lastTs = pathPoints[pathPoints.length - 1].timestamp || 'N/A';
441
                var currentIw = new google.maps.InfoWindow({
442
                    content: '<div style="font-size:13px;"><strong><i class="fa fa-crosshairs"></i> Last Known Location</strong><br>Time: ' + lastTs + '</div>'
443
                });
444
                liveTrackingMap._currentMarker.addListener('click', function () {
445
                    currentIw.open(liveTrackingMap, liveTrackingMap._currentMarker);
446
                });
447
            }
448
        }
449
 
450
        if (hasPoints) {
451
            liveTrackingMap.fitBounds(bounds);
452
        }
453
 
454
        var totalVisits = visits.filter(function (v) { return v.markType !== 'PUNCHIN' && v.markType !== 'PUNCHOUT'; }).length;
455
        var completedVisits = visits.filter(function (v) { return v.markType === 'CHECKIN-CHECKOUT' || v.markType === 'CHECKOUT'; }).length;
36682 vikas 456
        var now = new Date();
457
        var timeStr = now.getHours().toString().padStart(2, '0') + ':' + now.getMinutes().toString().padStart(2, '0') + ':' + now.getSeconds().toString().padStart(2, '0');
36664 vikas 458
        $('#liveTrackingInfo').html(
459
            '<strong>' + username + '</strong> | ' +
460
            'Visits: <strong>' + totalVisits + '</strong> | ' +
461
            'Completed: <strong>' + completedVisits + '</strong> | ' +
462
            'Path Points: <strong>' + pathPoints.length + '</strong>' +
36682 vikas 463
            (pathPoints.length > 0 ? ' | <span style="color:#e74c3c;"><i class="fa fa-circle"></i></span> Last Known' : '') +
464
            ' | <span style="color:#3498db;">━</span> GPS Path' +
465
            (visitCoords.length > 1 ? ' | <span style="color:#8e44ad;">┅</span> Visit Route' : '') +
466
            ' | <span style="color:#999;">Updated: ' + timeStr + '</span>'
36664 vikas 467
        );
468
    }
469
 
470
    function ensureGoogleMaps(callback) {
471
        if (window.google && window.google.maps) {
472
            callback();
473
            return;
474
        }
475
        var s = document.createElement('script');
476
        s.src = 'https://maps.googleapis.com/maps/api/js?key=AIzaSyAckO0y4Z6WhBOuMjNjioWLSYZDhGEvGBc&v=weekly';
477
        s.onload = callback;
478
        document.head.appendChild(s);
479
    }
480
 
36682 vikas 481
    var liveTrackingUsername = '';
482
 
483
    function startAutoRefresh() {
484
        stopAutoRefresh();
485
        if ($('#autoRefreshToggle').is(':checked') && liveTrackingUserId) {
486
            liveTrackingInterval = setInterval(function () {
487
                loadLiveTracking(liveTrackingUserId, liveTrackingUsername);
488
            }, 30000);
489
        }
490
    }
491
 
492
    function stopAutoRefresh() {
493
        if (liveTrackingInterval) {
494
            clearInterval(liveTrackingInterval);
495
            liveTrackingInterval = null;
496
        }
497
    }
498
 
36664 vikas 499
    $(document).on('click.livetrack', '.live-tracking-btn', function () {
500
        liveTrackingUserId = $(this).data('userid');
36682 vikas 501
        liveTrackingUsername = $(this).data('username');
502
        $('#liveTrackingModalTitle').html('<i class="fa fa-map-marker"></i> Live Tracking - ' + liveTrackingUsername);
36664 vikas 503
        $('#liveTrackingInfo').html('<div class="text-center"><i class="fa fa-spinner fa-spin"></i> Loading...</div>');
504
        $('#liveTrackingModal').modal('show');
505
 
506
        setTimeout(function () {
507
            liveTrackingMap = null;
508
            ensureGoogleMaps(function () {
36682 vikas 509
                loadLiveTracking(liveTrackingUserId, liveTrackingUsername);
510
                startAutoRefresh();
36664 vikas 511
            });
512
        }, 300);
513
    });
514
 
515
    $(document).on('click.livetrack', '#refreshTrackingBtn', function () {
516
        if (liveTrackingUserId) {
517
            $('#liveTrackingInfo').html('<div class="text-center"><i class="fa fa-spinner fa-spin"></i> Refreshing...</div>');
36682 vikas 518
            loadLiveTracking(liveTrackingUserId, liveTrackingUsername);
36664 vikas 519
        }
520
    });
521
 
36682 vikas 522
    $(document).on('change', '#autoRefreshToggle', function () {
523
        if ($(this).is(':checked')) {
524
            startAutoRefresh();
525
        } else {
526
            stopAutoRefresh();
36664 vikas 527
        }
528
    });
36682 vikas 529
 
530
    $('#liveTrackingModal').on('hidden.bs.modal', function () {
531
        stopAutoRefresh();
532
        liveTrackingUserId = null;
533
    });
36645 vikas 534
</script>