1 // Source http://stackoverflow.com/questions/210717/using-jquery-to-center-a-div-on-the-screen
4 $.fn.center = function () {
5 this.css("position","absolute");
6 this.css("top", Math.max(0, (($(window).height() - $(this).outerHeight()) / 2) +
7 $(window).scrollTop()) + "px");
8 this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) +
9 $(window).scrollLeft()) + "px");
14 // type = ['error', 'warning', 'info']
15 function show_message(text, type)
17 if (!type) type = 'info';
19 if (type == 'error') {
20 var classname = 'alert-danger';
21 } else if (type == 'warning') {
22 var classname = 'alert-warning';
24 var classname = 'alert-success';
27 $('div#message').attr('class', 'alert ' + classname).text(text).center().show();
28 setTimeout(function(){$('div#message').hide();}, 3000);
33 function ajax_request(route, parms, callback)
35 $.post(tour_base_url + route,
40 if (data.redirect_login) {
41 show_message(data.error, 'error');
42 setTimeout(function(){window.location.href = '/';}, 5000);
45 return show_message(data.error, 'error');
47 return show_message('Fehler im Backend zu "'+route+'" aufgetreten', 'error');
50 show_message(data.warning, 'warning');
52 show_message(data.info, 'info');
53 if (typeof(callback) == 'function')
60 ajax_request('tour/'+tour_key+'/dates', '', function(data){
61 $('#datelist').html(data.table);
67 ajax_request('tour/'+tour_key+'/pov', '', function(data){
68 $('#povlist').html(data.table);
70 $('#povlist table button.btn-warning').click(function(e){
71 ajax_request('tour/'+tour_key+'/povmove',
72 {'pov': $(this).parents('tr:first').attr('data-id'),
73 'direction': $(this).attr('data-dir')},
78 $('#povlist table button.btn-warning:first').attr('disabled', 'disabled');
79 $('#povlist table button.btn-warning:last').attr('disabled', 'disabled');
81 $('#povlist table button.btn-danger').click (function(e){
82 ajax_request('tour/'+tour_key+'/povdel',
83 {'pov': $(this).parents('tr:first').attr('data-id')},
92 $('input').on('keydown', function(e){
98 $('.lostpw a').click(function(e){
99 if (!$('.loginform form #login').val().length)
100 return show_message('Bitte E-Mail angeben', 'error');
102 ajax_request('account/lostpw', 'email='+$('.loginform form #login').val(), function(data){
103 return show_message('Eine Mail an wurde verschickt.');
110 $('.lostpwform .btn').click(function(e){
111 if (!$('.lostpwform #password').val().length)
112 return show_message('Bitte ein neues Passwort setzen', 'error');
114 if ($('.lostpwform #password').val() != $('.lostpwform #password2').val())
115 return show_message('Die Passwörter stimmen nicht überein', 'error');
117 if ($('.lostpwform #password').val().length < 8)
118 return show_message('Das Passwort muss mindestens 8 Zeichen lang sein', 'error');
120 ajax_request('account/setpw', $('.lostpwform form').serialize(), function(data){
122 show_message('Gespeichert. Bitte neu anmelden.');
123 setTimeout(function(){window.location.href = data.goto;}, 2000);
131 $('#settings_save').click(function(e){
132 ajax_request('index/settings', $('form[name="settings"]').serialize(), function(data){
133 show_message('Einstellungen gespeichert', 'info');
134 setTimeout(function(){window.location.href = tour_base_url + 'index/index';}, 4000);
139 $('#newtour_save').click(function(e){
140 if (!$('form[name="newtour"] #name').val().length ||
141 !$('form[name="newtour"] #urlkey').val().length ||
142 !$('form[name="newtour"] #year').val().length ||
143 !$('form[name="newtour"] #duration').val().length ||
144 !$('form[name="newtour"] #leader').val().length)
145 return show_message('Alle Felder müssen ausgefüllt sein', 'error');
147 if ($('form[name="newtour"] #urlkey').val().indexOf(' ') != -1)
148 return show_message('Leerzeichen nicht erlaubt im URL-Key', 'error');
150 ajax_request('tour/newtour', $('form[name="newtour"]').serialize(), function(data){
151 show_message('Tour gespeichert', 'info');
152 setTimeout(function(){window.location.href = tour_base_url + 'index/index';}, 4000);
156 // Toggle status for date
157 $('div.tour table#plan td#date-status').click(function(e){
159 ajax_request('tour/'+tour_key+'/togglestatus',
160 'id='+cell.attr('data-id'),
162 cell.attr('class', 'bg-'+data.status_key);
163 cell.text(data.status_text);
167 // Toggle status for date in matrix
168 $('div.tour table#matrix td#date-toggle').click(function(e){
170 ajax_request('tour/'+tour_key+'/togglestatus',
171 {id: cell.attr('data-date-id'),
172 user: cell.attr('data-user-id')},
174 cell.attr('class', 'bg-'+data.status_key);
178 // Set tour member status
179 $('#tourmember_save').click(function(e){
180 ajax_request('tour/'+tour_key+'/tourmember', $('form[name="tourmember"]').serialize(), function(data){
181 show_message('Status gespeichert', 'info');
185 // Add new date to tour
186 $('#newdate_save').click(function(e){
187 if (!$('#start_date').val().length) return;
188 ajax_request('tour/'+tour_key+'/newdate', $('form[name="newdate"]').serialize(), function(data){
190 show_message('Termin gespeichert', 'info');
195 $('#newpov_save').click(function(e){
196 if (!$('form[name="newpov"] #destination').val().length) return;
197 ajax_request('tour/'+tour_key+'/newpov', $('form[name="newpov"]').serialize(), function(data){
199 show_message('Zwischenziel gespeichert', 'info');
200 $('form[name="newpov"] #destination').val('');
204 // Add new member to tour
205 $('div.invite button.btn-primary').click(function(e){
206 var button = $(this);
207 if (!button.attr('data-id').length) return;
208 ajax_request('tour/'+tour_key+'/invite',
209 'sys_user_id='+button.attr('data-id'),
211 button.removeClass('btn-primary').addClass('btn-success').attr('disabled', 'disabled');
214 // Create new biker and add new member to tour
215 $('div.invite button.btn-warning').click(function(e){
216 window.location.href = tour_base_url + 'tour/' + tour_key + '/newmember';
218 $('#newbiker_save').click(function(e){
219 if (!$('form[name="newbiker"] #name').val().length ||
220 !$('form[name="newbiker"] #email').val().length)
221 return show_message('Name und E-Mail müssen ausgefüllt sein', 'error');
223 if (typeof tour_key == 'string')
224 var backend = 'tour/'+tour_key+'/newbiker';
226 var backend = 'tour/newbiker';
227 ajax_request(backend, $('form[name="newbiker"]').serialize(), function(data){
228 show_message('Biker gespeichert', 'info');
229 if (typeof tour_key == 'string')
230 setTimeout(function(){window.location.href = tour_base_url + 'tour/' + tour_key + '/invite';}, 4000);
235 $('.container.notes #btn_new').click(function(e){
236 window.location.href = tour_base_url + 'tour/'+tour_key+'/notenew';
238 $('.container.notes .alert-dark .alert-primary').click(function(e){
239 $('div#note_del').center().show();
240 $('div#note_del button').attr('data-id', $(this).attr('data-id'));
242 $('div#note_del button#btn_del').click(function(e){
243 var note_id = $(this).attr('data-id');
245 ajax_request('tour/'+tour_key+'/notedel', 'id='+note_id, function(data){
246 $('div#note_del').hide();
247 $('div.note[data-id="'+note_id+'"]').hide();
248 show_message('Notiz gelöscht', 'info');
251 $('div#note_del button#btn_close').click(function(e){
252 $('div#note_del').hide();
254 $('#newnote_save').click(function(e){
255 var dest_url = tour_base_url + 'tour/'+tour_key+'/notes';
256 if (!$('form[name="newnote"] #note').val().length) {
257 window.location.href = dest_url;
261 ajax_request('tour/'+tour_key+'/notenew', $('form[name="newnote"]').serialize(), function(data){
262 show_message('Notiz gespeichert', 'info');
263 setTimeout(function(){window.location.href = dest_url;}, 2000);
266 $('#newnote_second').click(function(e){
267 if (!$('form[name="newnote"] #note').val().length)
270 $('form[name="newnote"]').submit();
274 $('#tourplan_save').click(function(e){
275 if (!$('form[name="tourplan"] #name').val().length ||
276 !$('form[name="tourplan"] #urlkey').val().length ||
277 !$('form[name="tourplan"] #year').val().length ||
278 !$('form[name="tourplan"] #duration').val().length)
279 return show_message('Name, Key, Jahr und Dauer müssen ausgefüllt sein', 'error');
281 ajax_request('tour/'+tour_key+'/admin', $('form[name="tourplan"]').serialize(), function(data){
282 show_message('Informationen gespeichert', 'info');
285 $('#touradmin_save').click(function(e){
286 if (!$('form[name="touradmin"] #tour_member_id').val().length) return;
288 ajax_request('tour/'+tour_key+'/touradmin', $('form[name="touradmin"]').serialize(), function(data){
289 show_message('Tourleiter gesetzt', 'info');
290 $('form[name="touradmin"] #tour_member_id option[value="'+$('form[name="touradmin"] #tour_member_id').val()+'"]').remove();
293 $('#touradmin .btn-danger').click(function(e){
294 var button = $(this);
295 ajax_request('tour/'+tour_key+'/deladmin', 'id='+button.attr('data-id'), function(data){
296 show_message('Tourleiter gelöscht', 'info');
297 button.parents('div.form-row:first').hide();