/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ "use strict"; /* import-globals-from widgets/mouseoverPreviews.js */ /* import-globals-from calendar-ui-utils.js */ /* global calendarNavigationBar, currentView, gCurrentMode, getSelectedCalendar, invokeEventDragSession, MozElements, MozXULElement, timeIndicator */ // Wrap in a block to prevent leaking to window scope. { const { cal } = ChromeUtils.import("resource:///modules/calendar/calUtils.jsm"); const MINUTES_IN_DAY = 24 * 60; /** * Get the nearest or next snap point for the given minute. The set of snap * points is given by `n * snapInterval`, where `n` is some integer. * * @param {number} minute - The minute to snap. * @param {number} snapInterval - The integer number of minutes between snap * points. * @param {"nearest","forward","backward"} [direction="nearest"] - Where to * find the snap point. "nearest" will return the closest snap point, * "forward" will return the closest snap point that is greater (and not * equal), and "backward" will return the closest snap point that is lower * (and not equal). * * @returns {number} - The nearest snap point. */ function snapMinute(minute, snapInterval, direction = "nearest") { switch (direction) { case "forward": return Math.floor((minute + snapInterval) / snapInterval) * snapInterval; case "backward": return Math.ceil((minute - snapInterval) / snapInterval) * snapInterval; case "nearest": return Math.round(minute / snapInterval) * snapInterval; default: throw new RangeError(`"${direction}" is not one of the allowed values for the direction`); } } /** * Determine whether the given event item can be edited by the user. * * @param {calItemBase} eventItem - The event item. * * @returns {boolean} - Whether the given event can be edited by the user. */ function canEditEventItem(eventItem) { return ( cal.acl.isCalendarWritable(eventItem.calendar) && cal.acl.userCanModifyItem(eventItem) && !( eventItem.calendar instanceof Ci.calISchedulingSupport && eventItem.calendar.isInvitation(eventItem) ) && eventItem.calendar.getProperty("capabilities.events.supported") !== false ); } /** * The MozCalendarEventColumn widget used for displaying event boxes in one column per day. * It is used to make the week view layout in the calendar. It manages the layout of the * events given via add/deleteEvent. */ class MozCalendarEventColumn extends MozXULElement { static get inheritedAttributes() { return { ".multiday-events-list": "context", ".timeIndicator": "orient", }; } /** * The background hour box elements this event column owns, ordered and * indexed by their starting hour. * * @type {Element[]} */ hourBoxes = []; /** * The date of the day this event column represents. * * @type {calIDateTime} */ date; connectedCallback() { if (this.delayConnectedCallback() || this.hasChildNodes()) { return; } this.appendChild( MozXULElement.parseXULToFragment(`