app/views/restaurants/index.html.erb
<% title t("layouts.application.menu") %>
<%= content_for "page-attributes" do %>id="restaurantPage"<% end %>
<% content_for :header do %>
<ul class="nav nav-pills" id="restaurantSelector">
<li class="dropdown active pull-right">
<a class="dropdown-toggle" data-toggle="dropdown" href="#"><i class="icon-list"></i><span class="long-text"><%= @restaurant.name %></span><b class="caret"></b></a>
<ul class="dropdown-menu" id="restaurantList">
<% @restaurants.each do |restaurant| %>
<li>
<a data-restaurant-name="<%= restaurant.name %>" class="restaurant-link" href="<%= restaurant_path(restaurant: restaurant.name) %>"><%= restaurant.name %></a>
</li>
<% end %>
</ul>
</li>
</ul>
<h2 class="center">
<a href="#" title="<%= t ".prev_day" %>" id="prev_link" style="left;"><i class="icon-chevron-left"></i></a>
<span id="day_title"><%= l(@today, format: '%a, %d. %b') %></span>
<a href="#" title="<%= t ".next_day" %>" id="next_link" style="right;"><i class="icon-chevron-right"></i></a>
</h2>
<p class="restaurant-name"><%= @restaurant.name %></p>
<% end %>
<ul id="menus" class="no-bullets no-left-margin">
<li class="well">
<%= t "please_wait" %>
</li>
</ul>
<div id="restaurants-all" class="row-fluid">
<% @restaurants.each do |restaurant| %>
<div class="span4">
<h3><%= restaurant.name %></h3>
<ul data-restaurant="<%= restaurant.name %>" class="menu-list no-bullets no-left-margin">
<li class="well">
<%= t "please_wait" %>
</li>
</ul>
</div>
<% end %>
</div>
<p class="center text-warning"><%= t ".allergic_text" %></p>
<p class="center">
<a data-toggle="modal" title="<%= t ".hours" %> / <%= t ".additives" %>" class="btn btn-info" href="#infoText" style="font-style:italic;">Info</a>
</p>
<div class="modal" style="display: none;" id="infoText">
<div class="modal-header">
<button class="close" data-dismiss="modal">
×
</button>
<h3>Info</h3>
</div>
<div class="modal-body">
<h3><%= t ".allergic_headline" %></h3>
<p class="text-warning"><%= t ".allergic_text" %> <%= t ".allergic_text2" %></p>
<h3><%= t ".hours" %></h3>
<ul>
<li>
<strong>Mensa:</strong> Mo-Do 11:15 - 14:00<br>Fr 11:15 - 13:30
</li>
<li>
<strong>G'mens Pub:</strong> Mo-Do 8:00 - 23:00<br>Fr 8:00 - 18:00
</li>
<li>
<strong>Caféte:</strong> Mo-Do 8:00 bis 17:00<br>Fr 8:00 - 15:45
<br>Sa 10:00 - 14:00 (Semester)
</li>
<li>
<strong>1-Way-Snacks:</strong> Mo-Fr 11:00 - 14:30
</li>
<li>
<strong>Hotspot:</strong> Mo-Fr 9:00 - 17:00<br>Sa-So 11:00 - 17:00
</li>
</ul>
<h3><%= t ".additives" %></h3>
<ul>
<li>
1 - mit Farbstoff
</li>
<li>
2 - mit Konservierungsstoff
</li>
<li>
3 - mit Antioxidationsmittel
</li>
<li>
4 - mit Geschmacksverstärker
</li>
<li>
5 - mit Phosphat
</li>
<li>
6 - geschwefelt
</li>
<li>
7 - eventuell gewachst oder mit Thiabendazol behandelt
</li>
<li>
8 - geschwärzt
</li>
<li>
9 - mit Süßungsmittel
</li>
<li>
10 - enthält eine Phenylalaninquelle
</li>
<li>
In allen angebotenen Speisen können Geschmacksverstärker enthalten sein.
</li>
<li>
Speisen werden mit jodiertem Salz zubereitet.
</li>
</ul>
</div>
</div>
<p class="source-info">
<%= t "source" %>: <a target="_blank" href="http://www.studentenwerk-pb.de/">Studentenwerk PB</a>.
</p>
<% content_for :javascript do %>
<script>
window.iUPB.Restaurant.vars.today = new Date(<%= @today_js %>);
window.iUPB.Restaurant.vars.restaurant = "<%= @restaurant.name %>";
// #TODO: put the following code in the Restaurant class (Restaurant.initMenuView(Date day) or so)
$(document).ready(function() {
var iUPB = window.iUPB;
/*
$('#restaurantPage').swipe({
swipeLeft: function() {
nextDay();
},
swipeRight: function() {
prevDay();
},
});
*/
var singleUpToDate = false;
var multipleUpToDate = false;
$(window).resize(function() {
updateAllRestaurants();
});
var clearCache = function(){
multipleUpToDate = false;
singleUpToDate = false;
}
var updateTitles = function(){
if(!multipleUpToDate || !singleUpToDate){
$("#day_title").text(I18n.l("date.formats.weekday_date", iUPB.Restaurant.vars.today));
window.iUPB.Restaurant.indicateCurrentRestaurant(window.iUPB.Restaurant.vars.restaurant);
}
}
var updateAllRestaurants = function() {
if(!multipleUpToDate && !$("#restaurants-all").is(':hidden'))
{
$.xhrPool.abortAll();
$("#restaurants-all").find(".menu-list").each(function(i, list){
$list = $(list);
iUPB.Restaurant.updateMenus($list, iUPB.Restaurant.vars.today, $list.attr("data-restaurant"));
});
updateTitles();
multipleUpToDate = true;
}
else if (!singleUpToDate)
{
$.xhrPool.abortAll();
iUPB.Restaurant.updateMenus($("#menus"), iUPB.Restaurant.vars.today, window.iUPB.Restaurant.vars.restaurant);
// updateTitles();
singleUpToDate = true;
}
}
var updateMenus = function(){
updateAllRestaurants();
}
var nextDay = function(){
clearCache();
if(!$("#restaurants-all").is(':hidden'))
{
$.xhrPool.abortAll();
var date;
$("#restaurants-all").find(".menu-list").each(function(i, list){
$list = $(list);
date = iUPB.Restaurant.loadNextDay($list, iUPB.Restaurant.vars.today, $list.attr("data-restaurant"));
});
iUPB.Restaurant.vars.today = date;
updateTitles();
multipleUpToDate = true;
}
else
{
$.xhrPool.abortAll();
iUPB.Restaurant.vars.today = iUPB.Restaurant.loadNextDay($("#menus"), iUPB.Restaurant.vars.today, window.iUPB.Restaurant.vars.restaurant);
updateTitles();
singleUpToDate = true;
}
}
var prevDay = function(){
clearCache();
if(!$("#restaurants-all").is(':hidden'))
{
$.xhrPool.abortAll();
var date;
$("#restaurants-all").find(".menu-list").each(function(i, list){
$list = $(list);
date = iUPB.Restaurant.loadPrevDay($list, iUPB.Restaurant.vars.today, $list.attr("data-restaurant"));
});
iUPB.Restaurant.vars.today = date;
updateTitles();
multipleUpToDate = true;
}
else
{
$.xhrPool.abortAll();
iUPB.Restaurant.vars.today = iUPB.Restaurant.loadPrevDay($("#menus"), iUPB.Restaurant.vars.today, window.iUPB.Restaurant.vars.restaurant);
updateTitles();
singleUpToDate = true;
}
}
updateMenus();
updateTitles();
$("#prev_link").click(function(e) {
prevDay();
e.preventDefault();
});
$("#next_link").click(function(e) {
nextDay();
e.preventDefault();
});
$(document).keydown(function(e) {
if(e.keyCode == 37) {// left key
prevDay();
return false;
}
});
$(document).keydown(function(e) {
if(e.keyCode == 39) {// right key
nextDay();
return false;
}
});
$(".btn-info").click(function(){
if(window.innerWidth && window.innerWidth < 600)
window.setTimeout(function(){$(window).scrollTop(0)}, 300);
});
$(".restaurant-link").click(function(e){
var restaurant = $(this).data("restaurant-name");
var href = $(this).attr("href");
History.pushState({restaurant_name:restaurant}, restaurant, href);
clearCache();
iUPB.Restaurant.vars.restaurant = restaurant;
updateMenus();
updateTitles();
e.preventDefault();
});
});
</script>
<% end %>