]> err.no Git - scalable-opengroupware.org/blob - UI/Scheduler/UIxCalTasksListView.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1039 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / Scheduler / UIxCalTasksListView.m
1 /* UIxCalTasksListView.m - this file is part of SOGo
2  *
3  * Copyright (C) 2006 Inverse groupe conseil
4  *
5  * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
6  *
7  * This file is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This file is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #import <Foundation/NSDate.h>
24 #import <Foundation/NSDictionary.h>
25 #import <Foundation/NSString.h>
26 #import <Foundation/NSValue.h>
27
28 #import <NGExtensions/NSCalendarDate+misc.h>
29 #import <Appointments/SOGoAppointmentFolder.h>
30 #import <SOGoUI/SOGoDateFormatter.h>
31
32 #import "UIxCalTasksListView.h"
33
34 @implementation UIxCalTasksListView
35
36 - (id) init
37 {
38   if ((self = [super init]))
39     {
40       startDate = nil;
41       endDate = nil;
42       knowsToHide = NO;
43       hideCompleted = NO;
44     }
45
46   return self;
47 }
48
49 - (void) setCurrentTask: (NSDictionary *) task
50 {
51   currentTask = task;
52 }
53
54 - (NSDictionary *) currentTask
55 {
56   return currentTask;
57 }
58
59 - (NSCalendarDate *) startDate
60 {
61   return nil;
62 }
63
64 - (NSCalendarDate *) endDate
65 {
66   return nil;
67 }
68
69 - (NSString *) currentStatusClass
70 {
71   NSCalendarDate *taskDate, *now;
72   NSString *statusClass, *allClasses;
73   NSNumber *taskDueStamp;
74
75   if ([[currentTask objectForKey: @"status"] intValue] == 1)
76     statusClass = @"completed";
77   else
78     {
79       taskDueStamp = [currentTask objectForKey: @"enddate"];
80       if ([taskDueStamp intValue])
81         {
82           now = [NSCalendarDate calendarDate];
83           taskDate = [NSCalendarDate dateWithTimeIntervalSince1970:
84                                        [taskDueStamp intValue]];
85           if ([taskDate earlierDate: now] == taskDate)
86             statusClass = @"overdue";
87           else
88             {
89               if ([taskDate isToday])
90                 statusClass = @"duetoday";
91               else
92                 statusClass = @"duelater";
93             }
94         }
95       else
96         statusClass = @"duelater";
97     }
98
99   allClasses = [NSString stringWithFormat: @"%@ ownerIs%@",
100                          statusClass,
101                          [currentTask objectForKey: @"owner"]];
102
103   return allClasses;
104 }
105
106 - (BOOL) shouldDisplayCurrentTask
107 {
108   if (!knowsToHide)
109     {
110       hideCompleted
111         = [[self queryParameterForKey: @"hide-completed"] intValue];
112       knowsToHide = YES;
113     }
114
115   return !(hideCompleted
116            && [[currentTask objectForKey: @"status"] intValue] == 1);
117 }
118
119 - (BOOL) shouldHideCompletedTasks
120 {
121   if (!knowsToHide)
122     {
123       hideCompleted
124         = [[self queryParameterForKey: @"hide-completed"] intValue];
125       knowsToHide = YES;
126     }
127
128   return hideCompleted;
129 }
130
131 - (BOOL) isCurrentTaskCompleted
132 {
133   return ([[currentTask objectForKey: @"status"] intValue] == 1);
134 }
135
136 @end