forked from extern/egroupware
Calendar: Fix favorite with planner by user and a group could not find group members
It would then display one row for the group, instead of one row per group member. Did not happen if you had viewed the calendar for the group in another view, or group was selected when calendar opened.
This commit is contained in:
parent
541df7733d
commit
71b8d6ec6b
@ -151,7 +151,7 @@ class calendar_owner_etemplate_widget extends Etemplate\Widget\Taglist
|
||||
$labels = Array();
|
||||
foreach($id as $index => $_id)
|
||||
{
|
||||
$labels[$_id] = self::get_owner_label($_id);
|
||||
$labels[$_id] = self::format_owner($_id, self::get_owner_label($_id));
|
||||
}
|
||||
Api\Json\Response::get()->data($labels);
|
||||
return $labels;
|
||||
@ -232,38 +232,7 @@ class calendar_owner_etemplate_widget extends Etemplate\Widget\Taglist
|
||||
{
|
||||
if($id && $title)
|
||||
{
|
||||
// Magicsuggest uses id, not value.
|
||||
$value = array(
|
||||
'id' => $type.$id,
|
||||
'value'=> $type.$id,
|
||||
'label' => $title,
|
||||
'app' => lang($data['app'])
|
||||
);
|
||||
if(is_array($value['label']))
|
||||
{
|
||||
$value = array_merge($value, $value['label']);
|
||||
}
|
||||
switch($type)
|
||||
{
|
||||
case 'r':
|
||||
// TODO: fetch resources photo
|
||||
break;
|
||||
case 'c':
|
||||
case '':
|
||||
$contact = $contacts_obj->read($type === '' ? 'account:'.$id : $id, true);
|
||||
if (is_array($contact)) $value['icon'] = Api\Framework::link('/api/avatar.php', array(
|
||||
'contact_id' => $contact['id'],
|
||||
'etag' => $contact['etag'] ? $contact['etag'] : 1
|
||||
));
|
||||
if($id < 0)
|
||||
{
|
||||
$value['resources'] = array_map('strval',$GLOBALS['egw']->accounts->members($id, true));
|
||||
}
|
||||
break;
|
||||
default :
|
||||
// do nothing
|
||||
}
|
||||
$mapped[] = $value;
|
||||
$mapped[] = static::format_owner($id, $title, $data);
|
||||
}
|
||||
}
|
||||
if(count($mapped))
|
||||
@ -280,6 +249,68 @@ class calendar_owner_etemplate_widget extends Etemplate\Widget\Taglist
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an ID & title, format the result into data the client side wants
|
||||
*
|
||||
* @param $id
|
||||
* @param $title
|
||||
* @param $type
|
||||
*/
|
||||
protected static function format_owner($id, $title, $data = array())
|
||||
{
|
||||
static $contacts_obj = null;
|
||||
if(is_null($contacts_obj))
|
||||
{
|
||||
$contacts_obj = new Api\Contacts();
|
||||
}
|
||||
if(!$data)
|
||||
{
|
||||
$bo = new calendar_bo();
|
||||
if(!is_numeric($id))
|
||||
{
|
||||
$data = $bo->resources[substr($id, 0, 1)];
|
||||
}
|
||||
else
|
||||
{
|
||||
$data = $bo->resources[''];
|
||||
}
|
||||
}
|
||||
$type = $data['type'];
|
||||
|
||||
// Magicsuggest uses id, not value.
|
||||
$value = array(
|
||||
'id' => $type.$id,
|
||||
'value'=> $type.$id,
|
||||
'label' => $title,
|
||||
'app' => lang($data['app'])
|
||||
);
|
||||
if(is_array($value['label']))
|
||||
{
|
||||
$value = array_merge($value, $value['label']);
|
||||
}
|
||||
switch($type)
|
||||
{
|
||||
case 'r':
|
||||
// TODO: fetch resources photo
|
||||
break;
|
||||
case 'c':
|
||||
case '':
|
||||
$contact = $contacts_obj->read($type === '' ? 'account:'.$id : $id, true);
|
||||
if (is_array($contact)) $value['icon'] = Api\Framework::link('/api/avatar.php', array(
|
||||
'contact_id' => $contact['id'],
|
||||
'etag' => $contact['etag'] ? $contact['etag'] : 1
|
||||
));
|
||||
if($id < 0)
|
||||
{
|
||||
$value['resources'] = array_map('strval',$GLOBALS['egw']->accounts->members($id, true));
|
||||
}
|
||||
break;
|
||||
default :
|
||||
// do nothing
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get just the label for a single owner
|
||||
* @param string $id
|
||||
|
@ -135,8 +135,10 @@ var et2_calendar_owner = (function(){ "use strict"; return et2_taglist_email.ext
|
||||
let idx = this.options.value.find(element => element.id == owner);
|
||||
if(idx)
|
||||
{
|
||||
idx.label = data[owner];
|
||||
idx = jQuery.extend(idx, data[owner]);
|
||||
}
|
||||
// Put it in the list of options for next time
|
||||
this.options.select_options.push(data[owner]);
|
||||
}
|
||||
this.set_value(this.options.value);
|
||||
}, this,true,this).sendRequest();
|
||||
|
@ -415,7 +415,14 @@ var et2_calendar_planner = (function(){ "use strict"; return et2_calendar_view.e
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(already_added.indexOf(''+user) < 0)
|
||||
else if (user < 0)
|
||||
{
|
||||
// Group, but no users found. Need those.
|
||||
egw.accountData(parseInt(user),'account_fullname',true,function(result) {
|
||||
this.invalidate();
|
||||
},this);
|
||||
}
|
||||
else if(already_added.indexOf(''+user) < 0 && parseInt(user) >= 0)
|
||||
{
|
||||
labels.push({
|
||||
id: user,
|
||||
@ -2022,6 +2029,74 @@ var et2_calendar_planner = (function(){ "use strict"; return et2_calendar_view.e
|
||||
this.invalidate(true);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Set which users to display
|
||||
*
|
||||
* Changing the owner will invalidate the display, and it will be redrawn
|
||||
* after a timeout. Overwriting here to check for groups without members.
|
||||
*
|
||||
* @param {number|number[]|string|string[]} _owner - Owner ID, which can
|
||||
* be an account ID, a resource ID (as defined in calendar_bo, not
|
||||
* necessarily an entry from the resource app), or a list containing a
|
||||
* combination of both.
|
||||
*
|
||||
* @memberOf et2_calendar_view
|
||||
*/
|
||||
set_owner: function(_owner)
|
||||
{
|
||||
this._super.apply(this, arguments);
|
||||
|
||||
// If we're grouping by user, we need group members
|
||||
if(this.update_timer !== null && this.options.group_by == 'user')
|
||||
{
|
||||
let options = [];
|
||||
let resource = {};
|
||||
let missing_resources = [];
|
||||
|
||||
if(app.calendar && app.calendar.sidebox_et2 && app.calendar.sidebox_et2.getWidgetById('owner'))
|
||||
{
|
||||
options = app.calendar.sidebox_et2.getWidgetById('owner').taglist.getSelection();
|
||||
}
|
||||
else
|
||||
{
|
||||
options = this.getArrayMgr("sel_options").getRoot().getEntry('owner');
|
||||
}
|
||||
for(var i = 0; i < this.options.owner.length; i++)
|
||||
{
|
||||
var user = this.options.owner[i];
|
||||
if(isNaN(user) || user >= 0 || !options) continue;
|
||||
|
||||
// Owner is a group, see if we have its members
|
||||
if(options.find &&
|
||||
((resource = options.find(function (element)
|
||||
{
|
||||
return element.id == user;
|
||||
}))))
|
||||
{
|
||||
// Members found
|
||||
continue;
|
||||
}
|
||||
// Group, but no users found. Need those.
|
||||
missing_resources.push(user);
|
||||
|
||||
// Maybe api already has them?
|
||||
egw.accountData(parseInt(user),'account_fullname',true,function(result) {
|
||||
missing_resources.splice(missing_resources.indexOf(this),1);
|
||||
}.bind(user),user);
|
||||
}
|
||||
if(missing_resources.length > 0)
|
||||
{
|
||||
// Ask server, and WAIT or we have to redraw
|
||||
egw.json('calendar_owner_etemplate_widget::ajax_owner',[missing_resources],function(data) {
|
||||
for(let owner in data)
|
||||
{
|
||||
if(!owner || typeof owner == "undefined") continue;
|
||||
options.push(data[owner]);
|
||||
}
|
||||
}, this,false,this).sendRequest(false);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Turn on or off the visibility of weekends
|
||||
|
Loading…
Reference in New Issue
Block a user