Skip to content

Commit

Permalink
Add Nag_Task::backgroundColor() and foregroundColor().
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed Oct 2, 2014
1 parent 75f3704 commit 8959735
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
36 changes: 27 additions & 9 deletions nag/lib/Task.php
Expand Up @@ -789,23 +789,41 @@ public function process($indent = null)
}

/**
* Returns the HTML code for any tree icons, when displaying this task in
* a tree view.
* Returns the background color.
*
* @return string The HTML code for necessary tree icons.
* @return string A HTML color code.
*/
public function treeIcons()
public function backgroundColor()
{
$foreground = '';
try {
$share = $GLOBALS['nag_shares']->getShare($this->tasklist);
$background = $share->get('color') ?: '#ddd';
if (Horde_Image::brightness($background) < 128) {
$foreground = '-fff';
}
return $share->get('color') ?: '#ddd';
} catch (Horde_Exception_NotFound $e) {
}
return '#ddd';
}

/**
* Returns the foreground color.
*
* @return string A HTML color code.
*/
public function foregroundColor($calendar)
{
return Horde_Image::brightness($this->backgroundColor()) < 128
? '#fff'
: '#000';
}

/**
* Returns the HTML code for any tree icons, when displaying this task in
* a tree view.
*
* @return string The HTML code for necessary tree icons.
*/
public function treeIcons()
{
$foreground = $this->foregroundColor() == '#fff' ? '-fff' : '';
$html = '';

$parent = $this->parent;
Expand Down
7 changes: 0 additions & 7 deletions nag/templates/list.html.php
Expand Up @@ -54,15 +54,8 @@ function doPrefsUpdate(column, sortDown)
$owner = $task->tasklist;
}
}
$background = $share->get('color') ?: '#ddd';
$foreground = '000';
if (Horde_Image::brightness($background) < 128) {
$foreground = 'fff';
}
$locals = array(
'style' => $style,
'background' => $background,
'foreground' => $foreground,
'have_read' => $share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ),
'have_edit' => $share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT),
'owner' => $owner,
Expand Down
6 changes: 3 additions & 3 deletions nag/templates/list/_task.html.php
@@ -1,4 +1,4 @@
<tr class="<?php echo $style ?>" style="background-color:<?php echo $background ?>; color: #<?php echo $foreground ?>">
<tr class="<?php echo $style ?>" style="background-color:<?php echo $task->backgroundColor() ?>;color:<?php echo $task->foregroundColor() ?>">
<td>
<?php
if ($have_edit) {
Expand Down Expand Up @@ -39,7 +39,7 @@
if ($this->smartShare) {
$params['list'] = $this->smartShare->getName();
}
echo Horde::link($task->edit_link->add($params), $label) . Horde::img('edit-sidebar-' . $foreground . '.png', $label) . '</a>';
echo Horde::link($task->edit_link->add($params), $label) . Horde::img('edit-sidebar-' . substr($task->foregroundColor(), 1) . '.png', $label) . '</a>';
}
?>
</td>
Expand All @@ -54,7 +54,7 @@
if ($this->smartShare) {
$params['list'] = $this->smartShare->getName();
}
echo Horde::linkTooltip($task->view_link->add($params), '', '', '', '', $task->desc, '', array('style' => 'color:#' . $foreground))
echo Horde::linkTooltip($task->view_link->add($params), '', '', '', '', $task->desc, '', array('style' => 'color:' . $task->foregroundColor()))
. $task_name . '</a>';
} else {
echo $task_name;
Expand Down

0 comments on commit 8959735

Please sign in to comment.