Add "Load" button

This commit is contained in:
David Rowe 2017-04-11 15:23:09 +12:00
parent 559fba39ab
commit 86baf785aa
3 changed files with 32 additions and 2 deletions

View file

@ -11,11 +11,13 @@
// //
var isUsingToolbar = false, var isUsingToolbar = false,
numberOfPlayers = 0,
recordingsBeingPlayed = [], recordingsBeingPlayed = [],
elEnableRecording, elEnableRecording,
elInstructions, elInstructions,
elRecordingsPlaying, elRecordingsPlaying,
elNumberOfPlayers, elNumberOfPlayers,
elLoadButton,
EVENT_BRIDGE_TYPE = "record", EVENT_BRIDGE_TYPE = "record",
BODY_LOADED_ACTION = "bodyLoaded", BODY_LOADED_ACTION = "bodyLoaded",
USING_TOOLBAR_ACTION = "usingToolbar", USING_TOOLBAR_ACTION = "usingToolbar",
@ -23,6 +25,7 @@ var isUsingToolbar = false,
RECORDINGS_BEING_PLAYED_ACTION = "recordingsBeingPlayed", RECORDINGS_BEING_PLAYED_ACTION = "recordingsBeingPlayed",
NUMBER_OF_PLAYERS_ACTION = "numberOfPlayers", NUMBER_OF_PLAYERS_ACTION = "numberOfPlayers",
STOP_PLAYING_RECORDING_ACTION = "stopPlayingRecording", STOP_PLAYING_RECORDING_ACTION = "stopPlayingRecording",
LOAD_RECORDING_ACTION = "loadRecording",
TABLET_INSTRUCTIONS = "Close the tablet to start recording", TABLET_INSTRUCTIONS = "Close the tablet to start recording",
WINDOW_INSTRUCTIONS = "Close the window to start recording"; WINDOW_INSTRUCTIONS = "Close the window to start recording";
@ -77,6 +80,14 @@ function updateRecordings() {
elRecordingsPlaying.replaceChild(tbody, elRecordingsPlaying.getElementsByTagName("tbody")[0]); elRecordingsPlaying.replaceChild(tbody, elRecordingsPlaying.getElementsByTagName("tbody")[0]);
} }
function updateLoadButton() {
if (numberOfPlayers > recordingsBeingPlayed.length) {
elLoadButton.removeAttribute("disabled");
} else {
elLoadButton.setAttribute("disabled", "disabled");
}
}
function onScriptEventReceived(data) { function onScriptEventReceived(data) {
var message = JSON.parse(data); var message = JSON.parse(data);
if (message.type === EVENT_BRIDGE_TYPE) { if (message.type === EVENT_BRIDGE_TYPE) {
@ -92,9 +103,12 @@ function onScriptEventReceived(data) {
case RECORDINGS_BEING_PLAYED_ACTION: case RECORDINGS_BEING_PLAYED_ACTION:
recordingsBeingPlayed = JSON.parse(message.value); recordingsBeingPlayed = JSON.parse(message.value);
updateRecordings(); updateRecordings();
updateLoadButton();
break; break;
case NUMBER_OF_PLAYERS_ACTION: case NUMBER_OF_PLAYERS_ACTION:
elNumberOfPlayers.innerHTML = message.value; numberOfPlayers = message.value;
elNumberOfPlayers.innerHTML = numberOfPlayers;
updateLoadButton();
break; break;
} }
} }
@ -118,6 +132,14 @@ function onBodyLoaded() {
elRecordingsPlaying = document.getElementById("recordings-playing"); elRecordingsPlaying = document.getElementById("recordings-playing");
elNumberOfPlayers = document.getElementById("number-of-players"); elNumberOfPlayers = document.getElementById("number-of-players");
elLoadButton = document.getElementById("load-button");
elLoadButton.onclick = function () {
EventBridge.emitWebEvent(JSON.stringify({
type: EVENT_BRIDGE_TYPE,
action: LOAD_RECORDING_ACTION
}));
}
EventBridge.emitWebEvent(JSON.stringify({ EventBridge.emitWebEvent(JSON.stringify({
type: EVENT_BRIDGE_TYPE, type: EVENT_BRIDGE_TYPE,
action: BODY_LOADED_ACTION action: BODY_LOADED_ACTION

View file

@ -41,6 +41,9 @@
<div> <div>
<p>Number of players: <span id="number-of-players">0</span></p> <p>Number of players: <span id="number-of-players">0</span></p>
</div> </div>
<div>
<input id="load-button" type="button" value="Load" disabled />
</div>
<script> <script>
onBodyLoaded(); onBodyLoaded();
</script> </script>

View file

@ -417,7 +417,8 @@
ENABLE_RECORDING_ACTION = "enableRecording", ENABLE_RECORDING_ACTION = "enableRecording",
RECORDINGS_BEING_PLAYED_ACTION = "recordingsBeingPlayed", RECORDINGS_BEING_PLAYED_ACTION = "recordingsBeingPlayed",
NUMBER_OF_PLAYERS_ACTION = "numberOfPlayers", NUMBER_OF_PLAYERS_ACTION = "numberOfPlayers",
STOP_PLAYING_RECORDING_ACTION = "stopPlayingRecording"; STOP_PLAYING_RECORDING_ACTION = "stopPlayingRecording",
LOAD_RECORDING_ACTION = "loadRecording";
function onWebEventReceived(data) { function onWebEventReceived(data) {
var message = JSON.parse(data); var message = JSON.parse(data);
@ -451,6 +452,10 @@
// Stop the specified player. // Stop the specified player.
Player.stopPlayingRecording(message.value); Player.stopPlayingRecording(message.value);
break; break;
case LOAD_RECORDING_ACTION:
// User wants to select an ATP recording to play.
log("TODO: Open dialog for user to select ATP recording to play");
break;
} }
} }
} }