2017-09-20 18:49:05 +02:00
|
|
|
/* drop zone functions */
|
|
|
|
|
|
|
|
function drop_handler(ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
// if dropped items aren't files, reject them
|
|
|
|
var dt = ev.dataTransfer;
|
|
|
|
if (dt.items) {
|
|
|
|
if (dt.items[0].kind == 'file') {
|
|
|
|
var droppedFile = dt.items[0].getAsFile();
|
|
|
|
previewAndStageFile(droppedFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function dragover_handler(ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
function dragend_handler(ev) {
|
|
|
|
var dt = ev.dataTransfer;
|
|
|
|
if (dt.items) {
|
|
|
|
for (var i = 0; i < dt.items.length; i++) {
|
|
|
|
dt.items.remove(i);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ev.dataTransfer.clearData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* publish functions */
|
|
|
|
|
2017-07-06 22:37:03 +02:00
|
|
|
// update the publish status
|
|
|
|
function updatePublishStatus(msg){
|
2017-09-20 18:49:05 +02:00
|
|
|
document.getElementById('publish-status').innerHTML = msg;
|
2017-07-06 22:37:03 +02:00
|
|
|
}
|
2017-07-08 05:26:46 +02:00
|
|
|
|
2017-07-23 00:09:58 +02:00
|
|
|
// When a file is selected for publish, validate that file and
|
|
|
|
// stage it so it will be ready when the publish button is clicked.
|
2017-07-06 22:37:03 +02:00
|
|
|
function previewAndStageFile(selectedFile){
|
2017-07-08 06:08:42 +02:00
|
|
|
var previewHolder = document.getElementById('asset-preview-holder');
|
2017-07-06 22:37:03 +02:00
|
|
|
var dropzone = document.getElementById('drop-zone');
|
|
|
|
var previewReader = new FileReader();
|
2017-07-23 03:01:17 +02:00
|
|
|
var nameInput = document.getElementById('claim-name-input');
|
2017-07-23 00:09:58 +02:00
|
|
|
// validate the file's name, type, and size
|
2017-07-08 01:08:35 +02:00
|
|
|
try {
|
|
|
|
validateFile(selectedFile);
|
|
|
|
} catch (error) {
|
2017-07-14 17:57:12 +02:00
|
|
|
showError('input-error-file-selection', error.message);
|
2017-07-08 01:08:35 +02:00
|
|
|
return;
|
2017-07-06 22:37:03 +02:00
|
|
|
}
|
2017-09-20 00:39:54 +02:00
|
|
|
// set the image preview, if an image was provided
|
2017-07-23 00:09:58 +02:00
|
|
|
if (selectedFile.type !== 'video/mp4') {
|
2017-07-08 06:08:42 +02:00
|
|
|
previewReader.readAsDataURL(selectedFile);
|
|
|
|
previewReader.onloadend = function () {
|
|
|
|
dropzone.style.display = 'none';
|
|
|
|
previewHolder.style.display = 'block';
|
2017-07-28 23:39:39 +02:00
|
|
|
previewHolder.innerHTML = '<img width="100%" src="' + previewReader.result + '" alt="image preview"/>';
|
2017-07-08 06:08:42 +02:00
|
|
|
};
|
2017-07-08 05:26:46 +02:00
|
|
|
}
|
2017-07-08 01:08:35 +02:00
|
|
|
// set the name input value to the image name if none is set yet
|
|
|
|
if (nameInput.value === "") {
|
2017-07-23 00:09:58 +02:00
|
|
|
var filename = selectedFile.name.substring(0, selectedFile.name.indexOf('.'))
|
2017-07-28 23:39:39 +02:00
|
|
|
nameInput.value = cleanseClaimName(filename);
|
|
|
|
checkClaimName(nameInput.value);
|
2017-07-08 01:08:35 +02:00
|
|
|
}
|
|
|
|
// store the selected file for upload
|
|
|
|
stagedFiles = [selectedFile];
|
2017-07-06 22:37:03 +02:00
|
|
|
}
|
|
|
|
|
2017-07-23 00:09:58 +02:00
|
|
|
// Validate the publish submission and then trigger publishing.
|
|
|
|
function publishSelectedImage(event) {
|
2017-09-20 00:39:54 +02:00
|
|
|
var claimName = document.getElementById('claim-name-input').value;
|
|
|
|
var channelName = document.getElementById('channel-name-select').value;
|
2017-09-20 18:49:05 +02:00
|
|
|
// prevent default so this script can handle submission
|
|
|
|
event.preventDefault();
|
|
|
|
// validate, submit, and handle response
|
|
|
|
validateFilePublishSubmission(stagedFiles, claimName, channelName)
|
|
|
|
.then(() => {
|
2017-07-23 00:09:58 +02:00
|
|
|
uploader.submitFiles(stagedFiles);
|
|
|
|
})
|
2017-09-20 18:49:05 +02:00
|
|
|
.catch(error => {
|
2017-09-20 00:39:54 +02:00
|
|
|
if (error.name === 'FileError') {
|
|
|
|
showError(document.getElementById('input-error-file-selection'), error.message);
|
2017-07-23 00:09:58 +02:00
|
|
|
} else if (error.name === 'NameError') {
|
2017-09-20 00:39:54 +02:00
|
|
|
showError(document.getElementById('input-error-claim-name'), error.message);
|
2017-09-20 18:49:05 +02:00
|
|
|
} else if (error.name === 'ChannelNameError'){
|
2017-09-20 00:39:54 +02:00
|
|
|
console.log(error);
|
|
|
|
showError(document.getElementById('input-error-channel-select'), error.message);
|
2017-07-23 00:09:58 +02:00
|
|
|
} else {
|
2017-09-20 00:39:54 +02:00
|
|
|
showError(document.getElementById('input-error-publish-submit'), error.message);
|
2017-07-23 00:09:58 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
})
|
2017-09-20 18:49:05 +02:00
|
|
|
};
|