Branch 'dev/calendar-resources' - plugins/calendar
Thomas Brüderli
bruederli at kolabsys.com
Mon Mar 17 21:11:42 CET 2014
plugins/calendar/calendar_ui.js | 43 +++++++++++-----
plugins/calendar/drivers/ldap/resources_driver_ldap.php | 5 +
2 files changed, 37 insertions(+), 11 deletions(-)
New commits:
commit 761c79dbadc33cbe37e8ccca52acc2d8e0ab8f65
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Mon Mar 17 21:11:36 2014 +0100
Fix resolving and displaying tree structure of resource records loaded from the server
diff --git a/plugins/calendar/calendar_ui.js b/plugins/calendar/calendar_ui.js
index 9d03987..f74880e 100644
--- a/plugins/calendar/calendar_ui.js
+++ b/plugins/calendar/calendar_ui.js
@@ -1333,7 +1333,7 @@ function rcube_calendar_ui(settings)
var event = me.selected_event,
eventstart = clone_date(event.start, event.allDay ? 1 : 0).getTime(), // calculate with integers
eventend = clone_date(event.end, event.allDay ? 2 : 0).getTime(),
- duration = eventend - eventstart - (event.allDay ? HOUR_MS : 0), // make sure we don't cross day borders on DST change
+ duration = eventend - eventstart - (event.allDay ? HOUR_MS : 0), /* make sure we don't cross day borders on DST change */
sinterval = freebusy_data.interval * 60000,
intvlslots = 1,
numslots = Math.ceil(duration / sinterval),
@@ -1769,25 +1769,46 @@ function rcube_calendar_ui(settings)
// callback from server for resource listing
var resource_data_load = function(data)
{
- data.sort(function(a,b) {
- var j = a._type == 'collection' ? 1 : 0,
- k = b._type == 'collection' ? 1 : 0;
- return k != j ? (j - k) : (a.name < b.name ? 1 : 0);
- });
+ var resources_tree = {};
- // assign parent-relations
+ // store data by ID
$.each(data, function(i, rec) {
resources_data[rec.ID] = rec;
- resources_index.push(rec.ID);
+ // assign parent-relations
if (rec.members) {
$.each(rec.members, function(j, m){
- resources_data[m].parent_id = rec.ID;
+ resources_tree[m] = rec.ID;
});
}
});
- resources_index.reverse();
+ // walk the parent-child tree to determine the depth of each node
+ $.each(data, function(i, rec) {
+ rec._depth = 0;
+ if (resources_tree[rec.ID])
+ rec.parent_id = resources_tree[rec.ID];
+
+ var parent_id = resources_tree[rec.ID];
+ while (parent_id) {
+ rec._depth++;
+ parent_id = resources_tree[parent_id];
+ }
+ });
+
+ // sort by depth, collection and name
+ data.sort(function(a,b) {
+ var j = a._type == 'collection' ? 1 : 0,
+ k = b._type == 'collection' ? 1 : 0,
+ d = a._depth - b._depth;
+ if (!d) d = (k - j);
+ if (!d) d = b.name < a.name ? 1 : -1;
+ return d;
+ });
+
+ $.each(data, function(i, rec) {
+ resources_index.push(rec.ID);
+ });
// apply search filter...
if ($('#resourcesearchbox').val() != '')
@@ -2130,7 +2151,7 @@ function rcube_calendar_ui(settings)
date: date.getDate(),
month: date.getMonth(),
year: date.getFullYear(),
- ignoreTimezone: true, // will treat the given date strings as in local (browser's) timezone
+ ignoreTimezone: true, /* will treat the given date strings as in local (browser's) timezone */
eventSources: sources,
monthNames : settings['months'],
monthNamesShort : settings['months_short'],
diff --git a/plugins/calendar/drivers/ldap/resources_driver_ldap.php b/plugins/calendar/drivers/ldap/resources_driver_ldap.php
index 2f10a1e..c377393 100644
--- a/plugins/calendar/drivers/ldap/resources_driver_ldap.php
+++ b/plugins/calendar/drivers/ldap/resources_driver_ldap.php
@@ -127,6 +127,11 @@ class resources_driver_ldap extends resources_driver
$rec['attributes'] = $attributes;
}
+ // force $rec['members'] to be an array
+ if (!empty($rec['members']) && !is_array($rec['members'])) {
+ $rec['members'] = array($rec['members']);
+ }
+
// remove unused cruft
unset($rec['_raw_attrib']);
More information about the commits
mailing list