From b6aa463627b2a222af1054c9b971f5ab4ad85fb1 Mon Sep 17 00:00:00 2001 From: Janos Brauer Date: Wed, 10 Dec 2014 15:06:15 +0100 Subject: [PATCH] fixed issue that javascript is only executed after reload --- app/assets/javascripts/event_suggestions.js | 68 +++++++------ app/assets/javascripts/events_approval.js | 107 +++++++++++--------- 2 files changed, 92 insertions(+), 83 deletions(-) diff --git a/app/assets/javascripts/event_suggestions.js b/app/assets/javascripts/event_suggestions.js index 30fea445..efb8fdaf 100644 --- a/app/assets/javascripts/event_suggestions.js +++ b/app/assets/javascripts/event_suggestions.js @@ -3,7 +3,8 @@ EVENT_URL = '/events/' SUGGEST_URL = '/new_event_suggestion' -$(document).ready(function() { +var ready; +ready = function() { var typingTimer; var doneTypingInterval = 1000; $('#sugguest-form input').change(function() { @@ -22,9 +23,8 @@ $(document).ready(function() { // if(flash.warning) { $('.notice').html('
' + flash.warning + '
');} // if(flash.error) { /* code to display the 'error' flash */ alert("aa"); } // }); -}); -function checkVacancy(e) { + function checkVacancy(e) { rooms = [] $("#selectpicker option:selected").each(function(){ rooms.push($(this).val());}); @@ -59,9 +59,9 @@ function checkVacancy(e) { }) // }) }); -}; - -function flashWarning(data) { + }; + + function flashWarning(data) { messages = [] for(var i in data) { if(isNum(i)) { @@ -106,9 +106,9 @@ function flashWarning(data) { } $(".notice").html(output); -} - -function convertUTCDateToLocalDate(date) { + } + + function convertUTCDateToLocalDate(date) { var newDate = new Date(date.getTime()+date.getTimezoneOffset()*60*1000); var offset = date.getTimezoneOffset() / 60; @@ -117,34 +117,36 @@ function convertUTCDateToLocalDate(date) { newDate.setHours(hours - offset); return newDate; -} -function isNum(val) { - return /^\d+$/.test(val); -} - -function isSameDay(startDate, endDate) { + } + 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 "
Alternative für Event " + id + " vorschlagen"; -} - -function clearFlash() { - $(".notice").html(""); -} \ No newline at end of file + 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 "
Alternative für Event " + id + " vorschlagen"; + } + + function clearFlash() { + $(".notice").html(""); + } +}; +$(document).ready(ready); +$(document).on('page:load', ready); \ No newline at end of file diff --git a/app/assets/javascripts/events_approval.js b/app/assets/javascripts/events_approval.js index 7dfad7fd..bbfd26d3 100644 --- a/app/assets/javascripts/events_approval.js +++ b/app/assets/javascripts/events_approval.js @@ -4,7 +4,11 @@ EVENT_URL = '/events/' SUGGEST_URL = '/new_event_suggestion' DECLINE_URL = '/decline' -$(document).ready(function() { + + +var ready; + +ready = function () { $(".decline-btn").click(function(e) { e.preventDefault(); var id = this.id; @@ -21,53 +25,56 @@ $(document).ready(function() { 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); + }) + }); + }); + 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; + } +}; - return newDate; -} +$(document).ready(ready); +$(document).on('page:load', ready); \ No newline at end of file