(feature) Convert a message to an event or task

Resolves #1722
This commit is contained in:
Francis Lachapelle
2016-02-10 16:15:00 -05:00
parent fec263a3d6
commit 99e5c1b93c
14 changed files with 192 additions and 43 deletions
+3 -3
View File
@@ -328,7 +328,7 @@ Date.prototype.beginOfDay = function() {
return beginOfDay;
};
Date.prototype.beginOfWeek = function() {
Date.prototype.beginOfWeek = function(firstDayOfWeek) {
var offset = firstDayOfWeek - this.getDay();
if (offset > 0)
offset -= 7;
@@ -340,8 +340,8 @@ Date.prototype.beginOfWeek = function() {
return beginOfWeek;
};
Date.prototype.endOfWeek = function() {
var endOfWeek = this.beginOfWeek();
Date.prototype.endOfWeek = function(firstDayOfWeek) {
var endOfWeek = this.beginOfWeek(firstDayOfWeek);
endOfWeek.addDays(6);
endOfWeek.setHours(23);
@@ -4,7 +4,7 @@
(function() {
'use strict';
angular.module('SOGo.MailerUI', ['ui.router', 'ck', 'angularFileUpload', 'SOGo.Common', 'SOGo.ContactsUI', 'ngAnimate', 'SOGo.PreferencesUI'])
angular.module('SOGo.MailerUI', ['ui.router', 'ck', 'angularFileUpload', 'SOGo.Common', 'SOGo.ContactsUI', 'SOGo.SchedulerUI', 'ngAnimate', 'SOGo.PreferencesUI'])
.config(configure)
.run(runBlock);
@@ -362,6 +362,15 @@
});
};
/**
* @function $plainContent
* @memberof Message.prototype
* @returns the a plain text representation of the subject and body
*/
Message.prototype.$plainContent = function() {
return Message.$$resource.fetch(this.$absolutePath(), 'viewplain');
};
/**
* @function addTag
* @memberof Message.prototype
@@ -6,8 +6,8 @@
/**
* @ngInject
*/
MessageController.$inject = ['$window', '$scope', '$state', '$mdDialog', 'stateAccounts', 'stateAccount', 'stateMailbox', 'stateMessage', 'encodeUriFilter', 'sgSettings', 'sgFocus', 'Dialog', 'Account', 'Mailbox', 'Message'];
function MessageController($window, $scope, $state, $mdDialog, stateAccounts, stateAccount, stateMailbox, stateMessage, encodeUriFilter, sgSettings, focus, Dialog, Account, Mailbox, Message) {
MessageController.$inject = ['$window', '$scope', '$state', '$mdDialog', 'stateAccounts', 'stateAccount', 'stateMailbox', 'stateMessage', 'encodeUriFilter', 'sgSettings', 'sgFocus', 'Dialog', 'Calendar', 'Component', 'Account', 'Mailbox', 'Message'];
function MessageController($window, $scope, $state, $mdDialog, stateAccounts, stateAccount, stateMailbox, stateMessage, encodeUriFilter, sgSettings, focus, Dialog, Calendar, Component, Account, Mailbox, Message) {
var vm = this, messageDialog = null, popupWindow = null;
// Expose controller
@@ -35,6 +35,8 @@
vm.saveMessage = saveMessage;
vm.toggleRawSource = toggleRawSource;
vm.showRawSource = false;
vm.convertToEvent = convertToEvent;
vm.convertToTask = convertToTask;
// One-way refresh of the parent window when modifying the message from a popup window.
if ($window.opener) {
@@ -254,6 +256,45 @@
vm.showRawSource = !vm.showRawSource;
}
}
function convertToEvent($event) {
return convertToComponent($event, 'appointment');
}
function convertToTask($event) {
return convertToComponent($event, 'task');
}
function convertToComponent($event, type) {
vm.message.$plainContent().then(function(data) {
var componentData = {
pid: Calendar.$defaultCalendar(),
type: type,
summary: data.subject,
comment: data.content
};
var component = new Component(componentData);
// UI/Templates/SchedulerUI/UIxAppointmentEditorTemplate.wox or
// UI/Templates/SchedulerUI/UIxTaskEditorTemplate.wox
var templateUrl = [
sgSettings.activeUser('folderURL'),
'Calendar',
'UIx' + type.capitalize() + 'EditorTemplate'
].join('/');
return $mdDialog.show({
parent: angular.element(document.body),
targetEvent: $event,
clickOutsideToClose: true,
escapeToClose: true,
templateUrl: templateUrl,
controller: 'ComponentEditorController',
controllerAs: 'editor',
locals: {
stateComponent: component
}
});
});
}
}
angular
@@ -124,6 +124,14 @@
_this.$calendars.push(calendar);
});
}
else if (angular.isUndefined(this.$calendars)) {
this.$calendars = [];
this.$subscriptions = [];
this.$webcalendars = [];
Calendar.$$resource.fetch('calendarslist').then(function(data) {
Calendar.$findAll(data.calendars, writable);
});
}
if (writable) {
return _.union(this.$calendars, _.filter(this.$subscriptions, function(calendar) { return calendar.acls.objectCreator; }));
@@ -39,7 +39,7 @@
$Preferences: Preferences,
$Card: Card,
$gravatar: Gravatar,
$$resource: new Resource(Settings.baseURL(), Settings.activeUser()),
$$resource: new Resource(Settings.activeUser('folderURL') + 'Calendar', Settings.activeUser()),
timeFormat: "%H:%M",
// Filter parameters common to events and tasks
$query: { value: '', search: 'title_Category_Location' },
@@ -236,35 +236,40 @@
* @returns a promise of a collection of objects describing the events blocks
*/
Component.$eventsBlocksForView = function(view, date) {
var viewAction, startDate, endDate, params;
var _this = this;
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();
endDate = new Date();
endDate.setTime(startDate.getTime());
endDate.addDays(6);
}
else if (view == 'month') {
viewAction = 'monthView';
startDate = date;
startDate.setDate(1);
startDate = startDate.beginOfWeek();
endDate = new Date();
endDate.setTime(startDate.getTime());
endDate.setMonth(endDate.getMonth() + 1);
endDate.addDays(-1);
endDate = endDate.endOfWeek();
}
return this.$eventsBlocks(viewAction, startDate, endDate);
return Component.$Preferences.ready().then(function(data) {
var firstDayOfWeek, viewAction, startDate, endDate, params;
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(startDate.getTime());
endDate.setMonth(endDate.getMonth() + 1);
endDate.addDays(-1);
endDate = endDate.endOfWeek(firstDayOfWeek);
}
return _this.$eventsBlocks(viewAction, startDate, endDate);
});
};
/**