API Docs for: 1.0.0
Show:

File: scotts\widgets\gsp_calendar_summary\server.js

(function() {
	/**
	 * 
	 * @class GSPCalendarSummary.Server
	 * @constructor
	 * @extends Widget.Server
	 * @module Widgets
	 */
	
	/**
	 * The PortalCalendar for the active service portal.
	 * @property calendar
	 * @type GlideRecord | PortalCalendar
	 */
	var calendar = new GlideRecord("u_portal_calendar"),
	/**
	 * The GlideRecord for the active ServicePortal from which to pull values
	 * such as the current calendar or owner information if needed.
	 * @property sp
	 * @type GlideRecord | ServicePortal
	 */
		sp = $sp.getPortalRecord(),
	/**
	 * Used for retrieving necessary calendar information.
	 * @property utility
	 * @type CWTCalendarUtil
	 */
		utility,
		isTrue,
		x;
	
	calendar.get("u_sp_portal", sp.sys_id.getValue());
	utility = new CWTCalendarUtil(calendar.getValue("sys_id"));
	
	/**
	 * 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;
	};
	
	/**
	 * The number of featured events to display.
	 * @property options.limit
	 * @type Number
	 * @default 5
	 */
	options.limit = parseInt(options.limit) || 5;
	
	/**
	 * Indicates if events that are not flagged as featured should be included
	 * in the list of events to display.
	 * @property options.nonFeatured
	 * @type Boolean
	 * @default false
	 */
	options.nonFeatured = isTrue(options.nonFeatured);
	
	/**
	 * The data to describe the basics of the current calendar such
	 * as title and description.
	 * 
	 * See the Calendar utility for the details retrieved by the
	 * {{#crossLink "CWTCalendarUtil/getCalendarJSON:method"}}{{/crossLink}}
	 * method.
	 * @property data.calendar
	 * @type Object
	 */
	data.calendar = utility.getCalendarJSON();
	/**
	 * All active events for the currently associated Calendar.
	 * 
	 * This may pose a memory issue at a future point, but the current
	 * use case lets this remain simple.
	 * 
	 * See the Calendar utility for the details retrieved by the
	 * {{#crossLink "CWTCalendarUtil/getEvents:method"}}{{/crossLink}}
	 * method.
	 * @property data.events
	 * @type Object
	 */
	data.events = utility.getEvents(true, !options.nonFeatured, new GlideDate());
	
	// Limit to a set number of events
	if(data.events && data.events.length > options.limit) {
		data.events.splice(options.limit);
	}
	
	// Level set values for UI side use
	for(x=0; x<data.events.length; x++) {
		data.events[x].u_all_day_event = isTrue(data.events[x].u_all_day_event);
	}
})();