function show_message(text, timeout)
{
if (typeof timeout == 'undefined') timeout = 3;
var div = $('#message_div');
if (!div.length) {
div = $('
');
div.attr('id', 'message_div').css('z-index','1000');
div.hide();
$(document.body).append(div);
}
div.text(text);
div.center();
div.show();
window.setTimeout(hide_message,timeout*1000);
}
function hide_message(text)
{
$('#message_div').hide();
}
var errorwindow = false;
function show_error(text, timeout)
{
if (!errorwindow) {
errorwindow = new Popup('Fehler', '500px', false, '
');
errorwindow.setId('errorwindow');
$('#errorwindow').css('z-index','1000');
errorwindow.centerPopup();
} else {
errorwindow.openPopup();
}
$('#errorbody').html(text);
if (typeof timeout != 'undefined')
window.setTimeout(function(){errorwindow.closePopup()},timeout*1000);
}
function editable_callback(data)
{
if (data.content) {
var elem = $(data.$el);
var route = elem.attr('route');
var item_id = elem.attr('item_id');
if (typeof(route) == 'string' && typeof(item_id) == 'string')
$.invoke(route,
{id: item_id,
name: elem.attr('name'),
content: data.content});
}
return false;
}
function make_editable(selector)
{
var list = $(selector);
if (list.length)
list.editable({
closeOnEnter : true,
event : 'click',
callback: editable_callback
});
}
(function($){
$.fn.ltag = function() {
return this.prop("tagName").toLowerCase();
};
$.fn.center = function () {
this.css("position","absolute");
this.css("top", Math.max(0, ((window.innerHeight - $(this).outerHeight()) / 2) +
$(window).scrollTop()) + "px");
this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) +
$(window).scrollLeft()) + "px");
return this;
};
$.fn.positionOn = function(element, align) {
return this.each(function() {
var target = $(this);
var position = element.offset();
var x = position.left;
var y = position.top;
if(align == 'right') {
x -= (target.outerWidth() - element.outerWidth());
} else if(align == 'center') {
x -= target.outerWidth() / 2 - element.outerWidth() / 2;
}
target.css({
position: 'absolute',
zIndex: 5000,
top: y,
left: x
});
});
};
$.invoke = function(name, parms, callback) {
if (typeof(parms) == 'string' && parms.length)
parms = 'route='+name+'&'+parms;
else if (typeof(parms) == 'object')
parms['route'] = name;
else
parms = 'route='+name;
$.post('/ajax.php',
parms,
function(data){
if (!data.status) {
if (data.error) {
if (data.redirect_login) {
show_message(data.error, 5);
setTimeout(function(){window.location.href = '/';}, 5000);
return;
} else
return show_error(data.error);
} else
return show_error('Fehler im Backend zu "'+name+'" aufgetreten');
}
if (typeof(data.html) == 'object')
for (id in data.html) {
var elem = $('#'+id);
if (elem.length) {
elem.html(data.html[id]);
}
}
if (typeof(data.values) == 'object')
for (id in data.values) {
var elem = $('#'+id);
if (elem.length)
elem.val(data.values[id]);
}
if (typeof(callback) == 'function')
return callback(data);
});
};
})(jQuery);
function Popup(title, width, height, body) {
return this.initialize(title, width, height, body);
}
Popup.prototype = {
initialize: function(title, width, height, body)
{
this.createPopup(width, height);
if (title) this.setTitle(title);
if (body) this.setBody(body);
return this;
},
createPopup: function(width, height)
{
this.popup = $('