From 47252affba52c706ec2d7bd1e98fbf001c33ef91 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Wed, 12 Aug 2015 16:11:38 -0400 Subject: [PATCH] (feat) initial selection + ops in calendar module --- UI/Templates/SchedulerUI/UIxCalMainView.wox | 29 +++++++++++++++++-- .../js/Scheduler/Calendar.service.js | 25 ++++++++++++++++ .../js/Scheduler/CalendarListController.js | 26 +++++++++++++++++ .../js/Scheduler/Component.service.js | 23 ++++++++++++++- 4 files changed, 99 insertions(+), 4 deletions(-) diff --git a/UI/Templates/SchedulerUI/UIxCalMainView.wox b/UI/Templates/SchedulerUI/UIxCalMainView.wox index c7b562226..5d83d06e1 100644 --- a/UI/Templates/SchedulerUI/UIxCalMainView.wox +++ b/UI/Templates/SchedulerUI/UIxCalMainView.wox @@ -319,7 +319,9 @@ --> -
+
@@ -526,6 +528,19 @@ href="#/calendar/month">view_module
+
+ + arrow_back + + + + + select_all + + + delete + +
@@ -538,7 +553,11 @@ - +
+ +
+

{{event.c_title}}

{{event.c_location}}

@@ -563,7 +582,11 @@ - +
+ +
+

{{task.c_title}}

diff --git a/UI/WebServerResources/js/Scheduler/Calendar.service.js b/UI/WebServerResources/js/Scheduler/Calendar.service.js index e939eeb30..af7596dd0 100644 --- a/UI/WebServerResources/js/Scheduler/Calendar.service.js +++ b/UI/WebServerResources/js/Scheduler/Calendar.service.js @@ -255,6 +255,31 @@ return d.promise; }; + /** + * @function $deleteComponents + * @memberof Calendar + * @desc Delete multiple components from calendar. + * @return a promise of the HTTP operation + */ + Calendar.$deleteComponents = function(components) { + + // We create a c_folder -> event hash + var calendars = {}, _this = this; + + _.forEach(components, function(component) { + if (!angular.isDefined(calendars[component.c_folder])) + calendars[component.c_folder] = []; + + calendars[component.c_folder].push(component.c_name); + }); + + _.forEach(calendars, function(uids, c_folder) { + Calendar.$$resource.post(c_folder, 'batchDelete', {uids: uids}); + }); + + _this.$Component.$events = _.difference(_this.$Component.$events, components); + }; + /** * @function $save * @memberof Calendar.prototype diff --git a/UI/WebServerResources/js/Scheduler/CalendarListController.js b/UI/WebServerResources/js/Scheduler/CalendarListController.js index 846180e5f..a431233e8 100644 --- a/UI/WebServerResources/js/Scheduler/CalendarListController.js +++ b/UI/WebServerResources/js/Scheduler/CalendarListController.js @@ -14,6 +14,9 @@ vm.componentType = 'events'; vm.selectedList = 0; vm.selectComponentType = selectComponentType; + vm.unselectComponents = unselectComponents; + vm.selectAll = selectAll; + vm.confirmDeleteSelectedComponents = confirmDeleteSelectedComponents; vm.openEvent = openEvent; vm.openTask = openTask; vm.newComponent = newComponent; @@ -45,11 +48,34 @@ // TODO: save user settings (Calendar.SelectedList) if (angular.isUndefined(Component['$' + type])) Component.$filter(type); + vm.unselectComponents(); vm.componentType = type; Component.saveSelectedList(type); } } + function unselectComponents() { + _.each(Component['$' + vm.componentType], function(component) { component.selected = false; }); + } + + function selectAll() { + _.each(Component['$' + vm.componentType], function(component) { + component.selected = true; + }); + } + + function confirmDeleteSelectedComponents() { + Dialog.confirm(l('Warning'), + l('Are you sure you want to delete the selected components?')) + .then(function() { + // User confirmed the deletion + var components = _.filter(Component['$' + vm.componentType], function(component) { return component.selected; }); + Calendar.$deleteComponents(components); + }, function(data, status) { + // Delete failed + }); + } + function openEvent($event, event) { openComponent($event, event, 'appointment'); } diff --git a/UI/WebServerResources/js/Scheduler/Component.service.js b/UI/WebServerResources/js/Scheduler/Component.service.js index 0cef62f3a..3f6599efe 100644 --- a/UI/WebServerResources/js/Scheduler/Component.service.js +++ b/UI/WebServerResources/js/Scheduler/Component.service.js @@ -86,9 +86,28 @@ angular.module('SOGo.SchedulerUI') .factory('Component', Component.$factory); + /** + * @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) { + count = (_.filter(Component.$events, function(event) { return event.selected; })).length; + } + if (Component.$tasks) { + count = (_.filter(Component.$tasks, function(event) { return event.selected; })).length; + } + return count; + }; + /** * @function $filter - * @memberof Component.prototype + * @memberof Component * @desc Search for components matching some criterias * @param {string} type - either 'events' or 'tasks' * @param {object} [options] - additional options to the query @@ -403,6 +422,8 @@ _this.updateFreeBusy(attendee); }); } + + this.selected = false; }; /**