]> err.no Git - scalable-opengroupware.org/commitdiff
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1079 d1b88da0-ebda-0310...
authorwolfgang <wolfgang@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Thu, 7 Jun 2007 18:51:04 +0000 (18:51 +0000)
committerwolfgang <wolfgang@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Thu, 7 Jun 2007 18:51:04 +0000 (18:51 +0000)
UI/Scheduler/UIxCalTasksListView.h
UI/Scheduler/UIxCalTasksListView.m

index 5cdc7f84d8b87cefa7386c778b19f535d86664ff..8cefb7cae26dc09a11a7187d334c4f24f5797655 100644 (file)
 #ifndef UIXCALTASKSLISTVIEW_H
 #define UIXCALTASKSLISTVIEW_H
 
-#import "UIxCalView.h"
 
-@class NSDictionary;
+#import <NGObjWeb/WODirectAction.h>
 
-@interface UIxCalTasksListView : UIxCalView
-{
-  NSCalendarDate *startDate;
-  NSCalendarDate *endDate;
+@class WOResponse;
 
-  BOOL knowsToShow;
-  BOOL showCompleted;
+@interface UIxCalTasksListView : WODirectAction
 
-  NSDictionary *currentTask;
-}
-
-- (void) setCurrentTask: (NSDictionary *) task;
-- (NSDictionary *) currentTask;
+- (WOResponse *) tasksListAction;
 
 @end
 
index 349cee29c14b1e4bdf1e76080da3309d494e5ce8..ab01e05670e07716348c562e319a3d9c081f4989 100644 (file)
   return self;
 }
 
-- (void) setCurrentTask: (NSDictionary *) task
+- (void) _updatePrivacyInObjects: (NSArray *) objectInfos
+                     fromFolder: (SOGoAppointmentFolder *) folder
 {
-  currentTask = task;
+  int hideDetails[] = {-1, -1, -1};
+  NSMutableDictionary *currentRecord;
+  int privacyFlag;
+  NSString *roleString, *userLogin;
+  NSEnumerator *infos;
+
+  userLogin = [[context activeUser] login];
+  infos = [objectInfos objectEnumerator];
+  currentRecord = [infos nextObject];
+  while (currentRecord)
+    {
+      privacyFlag = [[currentRecord objectForKey: @"classification"] intValue];
+      if (hideDetails[privacyFlag] == -1)
+       {
+         roleString = [folder roleForComponentsWithAccessClass: privacyFlag
+                              forUser: userLogin];
+         hideDetails[privacyFlag] = ([roleString isEqualToString: @"ComponentDAndTViewer"]
+                                     ? 1 : 0);
+       }
+      if (hideDetails[privacyFlag])
+       {
+         [currentRecord setObject: [self labelForKey: @"(Private Event)"]
+                        forKey: @"title"];
+         [currentRecord setObject: @"" forKey: @"location"];
+       }
+      currentRecord = [infos nextObject];
+    }
 }
 
-- (NSDictionary *) currentTask
+- (NSArray *) _fetchCoreInfosForComponent: (NSString *) component
 {
-  return currentTask;
-}
+  NSArray *currentInfos;
+  NSMutableArray *infos;
+  NSEnumerator *folders;
+  SOGoAppointmentFolder *currentFolder;
 
-- (NSCalendarDate *) startDate
-{
-  return nil;
+  infos = [componentsData objectForKey: component];
+  if (!infos)
+    {
+      infos = [NSMutableArray array];
+      folders = [[self _activeCalendarFolders] objectEnumerator];
+      currentFolder = [folders nextObject];
+      while (currentFolder)
+        {
+          currentInfos = [currentFolder fetchCoreInfosFrom: [[self startDate] beginOfDay]
+                                        to: [[self endDate] endOfDay]
+                                        component: component];
+          [currentInfos makeObjectsPerform: @selector (setObject:forKey:)
+                        withObject: [currentFolder ownerInContext: nil]
+                        withObject: @"owner"];
+         [self _updatePrivacyInObjects: currentInfos
+               fromFolder: currentFolder];
+          [infos addObjectsFromArray: currentInfos];
+          currentFolder = [folders nextObject];
+        }
+      [componentsData setObject: infos forKey: component];
+    }
+
+  return infos;
 }
 
-- (NSCalendarDate *) endDate
+- (NSArray *) fetchCoreAppointmentsInfos
 {
-  return nil;
+  if (!appointments)
+    [self setAppointments: [self _fetchCoreInfosForComponent: @"vevent"]];
+  
+  return appointments;
 }
 
-- (NSString *) currentStatusClass
+- (WOResponse *) tasksListAction
 {
-  NSCalendarDate *taskDate, *now;
-  NSString *statusClass, *allClasses;
-  NSNumber *taskDueStamp;
-
-  if ([[currentTask objectForKey: @"status"] intValue] == 1)
-    statusClass = @"completed";
-  else
-    {
-      taskDueStamp = [currentTask objectForKey: @"enddate"];
-      if ([taskDueStamp intValue])
-        {
-          now = [NSCalendarDate calendarDate];
-          taskDate = [NSCalendarDate dateWithTimeIntervalSince1970:
-                                       [taskDueStamp intValue]];
-          if ([taskDate earlierDate: now] == taskDate)
-            statusClass = @"overdue";
-          else
-            {
-              if ([taskDate isToday])
-                statusClass = @"duetoday";
-              else
-                statusClass = @"duelater";
-            }
-        }
-      else
-        statusClass = @"duelater";
+  WOResponse *response;
+  NSDictionary *tasks;
+  NSMutableArray *filteredTasks;
+  BOOL showCompleted;
+  unsigned i, count;
+
+  response = [context response];
+  filteredTasks = [NSMutableArray new];
+  [filteredTasks autorelease];
+  tasks = [self _fetchCoreInfosForComponent: @"vtodo"];
+  showCompleted = [[self queryParameterForKey: @"show-completed"] intValue];
+  
+  count = [tasks count];
+  for (i = 0; i < count; i++) {
+    NSDictionary *task;
+    NSArray *filteredTask;
+
+    task = [tasks objectAtIndex: i];
+    
+    if ([[task objectForKey: @"status"] intValue] != 1 
+       || showCompleted)
+      {
+       filteredTask = [NSArray arrayWithObjects:
+                                 [task objectForKey: @"c_name"],
+                               [task objectForKey: @"owner"],
+                               [task objectForKey: @"status"],
+                               [task objectForKey: @"title"],
+                               [self getStatusClassForTask: task],
+                               nil];
+      [filteredTasks addObject: filteredTask];
     }
+  }
+  
+  [response setStatus: 200];
+  [response appendContentString: [filteredTasks jsonRepresentation]];
 
-  allClasses = [NSString stringWithFormat: @"%@ ownerIs%@",
-                         statusClass,
-                         [currentTask objectForKey: @"owner"]];
-
-  return allClasses;
+  return response;
 }
 
 - (BOOL) shouldDisplayCurrentTask
   return showCompleted;
 }
 
-- (BOOL) isCurrentTaskCompleted
-{
-  return ([[currentTask objectForKey: @"status"] intValue] == 1);
-}
-
 @end