net.liftmodules.widgets.calendars.CalendarDayView.scala Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2007-2011 WorldWide Conferencing, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.liftmodules
package widgets
package calendars
import java.util.{Calendar, Locale}
import java.util.Calendar._
import xml._
import net.liftweb._
import common.Box
import util.Helpers._
import http.LiftRules
import http.js._
import http.SHtml._
import JsCmds._
import JE._
object CalendarDayView {
/**
* Call this function typically in boot
*/
def init() {
import _root_.net.liftweb.http.ResourceServer
ResourceServer.allow({
case "calendars" :: _ => true
case "common" :: _ => true
})
}
def apply(when: Calendar,
calendars: List[CalendarItem],
itemClick: Box[AnonFunc]) = new CalendarDayView(when).render(calendars, itemClick)
def apply(when: Calendar,
meta: DayViewMeta,
calendars: List[CalendarItem],
itemClick: Box[AnonFunc]) = new CalendarDayView(when, meta) render(calendars, itemClick)
}
class CalendarDayView(val when: Calendar, val meta: DayViewMeta) {
def this(when: Calendar) = this(when, DayViewMeta(Locale getDefault))
def makeHead(headCal: Calendar) = {
(0 to 6) map(x => {
try{
meta.weekDaysFormatter format(headCal getTime)
} finally {
headCal add(DAY_OF_MONTH, 1)
}
} )
}
def render(calendars: List[CalendarItem], itemClick: Box[AnonFunc]): NodeSeq = {
val cal = when.clone().asInstanceOf[Calendar]
{Script(
JsCrVar("itemClick", itemClick openOr JsRaw("function(param){}")) &
JsCrVar("calendars", CalendarUtils.toJSON(calendars filter (c => CalendarUtils.sameDay(c.start, when)))) &
JsRaw("""
jQuery(document).ready(function() {
CalendarWeekView.buildDayViewCalendars();
})
""")
)}
{
val time = cal.getTime
meta.weekDaysFormatter.format(time) + " " + dateFormatter.format(time)
}
{
val cal = Calendar getInstance;
cal set(HOUR_OF_DAY, 0)
cal set(MINUTE, 0)
for (i <- 0 to 23) yield
try{
{(meta.timeFormatter format(cal getTime)).toString}
{
}
{
}
} finally {
cal add(HOUR_OF_DAY, 1)
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy