thrimbletrimmer: manual link and download buttons: cleanup, error handling, no-auth mode

pull/116/head
Mike Lang 5 years ago
parent b06721df07
commit cdd286c0ee

@ -97,7 +97,7 @@
<a id="UltrawideButton" style="float:right;margin-right:10px;" href="JavaScript:toggleUltrawide();">Ultrawide</a> <a id="UltrawideButton" style="float:right;margin-right:10px;" href="JavaScript:toggleUltrawide();">Ultrawide</a>
</div> </div>
<div id="ManualLinkPane" style="display:none"> <div id="ManualLinkPane" style="display:none">
<input id="ManualLink" /> <input type="button" onclick="thrimbletrimmerManualLink()" value="Set Link" /> <input id="ManualLink" /> <input type="button" id="ManualButton" onclick="thrimbletrimmerManualLink()" value="Set Link" />
</div> </div>
<div id="HelpPane" style="display:none;"> <div id="HelpPane" style="display:none;">
<ul> <ul>

@ -154,36 +154,66 @@ thrimbletrimmerDownload = function() {
}; };
thrimbletrimmerManualLink = function() { thrimbletrimmerManualLink = function() {
document.getElementById("ManualButton").disabled = true;
var rowId = /id=(.*)(?:&|$)/.exec(document.location.search)[1]; var rowId = /id=(.*)(?:&|$)/.exec(document.location.search)[1];
body = {link: document.getElementById("ManualLink").value};
if (!!user) {
body.token = user.getAuthResponse().id_token;
}
fetch("/thrimshim/manual-link/"+rowId, { fetch("/thrimshim/manual-link/"+rowId, {
method: 'POST', method: 'POST',
headers: { headers: {
'Accept': 'application/json', 'Accept': 'application/json',
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
body: JSON.stringify({ body: JSON.stringify(body)
link: document.getElementById("ManualLink").value,
token: user.getAuthResponse().id_token
}) })
}) .then(response => response.text().then(text => {
.then(response => { if (!response.ok) { throw Error(response.statusText); }; return response; }) if (!response.ok) {
.then(data => { console.log(data); setTimeout(() => { alert("Manual link set"); }, 500); }) error = response.statusText + ": " + text;
.catch(error => { console.log(error); alert(error); }); console.log(error);
alert(error);
document.getElementById("ManualButton").disabled = false;
} else {
alert("Manual link set to " + body.link);
setTimeout(() => window.location.href = '/thrimbletrimmer/dashboard.html'; }, 500);
}
}));
}; };
thrimbletrimmerResetLink = function() { thrimbletrimmerResetLink = function() {
var rowId = /id=(.*)(?:&|$)/.exec(document.location.search)[1]; var rowId = /id=(.*)(?:&|$)/.exec(document.location.search)[1];
if(confirm('Are you sure you want to reset this event?')) { if(!confirm(
'Are you sure you want to reset this event? ' +
'This will set the row back to UNEDITED and forget about any video that already may exist. ' +
'It is intended as a last-ditch command to clear a malfunctioning cutter, ' +
'or if a video needs to be re-edited and replaced. ' +
'IT IS YOUR RESPONSIBILITY TO DEAL WITH ANY VIDEO THAT MAY HAVE ALREADY BEEN UPLOADED. '
)) {
return;
}
document.getElementById("ResetButton").disabled = true;
body = {}
if (!!user) {
body.token = user.getAuthResponse().id_token;
}
fetch("/thrimshim/reset/"+rowId, { fetch("/thrimshim/reset/"+rowId, {
method: 'POST', method: 'POST',
headers: { headers: {
'Accept': 'application/json', 'Accept': 'application/json',
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
body: JSON.stringify({token: user.getAuthResponse().id_token}) body: JSON.stringify(body)
}) })
.then(response => { if (!response.ok) { throw Error(response.statusText); }; return response; }) .then(response => response.text().then(text => {
.then(data => { console.log(data); setTimeout(() => { window.location.reload() }, 500); }) if (!response.ok) {
.catch(error => { console.log(error); alert(error); }); error = response.statusText + ": " + text;
console.log(error);
alert(error);
document.getElementById("ResetButton").disabled = false;
} else {
alert("Row has been reset. Reloading...");
setTimeout(() => window.location.reload(); }, 500);
} }
}));
}; };

Loading…
Cancel
Save