Skip to content

Commit

Permalink
Merge branch 'c/feature/#81' into Clownfish
Browse files Browse the repository at this point in the history
Conflicts:
	app/views/events/show.html.erb
  • Loading branch information
DasDingGehtNicht committed Dec 12, 2014
2 parents ab2743c + 7294a78 commit d7d5e68
Show file tree
Hide file tree
Showing 33 changed files with 848 additions and 82 deletions.
152 changes: 152 additions & 0 deletions app/assets/javascripts/event_suggestions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
// // Place all the behaviors and hooks related to the matching controller here.
// // All this logic will automatically be available in application.js.
EVENT_URL = '/events/'
SUGGEST_URL = '/new_event_suggestion'

var ready;
ready = function() {
var typingTimer;
var doneTypingInterval = 1000;
$('#sugguest-form input').change(function() {
clearTimeout(typingTimer);
typingTimer = setTimeout(checkVacancy, doneTypingInterval);
});

$('#sugguest-form #selectpicker').change(function() {
clearTimeout(typingTimer);
typingTimer = setTimeout(checkVacancy, doneTypingInterval);
});
// $(document).ajaxComplete(function(event, request) {
// var flash = $.parseJSON(request.getResponseHeader('X-Flash-Messages'));
// if(!flash) return;
// if(flash.notice) { $('.notice').html('<div class="alert fade in alert-success"><button class="close" data-dismiss="alert">×</button>' + flash.notice + '</div>'); }
// if(flash.warning) { $('.notice').html('<div class="alert fade in alert-warning"><button class="close" data-dismiss="alert">×</button>' + flash.warning + '</div>');}
// if(flash.error) { /* code to display the 'error' flash */ alert("aa"); }
// });

function checkVacancy(e) {
rooms = []
$("#selectpicker option:selected").each(function(){ rooms.push($(this).val());});

var data = {
event: {
starts_at_date: $('#event_suggestion_starts_at_date').val(),
starts_at_time: $('#event_suggestion_starts_at_time').val(),
ends_at_date: $('#event_suggestion_ends_at_date').val(),
ends_at_time: $('#event_suggestion_ends_at_time').val(),
room_ids: rooms
}
}
$.ajax({
url: '/checkVacancy',
type: 'PATCH',
data: data,
dataType: 'json',
beforeSend: function(xhr) {
xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'));},
success:(function(data){
if (!data["status"]) {
flashWarning(data);
}
else
clearFlash();
// var data = JSON.parse(data);
// if(data['status']){
// alert('true');
// }
// else
// alert('false');
})
// })
});
};

function flashWarning(data) {
messages = []
for(var i in data) {
if(isNum(i)) {
if(data[i]["rooms"].length > 1) {
room = ""
for(var j in rooms) {
if( room == "") {
room = data[i]["rooms"][j];
}
else {
room += ", " + data[i]["rooms"][j];
}
}
room_msg = "in den Räumen " + room;
}
else {
room_msg = "im Raum " + data[i].rooms[0] ;
}
var starts_at = convertUTCDateToLocalDate(new Date(data[i]["starts_at"]));
var ends_at = convertUTCDateToLocalDate(new Date(data[i]["ends_at"]));
var starts_at_date = starts_at.getDate() + "." + (starts_at.getMonth() + 1) + "." + starts_at.getFullYear();

if(isSameDay(starts_at, ends_at)) {
time_msg = "am " + starts_at_date
}
else {
var ends_at_date = ends_at.getDate() + "." + (ends_at.getMonth() + 1) + "." + ends_at.getFullYear();
time_msg = "vom " + starts_at_date + " bis zum " + ends_at_date;
}
var starts_at_time = getTime(starts_at);
var ends_at_time = getTime(ends_at);

time_msg += " von " + starts_at_time + " bis " + ends_at_time;
msg = "Ihre Alternative konfligiert mit dem Event " + i + " stattfindend " + " " + time_msg + " " + room_msg;
msg += suggestionLink(i);
messages.push(msg)
}
}
output = ""
for( var i in messages) {
output += '<div class="alert fade in alert-warning "><button class="close" data-dismiss="alert">×</button>' + messages[i] + '</div>';
}

$(".notice").html(output);
}

function convertUTCDateToLocalDate(date) {
var newDate = new Date(date.getTime()+date.getTimezoneOffset()*60*1000);

var offset = date.getTimezoneOffset() / 60;
var hours = date.getHours();

newDate.setHours(hours - offset);

return newDate;
}
function isNum(val) {
return /^\d+$/.test(val);
}

function isSameDay(startDate, endDate) {
if(startDate.getDate() == endDate.getDate() && startDate.getMonth() == endDate.getMonth()) {
return true;
}
else {
return false;
}
}

function getTime(date) {
var hours = date.getHours();
var mins = date.getMinutes();

var hourOutput = ((hours < 10) ? "0" + hours : hours);
var minOutput = ((mins < 10) ? "0" + mins : mins);(hours < 10 );
return hourOutput + ":" + minOutput + " Uhr"
}

function suggestionLink(id) {
return "<br/><a target='_blank' href=" + EVENT_URL + id + SUGGEST_URL +"> Alternative für Event " + id + " vorschlagen</a>";
}

function clearFlash() {
$(".notice").html("");
}
};
$(document).ready(ready);
$(document).on('page:load', ready);
143 changes: 143 additions & 0 deletions app/assets/javascripts/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,147 @@
// // All this logic will automatically be available in application.js.


var ready;
ready = function() {
var typingTimer;
var doneTypingInterval = 1000;
$('#event-form input').change(function() {
clearTimeout(typingTimer);
typingTimer = setTimeout(checkVacancy, doneTypingInterval);
});

$('#event-form #selectpicker').change(function() {
clearTimeout(typingTimer);
typingTimer = setTimeout(checkVacancy, doneTypingInterval);
});
// $(document).ajaxComplete(function(event, request) {
// var flash = $.parseJSON(request.getResponseHeader('X-Flash-Messages'));
// if(!flash) return;
// if(flash.notice) { $('.notice').html('<div class="alert fade in alert-success"><button class="close" data-dismiss="alert">×</button>' + flash.notice + '</div>'); }
// if(flash.warning) { $('.notice').html('<div class="alert fade in alert-warning"><button class="close" data-dismiss="alert">×</button>' + flash.warning + '</div>');}
// if(flash.error) { /* code to display the 'error' flash */ alert("aa"); }
// });

function checkVacancy(e) {
rooms = []
$("#selectpicker option:selected").each(function(){ rooms.push($(this).val());});

var data = {
event: {
starts_at_date: $('#event_starts_at_date').val(),
starts_at_time: $('#event_starts_at_time').val(),
ends_at_date: $('#event_ends_at_date').val(),
ends_at_time: $('#event_ends_at_time').val(),
room_ids: rooms
}
}
$.ajax({
url: '/checkVacancy',
type: 'PATCH',
data: data,
dataType: 'json',
beforeSend: function(xhr) {
xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'));},
success:(function(data){
if (!data["status"]) {
flashWarning(data);
}
else
clearFlash();
// var data = JSON.parse(data);
// if(data['status']){
// alert('true');
// }
// else
// alert('false');
})
// })
});
};

function flashWarning(data) {
messages = []
for(var i in data) {
if(isNum(i)) {
if(data[i]["rooms"].length > 1) {
room = ""
for(var j in rooms) {
if( room == "") {
room = data[i]["rooms"][j];
}
else {
room += ", " + data[i]["rooms"][j];
}
}
room_msg = "in den Räumen " + room;
}
else {
room_msg = "im Raum " + data[i].rooms[0] ;
}
var starts_at = convertUTCDateToLocalDate(new Date(data[i]["starts_at"]));
var ends_at = convertUTCDateToLocalDate(new Date(data[i]["ends_at"]));
var starts_at_date = starts_at.getDate() + "." + (starts_at.getMonth() + 1) + "." + starts_at.getFullYear();

if(isSameDay(starts_at, ends_at)) {
time_msg = "am " + starts_at_date
}
else {
var ends_at_date = ends_at.getDate() + "." + (ends_at.getMonth() + 1) + "." + ends_at.getFullYear();
time_msg = "vom " + starts_at_date + " bis zum " + ends_at_date;
}
var starts_at_time = getTime(starts_at);
var ends_at_time = getTime(ends_at);

time_msg += " von " + starts_at_time + " bis " + ends_at_time;
msg = "Ihr Event konfligiert mit dem Event &rdquo;" + data[i]["event_name"] + "&rdquo; stattfindend " + " " + time_msg + " " + room_msg;
messages.push(msg)
}
}
output = ""
for( var i in messages) {
output += '<div class="alert fade in alert-warning "><button class="close" data-dismiss="alert">×</button>' + messages[i] + '</div>';
}

$(".notice").html(output);
}

function convertUTCDateToLocalDate(date) {
var newDate = new Date(date.getTime()+date.getTimezoneOffset()*60*1000);

var offset = date.getTimezoneOffset() / 60;
var hours = date.getHours();

newDate.setHours(hours - offset);

return newDate;
}
function isNum(val) {
return /^\d+$/.test(val);
}

function isSameDay(startDate, endDate) {
if(startDate.getDate() == endDate.getDate() && startDate.getMonth() == endDate.getMonth()) {
return true;
}
else {
return false;
}
}

function getTime(date) {
var hours = date.getHours();
var mins = date.getMinutes();

var hourOutput = ((hours < 10) ? "0" + hours : hours);
var minOutput = ((mins < 10) ? "0" + mins : mins);(hours < 10 );
return hourOutput + ":" + minOutput + " Uhr"
}



function clearFlash() {
$(".notice").html("");
}
};
$(document).ready(ready);
$(document).on('page:load', ready);
78 changes: 78 additions & 0 deletions app/assets/javascripts/events_approval.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,80 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
EVENT_URL = '/events/'
SUGGEST_URL = '/new_event_suggestion'
DECLINE_URL = '/decline'



var ready;

ready = function () {
$(".decline-btn").click(function(e) {
e.preventDefault();
var id = this.id;
var event_id = id.split("#")[1]
$.ajax({
url: EVENT_URL + event_id + ".json",
type: 'GET',
dataType: 'json',
beforeSend: function(xhr) {
xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'));},
success:(function(data){
// alert("success");
insertDeclineLink(data["id"]);
insertSuggestLink(data["id"]);
insertEventIntoModal(data);
$('#myModal').modal('toggle');
})
});
});
function insertEventIntoModal(data) {
var starts_at = convertUTCDateToLocalDate(new Date(data["starts_at"]));
var ends_at = convertUTCDateToLocalDate(new Date(data["ends_at"]));
$("#myModalLabel").html("Event " + data["id"]);
$("#event_id").html(data["id"]);
$("#event_name").html(data["name"]);
$("#event_description").html(data["description"]);
$("#event_rooms").html(getRoomNames(data["rooms"]));
$("#event_participant_count").html(data["participant_count"]);
$("#event_starts_at").html(starts_at.toLocaleString());
$("#event_ends_at").html(ends_at.toLocaleString());
$("#event_user").html(data["user"]);

}

function insertSuggestLink(id) {
$(".suggest-btn").attr("href", EVENT_URL + id + SUGGEST_URL);
}

function insertDeclineLink(id) {
$(".modal-decline-btn").attr("href", EVENT_URL + id + DECLINE_URL);
}

function getRoomNames(rooms) {
room_names = ""
for ( var i in rooms) {
if( room_names == "") {
room_names += rooms[i]["name"]
}
else {
room_names += ", " + rooms[i]["name"]
}
}
return room_names //rooms.toString();
}

function convertUTCDateToLocalDate(date) {
var newDate = new Date(date.getTime()+date.getTimezoneOffset()*60*1000);

var offset = date.getTimezoneOffset() / 60;
var hours = date.getHours();

newDate.setHours(hours - offset);

return newDate;
}
};

$(document).ready(ready);
$(document).on('page:load', ready);
4 changes: 4 additions & 0 deletions app/assets/stylesheets/bootstrap_and_overrides.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@
font-family: 'Glyphicons Halflings';
src: url('/assets/glyphicons-halflings-regular.eot');
src: url('/assets/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('/assets/glyphicons-halflings-regular.woff') format('woff'), url('/assets/glyphicons-halflings-regular.ttf') format('truetype'), url('/assets/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
}

.modal-body {
height: 200px;
}
Loading

0 comments on commit d7d5e68

Please sign in to comment.