Remove inline-script of flat() in calendar and move it to navigation.js, CSP concern

This commit is contained in:
Hadi Nategh 2014-01-10 17:31:24 +00:00
parent 3fe9c78c26
commit 8d4fc1001f
2 changed files with 73 additions and 5 deletions

View File

@ -732,8 +732,14 @@ class calendar_ui
unset($link_vars['date']); // gets set in jscal
$link[$view] = $l = egw::link('/index.php',$link_vars,false);
}
$jscalendar = $GLOBALS['egw']->jscalendar->flat($link['day'],$this->date,
$link['week'],lang('show this week'),$link['month'],lang('show this month'));
if (($flatdate = $this->date)) // string if format YYYYmmdd or timestamp
{
$flatdate = is_int($flatdate) ? adodb_date('m/d/Y',$flatdate) :
substr($flatdate,4,2).'/'.substr($flatdate,6,2).'/'.substr($flatdate,0,4);
}
$jscalendar = '<div id="calendar-container"></div>';
$file[++$n] = array('text' => $jscalendar,'no_lang' => True,'link' => False,'icon' => False);
// set a baseurl for selectboxes, if we are not running inside calendar (eg. prefs or admin)
@ -802,7 +808,13 @@ class calendar_ui
)+($this->view == 'listview' ? array('ajax' => 'true') : array()),false);
$file[] = array(
'text' => "
<script type=\"text/javascript\" src=\"{$GLOBALS['egw_info']['server']['webserver_url']}/calendar/js/navigation.js\" id=\"calendar-navigation-script\" data-current-view-url=\"".htmlspecialchars($current_view_url)."\"/></script>\n".
<script type=\"text/javascript\" src=\"{$GLOBALS['egw_info']['server']['webserver_url']}/calendar/js/navigation.js\" id=\"calendar-navigation-script\"".
" data-link-day-url =\"".htmlspecialchars($link['day']).
"\" data-link-week-url=\"".htmlspecialchars($link['week']).
"\" data-link-month-url=\"".htmlspecialchars($link['month']).
"\" data-date=\"".htmlspecialchars($flatdate).
"\" data-current-date=\"".htmlspecialchars(egw_time::to('now', 'Ymd')).
"\" data-current-view-url=\"".htmlspecialchars($current_view_url)."\"/></script>\n".
$this->accountsel->selection('owner','uical_select_owner',$accounts,'calendar+',count($accounts) > 1 ? 4 : 1,False,
' style="width: '.(count($accounts) > 1 && in_array($this->common_prefs['account_selection'],array('selectbox','groupmembers')) ? '99%' : '86%').';"'.

View File

@ -11,15 +11,19 @@
/**
* Sidebox navigation for calendar
*
* @todo add code from jscalendar->flat(), or better replace it altogether ...
*/
(function()
{
var script_tag = document.getElementById('calendar-navigation-script');
var current_view_url;
var current_view_url, link_day_url,link_week_url,link_month_url,flatdate, current_date;
if (script_tag)
{
current_view_url = script_tag.getAttribute('data-current-view-url');
link_day_url = script_tag.getAttribute('data-link-day-url');
link_week_url = script_tag.getAttribute('data-link-week-url');
link_month_url = script_tag.getAttribute('data-link-week-url');
flatdate = script_tag.getAttribute('data-date');
current_date = script_tag.getAttribute('data-current-date');
}
function load_cal(url,id,no_reset) {
var owner='';
@ -65,6 +69,47 @@
return false;
}
/*
*
* @param {type} calendar
* @returns {undefined}
*/
function dateChanged(calendar) {
if (calendar.dateClicked) {
egw_link_handler(link_day_url+"&date=" + calendar.date.print("%Y%m%d"),"calendar");
}
}
/*
*
* @param {type} calendar
* @returns {undefined}
*/
function todayClicked(calendar) {
egw_link_handler(link_day_url+"&date="+ current_date ,"calendar");
}
/*
*
* @param {type} calendar
* @param {type} weekstart
* @returns {undefined}
*/
function weekClicked(calendar,weekstart) {
egw_link_handler(link_week_url+"&date=" + weekstart.print("%Y%m%d"),"calendar");
}
/*
*
* @param {type} calendar
* @param {type} monthstart
* @returns {undefined}
*/
function monthClicked(calendar,monthstart) {
egw_link_handler(link_month_url+"&date=" + monthstart.print("%Y%m%d"),"calendar");
}
/**
* Initialisation after DOM *and* jQuery is loaded
*/
@ -104,5 +149,16 @@
}
});
});
Calendar.setup({
flat : "calendar-container",
flatCallback : dateChanged,
flatWeekCallback : (link_week_url)?weekClicked:'',
flatWeekTTip : egw.lang('show this week'),
flatMonthCallback : (link_month_url)?monthClicked:'',
flatMonthTTip : egw.lang('show this month'),
flatTodayCallback : (flatdate)?todayClicked:'',
date : (flatdate)?flatdate:'',
});
});
})();