2015-03-30 19:52:26 +02:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Component
|
|
|
|
* @constructor
|
|
|
|
* @param {object} futureComponentData - either an object literal or a promise
|
|
|
|
*/
|
|
|
|
function Component(futureComponentData) {
|
|
|
|
// Data is immediately available
|
|
|
|
if (typeof futureComponentData.then !== 'function') {
|
2015-04-24 22:48:41 +02:00
|
|
|
this.init(futureComponentData);
|
2015-05-01 18:19:33 +02:00
|
|
|
if (this.pid && !this.id) {
|
|
|
|
// Prepare for the creation of a new component;
|
|
|
|
// Get UID from the server.
|
|
|
|
var newComponentData = Component.$$resource.newguid(this.pid);
|
|
|
|
this.$unwrap(newComponentData);
|
|
|
|
this.isNew = true;
|
|
|
|
}
|
2015-03-30 19:52:26 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// The promise will be unwrapped first
|
|
|
|
this.$unwrap(futureComponentData);
|
|
|
|
}
|
|
|
|
}
|
2015-06-04 22:08:45 +02:00
|
|
|
|
2015-03-30 19:52:26 +02:00
|
|
|
/**
|
|
|
|
* @memberof Component
|
|
|
|
* @desc The factory we'll use to register with Angular
|
|
|
|
* @returns the Component constructor
|
|
|
|
*/
|
2016-10-12 17:01:59 +02:00
|
|
|
Component.$factory = ['$q', '$timeout', '$log', '$rootScope', 'sgSettings', 'sgComponent_STATUS', 'Preferences', 'Card', 'Gravatar', 'Resource', function($q, $timeout, $log, $rootScope, Settings, Component_STATUS, Preferences, Card, Gravatar, Resource) {
|
2015-03-30 19:52:26 +02:00
|
|
|
angular.extend(Component, {
|
2016-08-02 18:09:11 +02:00
|
|
|
STATUS: Component_STATUS,
|
2015-03-30 19:52:26 +02:00
|
|
|
$q: $q,
|
|
|
|
$timeout: $timeout,
|
|
|
|
$log: $log,
|
2016-10-12 17:01:59 +02:00
|
|
|
$rootScope: $rootScope,
|
2015-07-08 20:46:07 +02:00
|
|
|
$Preferences: Preferences,
|
2015-12-22 23:24:16 +01:00
|
|
|
$Card: Card,
|
2015-07-29 22:23:41 +02:00
|
|
|
$gravatar: Gravatar,
|
2016-02-10 22:15:00 +01:00
|
|
|
$$resource: new Resource(Settings.activeUser('folderURL') + 'Calendar', Settings.activeUser()),
|
2015-08-03 17:53:54 +02:00
|
|
|
timeFormat: "%H:%M",
|
2015-07-09 22:35:19 +02:00
|
|
|
// Filter parameters common to events and tasks
|
|
|
|
$query: { value: '', search: 'title_Category_Location' },
|
|
|
|
// Filter paramaters specific to events
|
|
|
|
$queryEvents: { sort: 'start', asc: 1, filterpopup: 'view_next7' },
|
|
|
|
// Filter parameters specific to tasks
|
2015-09-01 16:50:50 +02:00
|
|
|
$queryTasks: { sort: 'status', asc: 1, filterpopup: 'view_incomplete' },
|
2015-11-06 21:12:24 +01:00
|
|
|
$refreshTimeout: null,
|
|
|
|
$ghost: {}
|
2015-07-08 20:46:07 +02:00
|
|
|
});
|
2017-06-01 19:46:57 +02:00
|
|
|
// Initialize filter parameters from user's settings
|
|
|
|
if (Preferences.settings.Calendar.EventsFilterState)
|
|
|
|
Component.$queryEvents.filterpopup = Preferences.settings.Calendar.EventsFilterState;
|
|
|
|
if (Preferences.settings.Calendar.TasksFilterState)
|
|
|
|
Component.$queryTasks.filterpopup = Preferences.settings.Calendar.TasksFilterState;
|
|
|
|
if (Preferences.settings.Calendar.EventsSortingState) {
|
|
|
|
Component.$queryEvents.sort = Preferences.settings.Calendar.EventsSortingState[0];
|
|
|
|
Component.$queryEvents.asc = parseInt(Preferences.settings.Calendar.EventsSortingState[1]);
|
|
|
|
}
|
|
|
|
if (Preferences.settings.Calendar.TasksSortingState) {
|
|
|
|
Component.$queryTasks.sort = Preferences.settings.Calendar.TasksSortingState[0];
|
|
|
|
Component.$queryTasks.asc = parseInt(Preferences.settings.Calendar.TasksSortingState[1]);
|
|
|
|
}
|
|
|
|
Component.$queryTasks.show_completed = parseInt(Preferences.settings.ShowCompletedTasks);
|
|
|
|
// Initialize categories from user's defaults
|
|
|
|
Component.$categories = Preferences.defaults.SOGoCalendarCategoriesColors;
|
|
|
|
// Initialize time format from user's defaults
|
|
|
|
if (Preferences.defaults.SOGoTimeFormat) {
|
|
|
|
Component.timeFormat = Preferences.defaults.SOGoTimeFormat;
|
|
|
|
}
|
2015-06-04 22:08:45 +02:00
|
|
|
|
2015-03-30 19:52:26 +02:00
|
|
|
return Component; // return constructor
|
|
|
|
}];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @module SOGo.SchedulerUI
|
|
|
|
* @desc Factory registration of Component in Angular module.
|
|
|
|
*/
|
2015-07-29 17:47:01 +02:00
|
|
|
try {
|
|
|
|
angular.module('SOGo.SchedulerUI');
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
angular.module('SOGo.SchedulerUI', ['SOGo.Common']);
|
|
|
|
}
|
2015-03-30 19:52:26 +02:00
|
|
|
angular.module('SOGo.SchedulerUI')
|
2016-08-02 18:09:11 +02:00
|
|
|
.constant('sgComponent_STATUS', {
|
|
|
|
NOT_LOADED: 0,
|
|
|
|
DELAYED_LOADING: 1,
|
|
|
|
LOADING: 2,
|
|
|
|
LOADED: 3,
|
|
|
|
DELAYED_MS: 300
|
|
|
|
})
|
2015-05-06 04:06:13 +02:00
|
|
|
.factory('Component', Component.$factory);
|
2015-03-30 19:52:26 +02:00
|
|
|
|
2015-08-12 22:11:38 +02:00
|
|
|
/**
|
|
|
|
* @function $selectedCount
|
|
|
|
* @memberof Component
|
|
|
|
* @desc Return the number of events or tasks selected by the user.
|
|
|
|
* @returns the number of selected events or tasks
|
|
|
|
*/
|
|
|
|
Component.$selectedCount = function() {
|
|
|
|
var count;
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
if (Component.$events) {
|
2015-11-26 18:11:39 +01:00
|
|
|
count += (_.filter(Component.$events, function(event) { return event.selected; })).length;
|
2015-08-12 22:11:38 +02:00
|
|
|
}
|
|
|
|
if (Component.$tasks) {
|
2015-11-26 18:11:39 +01:00
|
|
|
count += (_.filter(Component.$tasks, function(task) { return task.selected; })).length;
|
2015-08-12 22:11:38 +02:00
|
|
|
}
|
|
|
|
return count;
|
|
|
|
};
|
|
|
|
|
2015-09-01 16:50:50 +02:00
|
|
|
/**
|
|
|
|
* @function $startRefreshTimeout
|
|
|
|
* @memberof Component
|
2016-10-12 17:01:59 +02:00
|
|
|
* @desc Starts the refresh timeout for the current selected list (events or tasks) and
|
|
|
|
* current view.
|
2015-09-01 16:50:50 +02:00
|
|
|
*/
|
|
|
|
Component.$startRefreshTimeout = function(type) {
|
|
|
|
if (Component.$refreshTimeout)
|
|
|
|
Component.$timeout.cancel(Component.$refreshTimeout);
|
|
|
|
|
2017-06-01 19:46:57 +02:00
|
|
|
// Restart the refresh timer, if needed
|
|
|
|
var refreshViewCheck = Component.$Preferences.defaults.SOGoRefreshViewCheck;
|
|
|
|
if (refreshViewCheck && refreshViewCheck != 'manually') {
|
|
|
|
var f = angular.bind(Component.$rootScope, Component.$rootScope.$emit, 'calendars:list');
|
|
|
|
Component.$refreshTimeout = Component.$timeout(f, refreshViewCheck.timeInterval()*1000);
|
|
|
|
}
|
2015-09-01 16:50:50 +02:00
|
|
|
};
|
|
|
|
|
2016-08-02 18:09:11 +02:00
|
|
|
/**
|
|
|
|
* @function $isLoading
|
|
|
|
* @memberof Component
|
|
|
|
* @returns true if the components list is still being retrieved from server after a specific delay
|
|
|
|
* @see sgMessage_STATUS
|
|
|
|
*/
|
|
|
|
Component.$isLoading = function() {
|
|
|
|
return Component.$loaded == Component.STATUS.LOADING;
|
|
|
|
};
|
|
|
|
|
2015-03-30 19:52:26 +02:00
|
|
|
/**
|
|
|
|
* @function $filter
|
2015-08-12 22:11:38 +02:00
|
|
|
* @memberof Component
|
2015-03-30 19:52:26 +02:00
|
|
|
* @desc Search for components matching some criterias
|
2015-05-20 17:11:01 +02:00
|
|
|
* @param {string} type - either 'events' or 'tasks'
|
2015-03-30 19:52:26 +02:00
|
|
|
* @param {object} [options] - additional options to the query
|
|
|
|
* @returns a collection of Components instances
|
|
|
|
*/
|
|
|
|
Component.$filter = function(type, options) {
|
|
|
|
var _this = this,
|
|
|
|
now = new Date(),
|
|
|
|
day = now.getDate(),
|
|
|
|
month = now.getMonth() + 1,
|
|
|
|
year = now.getFullYear(),
|
2015-07-09 22:35:19 +02:00
|
|
|
queryKey = '$query' + type.capitalize(),
|
|
|
|
params = {
|
2015-03-30 19:52:26 +02:00
|
|
|
day: '' + year + (month < 10?'0':'') + month + (day < 10?'0':'') + day,
|
2017-06-01 19:46:57 +02:00
|
|
|
},
|
|
|
|
futureComponentData,
|
|
|
|
dirty = false,
|
|
|
|
otherType;
|
2015-03-30 19:52:26 +02:00
|
|
|
|
2015-09-01 16:50:50 +02:00
|
|
|
Component.$startRefreshTimeout(type);
|
|
|
|
|
2017-06-01 19:46:57 +02:00
|
|
|
angular.extend(this.$query, params);
|
|
|
|
|
|
|
|
if (options) {
|
|
|
|
_.forEach(_.keys(options), function(key) {
|
|
|
|
// Query parameters common to events and tasks are compared
|
|
|
|
dirty |= (_this.$query[key] && options[key] != Component.$query[key]);
|
|
|
|
if (key == 'reload' && options[key])
|
|
|
|
dirty = true;
|
|
|
|
// Update either the common parameters or the type-specific parameters
|
|
|
|
else if (angular.isDefined(_this.$query[key]))
|
|
|
|
_this.$query[key] = options[key];
|
|
|
|
else
|
|
|
|
_this[queryKey][key] = options[key];
|
|
|
|
});
|
|
|
|
}
|
2015-07-08 20:46:07 +02:00
|
|
|
|
2017-06-01 19:46:57 +02:00
|
|
|
// Perform query with both common and type-specific parameters
|
|
|
|
futureComponentData = this.$$resource.fetch(null, type + 'list',
|
|
|
|
angular.extend(this[queryKey], this.$query));
|
2015-03-30 19:52:26 +02:00
|
|
|
|
2017-06-01 19:46:57 +02:00
|
|
|
// Invalidate cached results of other type if $query has changed
|
|
|
|
if (dirty) {
|
|
|
|
otherType = (type == 'tasks')? '$events' : '$tasks';
|
|
|
|
delete Component[otherType];
|
|
|
|
Component.$log.debug('force reload of ' + otherType);
|
|
|
|
}
|
2015-03-30 19:52:26 +02:00
|
|
|
|
2017-06-01 19:46:57 +02:00
|
|
|
return this.$unwrapCollection(type, futureComponentData);
|
2015-03-30 19:52:26 +02:00
|
|
|
};
|
|
|
|
|
2015-04-24 22:48:41 +02:00
|
|
|
/**
|
2015-05-20 17:11:01 +02:00
|
|
|
* @function $find
|
|
|
|
* @desc Fetch a component from a specific calendar.
|
|
|
|
* @param {string} calendarId - the calendar ID
|
|
|
|
* @param {string} componentId - the component ID
|
2015-07-27 22:02:05 +02:00
|
|
|
* @param {string} [occurrenceId] - the component ID
|
2015-05-20 17:11:01 +02:00
|
|
|
* @see {@link Calendar.$getComponent}
|
2015-04-24 22:48:41 +02:00
|
|
|
*/
|
2015-07-27 22:02:05 +02:00
|
|
|
Component.$find = function(calendarId, componentId, occurrenceId) {
|
|
|
|
var futureComponentData, path = [calendarId, componentId];
|
|
|
|
|
|
|
|
if (occurrenceId)
|
|
|
|
path.push(occurrenceId);
|
|
|
|
|
|
|
|
futureComponentData = this.$$resource.fetch(path.join('/'), 'view');
|
2015-04-24 22:48:41 +02:00
|
|
|
|
|
|
|
return new Component(futureComponentData);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function filterCategories
|
|
|
|
* @desc Search for categories matching some criterias
|
|
|
|
* @param {string} search - the search string to match
|
|
|
|
* @returns a collection of strings
|
|
|
|
*/
|
|
|
|
Component.filterCategories = function(query) {
|
|
|
|
var re = new RegExp(query, 'i');
|
|
|
|
return _.filter(_.keys(Component.$categories), function(category) {
|
|
|
|
return category.search(re) != -1;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-08-07 20:13:27 +02:00
|
|
|
/**
|
|
|
|
* @function saveSelectedList
|
|
|
|
* @desc Save to the user's settings the currently selected list.
|
|
|
|
* @param {string} componentType - either "events" or "tasks"
|
|
|
|
* @returns a promise of the HTTP operation
|
|
|
|
*/
|
|
|
|
Component.saveSelectedList = function(componentType) {
|
|
|
|
return this.$$resource.post(null, 'saveSelectedList', { list: componentType + 'ListView' });
|
|
|
|
};
|
|
|
|
|
2015-03-30 19:52:26 +02:00
|
|
|
/**
|
2015-04-01 17:18:19 +02:00
|
|
|
* @function $eventsBlocksForView
|
2015-03-30 19:52:26 +02:00
|
|
|
* @desc Events blocks for a specific week
|
2015-04-01 17:18:19 +02:00
|
|
|
* @param {string} view - Either 'day' or 'week'
|
|
|
|
* @param {Date} type - Date of any day of the desired period
|
|
|
|
* @returns a promise of a collection of objects describing the events blocks
|
2015-03-30 19:52:26 +02:00
|
|
|
*/
|
2015-04-01 17:18:19 +02:00
|
|
|
Component.$eventsBlocksForView = function(view, date) {
|
2017-06-01 19:46:57 +02:00
|
|
|
var firstDayOfWeek, viewAction, startDate, endDate, params;
|
2015-04-01 17:18:19 +02:00
|
|
|
|
2017-06-01 19:46:57 +02:00
|
|
|
firstDayOfWeek = Component.$Preferences.defaults.SOGoFirstDayOfWeek;
|
|
|
|
if (view == 'day') {
|
|
|
|
viewAction = 'dayView';
|
|
|
|
startDate = endDate = date;
|
|
|
|
}
|
|
|
|
else if (view == 'multicolumnday') {
|
|
|
|
viewAction = 'multicolumndayView';
|
|
|
|
startDate = endDate = date;
|
|
|
|
}
|
|
|
|
else if (view == 'week') {
|
|
|
|
viewAction = 'weekView';
|
|
|
|
startDate = date.beginOfWeek(firstDayOfWeek);
|
|
|
|
endDate = new Date();
|
|
|
|
endDate.setTime(startDate.getTime());
|
|
|
|
endDate.addDays(6);
|
|
|
|
}
|
|
|
|
else if (view == 'month') {
|
|
|
|
viewAction = 'monthView';
|
|
|
|
startDate = date;
|
|
|
|
startDate.setDate(1);
|
|
|
|
startDate = startDate.beginOfWeek(firstDayOfWeek);
|
|
|
|
endDate = new Date();
|
|
|
|
endDate.setTime(date.getTime());
|
|
|
|
endDate.setMonth(endDate.getMonth() + 1);
|
|
|
|
endDate.addDays(-1);
|
|
|
|
endDate = endDate.endOfWeek(firstDayOfWeek);
|
|
|
|
}
|
|
|
|
return this.$eventsBlocks(viewAction, startDate, endDate);
|
2015-04-01 17:18:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function $eventsBlocks
|
|
|
|
* @desc Events blocks for a specific view and period
|
2015-09-29 20:08:05 +02:00
|
|
|
* @param {string} view - Either 'day', 'multicolumnday', 'week' or 'month'
|
2015-04-01 17:18:19 +02:00
|
|
|
* @param {Date} startDate - period's start date
|
|
|
|
* @param {Date} endDate - period's end date
|
|
|
|
* @returns a promise of a collection of objects describing the events blocks
|
|
|
|
*/
|
|
|
|
Component.$eventsBlocks = function(view, startDate, endDate) {
|
2016-05-06 20:14:45 +02:00
|
|
|
var params, futureComponentData, i, j, dayDates = [], dayNumbers = [],
|
2015-03-30 19:52:26 +02:00
|
|
|
deferred = Component.$q.defer();
|
|
|
|
|
2015-04-08 22:01:52 +02:00
|
|
|
params = { view: view.toLowerCase(), sd: startDate.getDayString(), ed: endDate.getDayString() };
|
2015-04-01 17:18:19 +02:00
|
|
|
futureComponentData = this.$$resource.fetch(null, 'eventsblocks', params);
|
2015-09-29 20:08:05 +02:00
|
|
|
futureComponentData.then(function(views) {
|
|
|
|
var reduceComponent, associateComponent;
|
|
|
|
|
|
|
|
reduceComponent = function(objects, eventData, i) {
|
2016-03-03 19:38:54 +01:00
|
|
|
var componentData = _.zipObject(this.eventsFields, eventData),
|
2016-05-09 21:51:54 +02:00
|
|
|
start = new Date(componentData.c_startdate * 1000),
|
|
|
|
component;
|
2015-09-29 20:08:05 +02:00
|
|
|
componentData.hour = start.getHourString();
|
2015-11-06 21:12:24 +01:00
|
|
|
componentData.blocks = [];
|
2016-05-09 21:51:54 +02:00
|
|
|
component = new Component(componentData);
|
|
|
|
objects.push(component);
|
2015-09-29 20:08:05 +02:00
|
|
|
return objects;
|
|
|
|
};
|
|
|
|
|
|
|
|
associateComponent = function(block) {
|
2015-11-06 21:12:24 +01:00
|
|
|
this[block.nbr].blocks.push(block); // Associate block to component
|
|
|
|
block.component = this[block.nbr]; // Associate component to block
|
2016-09-21 21:04:09 +02:00
|
|
|
block.isFirst = (this[block.nbr].blocks.length == 1);
|
2015-09-29 20:08:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Component.$views = [];
|
2015-03-30 19:52:26 +02:00
|
|
|
Component.$timeout(function() {
|
2016-05-06 20:14:45 +02:00
|
|
|
_.forEach(views, function(data, viewIndex) {
|
2015-09-29 20:08:05 +02:00
|
|
|
var components = [], blocks = {}, allDayBlocks = {}, viewData;
|
|
|
|
|
2015-11-06 21:12:24 +01:00
|
|
|
// Change some attributes names
|
|
|
|
data.eventsFields.splice(_.indexOf(data.eventsFields, 'c_folder'), 1, 'pid');
|
|
|
|
data.eventsFields.splice(_.indexOf(data.eventsFields, 'c_name'), 1, 'id');
|
|
|
|
data.eventsFields.splice(_.indexOf(data.eventsFields, 'c_recurrence_id'), 1, 'occurrenceId');
|
|
|
|
data.eventsFields.splice(_.indexOf(data.eventsFields, 'c_title'), 1, 'summary');
|
|
|
|
|
2015-09-29 20:08:05 +02:00
|
|
|
// Instantiate Component objects
|
2016-03-03 19:38:54 +01:00
|
|
|
_.reduce(data.events, _.bind(reduceComponent, data), components);
|
2015-09-29 20:08:05 +02:00
|
|
|
|
|
|
|
// Associate Component objects to blocks positions
|
2016-03-03 19:38:54 +01:00
|
|
|
_.forEach(_.flatten(data.blocks), _.bind(associateComponent, components));
|
2015-09-29 20:08:05 +02:00
|
|
|
|
|
|
|
// Associate Component objects to all-day blocks positions
|
2016-03-03 19:38:54 +01:00
|
|
|
_.forEach(_.flatten(data.allDayBlocks), _.bind(associateComponent, components));
|
2015-09-29 20:08:05 +02:00
|
|
|
|
|
|
|
// Build array of dates
|
2016-05-06 20:14:45 +02:00
|
|
|
if (dayDates.length === 0) {
|
|
|
|
dayDates = _.flatMap(data.days, 'date');
|
|
|
|
dayNumbers = _.flatMap(data.days, 'number');
|
|
|
|
}
|
2015-09-29 20:08:05 +02:00
|
|
|
|
2016-05-06 20:14:45 +02:00
|
|
|
// Convert array of blocks to an object literal with date strings as keys
|
2015-09-29 20:08:05 +02:00
|
|
|
for (i = 0; i < data.blocks.length; i++) {
|
2016-05-06 20:14:45 +02:00
|
|
|
for (j = 0; j < data.blocks[i].length; j++) {
|
|
|
|
data.blocks[i][j].dayIndex = i + (viewIndex * data.blocks.length);
|
|
|
|
data.blocks[i][j].dayNumber = dayNumbers[i];
|
|
|
|
}
|
|
|
|
blocks[dayDates[i]] = data.blocks[i];
|
2015-09-29 20:08:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Convert array of all-day blocks to object with days as keys
|
|
|
|
for (i = 0; i < data.allDayBlocks.length; i++) {
|
2016-05-06 20:14:45 +02:00
|
|
|
for (j = 0; j < data.allDayBlocks[i].length; j++) {
|
|
|
|
data.allDayBlocks[i][j].dayIndex = i + (viewIndex * data.allDayBlocks.length);
|
|
|
|
data.allDayBlocks[i][j].dayNumber = dayNumbers[i];
|
|
|
|
}
|
|
|
|
allDayBlocks[dayDates[i]] = data.allDayBlocks[i];
|
2015-09-29 20:08:05 +02:00
|
|
|
}
|
|
|
|
|
2015-11-06 21:12:24 +01:00
|
|
|
// "blocks" is now an object literal with the following structure:
|
|
|
|
// { day: [
|
|
|
|
// { start: number,
|
|
|
|
// length: number,
|
|
|
|
// siblings: number,
|
|
|
|
// realSiblings: number,
|
|
|
|
// position: number,
|
|
|
|
// nbr: number,
|
|
|
|
// component: Component },
|
|
|
|
// .. ],
|
|
|
|
// .. }
|
|
|
|
//
|
|
|
|
// Where day is a string with format YYYYMMDD
|
|
|
|
|
2015-09-29 20:08:05 +02:00
|
|
|
Component.$log.debug('blocks ready (' + _.flatten(data.blocks).length + ')');
|
|
|
|
Component.$log.debug('all day blocks ready (' + _.flatten(data.allDayBlocks).length + ')');
|
|
|
|
|
|
|
|
// Save the blocks to the object model
|
|
|
|
viewData = { blocks: blocks, allDayBlocks: allDayBlocks };
|
|
|
|
if (data.id && data.calendarName) {
|
|
|
|
// The multicolumnday view also includes calendar information
|
|
|
|
viewData.id = data.id;
|
|
|
|
viewData.calendarName = data.calendarName;
|
|
|
|
}
|
|
|
|
Component.$views.push(viewData);
|
2015-09-18 22:11:31 +02:00
|
|
|
});
|
|
|
|
|
2015-09-29 20:08:05 +02:00
|
|
|
deferred.resolve(Component.$views);
|
2015-03-30 19:52:26 +02:00
|
|
|
});
|
|
|
|
}, deferred.reject);
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2015-05-20 17:11:01 +02:00
|
|
|
* @function $unwrapCollection
|
2015-03-30 19:52:26 +02:00
|
|
|
* @desc Unwrap a promise and instanciate new Component objects using received data.
|
2015-05-20 17:11:01 +02:00
|
|
|
* @param {string} type - either 'events' or 'tasks'
|
2015-03-30 19:52:26 +02:00
|
|
|
* @param {promise} futureComponentData - a promise of the components' metadata
|
|
|
|
* @returns a promise of the HTTP operation
|
|
|
|
*/
|
|
|
|
Component.$unwrapCollection = function(type, futureComponentData) {
|
|
|
|
var _this = this,
|
|
|
|
components = [];
|
|
|
|
|
2016-08-02 18:09:11 +02:00
|
|
|
// Components list is not loaded yet
|
|
|
|
Component.$loaded = Component.STATUS.DELAYED_LOADING;
|
|
|
|
Component.$timeout(function() {
|
|
|
|
if (Component.$loaded != Component.STATUS.LOADED)
|
|
|
|
Component.$loaded = Component.STATUS.LOADING;
|
|
|
|
}, Component.STATUS.DELAYED_MS);
|
|
|
|
|
2015-07-08 20:46:07 +02:00
|
|
|
return futureComponentData.then(function(data) {
|
|
|
|
return Component.$timeout(function() {
|
2016-03-03 19:38:54 +01:00
|
|
|
var fields = _.invokeMap(data.fields, 'toLowerCase');
|
2015-11-06 21:12:24 +01:00
|
|
|
fields.splice(_.indexOf(fields, 'c_folder'), 1, 'pid');
|
|
|
|
fields.splice(_.indexOf(fields, 'c_name'), 1, 'id');
|
|
|
|
fields.splice(_.indexOf(fields, 'c_recurrence_id'), 1, 'occurrenceId');
|
2015-03-30 19:52:26 +02:00
|
|
|
|
|
|
|
// Instanciate Component objects
|
|
|
|
_.reduce(data[type], function(components, componentData, i) {
|
2016-05-09 21:51:54 +02:00
|
|
|
var data = _.zipObject(fields, componentData), component;
|
|
|
|
component = new Component(data);
|
|
|
|
components.push(component);
|
2015-03-30 19:52:26 +02:00
|
|
|
return components;
|
|
|
|
}, components);
|
|
|
|
|
|
|
|
Component.$log.debug('list of ' + type + ' ready (' + components.length + ')');
|
|
|
|
|
|
|
|
// Save the list of components to the object model
|
|
|
|
Component['$' + type] = components;
|
|
|
|
|
2016-08-02 18:09:11 +02:00
|
|
|
Component.$loaded = Component.STATUS.LOADED;
|
|
|
|
|
2015-07-08 20:46:07 +02:00
|
|
|
return components;
|
2015-03-30 19:52:26 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-02-15 21:58:58 +01:00
|
|
|
/**
|
|
|
|
* @function $resetGhost
|
|
|
|
* @desc Prepare the ghost object for the next drag by resetting appropriate attributes
|
|
|
|
*/
|
|
|
|
Component.$resetGhost = function() {
|
|
|
|
this.$ghost.pointerHandler = null;
|
|
|
|
this.$ghost.component = null;
|
2016-03-09 15:18:21 +01:00
|
|
|
this.$ghost.startHour = null;
|
|
|
|
this.$ghost.endHour = null;
|
2016-02-15 21:58:58 +01:00
|
|
|
};
|
|
|
|
|
2015-12-17 04:16:04 +01:00
|
|
|
/**
|
|
|
|
* @function $parseDate
|
|
|
|
* @desc Parse a date string with format YYYY-MM-DDTHH:MM
|
|
|
|
* @param {string} dateString - the string representing the date
|
|
|
|
* @param {object} [options] - additional options (use {no_time: true} to ignore the time)
|
|
|
|
* @returns a date object
|
|
|
|
*/
|
|
|
|
Component.$parseDate = function(dateString, options) {
|
|
|
|
var date, time;
|
|
|
|
|
|
|
|
date = dateString.substring(0,10).split('-');
|
|
|
|
|
|
|
|
if (options && options.no_time)
|
|
|
|
return new Date(parseInt(date[0]), parseInt(date[1]) - 1, parseInt(date[2]));
|
|
|
|
|
|
|
|
time = dateString.substring(11,16).split(':');
|
|
|
|
|
|
|
|
return new Date(parseInt(date[0]), parseInt(date[1]) - 1, parseInt(date[2]),
|
|
|
|
parseInt(time[0]), parseInt(time[1]), 0, 0);
|
|
|
|
};
|
|
|
|
|
2015-05-01 18:19:33 +02:00
|
|
|
/**
|
|
|
|
* @function init
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Extend instance with required attributes and new data.
|
|
|
|
* @param {object} data - attributes of component
|
|
|
|
*/
|
2015-04-24 22:48:41 +02:00
|
|
|
Component.prototype.init = function(data) {
|
2015-06-04 22:08:45 +02:00
|
|
|
var _this = this;
|
|
|
|
|
2015-04-24 22:48:41 +02:00
|
|
|
this.categories = [];
|
2015-05-20 17:11:01 +02:00
|
|
|
this.repeat = {};
|
2015-06-22 21:48:52 +02:00
|
|
|
this.alarm = { action: 'display', quantity: 5, unit: 'MINUTES', reference: 'BEFORE', relation: 'START' };
|
2015-06-25 17:30:44 +02:00
|
|
|
this.status = 'not-specified';
|
2015-10-30 13:38:19 +01:00
|
|
|
this.delta = 60;
|
2015-04-24 22:48:41 +02:00
|
|
|
angular.extend(this, data);
|
2015-05-20 17:11:01 +02:00
|
|
|
|
2015-10-30 13:38:19 +01:00
|
|
|
if (this.component == 'vevent')
|
|
|
|
this.type = 'appointment';
|
2016-03-04 17:34:02 +01:00
|
|
|
else if (this.component == 'vtodo')
|
2015-10-30 13:38:19 +01:00
|
|
|
this.type = 'task';
|
|
|
|
|
|
|
|
if (this.startDate) {
|
|
|
|
if (angular.isString(this.startDate))
|
|
|
|
// Ex: 2015-10-25T22:34:51+00:00
|
2015-12-17 04:16:04 +01:00
|
|
|
this.start = Component.$parseDate(this.startDate);
|
2015-10-30 13:38:19 +01:00
|
|
|
else
|
|
|
|
// Date object
|
|
|
|
this.start = this.startDate;
|
|
|
|
}
|
2015-08-28 19:59:41 +02:00
|
|
|
else if (this.type == 'appointment') {
|
|
|
|
this.start = new Date();
|
2015-10-07 15:22:26 +02:00
|
|
|
this.start.setMinutes(Math.round(this.start.getMinutes()/15)*15);
|
2015-08-28 19:59:41 +02:00
|
|
|
}
|
|
|
|
|
2015-10-30 13:38:19 +01:00
|
|
|
if (this.endDate) {
|
2015-12-17 04:16:04 +01:00
|
|
|
this.end = Component.$parseDate(this.endDate);
|
2015-11-03 21:47:30 +01:00
|
|
|
this.delta = this.start.minutesTo(this.end);
|
2015-10-30 13:38:19 +01:00
|
|
|
}
|
2015-08-28 19:59:41 +02:00
|
|
|
else if (this.type == 'appointment') {
|
2015-11-03 21:47:30 +01:00
|
|
|
this.setDelta(this.delta);
|
2015-08-28 19:59:41 +02:00
|
|
|
}
|
|
|
|
|
2015-06-25 17:30:44 +02:00
|
|
|
if (this.dueDate)
|
2015-12-17 04:16:04 +01:00
|
|
|
this.due = Component.$parseDate(this.dueDate);
|
2015-06-04 22:08:45 +02:00
|
|
|
|
2016-03-04 17:34:02 +01:00
|
|
|
if (this.completedDate)
|
|
|
|
this.completed = Component.$parseDate(this.completedDate);
|
|
|
|
else if (this.type == 'task')
|
|
|
|
this.completed = new Date();
|
|
|
|
|
2017-03-23 18:55:14 +01:00
|
|
|
if (this.c_category) {
|
|
|
|
// c_category is only defined in list mode (when calling $filter)
|
2017-06-01 19:46:57 +02:00
|
|
|
// Filter out categories for which there's no associated color
|
|
|
|
this.categories = _.invokeMap(_.filter(this.c_category, function(name) {
|
|
|
|
return Component.$Preferences.defaults.SOGoCalendarCategoriesColors[name];
|
|
|
|
}), 'asCSSIdentifier');
|
2017-03-23 18:55:14 +01:00
|
|
|
}
|
2015-11-17 18:22:06 +01:00
|
|
|
|
2015-05-20 17:11:01 +02:00
|
|
|
// Parse recurrence rule definition and initialize default values
|
2015-08-05 22:44:25 +02:00
|
|
|
this.$isRecurrent = angular.isDefined(data.repeat);
|
2015-05-20 17:11:01 +02:00
|
|
|
if (this.repeat.days) {
|
|
|
|
var byDayMask = _.find(this.repeat.days, function(o) {
|
|
|
|
return angular.isDefined(o.occurrence);
|
|
|
|
});
|
2015-12-17 19:19:34 +01:00
|
|
|
if (byDayMask) {
|
2015-05-20 17:11:01 +02:00
|
|
|
if (this.repeat.frequency == 'yearly')
|
|
|
|
this.repeat.year = { byday: true };
|
|
|
|
this.repeat.month = {
|
|
|
|
type: 'byday',
|
|
|
|
occurrence: byDayMask.occurrence.toString(),
|
|
|
|
day: byDayMask.day
|
|
|
|
};
|
2015-12-17 19:19:34 +01:00
|
|
|
}
|
2015-05-20 17:11:01 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.repeat.days = [];
|
|
|
|
}
|
2015-06-04 20:48:52 +02:00
|
|
|
if (angular.isUndefined(this.repeat.frequency))
|
|
|
|
this.repeat.frequency = 'never';
|
2015-05-20 17:11:01 +02:00
|
|
|
if (angular.isUndefined(this.repeat.interval))
|
|
|
|
this.repeat.interval = 1;
|
|
|
|
if (angular.isUndefined(this.repeat.monthdays))
|
2015-08-24 20:54:25 +02:00
|
|
|
// TODO: initialize this.repeat.monthdays with month day of start date
|
2015-05-20 17:11:01 +02:00
|
|
|
this.repeat.monthdays = [];
|
2017-02-28 22:13:58 +01:00
|
|
|
else if (this.repeat.monthdays.length > 0)
|
|
|
|
this.repeat.month = { type: 'bymonthday' };
|
|
|
|
if (angular.isUndefined(this.repeat.month))
|
|
|
|
this.repeat.month = {};
|
|
|
|
if (angular.isUndefined(this.repeat.month.occurrence))
|
|
|
|
angular.extend(this.repeat.month, { occurrence: '1', day: 'SU' });
|
2015-05-20 17:11:01 +02:00
|
|
|
if (angular.isUndefined(this.repeat.months))
|
2015-08-24 20:54:25 +02:00
|
|
|
// TODO: initialize this.repeat.months with month of start date
|
2015-05-20 17:11:01 +02:00
|
|
|
this.repeat.months = [];
|
|
|
|
if (angular.isUndefined(this.repeat.year))
|
|
|
|
this.repeat.year = {};
|
|
|
|
if (this.repeat.count)
|
|
|
|
this.repeat.end = 'count';
|
|
|
|
else if (this.repeat.until) {
|
|
|
|
this.repeat.end = 'until';
|
2016-11-03 16:48:48 +01:00
|
|
|
if (angular.isString(this.repeat.until))
|
|
|
|
this.repeat.until = Component.$parseDate(this.repeat.until, { no_time: true });
|
2015-05-20 17:11:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
this.repeat.end = 'never';
|
|
|
|
this.$hasCustomRepeat = this.hasCustomRepeat();
|
|
|
|
|
2015-07-30 18:05:33 +02:00
|
|
|
if (this.isNew) {
|
2016-06-14 16:31:45 +02:00
|
|
|
// Set default values
|
2017-06-01 19:46:57 +02:00
|
|
|
var type = (this.type == 'appointment')? 'Events' : 'Tasks';
|
|
|
|
|
|
|
|
// Set default classification
|
|
|
|
this.classification = Component.$Preferences.defaults['SOGoCalendar' + type + 'DefaultClassification'].toLowerCase();
|
|
|
|
|
|
|
|
// Set default alarm
|
|
|
|
var units = { M: 'MINUTES', H: 'HOURS', D: 'DAYS', W: 'WEEKS' };
|
|
|
|
var match = /-PT?([0-9]+)([MHDW])/.exec(Component.$Preferences.defaults.SOGoCalendarDefaultReminder);
|
|
|
|
if (match) {
|
|
|
|
this.$hasAlarm = true;
|
|
|
|
this.alarm.quantity = parseInt(match[1]);
|
|
|
|
this.alarm.unit = units[match[2]];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set notitifications
|
|
|
|
this.sendAppointmentNotifications = Component.$Preferences.defaults.SOGoAppointmentSendEMailNotifications;
|
2015-07-30 18:05:33 +02:00
|
|
|
}
|
2017-02-28 22:13:58 +01:00
|
|
|
else if (angular.isUndefined(data.$hasAlarm)) {
|
2015-07-30 18:05:33 +02:00
|
|
|
this.$hasAlarm = angular.isDefined(data.alarm);
|
|
|
|
}
|
2015-06-22 21:48:52 +02:00
|
|
|
|
2015-06-25 17:30:44 +02:00
|
|
|
// Allow the component to be moved to a different calendar
|
2015-05-14 17:36:21 +02:00
|
|
|
this.destinationCalendar = this.pid;
|
2015-06-04 22:08:45 +02:00
|
|
|
|
2015-11-13 16:46:32 +01:00
|
|
|
// if (this.organizer && this.organizer.email) {
|
|
|
|
// this.organizer.$image = Component.$gravatar(this.organizer.email, 32);
|
|
|
|
// }
|
2015-08-05 22:44:25 +02:00
|
|
|
|
2016-11-29 21:48:15 +01:00
|
|
|
if (this.attendees) {
|
|
|
|
_.forEach(this.attendees, function(attendee) {
|
|
|
|
attendee.image = Component.$gravatar(attendee.email, 32);
|
|
|
|
});
|
|
|
|
}
|
2015-08-12 22:11:38 +02:00
|
|
|
|
2016-12-19 17:05:48 +01:00
|
|
|
// Load freebusy of attendees
|
|
|
|
this.updateFreeBusy();
|
|
|
|
|
2015-08-12 22:11:38 +02:00
|
|
|
this.selected = false;
|
2015-04-24 22:48:41 +02:00
|
|
|
};
|
|
|
|
|
2015-06-04 22:08:45 +02:00
|
|
|
/**
|
|
|
|
* @function hasCustomRepeat
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Check if the component has a custom recurrence rule.
|
2015-06-25 17:30:44 +02:00
|
|
|
* @returns true if the recurrence rule requires the full recurrence editor
|
2015-06-04 22:08:45 +02:00
|
|
|
*/
|
2015-05-20 17:11:01 +02:00
|
|
|
Component.prototype.hasCustomRepeat = function() {
|
|
|
|
var b = angular.isDefined(this.repeat) &&
|
|
|
|
(this.repeat.interval > 1 ||
|
2017-02-28 22:13:58 +01:00
|
|
|
angular.isDefined(this.repeat.days) && this.repeat.days.length > 0 ||
|
|
|
|
angular.isDefined(this.repeat.monthdays) && this.repeat.monthdays.length > 0 ||
|
|
|
|
angular.isDefined(this.repeat.months) && this.repeat.months.length > 0 ||
|
|
|
|
angular.isDefined(this.repeat.month) && angular.isDefined(this.repeat.month.type));
|
2015-05-20 17:11:01 +02:00
|
|
|
return b;
|
|
|
|
};
|
|
|
|
|
2015-08-05 22:44:25 +02:00
|
|
|
/**
|
|
|
|
* @function isEditable
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Check if the component is editable and not an occurrence of a recurrent component
|
|
|
|
* @returns true or false
|
|
|
|
*/
|
|
|
|
Component.prototype.isEditable = function() {
|
|
|
|
return (!this.occurrenceId && !this.isReadOnly);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function isEditableOccurrence
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Check if the component is editable and an occurrence of a recurrent component
|
|
|
|
* @returns true or false
|
|
|
|
*/
|
|
|
|
Component.prototype.isEditableOccurrence = function() {
|
|
|
|
return (this.occurrenceId && !this.isReadOnly);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function isInvitation
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Check if the component an invitation and not an occurrence of a recurrent component
|
|
|
|
* @returns true or false
|
|
|
|
*/
|
|
|
|
Component.prototype.isInvitation = function() {
|
|
|
|
return (!this.occurrenceId && this.userHasRSVP);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function isInvitationOccurrence
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Check if the component an invitation and an occurrence of a recurrent component
|
|
|
|
* @returns true or false
|
|
|
|
*/
|
|
|
|
Component.prototype.isInvitationOccurrence = function() {
|
|
|
|
return (this.occurrenceId && this.userHasRSVP);
|
|
|
|
};
|
|
|
|
|
2015-06-25 17:30:44 +02:00
|
|
|
/**
|
|
|
|
* @function enablePercentComplete
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Check if the percent completion should be enabled with respect to the
|
|
|
|
* component's type and status.
|
|
|
|
* @returns true if the percent completion should be displayed
|
|
|
|
*/
|
|
|
|
Component.prototype.enablePercentComplete = function() {
|
2015-11-06 21:12:24 +01:00
|
|
|
return (this.type == 'task' &&
|
2017-05-19 18:13:01 +02:00
|
|
|
this.percentComplete > 0 &&
|
2015-06-25 17:30:44 +02:00
|
|
|
this.status != 'cancelled');
|
|
|
|
};
|
|
|
|
|
2015-06-04 22:08:45 +02:00
|
|
|
/**
|
|
|
|
* @function coversFreeBusy
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Check if a specific quarter matches the component's period
|
|
|
|
* @returns true if the quarter covers the component's period
|
|
|
|
*/
|
|
|
|
Component.prototype.coversFreeBusy = function(day, hour, quarter) {
|
|
|
|
var b = (angular.isDefined(this.freebusy[day]) &&
|
|
|
|
angular.isDefined(this.freebusy[day][hour]) &&
|
|
|
|
this.freebusy[day][hour][quarter] == 1);
|
|
|
|
return b;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function updateFreeBusyCoverage
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Build a 15-minute-based representation of the component's period.
|
|
|
|
* @returns an object literal hashed by days and hours and arrays of four 1's and 0's
|
|
|
|
*/
|
|
|
|
Component.prototype.updateFreeBusyCoverage = function() {
|
|
|
|
var _this = this, freebusy = {};
|
|
|
|
|
|
|
|
if (this.start && this.end) {
|
|
|
|
var roundedStart = new Date(this.start.getTime()),
|
|
|
|
roundedEnd = new Date(this.end.getTime()),
|
|
|
|
startQuarter = parseInt(roundedStart.getMinutes()/15 + 0.5),
|
|
|
|
endQuarter = parseInt(roundedEnd.getMinutes()/15 + 0.5);
|
|
|
|
roundedStart.setMinutes(15*startQuarter);
|
|
|
|
roundedEnd.setMinutes(15*endQuarter);
|
|
|
|
|
2016-03-03 19:38:54 +01:00
|
|
|
_.forEach(roundedStart.daysUpTo(roundedEnd), function(date, index) {
|
2015-06-04 22:08:45 +02:00
|
|
|
var currentDay = date.getDate(),
|
|
|
|
dayKey = date.getDayString(),
|
|
|
|
hourKey;
|
|
|
|
if (dayKey == _this.start.getDayString()) {
|
|
|
|
hourKey = date.getHours().toString();
|
|
|
|
freebusy[dayKey] = {};
|
|
|
|
freebusy[dayKey][hourKey] = [];
|
|
|
|
while (startQuarter > 0) {
|
|
|
|
freebusy[dayKey][hourKey].push(0);
|
|
|
|
startQuarter--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
date = date.beginOfDay();
|
|
|
|
freebusy[dayKey] = {};
|
|
|
|
}
|
|
|
|
while (date.getTime() < _this.end.getTime() &&
|
|
|
|
date.getDate() == currentDay) {
|
|
|
|
hourKey = date.getHours().toString();
|
|
|
|
if (angular.isUndefined(freebusy[dayKey][hourKey]))
|
|
|
|
freebusy[dayKey][hourKey] = [];
|
|
|
|
freebusy[dayKey][hourKey].push(1);
|
|
|
|
date.addMinutes(15);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return freebusy;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-11-13 16:46:32 +01:00
|
|
|
/**
|
|
|
|
* @function updateFreeBusy
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Update the freebusy coverage representation and the attendees freebusy information
|
|
|
|
*/
|
|
|
|
Component.prototype.updateFreeBusy = function() {
|
|
|
|
var _this = this;
|
|
|
|
|
|
|
|
this.freebusy = this.updateFreeBusyCoverage();
|
|
|
|
|
|
|
|
if (this.attendees) {
|
2016-03-03 19:38:54 +01:00
|
|
|
_.forEach(this.attendees, function(attendee) {
|
2015-11-13 16:46:32 +01:00
|
|
|
_this.updateFreeBusyAttendee(attendee);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-11-03 21:47:30 +01:00
|
|
|
/**
|
|
|
|
* @function setDelta
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Set the end time to the specified number of minutes after the start time.
|
|
|
|
* @param {number} delta - the number of minutes
|
|
|
|
*/
|
|
|
|
Component.prototype.setDelta = function(delta) {
|
|
|
|
this.delta = delta;
|
|
|
|
this.end = new Date(this.start.getTime());
|
|
|
|
this.end.setMinutes(Math.round(this.end.getMinutes()/15)*15);
|
|
|
|
this.end.addMinutes(this.delta);
|
|
|
|
};
|
|
|
|
|
2015-06-04 22:08:45 +02:00
|
|
|
/**
|
2015-11-13 16:46:32 +01:00
|
|
|
* @function updateFreeBusyAttendee
|
2015-06-04 22:08:45 +02:00
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Update the freebusy information for the component's period for a specific attendee.
|
|
|
|
* @param {Object} card - an Card object instance of the attendee
|
|
|
|
*/
|
2015-11-13 16:46:32 +01:00
|
|
|
Component.prototype.updateFreeBusyAttendee = function(attendee) {
|
2016-11-29 21:48:15 +01:00
|
|
|
var resource, uid, params, days;
|
|
|
|
|
2015-06-04 22:08:45 +02:00
|
|
|
if (attendee.uid) {
|
2016-11-29 21:48:15 +01:00
|
|
|
uid = attendee.uid;
|
|
|
|
if (attendee.domain)
|
|
|
|
uid += '@' + attendee.domain;
|
2015-06-04 22:08:45 +02:00
|
|
|
params =
|
|
|
|
{
|
|
|
|
sday: this.start.getDayString(),
|
|
|
|
eday: this.end.getDayString()
|
|
|
|
};
|
2016-11-29 21:48:15 +01:00
|
|
|
|
|
|
|
if (attendee.isMSExchange) {
|
|
|
|
// Attendee is not a local user, but her freebusy data is available from an external MS Exchange server;
|
|
|
|
// we query /SOGo/so/<login_user>/freebusy.ifb/ajaxRead?uid=<uid>
|
|
|
|
resource = Component.$$resource.userResource();
|
|
|
|
params.uid = uid;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Attendee is a user;
|
|
|
|
// web query /SOGo/so/<uid>/freebusy.ifb/ajaxRead
|
|
|
|
resource = Component.$$resource.userResource(uid);
|
|
|
|
}
|
|
|
|
|
2015-06-04 22:08:45 +02:00
|
|
|
days = _.map(this.start.daysUpTo(this.end), function(day) { return day.getDayString(); });
|
|
|
|
|
|
|
|
if (angular.isUndefined(attendee.freebusy))
|
|
|
|
attendee.freebusy = {};
|
|
|
|
|
|
|
|
// Fetch FreeBusy information
|
2016-11-29 21:48:15 +01:00
|
|
|
resource.fetch('freebusy.ifb', 'ajaxRead', params).then(function(data) {
|
2016-03-03 19:38:54 +01:00
|
|
|
_.forEach(days, function(day) {
|
2015-06-04 22:08:45 +02:00
|
|
|
var hour;
|
|
|
|
|
|
|
|
if (angular.isUndefined(attendee.freebusy[day]))
|
|
|
|
attendee.freebusy[day] = {};
|
|
|
|
|
|
|
|
if (angular.isUndefined(data[day]))
|
|
|
|
data[day] = {};
|
|
|
|
|
|
|
|
for (var i = 0; i <= 23; i++) {
|
|
|
|
hour = i.toString();
|
|
|
|
if (data[day][hour])
|
|
|
|
attendee.freebusy[day][hour] = [
|
|
|
|
data[day][hour]["0"],
|
|
|
|
data[day][hour]["15"],
|
|
|
|
data[day][hour]["30"],
|
|
|
|
data[day][hour]["45"]
|
|
|
|
];
|
|
|
|
else
|
|
|
|
attendee.freebusy[day][hour] = [0, 0, 0, 0];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-24 22:48:41 +02:00
|
|
|
/**
|
|
|
|
* @function getClassName
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Return the component CSS class name based on its container (calendar) ID.
|
|
|
|
* @param {string} [base] - the prefix to add to the class name (defaults to "fg")
|
|
|
|
* @returns a string representing the foreground CSS class name
|
|
|
|
*/
|
|
|
|
Component.prototype.getClassName = function(base) {
|
|
|
|
if (angular.isUndefined(base))
|
|
|
|
base = 'fg';
|
2015-11-06 21:12:24 +01:00
|
|
|
return base + '-folder' + (this.destinationCalendar || this.c_folder || this.pid);
|
2015-04-24 22:48:41 +02:00
|
|
|
};
|
|
|
|
|
2015-06-04 22:08:45 +02:00
|
|
|
/**
|
|
|
|
* @function addAttendee
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Add an attendee and fetch his freebusy info.
|
|
|
|
* @param {Object} card - an Card object instance to be added to the attendees list
|
|
|
|
*/
|
|
|
|
Component.prototype.addAttendee = function(card) {
|
2015-12-22 23:24:16 +01:00
|
|
|
var _this = this, attendee, list, url, params;
|
2015-06-04 22:08:45 +02:00
|
|
|
if (card) {
|
2016-06-16 22:21:24 +02:00
|
|
|
if (card.$isList({expandable: true})) {
|
2015-12-22 23:24:16 +01:00
|
|
|
// Decompose list members
|
|
|
|
list = Component.$Card.$find(card.container, card.c_name);
|
|
|
|
list.$id().then(function(listId) {
|
|
|
|
_.forEach(list.refs, function(ref) {
|
|
|
|
attendee = {
|
|
|
|
name: ref.c_cn,
|
|
|
|
email: ref.$preferredEmail(),
|
|
|
|
role: 'req-participant',
|
2016-06-17 21:24:59 +02:00
|
|
|
partstat: 'needs-action',
|
2016-11-11 22:46:55 +01:00
|
|
|
uid: ref.c_uid,
|
|
|
|
$avatarIcon: 'person',
|
2015-12-22 23:24:16 +01:00
|
|
|
};
|
|
|
|
if (!_.find(_this.attendees, function(o) {
|
|
|
|
return o.email == attendee.email;
|
|
|
|
})) {
|
|
|
|
// Contact is not already an attendee, add it
|
|
|
|
attendee.image = Component.$gravatar(attendee.email, 32);
|
|
|
|
if (_this.attendees)
|
|
|
|
_this.attendees.push(attendee);
|
|
|
|
else
|
|
|
|
_this.attendees = [attendee];
|
|
|
|
_this.updateFreeBusyAttendee(attendee);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Single contact
|
|
|
|
attendee = {
|
2016-11-29 21:48:15 +01:00
|
|
|
uid: card.c_uid,
|
|
|
|
domain: card.c_domain,
|
|
|
|
isMSExchange: card.ismsexchange,
|
2015-12-22 23:24:16 +01:00
|
|
|
name: card.c_cn,
|
|
|
|
email: card.$preferredEmail(),
|
|
|
|
role: 'req-participant',
|
2016-06-17 21:24:59 +02:00
|
|
|
partstat: 'needs-action',
|
2016-11-11 22:46:55 +01:00
|
|
|
$avatarIcon: card.$avatarIcon
|
2015-12-22 23:24:16 +01:00
|
|
|
};
|
|
|
|
if (!_.find(this.attendees, function(o) {
|
|
|
|
return o.email == attendee.email;
|
|
|
|
})) {
|
|
|
|
attendee.image = Component.$gravatar(attendee.email, 32);
|
|
|
|
if (this.attendees)
|
|
|
|
this.attendees.push(attendee);
|
|
|
|
else
|
|
|
|
this.attendees = [attendee];
|
|
|
|
this.updateFreeBusyAttendee(attendee);
|
|
|
|
}
|
2015-06-04 22:08:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-05 22:20:57 +02:00
|
|
|
/**
|
|
|
|
* @function hasAttendee
|
|
|
|
* @memberof Component.prototype
|
2015-06-22 21:48:52 +02:00
|
|
|
* @desc Verify if one of the email addresses of a Card instance matches an attendee.
|
2015-06-05 22:20:57 +02:00
|
|
|
* @param {Object} card - an Card object instance
|
|
|
|
* @returns true if the Card matches an attendee
|
|
|
|
*/
|
|
|
|
Component.prototype.hasAttendee = function(card) {
|
|
|
|
var attendee = _.find(this.attendees, function(attendee) {
|
|
|
|
return _.find(card.emails, function(email) {
|
|
|
|
return email.value == attendee.email;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return angular.isDefined(attendee);
|
2015-06-22 21:48:52 +02:00
|
|
|
};
|
|
|
|
|
2015-10-02 17:21:43 +02:00
|
|
|
/**
|
|
|
|
* @function deleteAttendee
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Remove an attendee from the component
|
|
|
|
* @param {Object} attendee - an object literal defining an attendee
|
|
|
|
*/
|
|
|
|
Component.prototype.deleteAttendee = function(attendee) {
|
|
|
|
var index = _.findIndex(this.attendees, function(currentAttendee) {
|
|
|
|
return currentAttendee.email == attendee.email;
|
|
|
|
});
|
|
|
|
this.attendees.splice(index, 1);
|
|
|
|
};
|
|
|
|
|
2015-06-22 21:48:52 +02:00
|
|
|
/**
|
|
|
|
* @function canRemindAttendeesByEmail
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Verify if the component's reminder must be send by email and if it has at least one attendee.
|
|
|
|
* @returns true if attendees can receive a reminder by email
|
|
|
|
*/
|
|
|
|
Component.prototype.canRemindAttendeesByEmail = function() {
|
|
|
|
return this.alarm.action == 'email' &&
|
2015-08-05 22:44:25 +02:00
|
|
|
!this.isReadOnly &&
|
2015-06-22 21:48:52 +02:00
|
|
|
this.attendees && this.attendees.length > 0;
|
|
|
|
};
|
2015-06-05 22:20:57 +02:00
|
|
|
|
2015-07-01 20:34:35 +02:00
|
|
|
/**
|
|
|
|
* @function addAttachUrl
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Add a new attach URL if not already defined
|
|
|
|
* @param {string} attachUrl - the URL
|
|
|
|
* @returns the number of values in the list of attach URLs
|
|
|
|
*/
|
|
|
|
Component.prototype.addAttachUrl = function(attachUrl) {
|
|
|
|
if (angular.isUndefined(this.attachUrls)) {
|
|
|
|
this.attachUrls = [{value: attachUrl}];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (var i = 0; i < this.attachUrls.length; i++) {
|
|
|
|
if (this.attachUrls[i].value == attachUrl) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == this.attachUrls.length)
|
|
|
|
this.attachUrls.push({value: attachUrl});
|
|
|
|
}
|
|
|
|
return this.attachUrls.length - 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function deleteAttachUrl
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Remove an attach URL
|
|
|
|
* @param {number} index - the URL index in the list of attach URLs
|
|
|
|
*/
|
|
|
|
Component.prototype.deleteAttachUrl = function(index) {
|
|
|
|
if (index > -1 && this.attachUrls.length > index) {
|
|
|
|
this.attachUrls.splice(index, 1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-08-28 19:59:41 +02:00
|
|
|
/**
|
|
|
|
* @function $addDueDate
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Add a due date
|
|
|
|
*/
|
|
|
|
Component.prototype.$addDueDate = function() {
|
|
|
|
this.due = new Date();
|
2015-10-07 15:22:26 +02:00
|
|
|
this.due.setMinutes(Math.round(this.due.getMinutes()/15)*15);
|
2015-08-28 19:59:41 +02:00
|
|
|
this.dueDate = this.due.toISOString();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function $deleteDueDate
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Delete a due date
|
|
|
|
*/
|
|
|
|
Component.prototype.$deleteDueDate = function() {
|
|
|
|
delete this.due;
|
|
|
|
delete this.dueDate;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function $addStartDate
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Add a start date
|
|
|
|
*/
|
|
|
|
Component.prototype.$addStartDate = function() {
|
|
|
|
this.start = new Date();
|
2015-10-07 15:22:26 +02:00
|
|
|
this.start.setMinutes(Math.round(this.start.getMinutes()/15)*15);
|
2015-08-28 19:59:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function $deleteStartDate
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Delete a start date
|
|
|
|
*/
|
|
|
|
Component.prototype.$deleteStartDate = function() {
|
|
|
|
delete this.start;
|
|
|
|
delete this.startDate;
|
|
|
|
};
|
|
|
|
|
2015-04-24 22:48:41 +02:00
|
|
|
/**
|
|
|
|
* @function $reset
|
2015-05-20 17:11:01 +02:00
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Reset the original state the component's data.
|
2015-04-24 22:48:41 +02:00
|
|
|
*/
|
|
|
|
Component.prototype.$reset = function() {
|
|
|
|
var _this = this;
|
|
|
|
angular.forEach(this, function(value, key) {
|
|
|
|
if (key != 'constructor' && key[0] != '$') {
|
|
|
|
delete _this[key];
|
|
|
|
}
|
|
|
|
});
|
2015-08-24 20:54:25 +02:00
|
|
|
this.init(this.$shadowData);
|
2015-12-17 19:22:57 +01:00
|
|
|
this.$shadowData = this.$omit();
|
2015-04-24 22:48:41 +02:00
|
|
|
};
|
|
|
|
|
2015-08-05 22:44:25 +02:00
|
|
|
/**
|
2015-11-06 21:12:24 +01:00
|
|
|
* @function $reply
|
2015-08-05 22:44:25 +02:00
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Reply to an invitation.
|
|
|
|
* @returns a promise of the HTTP operation
|
|
|
|
*/
|
|
|
|
Component.prototype.$reply = function() {
|
|
|
|
var _this = this, data, path = [this.pid, this.id];
|
|
|
|
|
|
|
|
if (this.occurrenceId)
|
|
|
|
path.push(this.occurrenceId);
|
|
|
|
|
|
|
|
data = {
|
|
|
|
reply: this.reply,
|
|
|
|
delegatedTo: this.delegatedTo,
|
|
|
|
alarm: this.$hasAlarm? this.alarm : {}
|
|
|
|
};
|
|
|
|
|
|
|
|
return Component.$$resource.save(path.join('/'), data, { action: 'rsvpAppointment' })
|
|
|
|
.then(function(data) {
|
|
|
|
// Make a copy of the data for an eventual reset
|
2015-12-17 19:22:57 +01:00
|
|
|
_this.$shadowData = _this.$omit();
|
2015-08-05 22:44:25 +02:00
|
|
|
return data;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-11-06 21:12:24 +01:00
|
|
|
/**
|
|
|
|
* @function $adjust
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Adjust the start, day, and/or duration of the component
|
|
|
|
* @returns a promise of the HTTP operation
|
|
|
|
*/
|
|
|
|
Component.prototype.$adjust = function(params) {
|
|
|
|
var path = [this.pid, this.id];
|
|
|
|
|
|
|
|
if (_.every(_.values(params), function(v) { return v === 0; }))
|
|
|
|
// No changes
|
|
|
|
return Component.$q.when();
|
|
|
|
|
|
|
|
if (this.occurrenceId)
|
|
|
|
path.push(this.occurrenceId);
|
|
|
|
|
|
|
|
Component.$log.debug('adjust ' + path.join('/') + ' ' + JSON.stringify(params));
|
|
|
|
|
|
|
|
return Component.$$resource.save(path.join('/'), params, { action: 'adjust' });
|
|
|
|
};
|
|
|
|
|
2015-04-24 22:48:41 +02:00
|
|
|
/**
|
|
|
|
* @function $save
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Save the component to the server.
|
2016-02-15 21:58:58 +01:00
|
|
|
* @param {object} extraAttributes - additional attributes to send to the server
|
2015-04-24 22:48:41 +02:00
|
|
|
*/
|
2016-02-15 21:58:58 +01:00
|
|
|
Component.prototype.$save = function(extraAttributes) {
|
2016-01-18 22:32:26 +01:00
|
|
|
var _this = this, options, path, component, date, dlp;
|
2015-12-23 04:37:36 +01:00
|
|
|
|
|
|
|
component = this.$omit();
|
2016-05-06 20:14:45 +02:00
|
|
|
dlp = Component.$Preferences.$mdDateLocaleProvider;
|
2015-05-01 18:19:33 +02:00
|
|
|
|
2015-08-28 19:59:41 +02:00
|
|
|
// Format dates and times
|
2016-01-18 22:32:26 +01:00
|
|
|
component.startDate = component.start ? component.start.format(dlp, '%Y-%m-%d') : '';
|
|
|
|
component.startTime = component.start ? component.start.format(dlp, '%H:%M') : '';
|
|
|
|
component.endDate = component.end ? component.end.format(dlp, '%Y-%m-%d') : '';
|
|
|
|
component.endTime = component.end ? component.end.format(dlp, '%H:%M') : '';
|
|
|
|
component.dueDate = component.due ? component.due.format(dlp, '%Y-%m-%d') : '';
|
|
|
|
component.dueTime = component.due ? component.due.format(dlp, '%H:%M') : '';
|
2016-03-04 17:34:02 +01:00
|
|
|
component.completedDate = component.completed ? component.completed.format(dlp, '%Y-%m-%d') : '';
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2015-05-20 17:11:01 +02:00
|
|
|
// Update recurrence definition depending on selections
|
2016-11-04 19:29:54 +01:00
|
|
|
if (this.hasCustomRepeat()) {
|
2015-07-24 22:14:53 +02:00
|
|
|
if (this.repeat.frequency == 'monthly' && this.repeat.month.type && this.repeat.month.type == 'byday' ||
|
|
|
|
this.repeat.frequency == 'yearly' && this.repeat.year.byday) {
|
2015-05-20 17:11:01 +02:00
|
|
|
// BYDAY mask for a monthly or yearly recurrence
|
|
|
|
delete component.repeat.monthdays;
|
|
|
|
component.repeat.days = [{ day: this.repeat.month.day, occurrence: this.repeat.month.occurrence.toString() }];
|
|
|
|
}
|
2016-04-04 22:12:24 +02:00
|
|
|
else if ((this.repeat.frequency == 'monthly' || this.repeat.frequency == 'yearly') &&
|
|
|
|
this.repeat.month.type) {
|
2015-05-20 17:11:01 +02:00
|
|
|
// montly recurrence by month days or yearly by month
|
|
|
|
delete component.repeat.days;
|
|
|
|
}
|
|
|
|
}
|
2016-02-01 20:01:43 +01:00
|
|
|
else if (this.repeat.frequency && this.repeat.frequency != 'never') {
|
2015-05-20 17:11:01 +02:00
|
|
|
component.repeat = { frequency: this.repeat.frequency };
|
|
|
|
}
|
2016-11-04 19:29:54 +01:00
|
|
|
if (component.startDate && this.repeat.frequency && this.repeat.frequency != 'never') {
|
2015-06-04 20:48:52 +02:00
|
|
|
if (this.repeat.end == 'until' && this.repeat.until)
|
|
|
|
component.repeat.until = this.repeat.until.stringWithSeparator('-');
|
|
|
|
else if (this.repeat.end == 'count' && this.repeat.count)
|
|
|
|
component.repeat.count = this.repeat.count;
|
|
|
|
else {
|
|
|
|
delete component.repeat.until;
|
|
|
|
delete component.repeat.count;
|
|
|
|
}
|
|
|
|
}
|
2015-05-20 17:11:01 +02:00
|
|
|
else {
|
2015-06-04 20:48:52 +02:00
|
|
|
delete component.repeat;
|
2015-05-20 17:11:01 +02:00
|
|
|
}
|
|
|
|
|
2016-02-01 20:01:43 +01:00
|
|
|
// Check status
|
|
|
|
if (this.status == 'not-specified')
|
|
|
|
delete component.status;
|
2016-03-04 17:34:02 +01:00
|
|
|
else if (this.status != 'completed')
|
|
|
|
delete component.completedDate;
|
2016-02-01 20:01:43 +01:00
|
|
|
|
|
|
|
// Verify alarm
|
2016-11-01 19:52:18 +01:00
|
|
|
if (component.startDate && this.$hasAlarm) {
|
2015-08-04 19:45:17 +02:00
|
|
|
if (this.alarm.action && this.alarm.action == 'email' &&
|
|
|
|
!(this.attendees && this.attendees.length > 0)) {
|
2015-06-22 21:48:52 +02:00
|
|
|
// No attendees; email reminder must be sent to organizer only
|
2015-12-23 04:37:36 +01:00
|
|
|
component.alarm.attendees = 0;
|
|
|
|
component.alarm.organizer = 1;
|
2015-06-22 21:48:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
component.alarm = {};
|
|
|
|
}
|
|
|
|
|
2015-12-17 19:22:57 +01:00
|
|
|
// Build URL
|
2015-12-23 04:37:36 +01:00
|
|
|
path = [this.pid, this.id];
|
|
|
|
|
2015-12-17 19:22:57 +01:00
|
|
|
if (this.isNew)
|
|
|
|
options = { action: 'saveAs' + this.type.capitalize() };
|
|
|
|
|
|
|
|
if (this.occurrenceId)
|
|
|
|
path.push(this.occurrenceId);
|
|
|
|
|
2016-02-15 21:58:58 +01:00
|
|
|
angular.extend(component, extraAttributes);
|
|
|
|
|
2015-12-23 04:37:36 +01:00
|
|
|
return Component.$$resource.save(path.join('/'), component, options)
|
2015-12-17 19:22:57 +01:00
|
|
|
.then(function(data) {
|
|
|
|
// Make a copy of the data for an eventual reset
|
|
|
|
_this.$shadowData = _this.$omit();
|
|
|
|
return data;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function $delete
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Delete the component from the server.
|
|
|
|
* @param {boolean} occurrenceOnly - delete this occurrence only
|
|
|
|
*/
|
|
|
|
Component.prototype.remove = function(occurrenceOnly) {
|
|
|
|
var _this = this, path = [this.pid, this.id];
|
|
|
|
|
|
|
|
if (occurrenceOnly && this.occurrenceId)
|
|
|
|
path.push(this.occurrenceId);
|
|
|
|
|
|
|
|
return Component.$$resource.remove(path.join('/'));
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function $unwrap
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Unwrap a promise.
|
|
|
|
* @param {promise} futureComponentData - a promise of some of the Component's data
|
|
|
|
*/
|
|
|
|
Component.prototype.$unwrap = function(futureComponentData) {
|
|
|
|
var _this = this;
|
|
|
|
|
|
|
|
// Expose the promise
|
|
|
|
this.$futureComponentData = futureComponentData;
|
|
|
|
|
|
|
|
// Resolve the promise
|
|
|
|
this.$futureComponentData.then(function(data) {
|
|
|
|
_this.init(data);
|
|
|
|
// Make a copy of the data for an eventual reset
|
|
|
|
_this.$shadowData = _this.$omit();
|
|
|
|
}, function(data) {
|
|
|
|
angular.extend(_this, data);
|
|
|
|
_this.isError = true;
|
|
|
|
Component.$log.error(_this.error);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function $omit
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Return a sanitized object used to send to the server.
|
|
|
|
* @return an object literal copy of the Component instance
|
|
|
|
*/
|
|
|
|
Component.prototype.$omit = function() {
|
2015-12-23 04:37:36 +01:00
|
|
|
var component = {};
|
2015-12-17 19:22:57 +01:00
|
|
|
angular.forEach(this, function(value, key) {
|
|
|
|
if (key != 'constructor' &&
|
2017-02-28 22:13:58 +01:00
|
|
|
(key == '$hasAlarm' || key[0] != '$') &&
|
2015-12-17 19:22:57 +01:00
|
|
|
key != 'blocks') {
|
|
|
|
component[key] = angular.copy(value);
|
|
|
|
}
|
|
|
|
});
|
2015-08-28 19:59:41 +02:00
|
|
|
|
2015-03-30 19:52:26 +02:00
|
|
|
return component;
|
|
|
|
};
|
|
|
|
|
2015-11-12 18:29:10 +01:00
|
|
|
/**
|
|
|
|
* @function repeatDescription
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Return a localized description of the recurrence definition
|
|
|
|
* @return a localized string
|
|
|
|
*/
|
|
|
|
Component.prototype.repeatDescription = function() {
|
|
|
|
var localizedString = null;
|
|
|
|
if (this.repeat)
|
|
|
|
localizedString = l('repeat_' + this.repeat.frequency.toUpperCase());
|
|
|
|
|
|
|
|
return localizedString;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function alarmDescription
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Return a localized description of the reminder definition
|
|
|
|
* @return a localized string
|
|
|
|
*/
|
|
|
|
Component.prototype.alarmDescription = function() {
|
|
|
|
var key, localizedString = null;
|
|
|
|
if (this.alarm) {
|
|
|
|
key = ['reminder' + this.alarm.quantity, this.alarm.unit, this.alarm.reference].join('_');
|
|
|
|
localizedString = l(key);
|
|
|
|
if (key === localizedString)
|
|
|
|
// No localized string for this reminder definition
|
|
|
|
localizedString = [this.alarm.quantity,
|
|
|
|
l('reminder_' + this.alarm.unit),
|
|
|
|
l('reminder_' + this.alarm.reference)].join(' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
return localizedString;
|
|
|
|
};
|
|
|
|
|
2016-03-24 19:53:27 +01:00
|
|
|
/**
|
|
|
|
* @function copyTo
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Copy an event to a calendar
|
|
|
|
* @param {string} calendar - a target calendar UID
|
|
|
|
* @returns a promise of the HTTP operation
|
|
|
|
*/
|
|
|
|
Component.prototype.copyTo = function(calendar) {
|
|
|
|
return Component.$$resource.post(this.pid + '/' + this.id, 'copy', {destination: calendar});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function moveTo
|
|
|
|
* @memberof Component.prototype
|
|
|
|
* @desc Move an event to a calendar
|
|
|
|
* @param {string} calendar - a target calendar UID
|
|
|
|
* @returns a promise of the HTTP operation
|
|
|
|
*/
|
|
|
|
Component.prototype.moveTo = function(calendar) {
|
|
|
|
return Component.$$resource.post(this.pid + '/' + this.id, 'move', {destination: calendar});
|
|
|
|
};
|
|
|
|
|
2015-11-12 18:29:10 +01:00
|
|
|
Component.prototype.toString = function() {
|
|
|
|
return '[Component ' + this.id + ']';
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-03-30 19:52:26 +02:00
|
|
|
})();
|