-
Notifications
You must be signed in to change notification settings - Fork 6
/
staff.js
100 lines (75 loc) · 2.84 KB
/
staff.js
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
95
96
97
98
99
100
var assignedClosure = null,
deliveredClosure = null;
$(document).ready(function () {
var assignStr = "";
// popup dialog assign order to staff on click
$("#confirm-assign a").click(function (e) {
e.preventDefault();
// if staff clicked OK on assign popup dialog, proceed
if ($(this)[0] == $("#confirm-assign a:first")[0]) {
$.post("/staff/assign", assignStr, function(data) {
if ($(data.assign).unwrap().html() === $("#logged-in span").text()) {
socket.emit("assigned", {staff: data.assign, ID: data.ID})
$.colorbox.close();
$("tr td:contains('" + data.ID + "')").parent().children("td:nth-child(6)")
.html("<a href='delivered/?" + assignStr + "' class=delivered>assigned</a>").next().html(data.assign)
$(".delivered").on("click", deliveredClosure)
}
})
}
else {
$.colorbox.close();
}
});
assignedClosure = function(context) {
return function (e) {
e.preventDefault();
var customer = $(this).parent().siblings().eq(1).text().trim();
assignStr = "customer=" + encodeURIComponent(customer) + "&ID=" + $(this).parent().siblings().eq(4).text().trim();
// Customizing colorbox
$("#colorbox").click(CustomizingColorbox);
$("#confirm-assign").css("display", "flex");
$("body").css("overflow-y", "hidden");
// plugin colorbox upon it
$(this).colorbox({inline: true, width: '80%', onClosed: function(){
$("#confirm-assign").hide();
$("body").css("overflow-y", "initial");
}
});
return context;
}
}
function CustomizingColorbox(e) {
// remove colorbox when outside popup dialog is clicked
if ($("#confirm-assign").has($(e.target)).length > 0 || e.target == $("#confirm-assign")[0]) {
e.target.removeEventListener("click", CustomizingColorbox);
}
else {
$("#cboxOverlay").trigger("click");
}
}
// asynchronously assign order to staff
$('.nobody').click(assignedClosure($('.nobody')).bind($('.nobody')));
// get requests to deliver orders
deliveredClosure = function(context) {
return function (e) {
var that = $(this);
e.preventDefault();
$.get($(this).attr("href"), function(data) {
if (data.customer != undefined) {
that.html("delivered");
socket.emit("delivered", {staff: data.assign, ID: data.ID})
}
});
return context;
}
}
// wrap assigned orders in class and callback on page load
var assigned = $("td:contains('assigned')");
assigned.each(function() {
$(this).html(`<a href=delivered/?customer=${encodeURIComponent($(this).siblings().eq(1).text().trim())}&ID=${$(this).siblings().eq(4).text().trim()}>assigned</a>`)
})
.children().addClass('delivered');
$('.delivered').click(deliveredClosure($('.delivered')).bind($('.delivered')));
// se fin
})