$('#message_div').hide();
}
+var errorwindow = false;
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);
+ if (!errorwindow) {
+ errorwindow = new Popup('Fehler', '500px', false, '<div id="errorbody"></div>');
+ errorwindow.setId('errorwindow');
+ $('#errorwindow').css('z-index','1000');
+ errorwindow.centerPopup();
+ } else {
+ errorwindow.openPopup();
}
- div.find('div').html(text);
- div.center();
- div.show();
+ $('#errorbody').html(text);
if (typeof timeout != 'undefined')
- window.setTimeout(hide_error,timeout*1000);
+ window.setTimeout(function(){errorwindow.closePopup()},timeout*1000);
}
-function hide_error(text)
+function editable_callback(data)
{
- $('#error_div').hide();
+ 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();
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;
});
};
})(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 = $('<div class="popup">');
+ this.popup.css('width', width ? width : 'auto');
+ this.popup.css('height', height ? height : 'auto');
+ this.popup.hide().css('z-index', '1000');
+ var titlediv = $('<div class="popup_title" style="position:relative;">');
+ titlediv.append($('<p class="popup_title"></p>'));
+
+ var closeimg = $('<img src="/pix/close.gif" title="Close">');
+ titlediv.append(closeimg);
+
+ this.popup.append(titlediv);
+
+ this.popup.append($('<div class="popup_body" style="clear:both;">'));
+ $('body').append(this.popup);
+
+ this.popup.udraggable({'handle': 'div.popup_title'});
+ this.popup.find('div.popup_title img').bind('click', this.closePopup.bind(this));
+ },
+
+ openPopup: function()
+ {
+ this.popup.show();
+ },
+
+ centerPopup: function()
+ {
+ this.popup.center().show();
+ },
+
+ closePopup: function()
+ {
+ this.popup.hide();
+ },
+
+ setId: function(name)
+ {
+ this.popup.attr('id', name);
+ },
+
+ setTitle: function(title)
+ {
+ this.popup.find('div.popup_title p.popup_title').html(title);
+ },
+
+ setBody: function(body)
+ {
+ this.popup.find('div.popup_body').html(body);
+ }
+}