Fix insert into document from sidebox dropdown

This commit is contained in:
Nathan Gray 2015-06-15 21:38:03 +00:00
parent 7ccbdfe871
commit cdc3ad9a10
4 changed files with 71 additions and 34 deletions

View File

@ -267,7 +267,6 @@ class calendar_ui
// retrieve saved states from prefs // retrieve saved states from prefs
if(!$states) if(!$states)
{ {
error_log('HERE');
$states = unserialize($this->bo->cal_prefs['saved_states']); $states = unserialize($this->bo->cal_prefs['saved_states']);
error_log(array2string($states)); error_log(array2string($states));
} }
@ -605,6 +604,8 @@ class calendar_ui
$menu_title = lang('Calendar Menu'); $menu_title = lang('Calendar Menu');
display_sidebox($appname,$menu_title,$file); display_sidebox($appname,$menu_title,$file);
$this->sidebox_etemplate();
// resources menu hooks // resources menu hooks
foreach ($this->bo->resources as $resource) foreach ($this->bo->resources as $resource)
{ {
@ -636,6 +637,16 @@ class calendar_ui
{ {
if($content['merge']) if($content['merge'])
{ {
// View from sidebox is JSON encoded
$this->manage_states(array_merge($content,json_decode($content['view'],true)));
if($content['first'])
{
$this->first = egw_time::to($content['first'],'ts');
}
if($content['last'])
{
$this->last = egw_time::to($content['last'],'ts');
}
$_GET['merge'] = $content['merge']; $_GET['merge'] = $content['merge'];
$this->merge(); $this->merge();
return; return;

View File

@ -218,17 +218,20 @@ class calendar_uiviews extends calendar_ui
// handle views in other files // handle views in other files
if (!isset($this->public_functions[$this->view]) && $this->view !== 'listview') if (!isset($this->public_functions[$this->view]) && $this->view !== 'listview')
{ {
$GLOBALS['egw']->redirect_link('/index.php',array('menuaction'=>$this->view_menuaction,'ajax'=>'true'),'calendar'); $this->view = 'week';
} }
// get manual to load the right page // get manual to load the right page
$GLOBALS['egw_info']['flags']['params']['manual'] = array('page' => 'ManualCalendar'.ucfirst($this->view)); $GLOBALS['egw_info']['flags']['params']['manual'] = array('page' => 'ManualCalendar'.ucfirst($this->view));
// Sidebox & iframe for old views // Sidebox & iframe for old views
if(in_array($this->view,array('year','planner'))) if(in_array($this->view,array('year','planner')) && $_GET['view'])
{ {
$GLOBALS['egw_info']['flags']['nonavbar'] = true;
$this->manage_states($_GET);
$old_calendar = $this->{$this->view}(); $old_calendar = $this->{$this->view}();
echo $old_calendar;
return;
} }
$this->sidebox_etemplate(array('old_calendar' => $old_calendar));
// Load the different views once, we'll switch between them on the client side // Load the different views once, we'll switch between them on the client side
$tmpl = new etemplate_new('calendar.todo'); $tmpl = new etemplate_new('calendar.todo');

View File

@ -151,11 +151,10 @@ app.classes.calendar = AppJS.extend(
init: function() init: function()
{ {
// make calendar object available, even if not running in top window, as sidebox does // make calendar object available, even if not running in top window, as sidebox does
if (window.top !== window && !egw(window).is_popup()) if (window.top !== window && !egw(window).is_popup() && window.top.app.calendar)
{ {
// we have to explicitly delete old object or IE11 complains about accessing an already freed script window.app.calendar = window.top.app.calendar;
delete window.top.app.calendar; return;
window.top.app.calendar = this;
} }
// call parent // call parent
@ -368,6 +367,17 @@ app.classes.calendar = AppJS.extend(
{ {
return _url.replace(/menuaction=[^&]+/, 'menuaction=calendar.calendar_uilist.listview&ajax=true'); return _url.replace(/menuaction=[^&]+/, 'menuaction=calendar.calendar_uilist.listview&ajax=true');
} }
else if (this.sidebox_et2 && typeof this.views[state.view] == 'undefined')
{
this.sidebox_et2.getWidgetById('iframe').set_src(_url);
this.sidebox
return true;
}
}
else if (_url.indexOf('menuaction=calendar.calendar_uiviews') >= 0)
{
this.sidebox_et2.getWidgetById('iframe').set_src(_url);
return true;
} }
// can not load our own index page, has to be done by framework // can not load our own index page, has to be done by framework
return false; return false;
@ -1237,6 +1247,11 @@ app.classes.calendar = AppJS.extend(
*/ */
update_state: function(_set) update_state: function(_set)
{ {
// Make sure we're running in top window
if(window !== window.top)
{
return window.top.app.calendar.update_state(_set);
}
var changed = []; var changed = [];
var new_state = jQuery.extend({}, this.state); var new_state = jQuery.extend({}, this.state);
if (typeof _set == 'object') if (typeof _set == 'object')
@ -1276,11 +1291,6 @@ app.classes.calendar = AppJS.extend(
state = egw_script_tag.getAttribute('data-calendar-state'); state = egw_script_tag.getAttribute('data-calendar-state');
state = state ? JSON.parse(state) : {}; state = state ? JSON.parse(state) : {};
} }
// we are currently in list-view
if (this.et2 && this.et2.getWidgetById('nm'))
{
jQuery.extend(state, this._super.apply(this, arguments)); // call default implementation
}
// Don't store current user in state to allow admins to create favourites for all // Don't store current user in state to allow admins to create favourites for all
// Should make no difference for normal users. // Should make no difference for normal users.
@ -1319,8 +1329,25 @@ app.classes.calendar = AppJS.extend(
state.state.date = new Date(); state.state.date = new Date();
} }
// Hide other views
for(var _view in this.views)
{
if(state.state.view != _view && this.views[_view])
{
for(var i = 0; i < this.views[_view].etemplates.length; i++)
{
$j(this.views[_view].etemplates[i].DOMContainer).hide();
}
}
}
$j(this.sidebox_et2.getInstanceManager().DOMContainer).hide();
// Check for a supported client-side view // Check for a supported client-side view
if(this.views[state.state.view]) if(this.views[state.state.view] &&
// Check that the view is instanciated
typeof this.views[state.state.view].etemplates[0] !== 'string' && this.views[state.state.view].etemplates[0].widgetContainer
)
{ {
// Doing an update - this includes the selected view, and the sidebox // Doing an update - this includes the selected view, and the sidebox
// We set a flag to ignore changes from the sidebox which would // We set a flag to ignore changes from the sidebox which would
@ -1378,13 +1405,13 @@ app.classes.calendar = AppJS.extend(
{ {
// Need to redo the number of grids // Need to redo the number of grids
var value = []; var value = [];
var date = view.set_start_date(state.state); var date = state.state.first = view.set_start_date(state.state);
// Determine the different end date // Determine the different end date
switch(state.state.view) switch(state.state.view)
{ {
case 'month': case 'month':
var end = view.set_end_date(state.state); var end = state.state.last = view.set_end_date(state.state);
grid_count = Math.ceil((end - date) / (1000 * 60 * 60 * 24) / 7); grid_count = Math.ceil((end - date) / (1000 * 60 * 60 * 24) / 7);
// fall through // fall through
case 'weekN': case 'weekN':
@ -1400,9 +1427,10 @@ app.classes.calendar = AppJS.extend(
value.push(val); value.push(val);
date.setUTCHours(24*7); date.setUTCHours(24*7);
} }
state.state.last=val.end_date;
break; break;
default: default:
var end = view.set_end_date(state.state); var end = state.state.last = view.set_end_date(state.state);
for(var owner = 0; owner < grid_count && owner < state.state.owner.length; owner++) for(var owner = 0; owner < grid_count && owner < state.state.owner.length; owner++)
{ {
value.push({ value.push({
@ -1430,6 +1458,8 @@ app.classes.calendar = AppJS.extend(
if(typeof view[updater] === 'function') if(typeof view[updater] === 'function')
{ {
var value = view[updater].call(this,state.state); var value = view[updater].call(this,state.state);
if(updater === 'set_start_date') state.state.first = value.toJSON();
if(updater === 'set_end_date') state.state.last = value.toJSON();
// Set value // Set value
for(var i = 0; i < view.etemplates.length; i++) for(var i = 0; i < view.etemplates.length; i++)
@ -1444,19 +1474,9 @@ app.classes.calendar = AppJS.extend(
} }
} }
} }
// Include first & last dates in state, mostly for server side processing
if(state.state.first && state.state.first.toJSON) state.state.first = state.state.first.toJSON()
// Hide other views if(state.state.last && state.state.last.toJSON) state.state.last = state.state.last.toJSON()
for(var _view in this.views)
{
if(state.state.view != _view && this.views[_view])
{
for(var i = 0; i < this.views[_view].etemplates.length; i++)
{
$j(this.views[_view].etemplates[i].DOMContainer).hide();
}
}
}
// Show the templates for the current view // Show the templates for the current view
for(var i = 0; i < view.etemplates.length; i++) for(var i = 0; i < view.etemplates.length; i++)
@ -1605,7 +1625,8 @@ app.classes.calendar = AppJS.extend(
} }
} }
// setting internal state now, that linkHandler does not intercept switching from listview to any old view // setting internal state now, that linkHandler does not intercept switching from listview to any old view
this.state = state; this.state = jQuery.extend({},state.state);
$j(this.sidebox_et2.getInstanceManager().DOMContainer).show();
var query = jQuery.extend({menuaction: menuaction},state.state||{}); var query = jQuery.extend({menuaction: menuaction},state.state||{});

View File

@ -31,7 +31,7 @@ Egroupware
<buttononly align="center" class="sideboxstar" id="week" image="week" label="Weekview" onclick="app.calendar.update_state({view:'week'});"/> <buttononly align="center" class="sideboxstar" id="week" image="week" label="Weekview" onclick="app.calendar.update_state({view:'week'});"/>
<buttononly align="center" class="sideboxstar" id="weekN" image="multiweek" label="Multiple week view" onclick="app.calendar.update_state({view:'weekN'});"/> <buttononly align="center" class="sideboxstar" id="weekN" image="multiweek" label="Multiple week view" onclick="app.calendar.update_state({view:'weekN'});"/>
<buttononly align="center" class="sideboxstar" id="month" image="month" label="Multiple week view" onclick="app.calendar.update_state({view:'month'});"/> <buttononly align="center" class="sideboxstar" id="month" image="month" label="Multiple week view" onclick="app.calendar.update_state({view:'month'});"/>
<buttononly align="center" class="sideboxstar" id="planner" image="planner" label="Group planner"/> <buttononly align="center" class="sideboxstar" id="planner" image="planner" label="Group planner" onclick="app.calendar.update_state({view:'planner'});"/>
<buttononly align="center" class="sideboxstar" id="listview" image="list" label="Listview" onclick="app.calendar.update_state({view:'listview'});"/> <buttononly align="center" class="sideboxstar" id="listview" image="list" label="Listview" onclick="app.calendar.update_state({view:'listview'});"/>
</row> </row>
</rows> </rows>
@ -39,6 +39,8 @@ Egroupware
<select id="view" class="et2_fullWidth" onchange="app.calendar.update_state(JSON.parse(widget.getValue()));"/> <select id="view" class="et2_fullWidth" onchange="app.calendar.update_state(JSON.parse(widget.getValue()));"/>
<textbox id="keywords" class="et2_fullWidth" onchange="app.calendar.update_state({keywords: widget.getValue()});"/> <textbox id="keywords" class="et2_fullWidth" onchange="app.calendar.update_state({keywords: widget.getValue()});"/>
<date id="date" class="et2_fullWidth" inline="true" onchange="app.calendar.update_state({date:widget.getValue(),view:'day'});"/> <date id="date" class="et2_fullWidth" inline="true" onchange="app.calendar.update_state({date:widget.getValue(),view:'day'});"/>
<textbox type="hidden" id="first"/>
<textbox type="hidden" id="last"/>
<hbox width="100%"> <hbox width="100%">
<select-cat id="cat_id" empty_label="All categories" width="86%" onchange="app.calendar.update_state({cat_id: widget.getValue()});"/> <select-cat id="cat_id" empty_label="All categories" width="86%" onchange="app.calendar.update_state({cat_id: widget.getValue()});"/>
<button align="right" id="cat_id_multiple" image="category"/> <button align="right" id="cat_id_multiple" image="category"/>
@ -50,8 +52,8 @@ Egroupware
<taglist id="owner" class="et2_fullWidth" onchange="app.calendar.update_state({owner: widget.getValue()});" autocomplete_params=''/> <taglist id="owner" class="et2_fullWidth" onchange="app.calendar.update_state({owner: widget.getValue()});" autocomplete_params=''/>
--> -->
<select id="filter" no_lang="true" class="et2_fullWidth" onchange="app.calendar.update_state({filter: widget.getValue()});"/> <select id="filter" no_lang="true" class="et2_fullWidth" onchange="app.calendar.update_state({filter: widget.getValue()});"/>
<select id="merge" empty_label="Insert in document" onchange="widget.getInstanceManager().postSubmit();widget.set_value('');" class="et2_fullWidth"/>/> <select id="merge" empty_label="Insert in document" onchange="if(widget.getValue()) {widget.getInstanceManager().postSubmit();}window.setTimeout(function() {widget.set_value('');},100);return false;" class="et2_fullWidth"/>/>
</vbox> </vbox>
<html id="old_calendar"/> <iframe id="iframe" width="100%" height="100%"/>
</template> </template>
</overlay> </overlay>