1 function show_message(text, timeout)
3 if (typeof timeout == 'undefined') timeout = 3;
5 var div = $('#message_div');
8 div.attr('id', 'message_div').css('z-index','1000');
10 $(document.body).append(div);
17 window.setTimeout(hide_message,timeout*1000);
20 function hide_message(text)
22 $('#message_div').hide();
25 var errorwindow = false;
26 function show_error(text, timeout)
29 errorwindow = new Popup('Fehler', '500px', false, '<div id="errorbody"></div>');
30 errorwindow.setId('errorwindow');
31 $('#errorwindow').css('z-index','1000');
32 errorwindow.centerPopup();
34 errorwindow.openPopup();
37 $('#errorbody').html(text);
39 if (typeof timeout != 'undefined')
40 window.setTimeout(function(){errorwindow.closePopup()},timeout*1000);
43 function editable_callback(data)
46 var elem = $(data.$el);
47 var route = elem.attr('route');
48 var item_id = elem.attr('item_id');
49 if (typeof(route) == 'string' && typeof(item_id) == 'string')
52 name: elem.attr('name'),
53 content: data.content});
59 function make_editable(selector)
61 var list = $(selector);
66 callback: editable_callback
70 $.fn.ltag = function() {
71 return this.prop("tagName").toLowerCase();
74 $.fn.center = function () {
75 this.css("position","absolute");
76 this.css("top", Math.max(0, ((window.innerHeight - $(this).outerHeight()) / 2) +
77 $(window).scrollTop()) + "px");
78 this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) +
79 $(window).scrollLeft()) + "px");
83 $.fn.positionOn = function(element, align) {
84 return this.each(function() {
86 var position = element.offset();
88 var x = position.left;
91 if(align == 'right') {
92 x -= (target.outerWidth() - element.outerWidth());
93 } else if(align == 'center') {
94 x -= target.outerWidth() / 2 - element.outerWidth() / 2;
106 $.invoke = function(name, parms, callback) {
107 if (typeof(parms) == 'string' && parms.length)
108 parms = 'route='+name+'&'+parms;
109 else if (typeof(parms) == 'object')
110 parms['route'] = name;
112 parms = 'route='+name;
119 if (data.redirect_login) {
120 show_message(data.error, 5);
121 setTimeout(function(){window.location.href = '/';}, 5000);
124 return show_error(data.error);
126 return show_error('Fehler im Backend zu "'+name+'" aufgetreten');
128 if (typeof(data.html) == 'object')
129 for (id in data.html) {
130 var elem = $('#'+id);
132 elem.html(data.html[id]);
135 if (typeof(data.values) == 'object')
136 for (id in data.values) {
137 var elem = $('#'+id);
139 elem.val(data.values[id]);
142 if (typeof(callback) == 'function')
143 return callback(data);
148 function Popup(title, width, height, body) {
149 return this.initialize(title, width, height, body);
153 initialize: function(title, width, height, body)
155 this.createPopup(width, height);
156 if (title) this.setTitle(title);
157 if (body) this.setBody(body);
161 createPopup: function(width, height)
163 this.popup = $('<div class="popup">');
164 this.popup.css('width', width ? width : 'auto');
165 this.popup.css('height', height ? height : 'auto');
166 this.popup.hide().css('z-index', '1000');
167 var titlediv = $('<div class="popup_title" style="position:relative;">');
168 titlediv.append($('<p class="popup_title"></p>'));
170 var closeimg = $('<img src="/pix/close.gif" title="Close">');
171 titlediv.append(closeimg);
173 this.popup.append(titlediv);
175 this.popup.append($('<div class="popup_body" style="clear:both;">'));
176 $('body').append(this.popup);
178 this.popup.udraggable({'handle': 'div.popup_title'});
179 this.popup.find('div.popup_title img').bind('click', this.closePopup.bind(this));
182 openPopup: function()
187 centerPopup: function()
189 this.popup.center().show();
192 closePopup: function()
197 setId: function(name)
199 this.popup.attr('id', name);
202 setTitle: function(title)
204 this.popup.find('div.popup_title p.popup_title').html(title);
207 setBody: function(body)
209 this.popup.find('div.popup_body').html(body);