(function (window, document, $) { "use strict"; var attachmentUploader = function ($host) { var self = this; self.$host = $host; self.uploadUrl = $host.attr('data-uploadurl'); self.dropTarget = $host.find('.Disco-AttachmentUpload-DropTarget'); self.uploadProgressContainer = $host.find('.Disco-AttachmentUpload-Progress'); // #region File Selection Support self._uploadFilesInput = null; self.uploadFiles = function () { if (!!self._uploadFilesInput) { self._uploadFilesInput.remove(); } self._uploadFilesInput = $(''); self._uploadFilesInput.attr({ type: 'file', multiple: 'multiple', title: 'Disco ICT File Uploading' }) .hide() .change(function (e) { var files = e.target.files; if (!!files && files.length > 0) { self._uploadFiles(files); } self._uploadFilesInput.remove(); }).appendTo(self.uploadProgressContainer) .click(); }; // #endregion // #region File Drop Support if (!!self.dropTarget) { var $document = $(document); var dragFinished = false; var dragFinishedToken = null; $document.on('dragover', function () { self.dropTarget.addClass('dragHighlight'); self.dropTarget.removeClass('dragHover'); dragFinished = false; }); $document.on('dragleave', function () { if (!!dragFinishedToken) window.clearInterval(dragFinishedToken); dragFinished = true; window.setTimeout(function () { if (dragFinished) self.dropTarget.removeClass('dragHighlight'); dragFinishedToken = null; }, 200); }); self.dropTarget.on('dragover', function (e) { e.stopPropagation(); e.preventDefault(); self.dropTarget.addClass('dragHover'); dragFinished = false; e.originalEvent.dataTransfer.dropEffect = 'copy'; }); self.dropTarget.on('drop', function (e) { e.stopPropagation(); e.preventDefault(); dragFinished = true; self.dropTarget.removeClass('dragHighlight'); var files = e.originalEvent.dataTransfer.files; self._uploadFiles(files); }); } // #endregion // #region Webcam Support self.uploadImage = function () { let mediaStream = null; let videoStreaming = false; // Setup Dialog var dialog = $('
') .attr({ id: 'Disco_AttachmentUpload_ImageDialog', title: 'Upload Image', 'class': 'dialog Disco-AttachmentUpload-ImageDialog' }); dialog.dialog({ autoOpen: true, draggable: false, modal: true, resizable: false, width: 720, height: 405, close: function () { if (mediaStream) { mediaStream.getTracks().forEach(track => track.stop()); } window.setTimeout(function () { dialog.dialog('destroy'); }, 1); } }).closest('.ui-dialog').children('.ui-dialog-titlebar').css('border-bottom', 'none'); const video = dialog.find('video')[0]; navigator.mediaDevices .getUserMedia({ audio: false, video: { width: { ideal: 1920 }, height: { ideal: 1080 }, facingMode: 'environment' } }) .then(stream => { mediaStream = stream; video.srcObject = stream; video.play(); }) .catch(err => { console.error(err); dialog.dialog('destroy'); }); video.addEventListener('canplay', ev => { if (!videoStreaming) { const width = 720; let height = video.videoHeight / (video.videoWidth / width); if (isNaN(height)) { height = 405; } video.setAttribute('width', width); video.setAttribute('height', height); videoStreaming = true; dialog.dialog('option', 'buttons', [{ text: 'Capture', click: () => { const canvas = document.createElement('canvas'); canvas.width = video.videoWidth; canvas.height = video.videoHeight; const context = canvas.getContext('2d'); context.drawImage(video, 0, 0); canvas.toBlob(blob => { self._uploadImage(blob); }, 'image/jpg'); } }]); dialog.css('height', ''); dialog.closest('.ui-dialog') .children('.ui-dialog-buttonpane') .css('margin-top', 0) .find('.ui-button:first').focus(); } }) }; // #endregion // #region Helpers self.getFileComments = function (fileName, thumbnailHandler, complete) { var result = false; var dialog = $('| File Name: | |
|---|---|
| Comments: | |