(js) Fix batch delete of components

Fixes #3516
pull/189/merge
Francis Lachapelle 2016-02-11 09:33:58 -05:00
parent f70c0fa6e6
commit 9cc4bfd9be
3 changed files with 14 additions and 15 deletions

1
NEWS
View File

@ -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)
------------------

View File

@ -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);
};
/**

View File

@ -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');
});
});
}