});
}
+function load_dates()
+{
+ ajax_request('tour/'+tour_key+'/dates', '', function(data){
+ $('#datelist').html(data.table);
+ });
+}
+
+function load_pov()
+{
+ ajax_request('tour/'+tour_key+'/pov', '', function(data){
+ $('#povlist').html(data.table);
+
+ $('#povlist table button.btn-warning').click(function(e){
+ ajax_request('tour/'+tour_key+'/povmove',
+ {'pov': $(this).parents('tr:first').attr('data-id'),
+ 'direction': $(this).attr('data-dir')},
+ function(data){
+ load_pov();
+ });
+ });
+ $('#povlist table button.btn-warning:first').attr('disabled', 'disabled');
+ $('#povlist table button.btn-warning:last').attr('disabled', 'disabled');
+
+ $('#povlist table button.btn-danger').click (function(e){
+ ajax_request('tour/'+tour_key+'/povdel',
+ {'pov': $(this).parents('tr:first').attr('data-id')},
+ function(data){
+ load_pov();
+ });
+ });
+ });
+}
+
$(function(){
$('input').on('keydown', function(e){
if (e.which === 13)
setTimeout(function(){window.location.href = tour_base_url + 'index/index';}, 4000);
});
});
+
+ // Create new tour
+ $('#newtour_save').click(function(e){
+ if (!$('form[name="newtour"] #name').val().length ||
+ !$('form[name="newtour"] #urlkey').val().length ||
+ !$('form[name="newtour"] #year').val().length ||
+ !$('form[name="newtour"] #duration').val().length ||
+ !$('form[name="newtour"] #leader').val().length)
+ return show_message('Alle Felder müssen ausgefüllt sein', 'error');
+
+ if ($('form[name="newtour"] #urlkey').val().indexOf(' ') != -1)
+ return show_message('Leerzeichen nicht erlaubt im URL-Key', 'error');
+
+ ajax_request('tour/newtour', $('form[name="newtour"]').serialize(), function(data){
+ show_message('Tour gespeichert', 'info');
+ setTimeout(function(){window.location.href = tour_base_url + 'index/index';}, 4000);
+ });
+ });
+
+ // Toggle status for date
+ $('div.tour table#plan td#date-status').click(function(e){
+ var cell = $(this);
+ ajax_request('tour/'+tour_key+'/togglestatus',
+ 'id='+cell.attr('data-id'),
+ function(data){
+ cell.attr('class', 'bg-'+data.status_key);
+ cell.text(data.status_text);
+ });
+ });
+
+ // Toggle status for date in matrix
+ $('div.tour table#matrix td#date-toggle').click(function(e){
+ var cell = $(this);
+ ajax_request('tour/'+tour_key+'/togglestatus',
+ {id: cell.attr('data-date-id'),
+ user: cell.attr('data-user-id')},
+ function(data){
+ cell.attr('class', 'bg-'+data.status_key);
+ });
+ });
+
+ // Set tour member status
+ $('#tourmember_save').click(function(e){
+ ajax_request('tour/'+tour_key+'/tourmember', $('form[name="tourmember"]').serialize(), function(data){
+ show_message('Status gespeichert', 'info');
+ });
+ });
+
+ // Add new date to tour
+ $('#newdate_save').click(function(e){
+ if (!$('#start_date').val().length) return;
+ ajax_request('tour/'+tour_key+'/newdate', $('form[name="newdate"]').serialize(), function(data){
+ load_dates();
+ show_message('Termin gespeichert', 'info');
+ });
+ });
+
+ // Add new POV
+ $('#newpov_save').click(function(e){
+ if (!$('form[name="newpov"] #destination').val().length) return;
+ ajax_request('tour/'+tour_key+'/newpov', $('form[name="newpov"]').serialize(), function(data){
+ load_pov();
+ show_message('Zwischenziel gespeichert', 'info');
+ $('form[name="newpov"] #destination').val('');
+ });
+ });
+
+ // Add new member to tour
+ $('div.invite button.btn-primary').click(function(e){
+ var button = $(this);
+ if (!button.attr('data-id').length) return;
+ ajax_request('tour/'+tour_key+'/invite',
+ 'sys_user_id='+button.attr('data-id'),
+ function(data){
+ button.removeClass('btn-primary').addClass('btn-success').attr('disabled', 'disabled');
+ });
+ });
+ // Create new biker and add new member to tour
+ $('div.invite button.btn-warning').click(function(e){
+ window.location.href = tour_base_url + 'tour/' + tour_key + '/newmember';
+ });
+ $('#newbiker_save').click(function(e){
+ if (!$('form[name="newbiker"] #name').val().length ||
+ !$('form[name="newbiker"] #email').val().length)
+ return show_message('Name und E-Mail müssen ausgefüllt sein', 'error');
+
+ if (typeof tour_key == 'string')
+ var backend = 'tour/'+tour_key+'/newbiker';
+ else
+ var backend = 'tour/newbiker';
+ ajax_request(backend, $('form[name="newbiker"]').serialize(), function(data){
+ show_message('Biker gespeichert', 'info');
+ if (typeof tour_key == 'string')
+ setTimeout(function(){window.location.href = tour_base_url + 'tour/' + tour_key + '/invite';}, 4000);
+ });
+ });
+
+ // Notizen
+ $('.container.notes #btn_new').click(function(e){
+ window.location.href = tour_base_url + 'tour/'+tour_key+'/notenew';
+ });
+ $('.container.notes .alert-dark .alert-primary').click(function(e){
+ $('div#note_del').center().show();
+ $('div#note_del button').attr('data-id', $(this).attr('data-id'));
+ });
+ $('div#note_del button#btn_del').click(function(e){
+ var note_id = $(this).attr('data-id');
+
+ ajax_request('tour/'+tour_key+'/notedel', 'id='+note_id, function(data){
+ $('div#note_del').hide();
+ $('div.note[data-id="'+note_id+'"]').hide();
+ show_message('Notiz gelöscht', 'info');
+ });
+ });
+ $('div#note_del button#btn_close').click(function(e){
+ $('div#note_del').hide();
+ });
+ $('#newnote_save').click(function(e){
+ var dest_url = tour_base_url + 'tour/'+tour_key+'/notes';
+ if (!$('form[name="newnote"] #note').val().length) {
+ window.location.href = dest_url;
+ return;
+ }
+
+ ajax_request('tour/'+tour_key+'/notenew', $('form[name="newnote"]').serialize(), function(data){
+ show_message('Notiz gespeichert', 'info');
+ setTimeout(function(){window.location.href = dest_url;}, 2000);
+ });
+ });
+ $('#newnote_second').click(function(e){
+ if (!$('form[name="newnote"] #note').val().length)
+ return;
+
+ $('form[name="newnote"]').submit();
+ });
+
+ // Administration
+ $('#tourplan_save').click(function(e){
+ if (!$('form[name="tourplan"] #name').val().length ||
+ !$('form[name="tourplan"] #urlkey').val().length ||
+ !$('form[name="tourplan"] #year').val().length ||
+ !$('form[name="tourplan"] #duration').val().length)
+ return show_message('Name, Key, Jahr und Dauer müssen ausgefüllt sein', 'error');
+
+ ajax_request('tour/'+tour_key+'/admin', $('form[name="tourplan"]').serialize(), function(data){
+ show_message('Informationen gespeichert', 'info');
+ });
+ });
+ $('#touradmin_save').click(function(e){
+ if (!$('form[name="touradmin"] #tour_member_id').val().length) return;
+
+ ajax_request('tour/'+tour_key+'/touradmin', $('form[name="touradmin"]').serialize(), function(data){
+ show_message('Tourleiter gesetzt', 'info');
+ $('form[name="touradmin"] #tour_member_id option[value="'+$('form[name="touradmin"] #tour_member_id').val()+'"]').remove();
+ });
+ });
+ $('#touradmin .btn-danger').click(function(e){
+ var button = $(this);
+ ajax_request('tour/'+tour_key+'/deladmin', 'id='+button.attr('data-id'), function(data){
+ show_message('Tourleiter gelöscht', 'info');
+ button.parents('div.form-row:first').hide();
+ });
+ });
});