Fix resource participant search conflict checking

This commit is contained in:
Nathan Gray 2015-03-19 15:12:07 +00:00
parent 4612519199
commit 8c86b4b41f
4 changed files with 51 additions and 26 deletions

View File

@ -1466,21 +1466,17 @@ class calendar_uiforms extends calendar_ui
}
// adding extra content for the resource link-entry widget to
// * select resources or addressbook as a default selection on the app selectbox based on prefs
$content['participants']['resource']['default_sel'] = $this->cal_prefs['defaultresource_sel'];
$content['participants']['resource']['app'] = $this->cal_prefs['defaultresource_sel'];
// * get informations from the event on the ajax callback
if (in_array($content['participants']['resource']['default_sel'],array('resources_conflict','resources_without_conflict')))
if (in_array($content['participants']['resource']['app'],array('resources_conflict','resources_without_conflict')))
{
// fix real app string
$content['participants']['resource']['default_sel'] = 'resources';
// this will be used to get reservation information on the resource select list
$content['participants']['resource']['extra'] = "values2url(this.form,'start,end,duration,participants,recur_type,whole_day')".
"+'&exec[event_id]=".$content['id']."'"."+'&exec[show_conflict]=".
(($this->cal_prefs['defaultresource_sel'] == 'resources_without_conflict')? '0':'1')."'";
$content['participants']['resource']['app'] = 'resources';
}
// check if current pref. is an allowed application for the user
if (!isset($GLOBALS['egw_info']['user']['apps'][$content['participants']['resource']['default_sel']]))
if (!isset($GLOBALS['egw_info']['user']['apps'][$content['participants']['resource']['app']]))
{
$content['participants']['resource']['default_sel'] = 'home-accounts';
$content['participants']['resource']['app'] = 'home-accounts';
}
}
$content['participants']['status_date'] = $preserv['actual_date'];

View File

@ -939,6 +939,43 @@ app.classes.calendar = AppJS.extend(
}
},
/**
* In edit popup, search for calendar participants.
* Resources need to have the start & duration (etc.)
* passed along in the query.
*
* @param {Object} request
* @param {et2_link_entry} widget
*
* @returns {boolean} True to continue with the search
*/
edit_participant_search: function(request, widget)
{
if(widget.app_select.val() == 'resources')
{
// Resources search is expecting exec
var values = widget.getInstanceManager().getValues(widget.getRoot());
if(typeof request.options != 'object' || request.options == null)
{
request.options = {};
}
request.options.exec = {
start: values.start,
end: values.end,
duration: values.duration,
participants: values.participants,
recur_type: values.recur_type,
event_id: values.link_to.to_id, // cal_id, if available
show_conflict: (egw.preference('defaultresource_sel','calendar') == 'resources_without_conflict') ? '0' : '1'
};
if(values.whole_day)
{
request.options.exec.whole_date = true;
}
}
return true;
},
/**
* Handles to select freetime, and replace the selected one on Start,
* and End date&time in edit calendar entry popup.

View File

@ -112,7 +112,7 @@
<menulist>
<menupopup type="select-account" statustext="User or group" id="account" multiple="true" no_lang="true" tags="true" account_type="both" empty_label="User or group" class="et2_fullWidth" width="99%"/>
</menulist>
<link-entry id="resource" options="@cal_resources"/>
<link-entry id="resource" options="@cal_resources" query="app.calendar.edit_participant_search"/>
</vbox>
<vbox span="2" valign="middle">
<textbox type="integer" align="center" id="quantity" min="1" size="3"/>

View File

@ -588,11 +588,11 @@ class resources_bo
$data = $this->so->search($criteria,$only_keys,$order_by='name',$extra_cols='',$wildcard='%',$empty,$op='OR',$limit,$filter);
// maybe we need to check disponibility of the searched resources in the calendar if $pattern ['exec'] contains some extra args
$show_conflict=False;
if (is_array($pattern) && isset($pattern['exec']) )
if ($options['exec'])
{
// we'll use a cache for resources info taken from database
static $res_info_cache = array();
$cal_info=$pattern['exec'];
$cal_info=$options['exec'];
if ( isset($cal_info['start']) && isset($cal_info['duration']))
{
//get a calendar objet for reservations
@ -601,22 +601,14 @@ class resources_bo
require_once(EGW_INCLUDE_ROOT.'/calendar/inc/class.calendar_bo.inc.php');
$this->bocal =& CreateObject('calendar.calendar_bo');
}
//get the real timestamps from infos we have on the event
//use etemplate date widget to handle date values
require_once(EGW_INCLUDE_ROOT.'/phpgwapi/inc/class.jscalendar.inc.php');
$jscal=& CreateObject('phpgwapi.jscalendar');
$startarr= $jscal->input2date($cal_info['start']['str'],$raw='raw',$day='day',$month='month',$year='year');
$start = new egw_time($cal_info['start']);
$startarr= getdate($start->format('ts'));
if (isset($cal_info['whole_day'])) {
$startarr['hour'] = $startarr['minute'] = 0;
unset($startarr['raw']);
$start = $this->bocal->date2ts($startarr);
$end = $start + 86399;
$start = new egw_time($startarr);
$end = $start->format('ts') + 86399;
} else {
$startarr['hour'] = $cal_info['start']['H'];
$startarr['minute'] = $cal_info['start']['i'];
unset($startarr['raw']);
$start = $this->bocal->date2ts($startarr);
$start = $start->format('ts');
$end = $start + ($cal_info['duration']);
}
@ -673,7 +665,7 @@ class resources_bo
}
}
if (isset($res_info_cache)) {
$show_conflict= (isset($pattern['exec']['show_conflict'])&& ($pattern['exec']['show_conflict']=='0'))? False:True;
$show_conflict= (isset($options['exec']['show_conflict'])&& ($options['exec']['show_conflict']=='0'))? False:True;
// if we have this array indexed on resource id it means non-bookable resource are removed and we are working for calendar
// so we'll loop on this one and not $data
foreach($res_info_cache as $id => $resource) {