2016-05-11 23:07:57 +00:00
|
|
|
var checkinApp = new Vue({
|
|
|
|
|
el: '#app',
|
|
|
|
|
data: {
|
|
|
|
|
attendees: [],
|
|
|
|
|
searchTerm: '',
|
|
|
|
|
searchResultsCount: 0,
|
|
|
|
|
showScannerModal: false,
|
|
|
|
|
workingAway: false,
|
|
|
|
|
isInit: false,
|
|
|
|
|
isScanning: false,
|
|
|
|
|
videoElement: $('video#scannerVideo')[0],
|
|
|
|
|
canvasElement: $('canvas#QrCanvas')[0],
|
|
|
|
|
scannerDataUrl: '',
|
|
|
|
|
QrTimeout: null,
|
|
|
|
|
canvasContext: $('canvas#QrCanvas')[0].getContext('2d'),
|
|
|
|
|
successBeep: new Audio('/mp3/beep.mp3'),
|
|
|
|
|
scanResult: false,
|
|
|
|
|
scanResultMessage: '',
|
|
|
|
|
scanResultType: null
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
created: function () {
|
|
|
|
|
this.fetchAttendees()
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
ready: function () {
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
|
fetchAttendees: function () {
|
|
|
|
|
this.$http.post(Attendize.checkInSearchRoute, {q: this.searchTerm}).then(function (res) {
|
|
|
|
|
this.attendees = res.data;
|
|
|
|
|
this.searchResultsCount = (Object.keys(res.data).length);
|
|
|
|
|
}, function () {
|
|
|
|
|
console.log('Failed to fetch attendees')
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
toggleCheckin: function (attendee) {
|
2016-04-11 15:57:00 +00:00
|
|
|
|
2016-05-11 23:07:57 +00:00
|
|
|
if(this.workingAway) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.workingAway = true;
|
|
|
|
|
var that = this;
|
2016-04-11 15:57:00 +00:00
|
|
|
|
|
|
|
|
|
2016-05-11 23:07:57 +00:00
|
|
|
var checkinData = {
|
|
|
|
|
checking: attendee.has_arrived ? 'out' : 'in',
|
|
|
|
|
attendee_id: attendee.id,
|
|
|
|
|
};
|
2016-04-11 15:57:00 +00:00
|
|
|
|
2016-05-11 23:07:57 +00:00
|
|
|
this.$http.post(Attendize.checkInRoute, checkinData).then(function (res) {
|
|
|
|
|
if (res.data.status == 'success' || res.data.status == 'error') {
|
|
|
|
|
if (res.data.status == 'error') {
|
|
|
|
|
alert(res.data.message);
|
2016-04-11 15:57:00 +00:00
|
|
|
}
|
2016-05-11 23:07:57 +00:00
|
|
|
attendee.has_arrived = checkinData.checking == 'out' ? 0 : 1;
|
|
|
|
|
that.workingAway = false;
|
2016-04-11 15:57:00 +00:00
|
|
|
} else {
|
2016-05-11 23:07:57 +00:00
|
|
|
/* @todo handle error*/
|
|
|
|
|
that.workingAway = false;
|
2016-04-11 15:57:00 +00:00
|
|
|
}
|
2016-05-11 23:07:57 +00:00
|
|
|
});
|
2016-04-11 15:57:00 +00:00
|
|
|
|
2016-05-11 23:07:57 +00:00
|
|
|
},
|
|
|
|
|
clearSearch: function () {
|
|
|
|
|
this.searchTerm = '';
|
|
|
|
|
this.fetchAttendees();
|
|
|
|
|
},
|
2016-04-11 15:57:00 +00:00
|
|
|
|
2016-05-11 23:07:57 +00:00
|
|
|
/* QR Scanner Methods */
|
2016-04-11 15:57:00 +00:00
|
|
|
|
2016-05-11 23:07:57 +00:00
|
|
|
QrCheckin: function (attendeeReferenceCode) {
|
2016-04-11 15:57:00 +00:00
|
|
|
|
2016-05-11 23:07:57 +00:00
|
|
|
this.isScanning = false;
|
2016-04-11 15:57:00 +00:00
|
|
|
|
2016-05-11 23:07:57 +00:00
|
|
|
this.$http.post(Attendize.qrcodeCheckInRoute, {attendee_reference: attendeeReferenceCode}).then(function (res) {
|
|
|
|
|
this.successBeep.play();
|
|
|
|
|
this.scanResult = true;
|
|
|
|
|
this.scanResultMessage = res.data.message;
|
|
|
|
|
this.scanResultType = res.data.status;
|
2016-04-11 15:57:00 +00:00
|
|
|
|
2016-05-11 23:07:57 +00:00
|
|
|
}, function (response) {
|
|
|
|
|
this.scanResultMessage = 'Something went wrong! Refresh the page and try again';
|
|
|
|
|
});
|
|
|
|
|
},
|
2016-04-11 15:57:00 +00:00
|
|
|
|
2016-05-11 23:07:57 +00:00
|
|
|
showQrModal: function () {
|
|
|
|
|
this.showScannerModal = true;
|
|
|
|
|
this.initScanner();
|
|
|
|
|
},
|
2016-04-11 15:57:00 +00:00
|
|
|
|
2016-05-11 23:07:57 +00:00
|
|
|
initScanner: function () {
|
|
|
|
|
|
|
|
|
|
var that = this;
|
|
|
|
|
this.isScanning = true;
|
|
|
|
|
this.scanResult = false;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
If the scanner is already initiated clear it and start over.
|
|
|
|
|
*/
|
|
|
|
|
if (this.isInit) {
|
|
|
|
|
clearTimeout(this.QrTimeout);
|
|
|
|
|
this.QrTimeout = setTimeout(function () {
|
|
|
|
|
that.captureQrToCanvas();
|
|
|
|
|
}, 500);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-04-11 15:57:00 +00:00
|
|
|
|
2016-05-11 23:07:57 +00:00
|
|
|
qrcode.callback = this.QrCheckin;
|
|
|
|
|
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
|
2016-04-11 15:57:00 +00:00
|
|
|
|
2016-05-11 23:07:57 +00:00
|
|
|
navigator.getUserMedia({video: true, audio: false}, function (stream) {
|
2016-05-22 23:57:50 +00:00
|
|
|
|
|
|
|
|
that.stream = stream;
|
|
|
|
|
|
2016-05-11 23:07:57 +00:00
|
|
|
if (window.webkitURL) {
|
|
|
|
|
that.videoElement.src = window.webkitURL.createObjectURL(stream);
|
|
|
|
|
} else {
|
|
|
|
|
that.videoElement.mozSrcObject = stream;
|
|
|
|
|
}
|
2016-04-29 12:44:28 +00:00
|
|
|
|
2016-05-11 23:07:57 +00:00
|
|
|
that.videoElement.play();
|
2016-04-11 15:57:00 +00:00
|
|
|
|
2016-05-11 23:07:57 +00:00
|
|
|
}, function () { /* error*/
|
|
|
|
|
});
|
2016-04-11 15:57:00 +00:00
|
|
|
|
2016-05-11 23:07:57 +00:00
|
|
|
this.isInit = true;
|
|
|
|
|
this.QrTimeout = setTimeout(function () {
|
|
|
|
|
that.captureQrToCanvas();
|
|
|
|
|
}, 500);
|
2016-04-11 15:57:00 +00:00
|
|
|
|
|
|
|
|
},
|
2016-05-11 23:07:57 +00:00
|
|
|
/**
|
|
|
|
|
* Takes stills from the video stream and sends them to the canvas so
|
|
|
|
|
* they can be analysed for QR codes.
|
|
|
|
|
*/
|
|
|
|
|
captureQrToCanvas: function () {
|
|
|
|
|
|
|
|
|
|
if (!this.isInit) {
|
|
|
|
|
return;
|
2016-04-11 15:57:00 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-11 23:07:57 +00:00
|
|
|
this.canvasContext.clearRect(0, 0, 600, 300);
|
2016-04-11 15:57:00 +00:00
|
|
|
|
2016-05-11 23:07:57 +00:00
|
|
|
try {
|
|
|
|
|
this.canvasContext.drawImage(this.videoElement, 0, 0);
|
|
|
|
|
try {
|
|
|
|
|
qrcode.decode();
|
|
|
|
|
}
|
|
|
|
|
catch (e) {
|
|
|
|
|
console.log(e);
|
|
|
|
|
this.QrTimeout = setTimeout(this.captureQrToCanvas, 500);
|
|
|
|
|
}
|
2016-04-11 15:57:00 +00:00
|
|
|
}
|
2016-05-11 23:07:57 +00:00
|
|
|
catch (e) {
|
2016-04-11 15:57:00 +00:00
|
|
|
console.log(e);
|
2016-05-11 23:07:57 +00:00
|
|
|
this.QrTimeout = setTimeout(this.captureQrToCanvas, 500);
|
|
|
|
|
}
|
2016-04-11 15:57:00 +00:00
|
|
|
},
|
2016-05-11 23:07:57 +00:00
|
|
|
closeScanner: function () {
|
|
|
|
|
clearTimeout(this.QrTimeout);
|
|
|
|
|
this.showScannerModal = false;
|
2016-05-22 23:57:50 +00:00
|
|
|
track = this.stream.getTracks()[0];
|
|
|
|
|
track.stop();
|
2016-04-11 15:57:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
2016-05-11 23:07:57 +00:00
|
|
|
});
|
2016-04-11 15:57:00 +00:00
|
|
|
|