Skip to content

Commit

Permalink
(js) Fix batch delete of components
Browse files Browse the repository at this point in the history
Fixes #3516
  • Loading branch information
cgx committed Feb 11, 2016
1 parent f70c0fa commit 9cc4bfd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
1 change: 1 addition & 0 deletions NEWS
Expand Up @@ -21,6 +21,7 @@ Bug fixes
- [web] fixed virtual repeater when moving up in messages list
- [web] really delete mailboxes being deleted from the Trash folder (#595, #1189, #641)
- [web] fixed address autocompletion of mail editor affecting cards list of active addressbook
- [web] fixed batched delete of components (#3516)

3.0.1 (2016-02-05)
------------------
Expand Down
20 changes: 7 additions & 13 deletions UI/WebServerResources/js/Scheduler/Calendar.service.js
Expand Up @@ -243,25 +243,19 @@
* @return a promise of the HTTP operation
*/
Calendar.$deleteComponents = function(components) {

// We create a c_folder -> event hash
var calendars = {}, _this = this;
var _this = this, calendars = {}, promises = [];

_.forEach(components, function(component) {
if (!angular.isDefined(calendars[component.c_folder]))
calendars[component.c_folder] = [];

calendars[component.c_folder].push(component.c_name);
if (!angular.isDefined(calendars[component.pid]))
calendars[component.pid] = [];
calendars[component.pid].push(component.id);
});

_.forEach(calendars, function(uids, c_folder) {
Calendar.$$resource.post(c_folder, 'batchDelete', {uids: uids});
_.forEach(calendars, function(uids, pid) {
promises.push(Calendar.$$resource.post(pid, 'batchDelete', {uids: uids}));
});

// We slice both arrays - might be useful if in the future, we can delete
// events and tasks at the same time.
_this.$Component.$events = _.difference(_this.$Component.$events, components);
_this.$Component.$tasks = _.difference(_this.$Component.$tasks, components);
return Calendar.$q.all(promises);
};

/**
Expand Down
8 changes: 6 additions & 2 deletions UI/WebServerResources/js/Scheduler/CalendarListController.js
Expand Up @@ -80,8 +80,12 @@
{ ok: l('Delete') })
.then(function() {
// User confirmed the deletion
var components = _.filter(Component['$' + vm.componentType], function(component) { return component.selected; });
Calendar.$deleteComponents(components);
var components = _.filter(Component['$' + vm.componentType], function(component) {
return component.selected;
});
Calendar.$deleteComponents(components).then(function() {
$rootScope.$emit('calendars:list');
});
});
}

Expand Down

0 comments on commit 9cc4bfd

Please sign in to comment.