API Docs for: 1.0.0
Show:

File: scotts\widgets\gsp_calendar\client.js

function _controller($scope) {
	/**
	 * 
	 * @class GSPCalendar.Client
	 * @constructor
	 * @extends Widget.Client
	 * @module Widgets
	 */
	
	// Variable Declarations
	var isTrue;
	
	/**
	 * Due to the variety of ways that ServiceNow indicates "True" or "False"
	 * inside the system, this function interprets the variety of truthy
	 * values and assess if the passed value is one of them and returns false
	 * otherwise as the value is not "truthy".
	 * 
	 * @method isTrue
	 * @private
	 * @param {String | Number | Boolean} the value to check for truthiness.
	 * @return {Boolean} The leveled boolean value indicating if the passed
	 * 		value should be considered true of false.
	 */
	isTrue = function(value) {
		return value === "true" || value === "1" || value === 1 || value === true;
	};
	
	/**
	 * 
	 * @method getTitle
	 * @return {String} The title to display
	 */
	$scope.getTitle = function() {
		if($scope.data.calendar && $scope.data.calendar.name) {
			return $scope.data.calendar.name;
		}
		return $scope.options.title || "Calendar";
	};
	
	/**
	 * Map an event from the CalendarUtil to a FullCalendar event object.
	 * 
	 * See the FullCalendar event documentation for details on what the event
	 * object can contain; https://fullcalendar.io/docs/event-object
	 * 
	 * Additional information on rendering the event can be found at
	 * https://fullcalendar.io/docs/event-display but can vary in relation
	 * to where the options are specified.
	 * @method mapEvent
	 * @param {Object} source
	 * @return {Object} 
	 */
	$scope.mapEvent = function(source) {
		var event = {
			"title": source.u_title,
			"id": source.sys_id,
			"start": new Date(source.u_begin_date),
			"end": new Date(source.u_end_date),
			"allDay": isTrue(source.u_all_day_event),
		};
		
		if(event.allDay) {
			delete(event.end);
		}
		
		return event;
	};
	
	/**
	 * Holds the event data for the calendar that was loaded after being
	 * processed by mapEvent so that FullCalendar can display the events
	 * accordingly.
	 * @property events
	 * @type Array
	 */
	$scope.events = $scope.data.events.map($scope.mapEvent);
	
	/**
	 * Defines the configuration for FullCalendar to use.
	 * 
	 * This is currently set to display the Month view and make the
	 * Calendar display not editable since the controls for Events are
	 * inside ServiceNow.
	 * 
	 * See FullCalendar's documentation for further details at
	 * https://fullcalendar.io/docs .
	 * 
	 * Additionally, the Event Display documentation for FullCalendar
	 * described at https://fullcalendar.io/docs/event-display can
	 * be useful for managing Event rendering and some may need to
	 * be specified as part of the Calendar's configuration.
	 * 
	 * @property calendarConfiguration
	 * @type Object
	 * @see https://fullcalendar.io/docs
	 * 
	 */
	$scope.calendarConfiguration = {
		"editable": false,
		"allDaySlot": true,
		"defaultView": "dayGridMonth",
		"timegrid": {
			"allDaySlot": true
		}
	};
	// Additional configurations
	$scope.calendarConfiguration.dayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
	$scope.calendarConfiguration.dayNamesShort = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
	
	/**
	 * FullCalendar supports receiving an array of arrays to describe
	 * the events present on the Calendar so that multiple sources
	 * can easily be read and loaded.
	 * 
	 * As we only have one source, this isn't particularly necessary,
	 * but a future state may involve something akin to pulling in the
	 * calendar for the current user as well, in which case this could
	 * be useful.
	 * @property eventSources
	 * @type Array
	 */
    $scope.eventSources = [$scope.events];
	
	// Test Data
	/*
    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();
	$scope.eventSources.push([
		{title: "Birthday Party 1",start: new Date(y, m, d + 1, 19, 0),end: new Date(y, m, d + 1, 22, 30),allDay: false},
		{title: "Birthday Party 2",start: new Date(y, m, d + 5, 19, 0),end: new Date(y, m, d + 1, 22, 30),allDay: false},
		{title: "Birthday Party 3",start: new Date(y, m, d + 16, 19, 0),end: new Date(y, m, d + 1, 22, 30),allDay: false}
	]);
	$scope.eventSources.push([
		{title: "All Day Event",start: new Date(y, m, 1)},
		{title: "Long Event",start: new Date(y, m, d - 5),end: new Date(y, m, d - 2)},
		{title: "Birthday Party",start: new Date(y, m, d + 1, 19, 0),end: new Date(y, m, d + 1, 22, 30),allDay: false}
	]);
	*/
}