From f4e37e874b474742feafc1af0a7173fa6bd2b256 Mon Sep 17 00:00:00 2001 From: Robin Sonnabend <robin@fsmpi.rwth-aachen.de> Date: Thu, 8 Oct 2015 21:14:32 +0200 Subject: [PATCH] Added next-speaker-shortcut. --- static/js/nextbutton.js | 46 +++++++++++++++++++++++++++++++++++++ templates/layout.html | 5 ++++ templates/speech_index.html | 10 +++++++- templates/update.js | 2 +- 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 static/js/nextbutton.js diff --git a/static/js/nextbutton.js b/static/js/nextbutton.js new file mode 100644 index 0000000..48060e4 --- /dev/null +++ b/static/js/nextbutton.js @@ -0,0 +1,46 @@ +var keyhash = ""; +var changehash = false; +var notificationArea; +var timeout; + +function hashkey(e) { + return e.keyCode + ";" + e.charCode; +} + +function clickNextSpeaker() { + var rows = document.getElementById("next-speaker-table").rows; + if (rows.length > 1) { + var row = rows[1]; + var a = row.children[2].childNodes[1]; + a.click(); + } +} + +window.onkeypress = function(e) { + if (changehash) { + keyhash = hashkey(e); + changehash = false; + sessionStorage["keyhash"] = keyhash; + notificationArea.innerHTML = "Key has been set."; + timeout = window.setTimeout(function() { notificationArea.innerHTML = ""; }, 5000); + } else { + if (hashkey(e) == keyhash) { + clickNextSpeaker(); + } + } +}; + +function setkeyhash() { + changehash = true; + notificationArea.innerHTML = "Please click the key."; + window.clearTimeout(timeout); +} + +var nextbuttoncachedonloadfunction = window.onload; +window.onload = function() { + nextbuttoncachedonloadfunction(); + if (sessionStorage["keyhash"]) { + keyhash = sessionStorage["keyhash"]; + } + notificationArea = document.getElementById("rede-layout-notification"); +}; diff --git a/templates/layout.html b/templates/layout.html index cc60baf..318dc34 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -28,6 +28,8 @@ {% include "content_time.html" %} </span> <div class="mdl-layout-spacer"></div> + <span id="rede-layout-notification" class="rede-layout-title"></span> + <div class="mdl-layout-spacer"></div> <button class="mdl-button mdl-js-button mdl-js-ripple-effet mdl-button--icon" id="hdrbtn"> <i class="material-icons">more_vert</i> </button> @@ -83,6 +85,9 @@ <a class="mdl-navigation__link" href="{{ url_for("speech.show") }}"><i class="mdl-color-text--blue-grey-400 material-icons" role="presentation">announcement</i>Pending speakers</a> {% if current_user.is_authenticated() and "admin" in current_user.roles %} <a class="mdl-navigation__link" href="{{ url_for("admin.index") }}"><i class="mdl-color-text--blue-grey-400 material-icons" role="presentation">computer</i>Administration</a> + {% block additional_sidelinks %} + <!-- put your additional sidelinks here --> + {% endblock %} {% endif %} </nav> </div> diff --git a/templates/speech_index.html b/templates/speech_index.html index ad81430..cf9cf50 100644 --- a/templates/speech_index.html +++ b/templates/speech_index.html @@ -2,9 +2,17 @@ {% from "macros.html" import render_form %} {% block title %}Statements{% endblock %} +{% block additional_js %} +<script src="{{ url_for('static', filename='js/nextbutton.js') }}" async></script> +{% endblock %} + +{% block additional_sidelinks %} +<a href="#" class="mdl-navigation__link" onclick="setkeyhash()">Set Next Key</a> +{% endblock %} + {% block content %} {% for statements, add_form, event in meta %} - <table class="mdl-data-table mdl-js-table mdl-shadow--2dp mdl-cell mdl-cell--6-col mdl-cell--4-col-tablet mdl-cell--4-col-phone sortable"> + <table id="next-speaker-table" class="mdl-data-table mdl-js-table mdl-shadow--2dp mdl-cell mdl-cell--6-col mdl-cell--4-col-tablet mdl-cell--4-col-phone sortable"> <thead> <tr> <th class="mdl-data-table__cell--non-numeric">Speaker</th> diff --git a/templates/update.js b/templates/update.js index 6246d0f..754d490 100644 --- a/templates/update.js +++ b/templates/update.js @@ -27,5 +27,5 @@ var {{ prefix }}f = window.onload; window.onload=function() { {{ prefix }}f(); window.setInterval({{ prefix }}request, 1000 * {{ update_interval }}); -} +}; -- GitLab