link-shared calendar timezone display and settings

master
Michał 'rysiek' Woźniak 2014-02-11 00:03:33 +01:00
parent 593422273e
commit e28e513668
5 changed files with 87 additions and 15 deletions

View File

@ -8,19 +8,38 @@
// Init owncloud
$l = OCP\Util::getL10N('calendar');
// Check if we are a user
OCP\JSON::checkLoggedIn();
// Check if the app is enabled
OCP\JSON::checkAppEnabled('calendar');
OCP\JSON::callCheck();
// Get data
if( isset( $_POST['timezone'] ) ) {
$timezone=$_POST['timezone'];
OCP\Config::setUserValue( OCP\USER::getUser(), 'calendar', 'timezone', $timezone );
OCP\JSON::success(array('data' => array( 'message' => $l->t('Timezone changed') )));
}else{
OCP\JSON::error(array('data' => array( 'message' => $l->t('Invalid request') )));
// normal operation?
if (OCP\User::isLoggedIn()) {
// additional check
OCP\JSON::callCheck();
// set the value
OCP\Config::setUserValue( OCP\USER::getUser(), 'calendar', 'timezone', $_POST['timezone'] );
// public link-shared calendar
} elseif (\OC::$session->exists('public_link_token')) {
// save the value in session
\OC::$session->set('public_link_timezone', $_POST['timezone']);
// this isn't right...
} else {
OCP\JSON::error(array('data' => array( 'message' => $l->t('Invalid request') )));
exit;
}
// result
OCP\JSON::success(array('data' => array( 'message' => $l->t('Timezone changed') )));
// no data
} else {
OCP\JSON::error(array('data' => array( 'message' => $l->t('Invalid request') )));
}

View File

@ -165,6 +165,15 @@ button.category{margin:0 3px;}
font-weight: bold;
}
#controls .settings.timezonesettings {
float:right;
}
#controls .settings.timezonesettings > .chzn-container {
position:relative;
top:0.5em;
}
/* input fields take whole width */
#event-title,
#event-location,

View File

@ -328,10 +328,28 @@ class OC_Calendar_App{
* @return (string) $timezone as set by user or the default timezone
*/
public static function getTimezone() {
return OCP\Config::getUserValue(OCP\User::getUser(),
'calendar',
'timezone',
date_default_timezone_get());
// are we in a user session?
if (OCP\User::isLoggedIn()) {
// aye, let's use the normal infrastructure
return OCP\Config::getUserValue(OCP\User::getUser(),
'calendar',
'timezone',
date_default_timezone_get());
// nope! probably link-shared stuff (no need to check that)
} else {
// is the timezone set in session vars?
if (\OC::$session->exists('public_link_timezone')) {
// aye, using that
return \OC::$session->get('public_link_timezone');
// nope!
} else {
// use the default
return date_default_timezone_get();
}
}
}
/**

View File

@ -147,12 +147,14 @@ if (isset($rootLinkItem)) {
OCP\Util::addscript('calendar','jquery.multi-autocomplete');
OCP\Util::addscript('','tags');
OCP\Util::addscript('calendar','on-event');
OCP\Util::addscript('calendar','settings');
OCP\App::setActiveNavigationEntry('calendar_index');
#$tmpl = new OCP\Template('calendar', 'calendar', 'user');
$tmpl = new OCP\Template('calendar', 'calendar', 'base');
$tmpl->assign('link_shared_calendar_name', $linkItem['item_target']);
$tmpl->assign('link_shared_calendar_owner', $linkItem['uid_owner']);
$tmpl->assign('link_shared_calendar_url', $url);
$tmpl->assign('timezone', OC_Calendar_App::$tz);
$tmpl->assign('timezones',DateTimeZone::listIdentifiers());
$tmpl->printPage();
// Display the event
@ -163,6 +165,8 @@ if (isset($rootLinkItem)) {
$tmpl = new OCP\Template('calendar', 'event', 'base');
$tmpl->assign('link_shared_event', $linkItem);
$tmpl->assign('link_shared_event_url', $url);
$tmpl->assign('timezone', OC_Calendar_App::$tz);
$tmpl->assign('timezones',DateTimeZone::listIdentifiers());
$tmpl->printPage();
}
exit();

View File

@ -31,7 +31,29 @@
if (!array_key_exists('link_shared_calendar_name', $_)) { ?><form id="choosecalendar">
<!--<input type="button" id="today_input" value="<?php p($l->t("Today"));?>"/>-->
<button class="settings generalsettings" title="<?php p($l->t('Settings')); ?>"><img class="svg" src="<?php print_unescaped(OCP\Util::imagePath('core', 'actions/settings.svg')); ?>" alt="<?php p($l->t('Settings')); ?>" /></button>
</form><?php } ?>
</form><?php } else {?>
<div class="settings timezonesettings">
<label for="timezone" title="<?php p($l->t('Timezone settings')); ?>"><?php p($l->t('Timezone'))?></label>
<select id="timezone" name="timezone">
<?php
$continent = '';
foreach($_['timezones'] as $timezone):
$ex=explode('/', $timezone, 2);//obtain continent,city
if (!isset($ex[1])) {
$ex[1] = $ex[0];
$ex[0] = "Other";
}
if ($continent!=$ex[0]):
if ($continent!="") print_unescaped('</optgroup>');
print_unescaped('<optgroup label="'.OC_Util::sanitizeHTML($ex[0]).'">');
endif;
$city=strtr($ex[1], '_', ' ');
$continent=$ex[0];
print_unescaped('<option value="'.OC_Util::sanitizeHTML($timezone).'"'.($_['timezone'] == $timezone?' selected="selected"':'').'>'.OC_Util::sanitizeHTML($city).'</option>');
endforeach;?>
</select>
</div>
<?php } ?>
<form id="datecontrol">
<input type="button" value="&nbsp;&lt;&nbsp;" id="datecontrol_left"/>
<input type="button" value="" id="datecontrol_date"/>