-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathinspectionimages.js
More file actions
94 lines (79 loc) · 3.38 KB
/
Copy pathinspectionimages.js
File metadata and controls
94 lines (79 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
define(['views/dialog',
'utils/xhrimage',
'modules/imaging/collections/inspectionimages',
], function(DialogView,
XHRImage,
InspectionImages) {
return DialogView.extend({
template: '<div><ul class="images"></ul></div>',
ui: {
images: '.images',
},
initialize: function(options) {
// disable scrolling on the main page
$('body').addClass('dialog-open')
this.inspectionimages = new InspectionImages()
this.inspectionimages.queryParams.iid = options.CONTAINERINSPECTIONID
this.inspectionimages.queryParams.sort_by = 'LOCATION'
},
inspectionLoaded: function() {
var self = this
const loadDelay = 200 // milliseconds
this.imageTimers = new Map() // Track timers per image
this.observer = new IntersectionObserver(function(entries, observer) {
entries.forEach(entry => {
const img = $(entry.target)
if (entry.isIntersecting) {
// Start a delayed load
const timerId = setTimeout(() => {
let im = new XHRImage()
im.load(img.data('src'), function(loadedImage) {
img.attr('src', loadedImage.src)
})
observer.unobserve(entry.target) // Unobserve after loading
self.imageTimers.delete(entry.target)
}, loadDelay)
// Store timer so we can cancel if needed
self.imageTimers.set(entry.target, timerId)
} else {
// No longer visible: cancel pending load if exists
const timerId = self.imageTimers.get(entry.target)
if (timerId) {
clearTimeout(timerId)
self.imageTimers.delete(entry.target)
}
}
})
})
this.inspectionimages.each(function(inspectionimage) {
let locationEl = $('<li></li>').text(inspectionimage.get('LOCATION'))
let imageEl = $('<img>').css('min-height', '400px')
.data('src', app.apiurl + '/imaging/inspection/image/' + inspectionimage.get('BLSAMPLEIMAGEID') + '?f=1')
locationEl.append(imageEl)
self.ui.images.append(locationEl)
self.observer.observe(imageEl[0])
})
},
onRender: function() {
this.inspectionimages.fetch().done(this.inspectionLoaded.bind(this))
},
closeDialog: function(e) {
DialogView.prototype.closeDialog.apply(this, arguments)
this.destroy()
},
onDestroy: function() {
// re-enable scrolling on the main page
$('body').removeClass('dialog-open')
if (this.observer) {
this.observer.disconnect()
}
// Cancel all pending image timers
if (this.imageTimers) {
for (const timer of this.imageTimers.values()) {
clearTimeout(timer)
}
this.imageTimers.clear()
}
},
})
})