-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'c/feature/#81' into Clownfish
Conflicts: app/views/events/show.html.erb
- Loading branch information
Showing
33 changed files
with
848 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.