(feat) initial selection + ops in calendar module

This commit is contained in:
Ludovic Marcotte
2015-08-12 16:11:38 -04:00
parent 54334b294e
commit 47252affba
4 changed files with 99 additions and 4 deletions

View File

@@ -319,7 +319,9 @@
</md-button>
</div> -->
</div><!-- .md-toolbar-tools -->
<div class="md-toolbar-tools" layout="row" layout-align="space-between center">
<div class="md-toolbar-tools" layout="row"
layout-align="space-between center"
ng-show="list.component.$selectedCount() == 0">
<!-- sort/filter mode -->
<div class="view-list" layout="row" layout-align="space-between center"
ng-hide="list.mode.search">
@@ -526,6 +528,19 @@
href="#/calendar/month"><md-icon>view_module</md-icon></a>
</div>
</div>
<div layout="row" layout-align="start center" ng-show="list.component.$selectedCount() > 0">
<md-button class="sg-icon-button" ng-click="list.unselectComponents()">
<md-icon>arrow_back</md-icon>
</md-button>
<label>{{list.component.$selectedCount()}} selected</label>
<md-button class="sg-icon-button" ng-click="list.selectAll()">
<md-tooltip md-direction="left"><var:string label:value="Select All"/></md-tooltip>
<md-icon>select_all</md-icon>
</md-button>
<md-button class="sg-icon-button" ng-click="list.confirmDeleteSelectedComponents()">
<md-icon>delete</md-icon>
</md-button>
</div>
</md-toolbar>
<md-content layout="row" class="md-flex">
<md-content class="view-list md-flex" layout="column">
@@ -538,7 +553,11 @@
<md-list-item class="md-2-line"
ng-repeat="event in list.component.$events"
ng-click="list.openEvent($event, event)">
<i class="md-tile-left" ng-class="event.getClassName('bg')" ><!-- calendar color --></i>
<div class="sg-selected-avatar" ng-show="event.selected"
ng-click="event.selected = !event.selected">
<!-- selected avatar -->
</div>
<i class="md-tile-left" ng-class="event.getClassName('bg')" ng-show="!event.selected" ng-click="event.selected = !event.selected"><!-- calendar color --></i>
<div class="md-list-item-text">
<h3>{{event.c_title}}</h3>
<p>{{event.c_location}}</p>
@@ -563,7 +582,11 @@
<md-list-item class="md-2-line"
ng-repeat="task in list.component.$tasks"
ng-click="list.openTask($event, task)">
<i class="md-tile-left" ng-class="task.getClassName('bg')" ><!-- calendar color --></i>
<div class="sg-selected-avatar" ng-show="task.selected"
ng-click="task.selected = !task.selected">
<!-- selected avatar -->
</div>
<i class="md-tile-left" ng-class="task.getClassName('bg')" ng-show="!task.selected" ng-click="task.selected = !task.selected"><!-- calendar color --></i>
<div class="md-list-item-text">
<h3>{{task.c_title}}</h3>
<p class="md-secondary" layout="row">

View File

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

View File

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

View File

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