Use taglist for owner

This commit is contained in:
Nathan Gray 2016-02-09 20:28:57 +00:00
parent 3895b4ca0e
commit d7dfd44c8b
6 changed files with 156 additions and 13 deletions

View File

@ -621,17 +621,42 @@ class calendar_ui
$sel_options = array();
// Get user accounts, formatted nicely for grouping and matching
// the ajax call calendar_uiforms->ajax_owner()
$account_options = array('account_type' => 'both');
$accounts = accounts::link_query('',$account_options);
$sel_options['owner'] = array_map(
function($account_id, $account_name) {
return array(
'value' => $account_id,
'label' => $account_name,
'app' => lang('home-accounts')
);
},
array_keys($accounts), $accounts
);
// Add external owners that a select account widget will not find
$linked_owners = array();
foreach($owners as $owner)
foreach($owners as &$owner)
{
$owner = ''.$owner;
if(!is_numeric($owner))
{
$resource = $this->bo->resources[substr($owner, 0,1)];
$label = egw_link::title($resource['app'], substr($owner,1));
$linked_owners[$resource['app']][substr($owner,1)] = $label;
$sel_options['owner'][] = array('value' => $owner, 'label' => $label);
}
else if (!in_array($owner, array_keys($accounts)))
{
$label = egw_link::title('home-accounts',$owner);
$resource = array('app'=> 'home-accounts');
}
else
{
continue;
}
$sel_options['owner'][] = array('value' => $owner, 'label' => $label, 'app' => lang($resource['app']));
}
if($linked_owners)
{

View File

@ -2941,6 +2941,59 @@ class calendar_uiforms extends calendar_ui
}
}
/**
* Handle ajax searches for owner across all supported resources
*
* @return Array List of matching results
*/
public function ajax_owner()
{
$query = $_REQUEST['query'];
$options = ['num_rows' => 100];
$results = [];
if($query)
{
foreach($this->bo->resources as $type => $data)
{
$mapped = array();
if ($data['app'] && egw_link::get_registry($data['app'], 'query'))
{
$_results = egw_link::query($data['app'], $query,$options);
if(!$_results) continue;
$r_results = array_unique($_results);
foreach($_results as $id => $title)
{
if($id && $title)
{
// Magicsuggest uses id, not value.
$value = [
'id' => $type.$id,
'value'=> $type.$id,
'label' => $title,
'app' => lang($data['app'])
];
if(is_array($value['label']))
{
$value = array_merge($value, $value['label']);
}
$mapped[] = $value;
}
}
if(count($mapped))
{
$results = array_merge($results, $mapped);
}
}
}
}
// switch regular JSON response handling off
egw_json_request::isJSONRequest(false);
header('Content-Type: application/json; charset=utf-8');
echo json_encode($results);
common::egw_exit();
}
/**
* imports a mail as Calendar
*

View File

@ -12,6 +12,7 @@
/*egw:uses
/etemplate/js/etemplate2.js;
/calendar/js/et2_widget_owner.js;
/calendar/js/et2_widget_timegrid.js;
/calendar/js/et2_widget_planner.js;
*/
@ -1972,13 +1973,6 @@ app.classes.calendar = AppJS.extend(
{
state.state.owner[state.state.owner.indexOf('0')] = this.egw.user('account_id');
}
if(state.state.owner.length === 1 && this.sidebox_et2)
{
// If only one owner selected, go back to single select
var owner = this.sidebox_et2.getWidgetById('owner');
owner.set_multiple(false);
}
// Show the correct number of grids
var grid_count = 0;
@ -2747,6 +2741,10 @@ app.classes.calendar = AppJS.extend(
}
if(!found)
{
if(!widget.options.select_options.push)
{
widget.options.select_options = [];
}
widget.options.select_options.push(option);
}
}
@ -2884,7 +2882,7 @@ app.classes.calendar = AppJS.extend(
for(var day in updated_days)
{
// Might be split by user, so we have to check that too
for(var i = 0; i < state.owner.length; i++)
for(var i = 0; i < typeof state.owner == 'object' ? state.owner.length : 1; i++)
{
var owner = multiple_owner ? state.owner[i] : state.owner;
var cache_id = app.classes.calendar._daywise_cache_id(day, owner);
@ -3247,6 +3245,14 @@ app.classes.calendar = AppJS.extend(
button.parent().css('margin-right',button.outerWidth(true)+2);
button.parent().parent().css('white-space','nowrap');
}
$j(window).on('resize.calendar-owner', function() {
var preferred_width = $j('#calendar-et2_target').children().first().outerWidth()||0;
var owner = app.calendar.sidebox_et2.getWidgetById('owner');
if(preferred_width && owner.input.hasClass("chzn-done"))
{
owner.input.next().css('width',preferred_width);
}
});
},
/**

View File

@ -0,0 +1,59 @@
/*
* Egroupware
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package
* @subpackage
* @link http://www.egroupware.org
* @author Nathan Gray
* @version $Id$
*/
"use strict";
/*egw:uses
et2_widget_taglist;
*/
/**
* Tag list widget customised for calendar owner, which can be a user
* account or group, or an entry from almost any app, or an email address
*
* A cross between auto complete, selectbox and chosen multiselect
*
* Uses MagicSuggest library
* @see http://nicolasbize.github.io/magicsuggest/
* @augments et2_selectbox
*/
var et2_calendar_owner = et2_taglist_email.extend(
{
attributes: {
"autocomplete_url": {
"default": "calendar.calendar_uiforms.ajax_owner.etemplate"
},
"autocomplete_params": {
"name": "Autocomplete parameters",
"type": "any",
"default": {},
"description": "Extra parameters passed to autocomplete URL. It should be a stringified JSON object."
},
allowFreeEntries: {
"default": false,
ignore: true
},
select_options: {
"type": "any",
"name": "Select options",
// Set to empty object to use selectbox's option finding
"default": {},
"description": "Internaly used to hold the select options."
},
},
// Allows sub-widgets to override options to the library
lib_options: {
groupBy: 'app',
expandOnFocus: true
}
});
et2_register_widget(et2_calendar_owner, ["calendar_owner"]);

View File

@ -27,7 +27,7 @@ if(view_change >= 0) {update.view = app.calendar.sidebox_changes_views[view_chan
<textbox type="hidden" id="first"/>
<textbox type="hidden" id="last"/>
<select-cat id="cat_id" empty_label="All categories" width="86%" onchange="app.calendar.update_state({cat_id: widget.getValue()});" expand_multiple_rows="4"/>
<select-account id="owner" class="et2_fullWidth" onchange="app.calendar.update_state({owner: widget.getValue()});" expand_multiple_rows="4" account_type="both"/>
<calendar_owner id="owner" class="et2_fullWidth" onchange="app.calendar.update_state({owner: widget.getValue()}); return false;" multiple="true" allowFreeEntries="false"/>
<!--
<taglist id="owner" class="et2_fullWidth" onchange="app.calendar.update_state({owner: widget.getValue()});" autocomplete_params=''/>

View File

@ -11,7 +11,7 @@
* @package calendar
* @version $Id$
*/
/* $Id: app.css 54928 2016-02-04 23:14:54Z nathangray $ */
/* $Id: app.css 54941 2016-02-05 18:17:47Z nathangray $ */
/*Media print classes*/
@media print {
.th td,