mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-10-19 02:08:11 +00:00
(js) Improve search toolbar in Calendar module
- new distinct search toolbar - restored filtering options - honor user's settings
This commit is contained in:
1 parent
4d4458a183
commit
9514103031
7 files changed
+175
-42
No files matched your search
@@ -6,18 +6,28 @@
|
||||
/**
|
||||
* @ngInject
|
||||
*/
|
||||
CalendarListController.$inject = ['$scope', '$rootScope', '$timeout', '$state', 'sgFocus', 'encodeUriFilter', 'Dialog', 'sgSettings', 'Calendar', 'Component', '$mdSidenav'];
|
||||
function CalendarListController($scope, $rootScope, $timeout, $state, focus, encodeUriFilter, Dialog, Settings, Calendar, Component, $mdSidenav) {
|
||||
CalendarListController.$inject = ['$scope', '$rootScope', '$timeout', '$state', 'sgFocus', 'encodeUriFilter', 'Dialog', 'sgSettings', 'Preferences', 'Calendar', 'Component', '$mdSidenav'];
|
||||
function CalendarListController($scope, $rootScope, $timeout, $state, focus, encodeUriFilter, Dialog, Settings, Preferences, Calendar, Component, $mdSidenav) {
|
||||
var vm = this;
|
||||
|
||||
vm.component = Component;
|
||||
vm.componentType = null;
|
||||
vm.componentType = 'events';
|
||||
vm.selectedList = 0;
|
||||
vm.selectComponentType = selectComponentType;
|
||||
vm.newComponent = newComponent;
|
||||
// TODO: should reflect last state userSettings -> Calendar -> SelectedList
|
||||
vm.selectedList = 0;
|
||||
vm.selectComponentType('tasks');
|
||||
vm.selectComponentType('events');
|
||||
vm.filter = filter;
|
||||
vm.cancelSearch = cancelSearch;
|
||||
vm.mode = { search: false };
|
||||
|
||||
// Select list based on user's settings
|
||||
Preferences.ready().then(function() {
|
||||
var type = 'events';
|
||||
if (Preferences.settings.Calendar.SelectedList == 'tasksListView') {
|
||||
vm.selectedList = 1;
|
||||
type = 'tasks';
|
||||
}
|
||||
vm.selectComponentType(type, { reload: true });
|
||||
});
|
||||
|
||||
// Switch between components tabs
|
||||
function selectComponentType(type, options) {
|
||||
@@ -38,6 +48,18 @@
|
||||
$state.go('calendars.newComponent', { calendarId: 'personal', componentType: type });
|
||||
}
|
||||
|
||||
function filter(filterpopup) {
|
||||
if (filterpopup)
|
||||
Component.$query.filterpopup = filterpopup;
|
||||
|
||||
Component.$filter(vm.componentType, { value: '' });
|
||||
}
|
||||
|
||||
function cancelSearch() {
|
||||
vm.mode.search = false;
|
||||
filter();
|
||||
}
|
||||
|
||||
// Refresh current list when the list of calendars is modified
|
||||
$scope.$on('calendars:list', function() {
|
||||
Component.$filter(vm.componentType);
|
||||
|
||||
@@ -31,15 +31,20 @@
|
||||
* @desc The factory we'll use to register with Angular
|
||||
* @returns the Component constructor
|
||||
*/
|
||||
Component.$factory = ['$q', '$timeout', '$log', 'sgSettings', 'Resource', function($q, $timeout, $log, Settings, Resource) {
|
||||
Component.$factory = ['$q', '$timeout', '$log', 'sgSettings', 'Preferences', 'Resource', function($q, $timeout, $log, Settings, Preferences, Resource) {
|
||||
angular.extend(Component, {
|
||||
$q: $q,
|
||||
$timeout: $timeout,
|
||||
$log: $log,
|
||||
$Preferences: Preferences,
|
||||
$$resource: new Resource(Settings.baseURL, Settings.activeUser),
|
||||
$categories: window.UserDefaults.SOGoCalendarCategoriesColors
|
||||
$categories: window.UserDefaults.SOGoCalendarCategoriesColors,
|
||||
$query: { search: 'title_Category_Location' }
|
||||
});
|
||||
Preferences.ready().then(function() {
|
||||
Component.$query.filterpopup = Preferences.settings.CalendarDefaultFilter;
|
||||
Component.$query['show-completed'] = parseInt(Preferences.settings.ShowCompletedTasks);
|
||||
});
|
||||
|
||||
if (window.UserDefaults && window.UserDefaults.SOGoTimeFormat)
|
||||
Component.timeFormat = window.UserDefaults.SOGoTimeFormat;
|
||||
else
|
||||
@@ -70,19 +75,32 @@
|
||||
month = now.getMonth() + 1,
|
||||
year = now.getFullYear(),
|
||||
defaultParams = {
|
||||
search: 'title_Category_Location',
|
||||
day: '' + year + (month < 10?'0':'') + month + (day < 10?'0':'') + day,
|
||||
filterpopup: 'view_thismonth'
|
||||
};
|
||||
|
||||
if (angular.isUndefined(this.$filterOptions))
|
||||
this.$filterOptions = defaultParams;
|
||||
if (options)
|
||||
angular.extend(this.$filterOptions, options);
|
||||
return this.$Preferences.ready().then(function() {
|
||||
var futureComponentData, dirty = false, otherType;
|
||||
|
||||
var futureComponentData = this.$$resource.fetch(null, type + 'list', this.$filterOptions);
|
||||
angular.extend(_this.$query, defaultParams);
|
||||
if (options) {
|
||||
_.find(_.allKeys(options), function(key) {
|
||||
dirty = (options[key] != Component.$query[key]);
|
||||
return dirty;
|
||||
})
|
||||
angular.extend(_this.$query, options);
|
||||
}
|
||||
|
||||
return this.$unwrapCollection(type, futureComponentData);
|
||||
futureComponentData = _this.$$resource.fetch(null, type + 'list', _this.$query);
|
||||
|
||||
// Invalidate cached results of other type if $query has changed
|
||||
otherType = (type == 'tasks')? '$events' : '$tasks';
|
||||
if (dirty) {
|
||||
delete Component[otherType];
|
||||
Component.$log.debug('force reload of ' + otherType);
|
||||
}
|
||||
|
||||
return _this.$unwrapCollection(type, futureComponentData);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -206,11 +224,10 @@
|
||||
*/
|
||||
Component.$unwrapCollection = function(type, futureComponentData) {
|
||||
var _this = this,
|
||||
deferred = Component.$q.defer(),
|
||||
components = [];
|
||||
|
||||
futureComponentData.then(function(data) {
|
||||
Component.$timeout(function() {
|
||||
return futureComponentData.then(function(data) {
|
||||
return Component.$timeout(function() {
|
||||
var fields = _.invoke(data.fields, 'toLowerCase');
|
||||
|
||||
// Instanciate Component objects
|
||||
@@ -225,13 +242,9 @@
|
||||
// Save the list of components to the object model
|
||||
Component['$' + type] = components;
|
||||
|
||||
deferred.resolve(components);
|
||||
return components;
|
||||
});
|
||||
}, function(data) {
|
||||
deferred.reject();
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user