import * as observableModule from "tns-core-modules/data/observable" ; import * as calendarModule from "nativescript-ui-calendar" ; import { Frame } from "tns-core-modules/ui/frame" ; export class ViewModel extends observableModule . Observable { calendarEvents : Array < calendarModule . CalendarEvent > ; private _viewModesInfo ; private _eventTitles : Array < string > = [ "Meeting with Jack" , "Lunch with Peter" , "Planning meeting" , "Go shopping" , "Very important meeting" , "Another meeting" , "Random event" ] ; constructor ( ) { super ( ) ; this . createEvents ( ) ; this . _viewModesInfo = { options : [ "None" , "Inline" , "Popover (available on iPad only)" ] , index : 0 } ; } get eventsMode ( ) : calendarModule . CalendarEventsViewMode { return this . get ( "eventsViewMode" ) ; } set eventsMode ( value ) { this . set ( "eventsViewMode" , value ) ; } public createEvents ( ) { let events = new Array < calendarModule . CalendarEvent > ( ) ; let j = 1 ; for ( let i = 0 ; i < this . _eventTitles . length ; i ++ ) { const now = new Date ( ) ; const startDate = new Date ( now . getFullYear ( ) , now . getMonth ( ) , j * 2 , j * 2 ) ; const endDate = new Date ( now . getFullYear ( ) , now . getMonth ( ) , ( j * 2 ) + ( j % 3 ) , ( j * 2 ) + ( j % 3 ) ) ; const event = new calendarModule . CalendarEvent ( this . _eventTitles [ i ] , startDate , endDate ) ; events . push ( event ) ; j ++ ; } this . calendarEvents = events ; } public updateEventsViewMode ( ) { let radCalendar = < calendarModule . RadCalendar > ( Frame . topmost ( ) . getViewById ( "calendar" ) ) ; if ( ! radCalendar . ios ) { return ; } const index = this . _viewModesInfo . index ; if ( index === 0 ) { this . eventsMode = calendarModule . CalendarEventsViewMode . None ; } else if ( index === 1 ) { this . eventsMode = calendarModule . CalendarEventsViewMode . Inline ; } else { if ( UIDevice . currentDevice . userInterfaceIdiom === UIUserInterfaceIdiom . Pad ) { this . eventsMode = calendarModule . CalendarEventsViewMode . Popover ; } else { let prevIndex = 0 ; if ( this . eventsMode === calendarModule . CalendarEventsViewMode . Inline ) { prevIndex = 1 ; } this . _viewModesInfo . index = prevIndex ; } } } public onOptionsTapped ( ) { const navigationEntry = { moduleName : "navigation/options-menu/options-page" , context : this . _viewModesInfo , animated : true } ; Frame . topmost ( ) . navigate ( navigationEntry ) ; } }