From 76dd70cd9a6308e670b8ce183a25b0fcadfd1621 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Tue, 3 Feb 2009 19:55:26 +0100 Subject: [PATCH] Set colors per calendar (Request #7480). --- kronolith/calendars/edit.php | 1 + kronolith/docs/CHANGES | 1 + kronolith/lib/Driver.php | 49 ++++++++++++++++++++++++++++++---- kronolith/lib/Forms/CreateCalendar.php | 2 ++ kronolith/lib/Forms/EditCalendar.php | 2 ++ kronolith/lib/Kronolith.php | 20 ++++++++++++++ kronolith/lib/Views/Day.php | 6 +++-- kronolith/lib/Views/Month.php | 2 +- kronolith/lib/Views/Week.php | 6 +++-- kronolith/templates/panel.inc | 6 ++--- 10 files changed, 82 insertions(+), 13 deletions(-) diff --git a/kronolith/calendars/edit.php b/kronolith/calendars/edit.php index dadbdcaf8..ab8e31ec3 100644 --- a/kronolith/calendars/edit.php +++ b/kronolith/calendars/edit.php @@ -52,6 +52,7 @@ if ($form->validate($vars)) { } $vars->set('name', $calendar->get('name')); +$vars->set('color', $calendar->get('color')); $vars->set('description', $calendar->get('desc')); $tags = new Kronolith_Tagger(); $vars->set('tags', implode(',', array_values($tags->getTags($calendar->getName(), 'calendar')))); diff --git a/kronolith/docs/CHANGES b/kronolith/docs/CHANGES index b64c0a612..280b22514 100644 --- a/kronolith/docs/CHANGES +++ b/kronolith/docs/CHANGES @@ -2,6 +2,7 @@ v3.0-git -------- +[jan] Set colors per calendar (Request #7480). [jan] Add individual notification methods for single events (Alfonso Marín Marín ). [jan] Add Ajax interface. diff --git a/kronolith/lib/Driver.php b/kronolith/lib/Driver.php index 13e9bb2d8..1634b770b 100644 --- a/kronolith/lib/Driver.php +++ b/kronolith/lib/Driver.php @@ -442,6 +442,20 @@ class Kronolith_Event { var $_calendar; /** + * The HTML background color to be used for this event. + * + * @var string + */ + var $_backgroundColor; + + /** + * The HTML foreground color to be used for this event. + * + * @var string + */ + var $_foregroundColor; + + /** * The VarRenderer class to use for printing select elements. * * @var Horde_UI_VarRenderer @@ -474,6 +488,15 @@ class Kronolith_Event { $this->alarm = $alarm; $this->_calendar = $driver->getCalendar(); + if (!empty($this->_calendar)) { + $share = $GLOBALS['all_calendars'][$this->_calendar]; + $this->_backgroundColor = $share->get('color'); + if (empty($this->_backgroundColor)) { + $this->_backgroundColor = '#dddddd'; + } + $this->_foregroundColor = Horde_Image::brightness($this->_backgroundColor) < 128 ? '#f6f6f6' : '#000'; + } + if ($eventObject !== null) { $this->fromDriver($eventObject); } @@ -2301,7 +2324,9 @@ class Kronolith_Event { $link = Horde::linkTooltip($this->getViewUrl(array('datetime' => $datetime->strftime('%Y%m%d%H%M%S'), 'url' => $from_url), $full), $event_title, $this->getStatusClass(), '', '', - $this->getTooltip()); + $this->getTooltip(), + '', + array('style' => $this->getCSSColors(false))); } $link .= @htmlspecialchars($event_title, ENT_QUOTES, NLS::getCharset()); @@ -2313,10 +2338,7 @@ class Kronolith_Event { } if ($icons && $prefs->getValue('show_icons')) { - $icon_color = isset($GLOBALS['cManager_fgColors'][$this->category]) ? - ($GLOBALS['cManager_fgColors'][$this->category] == '#000' ? '000' : 'fff') : - ($GLOBALS['cManager_fgColors']['_default_'] == '#000' ? '000' : 'fff'); - + $icon_color = $this->_foregroundColor == '#000' ? '000' : 'fff'; $status = ''; if ($this->alarm) { if ($this->alarm % 10080 == 0) { @@ -2407,6 +2429,23 @@ class Kronolith_Event { } /** + * Returns the CSS color definition for this event. + * + * @param boolean $with_attribute Whether to wrap the colors inside a + * "style" attribute. + * + * @return string A CSS string with color definitions. + */ + function getCSSColors($with_attribute = true) + { + $css = 'background-color:' . $this->_backgroundColor . ';color:' . $this->_foregroundColor; + if ($with_attribute) { + $css = ' style="' . $css . '"'; + } + return $css; + } + + /** * @return string A tooltip for quick descriptions of this event. */ function getTooltip() diff --git a/kronolith/lib/Forms/CreateCalendar.php b/kronolith/lib/Forms/CreateCalendar.php index 685da9699..7ebe8c9df 100755 --- a/kronolith/lib/Forms/CreateCalendar.php +++ b/kronolith/lib/Forms/CreateCalendar.php @@ -31,6 +31,7 @@ class Kronolith_CreateCalendarForm extends Horde_Form { parent::Horde_Form($vars, _("Create Calendar")); $this->addVariable(_("Name"), 'name', 'text', true); + $this->addVariable(_("Color"), 'color', 'colorpicker', false); $this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60)); $this->addVariable(_("Tags"), 'tags', 'text', false); $this->setButtons(array(_("Create"))); @@ -44,6 +45,7 @@ class Kronolith_CreateCalendarForm extends Horde_Form { return $calendar; } $calendar->set('name', $this->_vars->get('name')); + $calendar->set('color', $this->_vars->get('color')); $calendar->set('desc', $this->_vars->get('description')); $tagger = new Kronolith_Tagger(); $tagger->tag($calendar->getName(), $this->_vars->get('tags'), 'calendar'); diff --git a/kronolith/lib/Forms/EditCalendar.php b/kronolith/lib/Forms/EditCalendar.php index 079db82f3..6dbdc0b8d 100644 --- a/kronolith/lib/Forms/EditCalendar.php +++ b/kronolith/lib/Forms/EditCalendar.php @@ -38,6 +38,7 @@ class Kronolith_EditCalendarForm extends Horde_Form { $this->addHidden('', 'c', 'text', true); $this->addVariable(_("Name"), 'name', 'text', true); + $this->addVariable(_("Color"), 'color', 'colorpicker', false); $this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60)); $this->addVariable(_("Tags"), 'tags', 'text', false); $this->setButtons(array(_("Save"))); @@ -48,6 +49,7 @@ class Kronolith_EditCalendarForm extends Horde_Form { $original_name = $this->_calendar->get('name'); $new_name = $this->_vars->get('name'); $this->_calendar->set('name', $new_name); + $this->_calendar->set('color', $this->_vars->get('color')); $this->_calendar->set('desc', $this->_vars->get('description')); if ($original_name != $new_name) { $result = $GLOBALS['kronolith_driver']->rename($original_name, $new_name); diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index ba37c6589..219c7d14f 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -2385,6 +2385,26 @@ class Kronolith { } /** + * Returns the CSS color definition for a calendar. + * + * @param array|Horde_Share_Object $calendar A calendar share or a hash + * from a remote calender + * definition. + * @param boolean $with_attribute Whether to wrap the colors + * inside a "style" attribute. + * + * @return string A CSS string with color definitions. + */ + function getCSSColors($calendar, $with_attribute = true) + { + $css = 'background-color:' . Kronolith::backgroundColor($calendar) . ';color:' . Kronolith::foregroundColor($calendar); + if ($with_attribute) { + $css = ' style="' . $css . '"'; + } + return $css; + } + + /** * Builds Kronolith's list of menu items. */ function getMenu($returnType = 'object') diff --git a/kronolith/lib/Views/Day.php b/kronolith/lib/Views/Day.php index 8c0c9a5ce..33e013e47 100644 --- a/kronolith/lib/Views/Day.php +++ b/kronolith/lib/Views/Day.php @@ -131,7 +131,8 @@ class Kronolith_View_Day extends Kronolith_Day { $eventCategories[$event->getCategory()] = true; } - $row .= 'getCSSColors() . 'width="' . round(90 / count($this->_currentCalendars)) . '%" ' . 'valign="top" colspan="' . $this->_span[$cid] . '">' . $event->getLink($this, true, $this->link(0, true)); @@ -246,7 +247,8 @@ class Kronolith_View_Day extends Kronolith_Day { } } - $row .= 'getCSSColors() . 'width="' . round((90 / count($this->_currentCalendars)) * ($span / $this->_span[$cid])) . '%" ' . 'valign="top" colspan="' . $span . '" rowspan="' . $event->rowspan . '">' . $event->getLink($this, true, $this->link(0, true)); diff --git a/kronolith/lib/Views/Month.php b/kronolith/lib/Views/Month.php index f53dec974..4af00e576 100644 --- a/kronolith/lib/Views/Month.php +++ b/kronolith/lib/Views/Month.php @@ -206,7 +206,7 @@ class Kronolith_View_Month { if ($event->hasPermission(PERMS_READ)) { $eventCategories[$event->getCategory()] = true; } - $html .= '
' + $html .= '
getCSSColors() . '>' . $event->getLink($date, true, $this->link(0, true)); if ($showTime) { $html .= '
' . htmlspecialchars($event->getTimeRange()) . '
'; diff --git a/kronolith/lib/Views/Week.php b/kronolith/lib/Views/Week.php index d9ac5033f..e0f369838 100644 --- a/kronolith/lib/Views/Week.php +++ b/kronolith/lib/Views/Week.php @@ -145,7 +145,8 @@ class Kronolith_View_Week { $eventCategories[$event->getCategory()] = true; } - $row .= 'getCSSColors() . 'width="' . round(99 / count($this->days[$j]->_currentCalendars)) . '%" ' . 'valign="top">' . $event->getLink($this->days[$j], true, $this->link(0, true)); @@ -272,7 +273,8 @@ class Kronolith_View_Week { } } - $row .= 'getCSSColors() . 'valign="top" ' . 'width="' . floor(((90 / count($this->days)) / count($this->_currentCalendars)) * ($span / $this->days[$j]->_span[$cid])) . '%" ' . 'colspan="' . $span . '" rowspan="' . $event->rowspan . '">' diff --git a/kronolith/templates/panel.inc b/kronolith/templates/panel.inc index a936eba6a..88267ccb6 100644 --- a/kronolith/templates/panel.inc +++ b/kronolith/templates/panel.inc @@ -51,7 +51,7 @@ $tagger = new Kronolith_Tagger();

    $cal): ?> -
  • + >
    getTags($id, 'calendar'); ?> ">+ @@ -91,7 +91,7 @@ $tagger = new Kronolith_Tagger();

      $cal): ?> -
    • + >
    @@ -114,7 +114,7 @@ $tagger = new Kronolith_Tagger();

      $cal): ?> -
    • + >
    -- 2.11.0