-function ajax_request(funcname, params, callback, error_callback)
+function show_message(text, timeout)
{
- if (params === null)
- params = 'func='+funcname;
- else if (typeof params == 'object')
- params['func'] = funcname
- else if (typeof params == 'string')
- params = 'func='+funcname+'&'+params
- else
- return false;
-
- $.post('/ajax.php', params,
- function(data){
- if (!data.status) {
- if (typeof data.error == 'string')
- var error = data.error;
- else
- var error = 'An error occurred'
- alert(error);
- if (typeof error_callback == 'function')
- error_callback(data);
- return;
- }
- if (typeof callback == 'function')
- callback(data);
- });
+ if (typeof timeout == 'undefined') timeout = 3;
+
+ var div = $('#message_div');
+ if (!div.length) {
+ div = $('<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();
+}
+
+function show_error(text, timeout)
+{
+ var div = $('#error_div');
+ if (!div.length) {
+ div = $('<div>');
+ div.attr('id', 'error_div').css('z-index','1000');
+ div.hide();
+ div.append($('<p ><img src="/pix/close.gif" title="close" onclick="return hide_error()"/></p>'));
+ div.append($('<div />'));
+ $(document.body).append(div);
+ }
+
+ div.find('div').html(text);
+ div.center();
+ div.show();
+
+ if (typeof timeout != 'undefined')
+ window.setTimeout(hide_error,timeout*1000);
+}
+
+function hide_error(text)
+{
+ $('#error_div').hide();
+ return false;
+}
+
+(function($){
+ $.fn.ltag = function() {
+ return this.prop("tagName").toLowerCase();
+ };
+
+ $.fn.center = function () {
+ this.css("position","absolute");
+ this.css("top", Math.max(0, (($(window).height() - $(this).outerHeight()) / 2) +
+ $(window).scrollTop()) + "px");
+ this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) +
+ $(window).scrollLeft()) + "px");
+ return this;
+ };
+
+$.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);