(js) Use more one-time bindings in Calendar module

This commit is contained in:
Francis Lachapelle
2017-06-22 11:56:16 -04:00
parent 9bde9b66ef
commit e8ec8180a8
7 changed files with 134 additions and 115 deletions
@@ -6,8 +6,8 @@
/**
* @ngInject
*/
CalendarListController.$inject = ['$rootScope', '$scope', '$timeout', '$state', '$mdDialog', 'sgHotkeys', 'sgFocus', 'Dialog', 'Preferences', 'CalendarSettings', 'Calendar', 'Component', 'Alarm'];
function CalendarListController($rootScope, $scope, $timeout, $state, $mdDialog, sgHotkeys, focus, Dialog, Preferences, CalendarSettings, Calendar, Component, Alarm) {
CalendarListController.$inject = ['$rootScope', '$scope', '$q', '$timeout', '$state', '$mdDialog', 'sgHotkeys', 'sgFocus', 'Dialog', 'Preferences', 'CalendarSettings', 'Calendar', 'Component', 'Alarm'];
function CalendarListController($rootScope, $scope, $q, $timeout, $state, $mdDialog, sgHotkeys, focus, Dialog, Preferences, CalendarSettings, Calendar, Component, Alarm) {
var vm = this, hotkeys = [], type;
vm.component = Component;
@@ -148,20 +148,30 @@
function openComponent($event, component, type) {
if (component.viewable) {
// UI/Templates/SchedulerUI/UIxAppointmentViewTemplate.wox or
// UI/Templates/SchedulerUI/UIxTaskViewTemplate.wox
var templateUrl = 'UIx' + type.capitalize() + 'ViewTemplate';
$mdDialog.show({
parent: angular.element(document.body),
targetEvent: $event,
clickOutsideToClose: true,
escapeToClose: true,
templateUrl: templateUrl,
controller: 'ComponentController',
controllerAs: 'editor',
locals: {
stateComponent: component
}
var promise = $q.when();
// Load component before opening dialog
if (angular.isUndefined(component.$futureComponentData)) {
component = Calendar.$get(component.pid).$getComponent(component.id, component.occurrenceId);
promise = component.$futureComponentData;
}
promise.then(function() {
// UI/Templates/SchedulerUI/UIxAppointmentViewTemplate.wox or
// UI/Templates/SchedulerUI/UIxTaskViewTemplate.wox
var templateUrl = 'UIx' + type.capitalize() + 'ViewTemplate';
$mdDialog.show({
parent: angular.element(document.body),
targetEvent: $event,
clickOutsideToClose: true,
escapeToClose: true,
templateUrl: templateUrl,
controller: 'ComponentController',
controllerAs: 'editor',
locals: {
stateComponent: component
}
});
});
}
}
@@ -672,6 +672,19 @@
return (this.occurrenceId && this.userHasRSVP);
};
/**
* @function showPercentComplete
* @memberof Component.prototype
* @desc Check if the percent completion should be displayed with respect to the
* component's type and status.
* @returns true if the percent completion should be displayed
*/
Component.prototype.showPercentComplete = function() {
return (this.type == 'task' &&
this.percentComplete > 0 &&
this.status != 'cancelled');
};
/**
* @function enablePercentComplete
* @memberof Component.prototype
@@ -681,7 +694,7 @@
*/
Component.prototype.enablePercentComplete = function() {
return (this.type == 'task' &&
this.percentComplete > 0 &&
this.status != 'not-specified' &&
this.status != 'cancelled');
};
@@ -14,6 +14,7 @@
vm.service = Component;
vm.component = stateComponent;
vm.close = close;
vm.highPriority = highPriority;
vm.cardFilter = cardFilter;
vm.newMessageWithAllRecipients = newMessageWithAllRecipients;
vm.newMessageWithRecipient = newMessageWithRecipient;
@@ -27,19 +28,19 @@
vm.copySelectedComponent = copySelectedComponent;
vm.moveSelectedComponent = moveSelectedComponent;
// Load all attributes of component
if (angular.isUndefined(vm.component.$futureComponentData)) {
component = Calendar.$get(vm.component.pid).$getComponent(vm.component.id, vm.component.occurrenceId);
component.$futureComponentData.then(function() {
vm.component = component;
vm.organizer = [vm.component.organizer];
});
}
// Put organizer in an array to display it as an mdChip
vm.organizer = [stateComponent.organizer];
function close() {
$mdDialog.hide();
}
function highPriority() {
return (vm.component &&
vm.component.priority &&
vm.component.priority < 5);
}
// Autocomplete cards for attendees
function cardFilter($query) {
return AddressBook.$filterAll($query);
@@ -302,11 +303,11 @@
function priorityLevel() {
if (vm.component && vm.component.priority) {
if (vm.component.priority > 5)
return l('low');
return l('low'); // 6-7-8-9
else if (vm.component.priority > 4)
return l('normal');
return l('normal'); // 5
else
return l('high');
return l('high'); // 1-2-3-4
}
}