include mixins

doctype strict
html
	include header
	script(src='/javascripts/pfiswebsocket.js')
	script(src='/templates/pcalimport_changes.js')
	script(src='/javascripts/runtime.js')
	link(href="/stylesheets/style_week.css", rel="stylesheet")
	style.
		.cell_element { display: table-cell; }
		.td_new_celebration { padding-top: 10px; }
		.give_margin_left { padding-left: 10px; }
		@media only screen and (max-width: 768px) {
			.cell_element {
				display: block;
				margin-bottom: 15px;
			}
			.td_new_celebration { padding-top: 0px; }
			.give_margin_left { padding-left: 0px; }
		}
		
		.changes_details {
			max-height: 250px;
			overflow-y: scroll;
			margin-top: 10px;
		}
		
		.day_details {
			max-height: 200px;
			overflow-y: scroll;
		}

	body
		.modal.fade(id="collectUserDataDialog", role="dialog", aria-labelledby="collectUserDataDialogLabel", aria-hidden="true")
			.modal-dialog(role="document")
				.modal-content
					.modal-header
						h4(class="modal-title", id="collectUserDataDialogLabel") Benutzer-Einträge auslesen
					.modal-body
						p(style="font-weight: bold; font-style: italic;") Bitte warten Sie, während die Einträge der Benutzer von PfIS zusammengestellt werden ...

		.modal.fade(id="confirmReject", role="dialog", aria-labelledby="confirmRejectLabel", aria-hidden="true")
			.modal-dialog(role="document")
				.modal-content
					.modal-header
						button(type="button", class="close", data-dismiss="modal", aria-hidden="true") &times;
						h4(class="modal-title", id="confirmRejectLabel") Ablehnung bestätigen
					.modal-body
						p Sind Sie sicher, dass Sie diese Änderung verwerfen wollen?
							br
							span Die entsprechende Datei wird vom Datenträger gelöscht!
					.modal-footer
						button(type="button", class="btn btn-default", data-dismiss="modal") Abbrechen
						button(type="button", class="btn btn-danger", id="confirm") Änderung tatsächlich ablehnen

		.root
			.new_flex_zero
				+nav("PfarrInfoSystem", "mainmenu")
				.container-fluid
					h1 Elemente in den Pfarrkalender importieren
					p Lesen sie alle von den Nutzern von PfIS erstellten Kalender-Einträge aus bzw. importieren Sie eine Datei und entscheiden Sie, welche Einträge übernommen werden sollen.
					.btn-toolbar(style="margin-bottom: 20px;")
						.btn-group.btn-group-xs
							button.btn.btn-primary.button-import-userdata Einträge der Nutzer auslesen
						.btn-group.btn-group-xs
							button.btn.btn-primary.button-import-file Datei importieren
								
			.new_flex_one
				.container-fluid#changes_parent
					
							
					//- var parishid = 0;		
					//-each parish in parishes
					//-	- var my_uid = generateUID();
					//-	if(parish.volunteergroups.length > 0)
					//-		.panel.panel-default.parish-marker(style="border-width: 3px;", data-parishid=parishid)
					//-			.panel-heading
					//-				h4.panel-title(data-toggle="collapse", data-target="#PANEL_#{my_uid}", aria-expanded="false", aria-controls="PANEL_#{my_uid}", style="cursor: pointer;") #{parish.name}
					//-			.panel-collapse.collapse(id="PANEL_#{my_uid}")
					//-				.panel-body(style="padding: 10px;")
					//-					.container-fluid
					//-						.row
					//-							button.btn.btn-primary.btn-xs.button-select-all Alle auswählen
					//-							button.btn.btn-default.btn-xs.button-deselect-all Alle abwählen
					//-					table(width='100%', class='table table-condensed', style='margin-bottom: 10px;')
					//-						thead
					//-							tr
					//-								td <b>Name</b>
					//-						tbody
					//-							for grp in parish.volunteergroups
					//-								tr(onclick="$(this).toggleClass('group_is_selected'); update_button_volunteergroupsselected();", style="cursor: pointer;", data-dn="#{grp.dn}", data-group)
					//-									td #{grp.name}
					//-	- parishid++;
			
		script.
			var ws = new PfISWebSocket("#{sessionuuid}", "#{taskuuid}");
			ws.bind_standard_close_handler();
		
			$(".button-import-userdata").on('click', function(event) {
				console.log('USERDATA');
				$('#collectUserDataDialog').modal({
					backdrop: 'static',
					keyboard: false
				});
				ws.send('collect_userdata', {});
			});
			
			$(".button-import-file").on('click', function(event) {
			
			});
			
			ws.bind("collected_changes", function(data) {
				console.log(data);
				var html = pcalimport_changes_template(data);
				if(data.source==="user-data")
					$('#collectUserDataDialog').modal('hide');
				$("#changes_parent").empty();
				$("#changes_parent").html(html);
				$("#changes_parent").find(".btn-success").on('click', on_click_accept);
				$('html, body').scrollTop(0);
			});
		
			function on_click_accept() {
				$(this).closest('.btn-group').find('.btn').attr('disabled', 'disabled');
				console.log('SUCCESS CLICKED', this);
			}
			
			function update_button_volunteergroupsselected() {
				if($(".group_is_selected").length > 0)
					$("#button_volunteergroupsselected").removeClass("disabled");
				else 
					$("#button_volunteergroupsselected").addClass("disabled")
			}
			
			function volunteergroupsselected() {
				if($("#button_volunteergroupsselected").hasClass("disabled"))
					return;
			
				var selected_groups = [];
				
				$("[data-parishid]").each(function(index){
					var this_parish = { id: $(this).data('parishid'), selected_groups : [] };
					$(this).find(".group_is_selected").each(function(index) {
						this_parish.selected_groups.push($(this).data('dn'));
					});	
					selected_groups.push(this_parish);
				});
				
				console.log(selected_groups);
				console.log($("#combo_sortorder").val());
			
				
				ws.send('get_volunteerslist', {sortorder: parseInt($("#combo_sortorder").val()), groups : selected_groups});
			}
			
			ws.bind('get_volunteerslist_result', function(data) {
				console.log(data);
				var html = volunteerslist_result_template(data);
				$("#volunteerslist_list").empty();
				$("#volunteerslist_list").html(html);
				$("#volunteerslist").show();
				$("#volunteerslist_list").parent().parent().scrollTop(0);
				
				$('html, body').scrollTop(0);
			})
			
