Skip to content

Commit

Permalink
fixed issue that javascript is only executed after reload
Browse files Browse the repository at this point in the history
  • Loading branch information
hsgfan committed Dec 10, 2014
1 parent a22d0f8 commit b6aa463
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 83 deletions.
68 changes: 35 additions & 33 deletions app/assets/javascripts/event_suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -22,9 +23,8 @@ $(document).ready(function() {
// 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) {
function checkVacancy(e) {
rooms = []
$("#selectpicker option:selected").each(function(){ rooms.push($(this).val());});

Expand Down Expand Up @@ -59,9 +59,9 @@ function checkVacancy(e) {
})
// })
});
};

function flashWarning(data) {
};
function flashWarning(data) {
messages = []
for(var i in data) {
if(isNum(i)) {
Expand Down Expand Up @@ -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;
Expand All @@ -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 "<br/><a target='_blank' href=" + EVENT_URL + id + SUGGEST_URL +"> Alternative für Event " + id + " vorschlagen</a>";
}

function clearFlash() {
$(".notice").html("");
}
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);
107 changes: 57 additions & 50 deletions app/assets/javascripts/events_approval.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

0 comments on commit b6aa463

Please sign in to comment.