/* * rhrdweb * * Copyright (C) 2016 Christian Pointner * * This file is part of rhrdweb. * * rhrdweb is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * * rhrdweb is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with rhrdweb. If not, see . */ 'use strict'; function getLastMonday() { var d = new Date(); d.setHours(0, 0, 0, 0); var dow = d.getDay() if(dow == 0) { return new Date(d - (6*24*3600000)); } else { return new Date(d - ((dow-1)*24*3600000)); } } function addDeltaDays(d, days) { return new Date(d.valueOf() + (days*24*3600000)) } function addWeekClass(row, week) { switch(week) { case 1: row.addClass('label-info'); break; case 2: row.addClass('label-warning'); break; case 3: row.addClass('label-success'); break; case 4: row.addClass('label-danger'); break; default: row.addClass('label-default'); } } function calendar_redraw() { var cal = $('#calendar'); cal.find("tr:gt(0)").remove(); var date = getLastMonday(); date = addDeltaDays(date, -28); for(var w = 0; w < 42; w++) { var week = get_rd_week(date.valueOf()); var row = $(''); addWeekClass(row, week); row.append($('').addClass('week').text(week)); row.append($('').addClass('month').text(monthname_short[date.getMonth()])); for(var d = 0; d < 7; d++) { var col = $('').text(date.getDate()); row.append(col); if(d < 6) { date = addDeltaDays(date, 1); } } row.append($('').addClass('month').text(monthname_short[date.getMonth()])); date = addDeltaDays(date, 1); $('#calendar').append(row); } } function calendar_init() { calendar_redraw() }