CalendarMonthView

From Lift

Jump to: navigation, search

CalendarMonthView widget provides support for rendering calendar entities impersonated by CalendarItem object into a month-view representation.

Code example:

Assuming the snippet:


class CalendarView {

  def render(html: Group) : NodeSeq = {
    val c = Calendar getInstance;
    c.set(MONTH, 4)
    bind("cal", html,
         "widget" --> CalendarMonthView(c, makeCals, itemClick, dayClick, weekClick)
    )
  }
  
  import JE._
  import JsCmds._
  
  /* The javascript function to be executed when a calendar item is clicked. 
   * The JS function takes two parameters: 
   *   - elem - the html node that was clicked. This allows you to apply effects on the clicked item
   *   - param - the identity of the CalendarItem that was clicked
   */
  def itemClick = Full(AnonFunc("elem, param", JsRaw("alert(param + ' - ' + elem.nodeName)"))) 
  /* The javascript function to be executed when a calendar day cell is clicked. 
   * The JS function takes two parameters: 
   *   - elem - the html node that was clicked. This allows you to apply effects on the clicked item
   *   - param - the date of clicked day in MM/dd/yyyy format
   */
  def dayClick = Full(AnonFunc("elem, param", JsRaw("alert(param + ' - ' + elem.nodeName)")))
  /* The javascript function to be executed when a calendar week cell is clicked. 
   * The JS function takes two parameters: 
   *   - elem - the html node that was clicked. This allows you to apply effects on the clicked item
   *   - param - the week number
   */
  def weekClick = Full(AnonFunc("elem, param", JsRaw("alert(param + ' - ' + elem.nodeName)")))

 
  private def makeCals = {
    val c1 = Calendar getInstance
    val c2 = Calendar getInstance
    val c2End = Calendar getInstance
    val c3 = Calendar getInstance

    c2.set(DAY_OF_MONTH, 29)
    c2.set(MONTH, 3)
    c2End.set(DAY_OF_MONTH, 2)
    c2End.set(MONTH, 5)
    c3.set(DAY_OF_MONTH, 2)
    c3.set(MONTH, 4)

    val item1 = CalendarItem("1", c1, CalendarType.MEETING) optional(
        _ end(c1),
        _ subject("Meet me"), 
        _ description("We really need to meet to settle things down. This is just a dumb comment to have something in it."))
        
    val item2 = CalendarItem("2", c2, CalendarType.MEETING) optional(
        _ end(c2End), 
        _ subject("Meet me again"))
        
    val item3 = CalendarItem("4", c3, CalendarType.MEETING) optional( 
        _ end(c3),
        _ subject("Other month"))
    
    item1 :: item2 :: item3 ::  Nil
  }
}

and the html fragment:

    <lift:CalendarView.render>
	<cal:widget/>
    </lift:CalendarView.render>
CalendarItem is a case class that defines the items that needs to be rendered. It has 3 mandatory fields:
- id item identity
- start date
- item type
the other fields like subject, description and end date are optional elements and they can be expressed using optional 
function and passing the functions that needs to be executed to "set" the end data,subject or description ... or any 
combination of those. Note that CalendarItem is fully immutable.

Br's, Marius

Personal tools