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 function show_error(text, timeout)
27 var div = $('#error_div');
30 div.attr('id', 'error_div').css('z-index','1000');
32 div.append($('<p ><img src="/pix/close.gif" title="close" onclick="return hide_error()"/></p>'));
33 div.append($('<div />'));
34 $(document.body).append(div);
37 div.find('div').html(text);
41 if (typeof timeout != 'undefined')
42 window.setTimeout(hide_error,timeout*1000);
45 function hide_error(text)
47 $('#error_div').hide();
51 function editable_callback(data)
54 var elem = $(data.$el);
55 var route = elem.attr('route');
56 var item_id = elem.attr('item_id');
57 if (typeof(route) == 'string' && typeof(item_id) == 'string')
60 name: elem.attr('name'),
61 content: data.content});
67 function make_editable(selector)
69 var list = $(selector);
74 callback: editable_callback
78 $.fn.ltag = function() {
79 return this.prop("tagName").toLowerCase();
82 $.fn.center = function () {
83 this.css("position","absolute");
84 this.css("top", Math.max(0, (($(window).height() - $(this).outerHeight()) / 2) +
85 $(window).scrollTop()) + "px");
86 this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) +
87 $(window).scrollLeft()) + "px");
91 $.invoke = function(name, parms, callback) {
92 if (typeof(parms) == 'string' && parms.length)
93 parms = 'route='+name+'&'+parms;
94 else if (typeof(parms) == 'object')
95 parms['route'] = name;
97 parms = 'route='+name;
104 if (data.redirect_login) {
105 show_message(data.error, 5);
106 setTimeout(function(){window.location.href = '/';}, 5000);
109 return show_error(data.error);
111 return show_error('Fehler im Backend zu "'+name+'" aufgetreten');
113 if (typeof(data.html) == 'object')
114 for (id in data.html) {
115 var elem = $('#'+id);
117 elem.html(data.html[id]);
120 if (typeof(data.values) == 'object')
121 for (id in data.values) {
122 var elem = $('#'+id);
124 elem.val(data.values[id]);
127 if (typeof(callback) == 'function')
128 return callback(data);
133 function Popup(title, width, height, body) {
134 return this.initialize(title, width, height, body);
138 initialize: function(title, width, height, body)
140 this.createPopup(width, height);
141 if (title) this.setTitle(title);
142 if (body) this.setBody(body);
146 createPopup: function(width, height)
148 this.popup = $('<div class="popup">');
149 this.popup.css('width', width ? width : 'auto');
150 this.popup.css('height', height ? height : 'auto');
151 this.popup.hide().css('z-index', '1000');
152 var titlediv = $('<div class="popup_title" style="position:relative;">');
153 titlediv.append($('<p class="popup_title"></p>'));
155 var closeimg = $('<img src="/pix/close.gif" title="Close">');
156 titlediv.append(closeimg);
158 this.popup.append(titlediv);
160 this.popup.append($('<div class="popup_body" style="clear:both;">'));
161 $('body').append(this.popup);
163 this.popup.udraggable({'handle': 'div.popup_title'});
164 this.popup.find('div.popup_title img').bind('click', this.closePopup.bind(this));
167 openPopup: function()
172 centerPopup: function()
174 this.popup.center().show();
177 closePopup: function()
182 setTitle: function(title)
184 this.popup.find('div.popup_title p.popup_title').html(title);
187 setBody: function(body)
189 this.popup.find('div.popup_body').html(body);