From d0e0d5300ac8b57b4ebf70f31cb8930c66e24456 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Thu, 8 Dec 2016 10:17:03 -0500 Subject: [PATCH] (js) Fix ordering of calendars Fixes #3931 --- NEWS | 1 + .../js/Scheduler/Calendar.service.js | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index a2e31e7c32..4bbfa44156 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,7 @@ Bug fixes - [web] fixed confusion between owner and active user in ACLs management of Administration module - [web] fixed JavaScript exception after renaming an address book - [web] fixed Sieve folder encoding support (#3904) + - [web] fixed ordering of calendars when renaming or adding a calendar (#3931) 3.2.4 (2016-12-01) ------------------ diff --git a/UI/WebServerResources/js/Scheduler/Calendar.service.js b/UI/WebServerResources/js/Scheduler/Calendar.service.js index 10e8912ab3..87cfd566fe 100644 --- a/UI/WebServerResources/js/Scheduler/Calendar.service.js +++ b/UI/WebServerResources/js/Scheduler/Calendar.service.js @@ -84,7 +84,7 @@ */ Calendar.$add = function(calendar) { // Insert new calendar at proper index - var list, sibling, i; + var list, sibling; if (calendar.isWebCalendar) list = this.$webcalendars; @@ -93,13 +93,15 @@ else list = this.$calendars; - sibling = _.find(list, function(o) { + sibling = _.findIndex(list, function(o, i) { + console.debug(i + ': "' + o.id + '".localeCompare("' + calendar.name + '") = ' + o.name.localeCompare(calendar.name)); return (calendar.id == 'personal' || - (o.id != 'personal' && - o.name.localeCompare(calendar.name) === 1)); + (o.id != 'personal' && o.name.localeCompare(calendar.name) > 0)); }); - i = sibling ? _.indexOf(_.map(list, 'id'), sibling.id) : 1; - list.splice(i, 0, calendar); + if (sibling < 0) + list.push(calendar); + else + list.splice(sibling, 0, calendar); this.$Preferences.ready().then(function() { if (Calendar.$Preferences.settings.Calendar.FoldersOrder)