Ionic calendar directive
This repository only supports Ionic v1.
Please visit https://github.com/twinssbc/Ionic2-Calendar which supports higher version of Ionic.
http://twinssbc.github.io/Ionic-Calendar/demo/
Bower Install: bower install ionic-calendar
Load the necessary dependent files:
<link rel="stylesheet" href="http://code.ionicframework.com/1.1.1/css/ionic.min.css"/>
<link rel="stylesheet" href="https://github.com/twinssbc/Ionic-Calendar/blob/master/<bower lib installation path>/ionic-calendar/dist/css/calendar.min.css"/>
<script src="http://code.ionicframework.com/1.1.1/js/ionic.bundle.min.js"></script>
<script src="https://github.com/twinssbc/Ionic-Calendar/raw/master/<bower lib installation path>/ionic-calendar/dist/js/calendar-tpls.min.js"></script>
Add the calendar module as a dependency to your application module:
var myAppModule = angular.module('MyApp', ['ui.rCalendar'])
Add the directive in the html page
<calendar calendar-mode="mode" event-source="eventSource">
To change calendar selected date, simply use ng-model
$scope.selectedDate = new Date();
<calendar calendar-mode="mode" event-source="eventSource" ng-model="selectedDate"></calendar>
<calendar ... monthview-display-event-template-url="monthviewDisplayEventTemplateUrl"></calendar>
$scope.monthviewDisplayEventTemplateUrl = 'myTemplate.html';
<calendar ... monthview-event-detail-template-url="monthviewEventDetailTemplateUrl"></calendar>
$scope.monthviewEventDetailTemplateUrl = 'myTemplate.html';
<calendar ... weekview-all-day-event-template-url="weekviewAllDayEventTemplateUrl"></calendar>
$scope.weekviewAllDayEventTemplateUrl = 'myTemplate.html';
<calendar ... weekview-normal-event-template-url="weekviewNormalEventTemplateUrl"></calendar>
$scope.weekviewNormalEventTemplateUrl = 'myTemplate.html';
<calendar ... dayview-all-day-event-template-url="dayviewAllDayEventTemplateUrl"></calendar>
$scope.dayviewAllDayEventTemplateUrl = 'myTemplate.html';
<calendar ... dayview-normal-event-template-url="dayviewNormalEventTemplateUrl"></calendar>
$scope.dayviewNormalEventTemplateUrl = 'myTemplate.html';
rangeChanged
The callback function triggered when the range or mode is changed if the queryMode is set to 'remote'
$scope.rangeChanged = function (startTime, endTime) {
Events.query({startTime: startTime, endTime: endTime}, function(events){
$scope.eventSource=events;
});
};
eventSelected
The callback function triggered when an event is clicked
<calendar ... event-selected="onEventSelected(event)"></calendar>
$scope.onEventSelected = function (event) {
console.log(event.title);
};
timeSelected
The callback function triggered when a date is selected in the monthview. If there's no event at the selected time, the events parameter will be either undefined or empty array
<calendar ... time-selected="onTimeSelected(selectedTime, events, disabled)”></calendar>
$scope.onTimeSelected = function (selectedTime, events, disabled) {
console.log('Selected time: ' + selectedTime + ', hasEvents: ' + (events !== undefined && events.length !== 0) + ‘, disabled: ’ + disabled);
};
titleChanged
The callback function triggered when the view title is changed
<calendar ... title-changed="onViewTitleChanged(title)”></calendar>
$scope.onViewTitleChanged = function (title) {
$scope.viewTitle = title;
};
isDateDisabled The callback function to determine if the date should be disabled
<calendar ... is-date-disabled="isDateDisabled(date)”></calendar>
$scope.isDateDisabled = function (date) {
var currentDate = new Date();
currentDate.setHours(0,0,0);
return date <= currentDate;
};
EventSource is an array of event object which contains at least below fields:
title
startTime
If allDay is set to true, the startTime has to be as a UTC date which time is set to 0:00 AM, because in an allDay event, only the date is considered, the exact time or timezone doesn't matter.
For example, if an allDay event starting from 2014-05-09, then startTime is
var startTime = new Date(Date.UTC(2014, 4, 8));
endTime
If allDay is set to true, the startTime has to be as a UTC date which time is set to 0:00 AM, because in an allDay event, only the date is considered, the exact time or timezone doesn't matter.
For example, if an allDay event ending to 2014-05-10, then endTime is
var endTime = new Date(Date.UTC(2014, 4, 9));
allDay
Indicates the event is allDay event or regular event
Note In the current version, the calendar controller only watches for the eventSource reference as it's the least expensive. That means only you manually reassign the eventSource value, the controller get notified, and this is usually fit to the scenario when the range is changed, you load a new data set from the backend. In case you want to manually insert/remove/update the element in the eventSource array, you can call broadcast the 'eventSourceChanged' event to notify the controller manually.
changeDate
When receiving this event, the calendar will move the current view to previous or next range.
Parameter: direction
1 - Forward
-1 - Backward
$scope.$broadcast('changeDate', 1);
eventSourceChanged
This event is only needed when you manually modify the element in the eventSource array.
Parameter: value
The whole event source object
$scope.$broadcast('eventSourceChanged',$scope.eventSource);
When including the angular locale script, the viewTitle and header of the calendar will be translated to local language automatically.
<script src="http://code.angularjs.org/1.4.3/i18n/angular-locale_xx.js"></script>