Skip to content

Commit

Permalink
[jan] Use colors of remote CalDAV calendars (Request #14612).
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed May 4, 2017
1 parent b34c41e commit ade113d
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 33 deletions.
1 change: 1 addition & 0 deletions kronolith/docs/CHANGES
Expand Up @@ -2,6 +2,7 @@
v5.0.0-git
----------

[jan] Use colors of remote CalDAV calendars (Request #14612).
[jan] Add headers to print views.
[mjr] Add support for tracking the ORGANIZER of an event independently of the
horde user (Bug #3965, PR: 127, Ralf Lang <lang@b1-systems.de>).
Expand Down
40 changes: 34 additions & 6 deletions kronolith/js/kronolith.js
Expand Up @@ -3174,6 +3174,7 @@ KronolithCore = {
// Fall through.
case 'tasklists':
$('kronolithCalendar' + type + 'LinkExport').up('li').hide();
this.setColor(type);
break;
case 'remote':
if (calendar) {
Expand All @@ -3192,22 +3193,18 @@ KronolithCore = {
.insert(calendar.value.name.escapeHTML())
);
});
this.setColor(type);
break;
}
$('kronolithCalendar' + type + 'Id').clear();
var color = '#', i;
for (i = 0; i < 3; i++) {
color += (Math.random() * 256 | 0).toColorPart();
}
$('kronolithCalendar' + type + 'Color').setValue(color).setStyle({ backgroundColor: color, color: Color.brightness(Color.hex2rgb(color)) < 125 ? '#fff' : '#000' });
form.down('.kronolithCalendarDelete').hide();
$('kronolithCalendarinternalImportButton').hide();
} else {
info = Kronolith.conf.calendars[type][calendar];

$('kronolithCalendar' + type + 'Id').setValue(calendar);
$('kronolithCalendar' + type + 'Name').setValue(info.name);
$('kronolithCalendar' + type + 'Color').setValue(info.bg).setStyle({ backgroundColor: info.bg, color: info.fg });
this.setColor(type, info.bg);
$('kronolithCalendarinternalImportButton').hide();

switch (type) {
Expand Down Expand Up @@ -3356,6 +3353,30 @@ KronolithCore = {
}
},

/**
* Updates the color field in a calendar dialog.
*
* @param string type The calendar type.
* @param string color The hex color string. If empty a random color is
* generated.
*/
setColor: function(type, color)
{
var i;
if (!color) {
color = '#';
for (i = 0; i < 3; i++) {
color += (Math.random() * 256 | 0).toColorPart();
}
}
$('kronolithCalendar' + type + 'Color')
.setValue(color)
.setStyle({
backgroundColor: color,
color: Color.brightness(Color.hex2rgb(color)) < 125 ? '#fff' : '#000'
});
},

/**
* Updates the select list in the resourcegroup calendar dialog.
*/
Expand Down Expand Up @@ -5206,6 +5227,9 @@ KronolithCore = {
if (r.desc) {
$('kronolithCalendarremoteDescription').setValue(r.desc);
}
if (r.color) {
this.setColor('remote', r.color);
}
this.calendarNext(type);
this.calendarNext(type);
} else if (r.auth) {
Expand Down Expand Up @@ -5234,6 +5258,10 @@ KronolithCore = {
!$F('kronolithCalendarremoteDescription')) {
$('kronolithCalendarremoteDescription').setValue(r.desc);
}
if (r.color &&
!$F('kronolithCalendarremoteColor')) {
this.setColor('remote', r.color);
}
this.calendarNext(type);
} else {
if (r.auth) {
Expand Down
31 changes: 12 additions & 19 deletions kronolith/lib/Ajax/Application/Handler.php
Expand Up @@ -1332,39 +1332,32 @@ public function getCalendar()
*/
public function getRemoteInfo()
{
global $conf, $injector, $notification;

$params = array('timeout' => 15);
if ($user = $this->vars->user) {
$params['user'] = $user;
$params['password'] = $this->vars->password;
}
if (!empty($GLOBALS['conf']['http']['proxy']['proxy_host'])) {
$params['proxy'] = $GLOBALS['conf']['http']['proxy'];
if (!empty($conf['http']['proxy']['proxy_host'])) {
$params['proxy'] = $conf['http']['proxy'];
}

$result = new stdClass;
try {
$driver = $GLOBALS['injector']->getInstance('Kronolith_Factory_Driver')->create('Ical', $params);
$driver = $injector->getInstance('Kronolith_Factory_Driver')
->create('Ical', $params);
$driver->open($this->vars->url);
if ($driver->isCalDAV()) {
$result->success = true;
// TODO: find out how to retrieve calendar information via CalDAV.
} else {
$ical = $driver->getRemoteCalendar(false);
$result->success = true;
try {
$name = $ical->getAttribute('X-WR-CALNAME');
$result->name = $name;
} catch (Horde_Icalendar_Exception $e) {}
try {
$desc = $ical->getAttribute('X-WR-CALDESC');
$result->desc = $desc;
} catch (Horde_Icalendar_Exception $e) {}
}
$info = $driver->getCalendarInfo();
$result->success = true;
$result->name = $info['name'];
$result->desc = $info['desc'];
$result->color = $info['color'];
} catch (Exception $e) {
if ($e->getCode() == 401) {
$result->auth = true;
} else {
$GLOBALS['notification']->push($e, 'horde.error');
$notification->push($e, 'horde.error');
}
}

Expand Down
47 changes: 46 additions & 1 deletion kronolith/lib/Driver/Ical.php
Expand Up @@ -10,7 +10,8 @@
* @package Kronolith
*/

use \Sabre\DAV\Client;
use Sabre\DAV\Client;
use Sabre\CalDAV;

/**
* The Kronolith_Driver_Ical class implements the Kronolith_Driver API for
Expand Down Expand Up @@ -787,6 +788,50 @@ public function isCalDAV()
return true;
}

/**
* Returns calendar information.
*
* @return array A hash with the keys 'name', 'desc', and 'color'.
*/
public function getCalendarInfo()
{
$result = array('name' => '', 'desc' => '', 'color' => '');
if ($this->isCalDAV()) {
$client = $this->_getClient($this->_getUrl());
try {
$properties = $client->propfind(
'',
array(
'{DAV:}displayname',
'{' . CalDAV\Plugin::NS_CALDAV . '}calendar-description',
'{http://apple.com/ns/ical/}calendar-color'
)
);
$result['name'] = $properties['{DAV:}displayname'];
$result['desc'] = $properties['{' . CalDAV\Plugin::NS_CALDAV . '}calendar-description'];
$result['color'] = substr(
$properties['{http://apple.com/ns/ical/}calendar-color'],
0,
7
);
} catch (Exception $e) {
}
} else {
$ical = $this->getRemoteCalendar(false);
try {
$name = $ical->getAttribute('X-WR-CALNAME');
$result['name'] = $name;
} catch (Horde_Icalendar_Exception $e) {
}
try {
$desc = $ical->getAttribute('X-WR-CALDESC');
$result['desc'] = $desc;
} catch (Horde_Icalendar_Exception $e) {
}
}
return $result;
}

/**
* Returns the permissions for the current calendar.
*
Expand Down
2 changes: 2 additions & 0 deletions kronolith/package.xml
Expand Up @@ -33,6 +33,7 @@
</stability>
<license uri="http://www.horde.org/licenses/gpl">GPL-2.0</license>
<notes>
* [jan] Use colors of remote CalDAV calendars (Request #14612).
* [jan] Add headers to print views.
* [mjr] Add support for tracking the ORGANIZER of an event independently of the horde user (Bug #3965, PR: 127, Ralf Lang &lt;lang@b1-systems.de&gt;).
* [jan] Use preferred start and end of day for color shades in dynamic view.
Expand Down Expand Up @@ -2833,6 +2834,7 @@
<date>2016-11-09</date>
<license uri="http://www.horde.org/licenses/gpl">GPL-2.0</license>
<notes>
* [jan] Use colors of remote CalDAV calendars (Request #14612).
* [jan] Add headers to print views.
* [mjr] Add support for tracking the ORGANIZER of an event independently of the horde user (Bug #3965, PR: 127, Ralf Lang &lt;lang@b1-systems.de&gt;).
* [jan] Use preferred start and end of day for color shades in dynamic view.
Expand Down
14 changes: 7 additions & 7 deletions kronolith/templates/chunks/calendar.php
Expand Up @@ -270,13 +270,6 @@
</label></p>
</div>

<div>
<p><label><?php echo _("Color") ?>:<br />
<input type="text" name="color" id="kronolithCalendarremoteColor" size="7" />
<?php echo Horde::url('#')->link(array('title' => _("Color Picker"), 'class' => 'kronolithColorPicker')) . Horde::img('colorpicker.png', _("Color Picker")) . '</a>' ?>
</label></p>
</div>

<div class="kronolithFormActions">
<input type="button" value="<?php echo _("Continue") ?>" class="kronolithCalendarContinue horde-default" />
<input type="button" value="<?php echo _("Delete") ?>" class="kronolithCalendarDelete horde-delete" />
Expand Down Expand Up @@ -318,6 +311,13 @@
</label></p>
</div>

<div>
<p><label><?php echo _("Color") ?>:<br />
<input type="text" name="color" id="kronolithCalendarremoteColor" size="7" />
<?php echo Horde::url('#')->link(array('title' => _("Color Picker"), 'class' => 'kronolithColorPicker')) . Horde::img('colorpicker.png', _("Color Picker")) . '</a>' ?>
</label></p>
</div>

<div class="kronolithFormActions">
<input type="button" value="<?php echo _("Save") ?>" class="kronolithCalendarSave horde-default" />
<input type="button" value="<?php echo _("Delete") ?>" class="kronolithCalendarDelete horde-delete" />
Expand Down

0 comments on commit ade113d

Please sign in to comment.