]> err.no Git - scalable-opengroupware.org/blob - UI/MailerUI/UIxFilterList.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1127 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / MailerUI / UIxFilterList.m
1 /*
2   Copyright (C) 2004-2005 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21
22 #import <Foundation/NSCalendarDate.h>
23 #import <NGObjWeb/SoObject.h>
24 #import <SoObjects/Mailer/SOGoMailFolder.h>
25 #import <SoObjects/Mailer/SOGoMailObject.h>
26 #import <SOGoUI/UIxComponent.h>
27
28 /*
29   UIxFilterList
30
31   This component shows a list of filter scripts and is (usually) attached to
32   a SOGoSieveScriptsFolder object.
33 */
34
35 @interface UIxFilterList : UIxComponent
36 {
37   NSArray *filters;
38   id filter;
39 }
40
41 @end
42
43 @implementation UIxFilterList
44
45 - (void)dealloc {
46   [self->filter  release];
47   [self->filters release];
48   [super dealloc];
49 }
50
51 /* notifications */
52
53 - (void)sleep {
54   [self->filter  release]; self->filter  = nil;
55   [self->filters release]; self->filters = nil;
56   [super sleep];
57 }
58
59 /* accessors */
60
61 - (void)setFilter:(id)_msg {
62   ASSIGN(self->filter, _msg);
63 }
64 - (id)filter {
65   return self->filter;
66 }
67
68 - (NSArray *)filters {
69   return self->filters;
70 }
71
72 - (NSString *)panelTitle {
73   return [self labelForKey:@"Mail Filters"];
74 }
75
76 /* JavaScript code */
77
78 - (NSString *)clickedFilterJS {
79   /* return 'false' aborts processing */
80   return [NSString stringWithFormat:
81                      @"clickedFilter(this, '%@'); return false", 
82                      [self filter]];
83 }
84
85 /* creating scripts */
86
87 - (NSString *)newScriptName {
88   NSCalendarDate *now;
89   
90   now = [NSCalendarDate date];
91   return [NSString stringWithFormat:@"MyFilter-%04d%02d%02d-%02d%02d%02d",
92                    [now yearOfCommonEra], [now monthOfYear], 
93                    [now dayOfMonth],
94                    [now hourOfDay], [now minuteOfHour], [now secondOfMinute]];
95 }
96
97 /* actions */
98
99 - (id)defaultAction {
100   [self debugWithFormat:@"fetch scripts in: %@", [self clientObject]];
101   self->filters = [[[self clientObject] toOneRelationshipKeys] copy];
102   return self;
103 }
104
105 - (id)createAction {
106   NSString *newURL;
107   
108   newURL = [[self clientObject] baseURLInContext:[self context]];
109   if (![newURL hasSuffix:@"/"]) newURL = [newURL stringByAppendingString:@"/"];
110   newURL = [newURL stringByAppendingString:[self newScriptName]];
111   newURL = [newURL stringByAppendingString:@"/edit"];
112   
113   return [self redirectToLocation:newURL];
114 }
115
116 @end /* UIxFilterList */