Fix resolving and displaying tree structure of resource records loaded from the server
This commit is contained in:
parent
0946cc37a4
commit
761c79dbad
2 changed files with 37 additions and 11 deletions
|
@ -1333,7 +1333,7 @@ function rcube_calendar_ui(settings)
|
||||||
var event = me.selected_event,
|
var event = me.selected_event,
|
||||||
eventstart = clone_date(event.start, event.allDay ? 1 : 0).getTime(), // calculate with integers
|
eventstart = clone_date(event.start, event.allDay ? 1 : 0).getTime(), // calculate with integers
|
||||||
eventend = clone_date(event.end, event.allDay ? 2 : 0).getTime(),
|
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,
|
sinterval = freebusy_data.interval * 60000,
|
||||||
intvlslots = 1,
|
intvlslots = 1,
|
||||||
numslots = Math.ceil(duration / sinterval),
|
numslots = Math.ceil(duration / sinterval),
|
||||||
|
@ -1769,25 +1769,46 @@ function rcube_calendar_ui(settings)
|
||||||
// callback from server for resource listing
|
// callback from server for resource listing
|
||||||
var resource_data_load = function(data)
|
var resource_data_load = function(data)
|
||||||
{
|
{
|
||||||
data.sort(function(a,b) {
|
var resources_tree = {};
|
||||||
var j = a._type == 'collection' ? 1 : 0,
|
|
||||||
k = b._type == 'collection' ? 1 : 0;
|
|
||||||
return k != j ? (j - k) : (a.name < b.name ? 1 : 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
// assign parent-relations
|
// store data by ID
|
||||||
$.each(data, function(i, rec) {
|
$.each(data, function(i, rec) {
|
||||||
resources_data[rec.ID] = rec;
|
resources_data[rec.ID] = rec;
|
||||||
resources_index.push(rec.ID);
|
|
||||||
|
|
||||||
|
// assign parent-relations
|
||||||
if (rec.members) {
|
if (rec.members) {
|
||||||
$.each(rec.members, function(j, m){
|
$.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...
|
// apply search filter...
|
||||||
if ($('#resourcesearchbox').val() != '')
|
if ($('#resourcesearchbox').val() != '')
|
||||||
|
@ -2130,7 +2151,7 @@ function rcube_calendar_ui(settings)
|
||||||
date: date.getDate(),
|
date: date.getDate(),
|
||||||
month: date.getMonth(),
|
month: date.getMonth(),
|
||||||
year: date.getFullYear(),
|
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,
|
eventSources: sources,
|
||||||
monthNames : settings['months'],
|
monthNames : settings['months'],
|
||||||
monthNamesShort : settings['months_short'],
|
monthNamesShort : settings['months_short'],
|
||||||
|
|
|
@ -127,6 +127,11 @@ class resources_driver_ldap extends resources_driver
|
||||||
$rec['attributes'] = $attributes;
|
$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
|
// remove unused cruft
|
||||||
unset($rec['_raw_attrib']);
|
unset($rec['_raw_attrib']);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue