(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] fixed virtual repeater when moving up in messages list
- [web] really delete mailboxes being deleted from the Trash folder (#595, #1189, #641) - [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 address autocompletion of mail editor affecting cards list of active addressbook
- [web] fixed batched delete of components (#3516)
3.0.1 (2016-02-05) 3.0.1 (2016-02-05)
------------------ ------------------

View File

@ -243,25 +243,19 @@
* @return a promise of the HTTP operation * @return a promise of the HTTP operation
*/ */
Calendar.$deleteComponents = function(components) { Calendar.$deleteComponents = function(components) {
var _this = this, calendars = {}, promises = [];
// We create a c_folder -> event hash
var calendars = {}, _this = this;
_.forEach(components, function(component) { _.forEach(components, function(component) {
if (!angular.isDefined(calendars[component.c_folder])) if (!angular.isDefined(calendars[component.pid]))
calendars[component.c_folder] = []; calendars[component.pid] = [];
calendars[component.pid].push(component.id);
calendars[component.c_folder].push(component.c_name);
}); });
_.forEach(calendars, function(uids, c_folder) { _.forEach(calendars, function(uids, pid) {
Calendar.$$resource.post(c_folder, 'batchDelete', {uids: uids}); promises.push(Calendar.$$resource.post(pid, 'batchDelete', {uids: uids}));
}); });
// We slice both arrays - might be useful if in the future, we can delete return Calendar.$q.all(promises);
// events and tasks at the same time.
_this.$Component.$events = _.difference(_this.$Component.$events, components);
_this.$Component.$tasks = _.difference(_this.$Component.$tasks, components);
}; };
/** /**

View File

@ -80,8 +80,12 @@
{ ok: l('Delete') }) { ok: l('Delete') })
.then(function() { .then(function() {
// User confirmed the deletion // User confirmed the deletion
var components = _.filter(Component['$' + vm.componentType], function(component) { return component.selected; }); var components = _.filter(Component['$' + vm.componentType], function(component) {
Calendar.$deleteComponents(components); return component.selected;
});
Calendar.$deleteComponents(components).then(function() {
$rootScope.$emit('calendars:list');
});
}); });
} }