countdown shortcuts

This commit is contained in:
Oskar Hahn 2014-03-29 13:20:23 +01:00
parent b3d615ddce
commit 3d092f6dcc
4 changed files with 97 additions and 2 deletions

View File

@ -13,6 +13,8 @@ Agenda:
- Added CSV import. - Added CSV import.
Assignment: Assignment:
- Coupled assignment candidates with list of speakers. - Coupled assignment candidates with list of speakers.
Dashboard:
- Shortcuts for the countdown.
Participants: Participants:
- Disabled widgets by default. - Disabled widgets by default.
- Added form field for multiple creation of new participants. - Added form field for multiple creation of new participants.

View File

@ -137,3 +137,22 @@
-moz-margin-start: 4px !important; -moz-margin-start: 4px !important;
margin-left: -6px; margin-left: -6px;
} }
/*
* style for countdown shortcuts
*
* TODO: move to projector app or merge projector with core
*/
#countdown_shortcut_storage .countdown_shortcut_time {
margin-right: 2px;
}
#countdown_shortcut_storage .countdown_shortcut_time span {
padding-right: 5px;
}
#countdown_shortcut_dummy {
display: none;
}

View File

@ -86,6 +86,8 @@ $(function() {
}); });
// control countdown // control countdown
// TODO: Move Countdown-code into the projector app, or merge the projector
// app with the core app.
$('.countdown_control').click(function(event) { $('.countdown_control').click(function(event) {
event.preventDefault(); event.preventDefault();
var link = $(this); var link = $(this);
@ -111,6 +113,69 @@ $(function() {
}); });
}); });
$('#countdown_set').click(function(event) {
// Create a shortcut from the value in the form
event.preventDefault();
var times = get_times();
times.push($("#countdown_time" ).val());
localStorage.setItem('countdown_shortcut', times.join());
build_countdown_shortcuts();
});
get_times = function() {
// Loads the time values from the local storages. Converts all values
// to integers and removes doubles.
// Returns an empty array if an error occurs
try {
return localStorage.getItem('countdown_shortcut').split(',')
.map(function(value) {
// converts times into int
return parseInt(value);
}).filter(function(value, index, self) {
// filters doubles
return self.indexOf(value) === index;
});
} catch(err) {
return [];
}
};
$('.countdown_shortcut_time').click(function(event) {
// click on a shortcut. Set the form value and simulate a click event.
event.preventDefault();
var time = $(this).children('span').html();
$('#countdown_time').val(time);
$('#countdown_set').click();
});
$('.countdown_shortcut_time .close').click(function(event) {
// Removes a shortcut.
event.preventDefault();
var time = $(this).parent().parent().children('span').html();
var times = get_times().filter(
function(value) {
return value !== parseInt(time);
}
);
localStorage.setItem('countdown_shortcut', times);
build_countdown_shortcuts();
});
build_countdown_shortcuts = function() {
// Recreates the countdown shortcuts
var times = get_times();
$('#countdown_shortcut_storage').empty();
$.each(times, function(index, time) {
var element = $('#countdown_shortcut_dummy').clone(withDataAndEvents=true);
element.attr('id', '');
$('span', element).html(time);
element.appendTo('#countdown_shortcut_storage');
});
};
// build shortcuts at start time.
build_countdown_shortcuts();
// activate/deactivate overlay // activate/deactivate overlay
$('.overlay_activate_link').click(function(event) { $('.overlay_activate_link').click(function(event) {
event.preventDefault(); event.preventDefault();

View File

@ -7,8 +7,8 @@
<input class="projector_countdown_spinval" id="countdown_time" name="countdown_time" type="number" min="0" value="{{ countdown_time }}"> <input class="projector_countdown_spinval" id="countdown_time" name="countdown_time" type="number" min="0" value="{{ countdown_time }}">
<span class="add-on">{% trans "s" context "seconds" %}</span> <span class="add-on">{% trans "s" context "seconds" %}</span>
<button id="countdown_set" class="countdown_control btn tooltip-bottom" href="{% url 'countdown_set_default' %}" <button id="countdown_set" class="countdown_control btn tooltip-bottom" href="{% url 'countdown_set_default' %}"
rel="tooltip" data-original-title="{% trans 'Save time as default' %}"> rel="tooltip" data-original-title="{% trans 'Add time to favourits' %}">
<i class="icon-refresh"></i> <i class="icon-star"></i>
</button> </button>
</div> </div>
<a id="countdown_reset" class="countdown_control btn" href="{% url 'countdown_reset' %}" <a id="countdown_reset" class="countdown_control btn" href="{% url 'countdown_reset' %}"
@ -25,5 +25,14 @@
{% if countdown_state == 'inactive' or countdown_state == 'paused' or countdown_state == 'expired' %} style="display:none"{% endif %}> {% if countdown_state == 'inactive' or countdown_state == 'paused' or countdown_state == 'expired' %} style="display:none"{% endif %}>
<i class="icon-pause"></i> <i class="icon-pause"></i>
</a> </a>
<!-- countdown_shortcut -->
<span id="countdown_shortcut_dummy" class="countdown_shortcut_time btn btn-default">
<span></span>
<a class="countdown_shortcut_remove" href="#">
<button type="button" class="close" aria-hidden="true">&times;</button>
</a>
</span>
<div id="countdown_shortcut_storage"></div>
</div> </div>
</span> </span>