2014-01-14 23:22:29 +01:00
|
|
|
/*
|
|
|
|
* JavaScript functions for OpenSlides dashboard.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-09-10 23:28:19 +02:00
|
|
|
// function that writes the widget list order to a cookie
|
2012-07-04 02:43:26 +02:00
|
|
|
function saveOrder() {
|
|
|
|
$(".column").each(function(index, value){
|
|
|
|
var colid = value.id;
|
2014-03-12 22:15:05 +01:00
|
|
|
var cookieName = "openslides-dashboard-" + colid;
|
2012-07-04 02:43:26 +02:00
|
|
|
// Get the order for this column.
|
|
|
|
var order = $('#' + colid).sortable("toArray");
|
2013-11-10 19:35:32 +01:00
|
|
|
var cookie_content = [];
|
|
|
|
for (var i = 0; i < order.length; i++) {
|
|
|
|
widget_id = order[i];
|
|
|
|
widget = $('#' + widget_id);
|
|
|
|
var is_collabsed = 0;
|
|
|
|
var is_pinned = 0;
|
|
|
|
if (!widget.find('.collapse').hasClass('in')) {
|
|
|
|
is_collabsed = 1;
|
|
|
|
}
|
|
|
|
if (widget.hasClass('affix')) {
|
|
|
|
is_pinned = 1;
|
|
|
|
}
|
|
|
|
cookie_content[i] = widget_id + '/' + is_collabsed + '/' + is_pinned;
|
|
|
|
}
|
2014-03-12 22:15:05 +01:00
|
|
|
$.cookie(cookieName, cookie_content);
|
2012-07-04 02:43:26 +02:00
|
|
|
});
|
|
|
|
}
|
2013-02-05 11:24:41 +01:00
|
|
|
|
2012-09-10 23:28:19 +02:00
|
|
|
// function that restores the widget list order from a cookie
|
2012-07-04 02:43:26 +02:00
|
|
|
function restoreOrder() {
|
|
|
|
$(".column").each(function(index, value) {
|
|
|
|
var colid = value.id;
|
2014-03-12 22:15:05 +01:00
|
|
|
var cookieName = "openslides-dashboard-" + colid;
|
2012-07-04 02:43:26 +02:00
|
|
|
var cookie = $.cookie(cookieName);
|
2014-03-12 22:15:05 +01:00
|
|
|
if ( cookie === undefined ) { return; }
|
2013-11-10 19:35:32 +01:00
|
|
|
var widgets = cookie.split(",");
|
|
|
|
for (var i = 0, n = widgets.length; i < n; i++ ) {
|
|
|
|
var widget_information = widgets[i].split('/');
|
|
|
|
var widgetID = widget_information[0];
|
|
|
|
var widget = $(".column").find('#' + widgetID);
|
|
|
|
widget.appendTo($('#' + colid));
|
|
|
|
if (widget_information[1] === "1") {
|
|
|
|
widget.find('.collapse').removeClass('in');
|
|
|
|
console.log(widget_information[0]);
|
|
|
|
widget.find('.collapsebutton').find('.btn').addClass('active');
|
|
|
|
}
|
|
|
|
if (widget_information[2] === "1") {
|
|
|
|
widget.addClass('affix');
|
|
|
|
widget.data('spy', 'affix');
|
|
|
|
widget.find('.fixbutton').find('.btn').addClass('active');
|
|
|
|
}
|
2012-07-04 02:43:26 +02:00
|
|
|
}
|
|
|
|
});
|
2013-11-10 19:35:32 +01:00
|
|
|
$('.collapse')
|
|
|
|
.on('hidden', function () { saveOrder(); })
|
|
|
|
.on('shown', function () { saveOrder(); });
|
2012-07-04 02:43:26 +02:00
|
|
|
}
|
|
|
|
|
2012-03-06 08:19:49 +01:00
|
|
|
$(function() {
|
2012-07-04 02:43:26 +02:00
|
|
|
$( ".column" ).sortable({
|
|
|
|
connectWith: ".column",
|
2014-05-18 20:42:29 +02:00
|
|
|
handle: ".widget-header",
|
2012-07-04 02:43:26 +02:00
|
|
|
stop: function() { saveOrder(); }
|
|
|
|
});
|
|
|
|
|
2013-02-05 11:24:41 +01:00
|
|
|
// control the projector view
|
2012-03-06 08:19:49 +01:00
|
|
|
$('.projector_edit').click(function(event) {
|
|
|
|
event.preventDefault();
|
2012-04-20 22:41:57 +02:00
|
|
|
var link = $(this);
|
2012-03-06 08:19:49 +01:00
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url: link.attr('href'),
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(data) {
|
2014-03-26 22:09:37 +01:00
|
|
|
// change scale level number
|
2013-10-23 17:08:08 +02:00
|
|
|
$('#scale_level').html(data['scale_level']);
|
2014-03-26 22:09:37 +01:00
|
|
|
if ( data['scale_level'] != 0 )
|
|
|
|
$('#scale_level').addClass('notNull');
|
|
|
|
else
|
|
|
|
$('#scale_level').removeClass('notNull');
|
|
|
|
// change scroll level number
|
2013-10-23 17:08:08 +02:00
|
|
|
$('#scroll_level').html(data['scroll_level']);
|
2014-03-26 22:09:37 +01:00
|
|
|
if ( data['scroll_level'] != 0 ) {
|
|
|
|
$('#scroll_level').addClass('notNull');
|
2013-10-23 17:08:08 +02:00
|
|
|
if ( $('#scroll_up_button').hasClass('disabled') )
|
|
|
|
$('#scroll_up_button').removeClass('disabled');
|
|
|
|
}
|
2014-03-26 22:09:37 +01:00
|
|
|
else {
|
|
|
|
$('#scroll_level').removeClass('notNull');
|
|
|
|
$('#scroll_up_button').addClass('disabled');
|
|
|
|
}
|
2012-03-06 08:19:49 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// control countdown
|
2014-03-29 13:20:23 +01:00
|
|
|
// TODO: Move Countdown-code into the projector app, or merge the projector
|
|
|
|
// app with the core app.
|
2012-07-04 02:43:26 +02:00
|
|
|
$('.countdown_control').click(function(event) {
|
2012-03-06 08:19:49 +01:00
|
|
|
event.preventDefault();
|
2012-04-20 22:41:57 +02:00
|
|
|
var link = $(this);
|
2012-04-26 12:43:35 +02:00
|
|
|
var requestData = {};
|
|
|
|
if (link.attr('id') == "countdown_set") {
|
|
|
|
requestData = { "countdown_time" : $( "#countdown_time" ).val() };
|
|
|
|
}
|
2012-03-06 08:19:49 +01:00
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url: link.attr('href'),
|
2012-04-26 12:43:35 +02:00
|
|
|
data: requestData,
|
2012-03-06 08:19:49 +01:00
|
|
|
dataType: 'json',
|
|
|
|
success: function(data) {
|
2012-07-04 02:43:26 +02:00
|
|
|
if (data['state'] == 'active') {
|
|
|
|
$('#countdown_play').hide();
|
|
|
|
$('#countdown_stop').show();
|
|
|
|
} else {
|
|
|
|
$('#countdown_play').show();
|
|
|
|
$('#countdown_stop').hide();
|
|
|
|
}
|
2013-10-04 11:38:39 +02:00
|
|
|
$('#countdown_time').val(data['countdown_time']);
|
2012-03-06 08:19:49 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2012-04-26 12:43:35 +02:00
|
|
|
|
2014-03-29 13:20:23 +01:00
|
|
|
$('#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();
|
|
|
|
|
2013-02-05 11:24:41 +01:00
|
|
|
// activate/deactivate overlay
|
|
|
|
$('.overlay_activate_link').click(function(event) {
|
2012-03-06 08:19:49 +01:00
|
|
|
event.preventDefault();
|
2012-04-20 22:41:57 +02:00
|
|
|
var link = $(this);
|
2012-03-06 08:19:49 +01:00
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url: link.attr('href'),
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(data) {
|
2013-02-05 11:24:41 +01:00
|
|
|
if (data['active']) {
|
2013-04-15 10:40:47 +02:00
|
|
|
$('#' + data['name'] + '_active').show();
|
|
|
|
$('#' + data['name'] + '_inactive').hide();
|
2012-03-06 08:19:49 +01:00
|
|
|
} else {
|
2013-04-15 10:40:47 +02:00
|
|
|
$('#' + data['name'] + '_active').hide();
|
|
|
|
$('#' + data['name'] + '_inactive').show();
|
2012-03-06 08:19:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2012-07-04 02:43:26 +02:00
|
|
|
|
2012-07-04 03:21:03 +02:00
|
|
|
$('#overlay_message').ajaxForm({
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(data) {
|
|
|
|
$('#overlay_message_text').val(data['overlay_message']);
|
|
|
|
}
|
2012-07-04 02:43:26 +02:00
|
|
|
});
|
2013-06-16 00:44:41 +02:00
|
|
|
$('.fixbutton button').click(function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
if($(this).hasClass('active')) {
|
|
|
|
$(this).closest('.widget').removeClass('affix');
|
|
|
|
$(this).closest('.widget').removeAttr('data-spy');
|
2013-11-10 19:35:32 +01:00
|
|
|
saveOrder();
|
2013-06-16 00:44:41 +02:00
|
|
|
} else {
|
|
|
|
$(this).closest('.widget').addClass('affix');
|
|
|
|
$(this).closest('.widget').attr('data-spy', 'affix');
|
2013-11-10 19:35:32 +01:00
|
|
|
saveOrder();
|
2013-06-16 00:44:41 +02:00
|
|
|
}
|
|
|
|
});
|
2013-02-05 11:24:41 +01:00
|
|
|
|
2013-10-04 11:38:39 +02:00
|
|
|
// control pdf pages
|
|
|
|
$('.pdf-page-ctl').click(function(event){
|
|
|
|
event.preventDefault();
|
|
|
|
var link = $(this);
|
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url: link.attr('href'),
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(data) {
|
|
|
|
if (typeof data.current_page !== 'undefined') {
|
|
|
|
$('#page_num').val(data.current_page);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.set-page-form').submit(function() {
|
|
|
|
$(this).ajaxSubmit();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.go-first-page').click(function() {
|
|
|
|
$('#page_num').val('1');
|
|
|
|
$('.set-page-form').ajaxSubmit();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.pdf-toggle-fullscreen').click(function(event){
|
|
|
|
event.preventDefault();
|
|
|
|
var link = $(this);
|
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url: link.attr('href'),
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(data) {
|
|
|
|
if(data.fullscreen) {
|
|
|
|
if (!link.hasClass('btn-primary')) {
|
|
|
|
link.addClass('btn-primary');
|
|
|
|
link.find('i').addClass('icon-white');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (link.hasClass('btn-primary')) {
|
|
|
|
link.removeClass('btn-primary');
|
|
|
|
link.find('i').removeClass('icon-white');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-02-05 11:24:41 +01:00
|
|
|
/* comment out this function because '$.browser' has been removed from jquery 1.9, see:
|
|
|
|
http://blog.jquery.com/2013/01/15/jquery-1-9-final-jquery-2-0-beta-migrate-final-released/
|
|
|
|
TODO: use jquery migrate to have $.browser support for IE8;
|
|
|
|
|
|
|
|
if ($.browser.msie) {
|
|
|
|
if ($.browser.version >= 8.0 && $.browser.version < 9.0)
|
|
|
|
{
|
|
|
|
// scaling bug in IE8.. iframe has to be 4 times bigger
|
|
|
|
$( "#iframe" ).css('width', 1024 * 4);
|
|
|
|
$( "#iframe" ).css('height', 768 * 4);
|
|
|
|
}
|
|
|
|
$( "#iframe" ).css('zoom', '0.25');
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
restoreOrder();
|
2012-03-06 08:19:49 +01:00
|
|
|
});
|