',
' ',
' error_outline',
' ' + err + '',
'
',
''
].join(''),
hideDelay: 5000,
position: 'top right'
});
}).finally(function () {
$timeout(scrollToStart);
});
}
this.priorityLevel = function () {
if (this.component && this.component.priority) {
if (this.component.priority > 5)
return l('low'); // 6-7-8-9
else if (this.component.priority > 4)
return l('normal'); // 5
else
return l('high'); // 1-2-3-4
}
};
this.changeAlarmRelation = function (form) {
if (form.alarmRelation) {
if (this.component.type == 'task' && this.component.$hasAlarm &&
(this.component.start || this.component.due) &&
((!this.component.start && this.component.alarm.relation == 'START') ||
(!this.component.due && this.component.alarm.relation == 'END'))) {
form.alarmRelation.$setValidity('alarm', false);
}
else {
form.alarmRelation.$setValidity('alarm', true);
}
}
};
this.onAlarmChange = function (form) {
if (this.component.type !== 'task') {
return;
}
if (!this.component.start && this.component.alarm.relation == 'START') {
this.component.alarm.relation = 'END';
} else if (!this.component.due && this.component.alarm.relation == 'END') {
this.component.alarm.relation = 'START';
}
this.changeAlarmRelation(form);
};
this.save = function (form, options) {
this.adjustStartTime();
this.adjustEndTime();
this.changeAlarmRelation(form);
this.addAttendee(this.searchText).then(function () {
if (form.$valid) {
vm.component.$save(options)
.then(function(data) {
$rootScope.$emit('calendars:list');
Preferences.getAlarms();
$mdDialog.hide();
}, function(response) {
if (response.status == CalendarSettings.ConflictHTTPErrorCode)
vm.attendeeConflictError = _.isObject(response.data.message) ? response.data.message : { reject: response.data.message };
else
vm.edit(form);
});
}
});
};
this.reset = function (form) {
this.component.$reset();
form.$setPristine();
};
this.cancel = function (form) {
this.reset(form);
if (this.component.isNew) {
// Cancelling the creation of a component
this.component = null;
}
$mdDialog.hide();
};
this.edit = function (form) {
this.attendeeConflictError = false;
form.$setPristine();
form.$setDirty();
};
function getHours() {
var hours = [];
for (var i = 0; i <= 23; i++) {
hours.push(i.toString());
}
return hours;
}
this.addStartDate = function (form) {
this.component.$addStartDate();
oldStartDate = new Date(this.component.start.getTime());
this.startTime = new Date(this.component.start.getTime());
if (!this.component.due) {
this.component.alarm.relation = 'START';
}
this.changeAlarmRelation(form);
form.$setDirty();
};
this.removeStartDate = function (form) {
this.component.$deleteStartDate();
if (this.component.due) {
this.component.alarm.relation = 'END';
}
this.changeAlarmRelation(form);
form.$setDirty();
};
this.addDueDate = function (form) {
this.component.$addDueDate();
oldDueDate = new Date(this.component.due.getTime());
this.dueTime = new Date(this.component.due.getTime());
if (!this.component.start) {
this.component.alarm.relation = 'END';
}
this.changeAlarmRelation(form);
form.$setDirty();
};
this.removeDueDate = function (form) {
this.component.$deleteDueDate();
if (this.component.start) {
this.component.alarm.relation = 'START';
}
this.changeAlarmRelation(form);
form.$setDirty();
};
this.adjustAllDay = function () {
if (!this.component.isAllDay) {
this.component.start.setHours(dayStartTime);
this.component.start.setMinutes(0);
this.startTime = new Date(this.component.start.getTime());
oldStartDate = new Date(this.component.start.getTime());
this.component.end.setHours(dayEndTime);
this.component.end.setMinutes(0);
this.endTime = new Date(this.component.end.getTime());
oldEndDate = new Date(this.component.end.getTime());
this.component.delta = this.component.start.minutesTo(this.component.end);
}
this.component.$attendees.updateFreeBusyCoverage();
};
this.adjustStartTime = function () {
var delta;
if (this.component.start && this.startTime) {
// Update the component start date
this.component.start.setHours(this.startTime.getHours());
this.component.start.setMinutes(this.startTime.getMinutes());
// Preserve the delta between the start and end dates
delta = oldStartDate.valueOf() - this.component.start.valueOf();
if (delta !== 0) {
oldStartDate = new Date(this.component.start.getTime());
if (this.component.type === 'appointment') {
this.component.end = new Date(this.component.start.getTime());
this.component.end.addMinutes(this.component.delta);
this.endTime = new Date(this.component.end.getTime());
oldEndDate = new Date(this.component.end.getTime());
}
updateFreeBusy();
}
}
};
this.adjustEndTime = function () {
var delta;
if (this.component.end && this.endTime) {
// Update the component end date
this.component.end.setHours(this.endTime.getHours());
this.component.end.setMinutes(this.endTime.getMinutes());
// The end date must be after the start date
delta = oldEndDate.valueOf() - this.component.end.valueOf();
if (delta !== 0) {
if (this.startTime) {
// Update the component start date
this.component.start.setHours(this.startTime.getHours());
this.component.start.setMinutes(this.startTime.getMinutes());
}
delta = this.component.start.minutesTo(this.component.end);
if (delta < 0) {
this.component.end = new Date(oldEndDate.getTime());
this.endTime = new Date(this.component.end.getTime());
}
else {
this.component.delta = delta;
oldEndDate = new Date(this.component.end.getTime());
}
updateFreeBusy();
}
}
};
this.adjustDueTime = function () {
if (this.component.due && this.dueTime) {
this.component.due.setHours(this.dueTime.getHours());
this.component.due.setMinutes(this.dueTime.getMinutes());
oldDueDate = new Date(this.component.due.getTime());
}
};
function updateFreeBusy() {
if (_.has(vm.component, '$attendees')) {
vm.component.$attendees.updateFreeBusyCoverage();
vm.component.$attendees.updateFreeBusy();
$timeout(scrollToStart);
}
}
}
angular
.module('SOGo.SchedulerUI')
.controller('ComponentController', ComponentController)
.controller('ComponentEditorController', ComponentEditorController);
})();