-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAddEventViewController.m
795 lines (535 loc) · 22.7 KB
/
AddEventViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
/*
Copyright (c) 2010 Rafael Chacon
g-Cal is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
g-Cal is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with g-Cal. If not, see <http://www.gnu.org/licenses/>.
*/
#import "AddEventViewController.h"
#import "SelectCalendarForEventViewController.h"
#import "Event.h"
#import "Calendar.h"
#import "GoogleCalAppDelegate.h"
#import "MonthCalendar.h"
#import "NSObject+DDExtensions.h"
#define kTextFieldWidth 277
#define kTextFieldHeight 31
#define kTextFieldWidthForHour 170
#define kTextFieldHeightForHour 20
#define allTrim( object ) [object stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet] ]
static NSString *kCellIdentifier = @"cell_ID";
static NSString *kTitleKey = @"title";
static NSString *kViewControllerKey = @"viewController";
static NSString *kRowSizeKey =@"rowSizeKey";
static NSString *kNormalRowsizeKey =@"normalRowSizeKey";
@implementation AddEventViewController
@synthesize menuList;
@synthesize event;
@synthesize delegate;
@synthesize addElementsTableView;
@synthesize dateFormater;
@synthesize managedObjectContext, fetchedResultsController;
@synthesize editingMode;
-(void)save{
if (event.title == nil)
event.title = NSLocalizedString(@"newEventKey", @"New Event");
if ( !event.calendar ) {
[self.managedObjectContext deleteObject:event];
NSError *error = nil;
if (![self.managedObjectContext save:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}
//
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: NSLocalizedString(@"noCalendarErrorKey", @"No Calendar error")
message:NSLocalizedString(@"noCalendarMsgErrorKey", @"noCalendarMsgErrorKey")
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
[alert release];
if (self.delegate != NULL && [self.delegate respondsToSelector:@selector(addEventViewController:didAddEvent:)]){
[self.delegate addEventViewController:self didAddEvent:nil];
}
return;
}
if (self.delegate != NULL && [self.delegate respondsToSelector:@selector(addEventViewController:didAddEvent:)])
[self.delegate addEventViewController:self didAddEvent:self.event];
}
-(void)cancel{
if (self.editingMode == NO){
[self.managedObjectContext deleteObject:event];
NSError *error = nil;
if (![self.managedObjectContext save:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}
}
if (self.delegate != NULL && [self.delegate respondsToSelector:@selector(addEventViewController:didAddEvent:)])
[self.delegate addEventViewController:self didAddEvent:nil];
}
#pragma mark -
#pragma mark Table View UIActionSheetDelegate delegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0 ) {
//perform the delete
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = NSLocalizedString(@"deletingKey", @"Deleting...");
self.navigationItem.rightBarButtonItem.enabled = NO;
self.navigationItem.leftBarButtonItem.enabled = NO;
[HUD showWhileExecuting:@selector(deleteEvent:) onTarget:self withObject:nil animated:YES];
}
}
#pragma mark -
#pragma mark Google Methods
-(void) deleteEvent:(id)object{
if (!self.event.editLink ) {
NSLog(@"This should never happened, something went wrong deleting");
return;
}
NSURL *editURL = [NSURL URLWithString:self.event.editLink];
if (editURL && self.event.etag) {
GoogleCalAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
GDataServiceGoogleCalendar *service = appDelegate.gCalService;
deleteDone = NO;
[[service dd_invokeOnMainThread] deleteResourceURL:editURL
ETag:self.event.etag
delegate:self
didFinishSelector:@selector(deleteTicket:deletedEntry:error:)];
[waitForDeleteEventLock lock];
while( !deleteDone) {
[waitForDeleteEventLock wait];
}
[waitForDeleteEventLock unlock];
}
}
// event deleted callback
- (void)deleteTicket:(GDataServiceTicket *)ticket
deletedEntry:(GDataFeedCalendarEvent *)nilObject
error:(NSError *)error {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if (error != nil) {
eventDeleted = NO;
NSString *title, *msg;
if( [error code]==kGDataBadAuthentication ){
title = NSLocalizedString(@"authenticationFailedKey",@"Authentication Failed");
msg = NSLocalizedString(@"authenticationFailedMsgKey",@"Authentication Failed Msg");
}else if ( [error code] == NSURLErrorNotConnectedToInternet || [error code] == -1018 ) {
title = NSLocalizedString(@"noInternetKey",@"No internet access.");
msg = NSLocalizedString(@"noInternetMsgKey",@"The application couldn't connect to internet. Please check your internet access.");
}else{
// some other error authenticating or retrieving the GData object or a 304 status
// indicating the data has not been modified since it was previously fetched
title = NSLocalizedString(@"unexpectedErrorKey", @"An unexpected error has ocurred.");
msg = [error localizedDescription];
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:msg
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
[alert release];
}
else {
eventDeleted = YES;
}
[pool release];
[waitForDeleteEventLock lock];
deleteDone = YES;
[waitForDeleteEventLock signal];
[waitForDeleteEventLock unlock];
}
#pragma mark -
#pragma mark MBProgressHUDDelegate methods
- (void)hudWasHidden {
// Remove HUD from screen when the HUD was hidded
self.navigationItem.rightBarButtonItem.enabled = YES;
self.navigationItem.leftBarButtonItem.enabled = YES;
[HUD removeFromSuperview];
[HUD release];
if (eventDeleted ) //just for now maybe is better this way
if (self.delegate != NULL && [self.delegate respondsToSelector:@selector(addEventViewController:didDeleteEvent:)])
[self.delegate addEventViewController:self didDeleteEvent:self.event];
}
#pragma mark -
#pragma mark Table View dataSource delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ( [indexPath section] < [menuList count ]){
NSString *className = [[menuList objectAtIndex: indexPath.section] objectForKey:kViewControllerKey];
Class viewControllerClass = NSClassFromString(className);
AddCalendarEventViewController *targetViewController = [[viewControllerClass alloc] initWithNibName:className bundle:nil];
targetViewController.event = self.event;
if ( [className isEqualToString:@"SelectCalendarForEventViewController"]) {
((SelectCalendarForEventViewController *)targetViewController).fetchedResultsController = self.fetchedResultsController;
((SelectCalendarForEventViewController *)targetViewController).editingMode = self.editingMode;
}
[self.navigationController pushViewController:targetViewController animated:YES];
[targetViewController release];
}
}
#pragma mark -
#pragma mark Table View dataSource Methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 1;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
if (!self.editingMode)
return [menuList count];
else
return [menuList count]+1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
if ( [indexPath section] < [menuList count ] ){
NSString *normalHeightSize = [[menuList objectAtIndex:indexPath.section] objectForKey:kNormalRowsizeKey];
if (normalHeightSize == @"NO") {
cell = [self cellForNoNormalHeight:cell indexAt:indexPath];
}
else {
cell = [self cellForNormalHeight:cell indexAt:indexPath];
}
}
else {
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellIdentifier] autorelease];
}
UIImage *buttonBackground = [UIImage imageNamed:@"redButton.png"];
CGRect frame = CGRectMake(0, -1, 300, 44);
UIButton *button = [AddEventViewController buttonWithTitle:NSLocalizedString(@"deleteEventKey", @"Delete Event")
target:self
selector:@selector(eventDeleteConfirmation)
frame:frame
image:buttonBackground
//imagePressed:buttonBackgroundPressed
darkTextColor:NO];
[cell.contentView addSubview:button];
//[button addTarget:self action:@selector(eventDeleteConfirmation) forControlEvents:UIControlEventTouchUpInside];
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat result;
if ( [indexPath section] < [menuList count ])
result = [[[menuList objectAtIndex:indexPath.section] objectForKey:kRowSizeKey] floatValue];
else
result = [@"40.0f" floatValue];
return result;
}
#pragma mark -
#pragma mark Fetched results controller
- (NSFetchedResultsController *)fetchedResultsController {
if (fetchedResultsController == nil) {
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Calendar" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat: @"edit_permission == %@", [NSNumber numberWithInt:1]];
[fetchRequest setPredicate:predicate];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
[aFetchedResultsController release];
[fetchRequest release];
[sortDescriptor release];
[sortDescriptors release];
}
return fetchedResultsController;
}
#pragma mark -
#pragma mark utility functions
+ (UIButton *)buttonWithTitle: (NSString *)title
target:(id)target
selector:(SEL)selector
frame:(CGRect)frame
image:(UIImage *)image
darkTextColor:(BOOL)darkTextColor
{
UIButton *button = [[[UIButton alloc] initWithFrame:frame] autorelease];
// or you can do this:
// UIButton *button = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
// button.frame = frame;
button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[button setTitle:title forState:UIControlStateNormal];
if (darkTextColor)
{
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
}
else
{
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}
UIImage *newImage = [image stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0];
[button setBackgroundImage:newImage forState:UIControlStateNormal];
//UIImage *newPressedImage = [imagePressed stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0];
//[button setBackgroundImage:newPressedImage forState:UIControlStateHighlighted];
[button addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
// in case the parent view draws with a custom color or gradient, use a transparent color
button.backgroundColor = [UIColor clearColor];
return button;
}
- (void)eventDeleteConfirmation
{
// open a alert with an OK and cancel button
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"areYouSureKey",@"Are you sure?")
delegate:self cancelButtonTitle:NSLocalizedString(@"cancelKey",@"Cancel") destructiveButtonTitle:@"Ok" otherButtonTitles:nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
actionSheet.delegate = self;
[actionSheet showInView:self.view]; // show from our table view (pops up in the middle of the table)
[actionSheet release];
}
-(UITableViewCell *)cellForNoNormalHeight:(UITableViewCell *)cell indexAt:(NSIndexPath *) indexPath {
if (cell == nil)
{
cell = [self getCellContentView:kCellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
UILabel *lblTemp1 = (UILabel *)[cell viewWithTag:1];
UILabel *lblTemp2 = (UILabel *)[cell viewWithTag:2];
if (indexPath.section == 0) {
if (self.event.title != nil && [self.event.title length] != 0)
lblTemp1.text = self.event.title;
else
lblTemp1.text = NSLocalizedString(@"whatKey", @"What?");
if (self.event.location != nil && [self.event.location length] != 0)
lblTemp2.text = self.event.location;
else
lblTemp2.text = NSLocalizedString(@"whereKey", @"Where?");
}
else{
UILabel *hLabel1;
// UILabel *hLabel2 = (UILabel *)[cell viewWithTag:4];
lblTemp1.textColor = [UIColor blackColor];
lblTemp1.font = [UIFont boldSystemFontOfSize:16];
lblTemp2.textColor = [UIColor blackColor];
lblTemp2.font = [UIFont boldSystemFontOfSize:16];
lblTemp1.text = NSLocalizedString(@"startsKey", @"Starts");
lblTemp2.text = NSLocalizedString(@"endsKey", @"Ends");
[self startDateFormater];
NSString *startDateString =[dateFormater stringFromDate:self.event.startDate];
if( ![[cell contentView] viewWithTag:3] ){
hLabel1 = [self newStartHourLabel:startDateString];
hLabel1.tag = 3;
[cell.contentView addSubview:hLabel1];
[hLabel1 release];
}
else{
UILabel *alreadySetLabel = (UILabel *)[[cell contentView] viewWithTag:3];
alreadySetLabel.text = startDateString;
}
[self endDateFormater];
NSString *endDateString =[dateFormater stringFromDate:self.event.endDate];
if( ![[cell contentView] viewWithTag:4] ){
hLabel1 = [self newEndHourLabel:endDateString];
hLabel1.tag = 4;
[cell.contentView addSubview:hLabel1];
[hLabel1 release];
}
else{
UILabel *alreadySetLabel = (UILabel *)[[cell contentView] viewWithTag:4];
alreadySetLabel.text = endDateString;
}
}
return cell;
}
-(UITableViewCell *)cellForNormalHeight:(UITableViewCell *)cell indexAt:(NSIndexPath *) indexPath {
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.textLabel.text = [[menuList objectAtIndex:indexPath.section] objectForKey:kTitleKey];
if (indexPath.section == 2) {
CGRect frame = CGRectMake(170, 13, 100, 20);
UILabel *calendarNameLabel = [[UILabel alloc] initWithFrame:frame] ;
// label.highlightedTextColor = [UIColor whiteColor];
calendarNameLabel.textColor = [UIColor colorWithRed:0.243 green:0.306 blue:0.435 alpha:1.0];
calendarNameLabel.highlightedTextColor = [UIColor whiteColor];
calendarNameLabel.textAlignment = UITextAlignmentRight;
calendarNameLabel.font = [UIFont systemFontOfSize:16.0];
calendarNameLabel.text = self.event.calendar.name;
[cell addSubview:calendarNameLabel];
[calendarNameLabel release];
}
return cell;
}
- (UITableViewCell *) getCellContentView:(NSString *)cellIdentifier {
CGRect CellFrame = CGRectMake(0, 0, 300, 60);
CGRect Label1Frame = CGRectMake(10, 5, 260, 20);
CGRect Label2Frame = CGRectMake(10, 25, 260, 20);
UILabel *lblTemp;
UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:cellIdentifier] autorelease];
//Initialize Label with tag 1.
lblTemp = [[UILabel alloc] initWithFrame:Label1Frame];
lblTemp.tag = 1;
lblTemp.textColor = [UIColor lightGrayColor];
[cell.contentView addSubview:lblTemp];
[lblTemp release];
//Initialize Label with tag 2.
lblTemp = [[UILabel alloc] initWithFrame:Label2Frame];
lblTemp.tag = 2;
//lblTemp.font = [UIFont boldSystemFontOfSize:12];
lblTemp.textColor = [UIColor lightGrayColor];
[cell.contentView addSubview:lblTemp];
[lblTemp release];
return cell;
}
- (UILabel *)newStartHourLabel:(NSString *)string{
CGRect frame = CGRectMake(100, 6, kTextFieldWidthForHour, kTextFieldHeightForHour);
UILabel *newHourLabel = [[UILabel alloc] initWithFrame:frame] ;
// label.highlightedTextColor = [UIColor whiteColor];
newHourLabel.textColor = [UIColor colorWithRed:0.243 green:0.306 blue:0.435 alpha:1.0];
newHourLabel.highlightedTextColor = [UIColor whiteColor];
newHourLabel.textAlignment = UITextAlignmentRight;
newHourLabel.font = [UIFont systemFontOfSize:16.0];
newHourLabel.text = string;
return newHourLabel;
}
- (UILabel *)newEndHourLabel:(NSString *)string{
CGRect frame = CGRectMake(100, 24, kTextFieldWidthForHour, kTextFieldHeightForHour);
UILabel *newHourLabel = [[UILabel alloc] initWithFrame:frame] ;
// label.highlightedTextColor = [UIColor whiteColor];
newHourLabel.textColor = [UIColor colorWithRed:0.243 green:0.306 blue:0.435 alpha:1.0];
newHourLabel.highlightedTextColor = [UIColor whiteColor];
newHourLabel.textAlignment = UITextAlignmentRight;
newHourLabel.font = [UIFont systemFontOfSize:16.0];
newHourLabel.text = string;
return newHourLabel;
}
-(void) initializeMenuList{
menuList = [[NSMutableArray alloc] init];
[menuList addObject:[NSDictionary dictionaryWithObjectsAndKeys:
@"Title and Place", kTitleKey,
@"AddTitlePlaceEventViewController", kViewControllerKey,
@"54.0f", kRowSizeKey,
@"NO",kNormalRowsizeKey,
nil]];
[menuList addObject:[NSDictionary dictionaryWithObjectsAndKeys:
@"Starts Ends", kTitleKey,
@"AddDateEventViewController", kViewControllerKey,
@"54.0f", kRowSizeKey,
@"NO",kNormalRowsizeKey,
nil]];
[menuList addObject:[NSDictionary dictionaryWithObjectsAndKeys:
NSLocalizedString(@"calendarKey", @"Calendar"), kTitleKey,
@"SelectCalendarForEventViewController", kViewControllerKey,
@"44.0f", kRowSizeKey,
@"YES",kNormalRowsizeKey,
nil]];
[menuList addObject:[NSDictionary dictionaryWithObjectsAndKeys:
NSLocalizedString(@"descriptionKey",@"Description"), kTitleKey,
@"AddNoteEventViewController", kViewControllerKey,
@"44.0f", kRowSizeKey,
@"YES",kNormalRowsizeKey,
nil]];
}
- (void) startDateFormater{
// if (wDaySelector.on){
// [dateFormater setDateStyle:NSDateFormatterLongStyle];
// [dateFormater setTimeStyle:NSDateFormatterNoStyle];
// }
// else{
[dateFormater setDateStyle:NSDateFormatterShortStyle];
[dateFormater setTimeStyle:NSDateFormatterShortStyle];
//
// }
}
- (void) endDateFormater{
// if (wDaySelector.on){
// [dateFormater setDateStyle:NSDateFormatterLongStyle];
// [dateFormater setTimeStyle:NSDateFormatterNoStyle];
// }
// else{
//
[dateFormater setDateStyle:NSDateFormatterNoStyle];
[dateFormater setTimeStyle:NSDateFormatterShortStyle];
// }
//
}
#pragma mark -
#pragma mark UIViewController Functions
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
self.menuList = nil;
self.event = nil;
addElementsTableView = nil;
self.dateFormater = nil;
self.managedObjectContext = nil;
self.fetchedResultsController = nil;
[super viewDidUnload];
}
- (void)dealloc {
[menuList release];
[event release];
[addElementsTableView release];
[dateFormater release];
[fetchedResultsController release];
[managedObjectContext release];
[waitForDeleteEventLock release];
[super dealloc];
}
- (void)viewWillAppear:(BOOL)animated
{
// this UIViewController is about to re-appear, make sure we remove the current selection in our table view
NSIndexPath *tableSelection = [addElementsTableView indexPathForSelectedRow];
[addElementsTableView deselectRowAtIndexPath:tableSelection animated:NO];
[addElementsTableView reloadData];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
dateFormater = [[NSDateFormatter alloc] init];
[dateFormater setPMSymbol:NSLocalizedString(@"pmKey",@"PM")];
[dateFormater setAMSymbol:NSLocalizedString(@"amKey",@"AM")];
[dateFormater setDateStyle:NSDateFormatterShortStyle];
[dateFormater setTimeStyle:NSDateFormatterShortStyle];
waitForDeleteEventLock = [NSCondition new];
if (!editingMode)
self.title = NSLocalizedString(@"addEventKey", @"Add Event");
else
self.title = NSLocalizedString(@"editEventKey", @"Edit Event");
self.navigationItem.prompt = NSLocalizedString(@"detailsKey", @"Set the details for this event");
UIBarButtonItem *cancelButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"cancelKey", @"Cancel")
style:UIBarButtonItemStyleBordered
target:self action:@selector(cancel)];
self.navigationItem.leftBarButtonItem = cancelButtonItem;
[cancelButtonItem release];
UIBarButtonItem *saveButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"doneKey", @"Done") style:UIBarButtonItemStyleDone target:self action:@selector(save)];
self.navigationItem.rightBarButtonItem = saveButtonItem;
[saveButtonItem release];
NSError *error = nil;
if (![[self fetchedResultsController] performFetch:&error]) {
NSLog(@"Unresolved error fetching calendars %@, %@", error, [error userInfo]);
}
Calendar *aDefaultCalendar = self.event.calendar;
if ( [fetchedResultsController.fetchedObjects count] > 0){
if (!self.event.calendar){
aDefaultCalendar = (Calendar *)[fetchedResultsController.fetchedObjects objectAtIndex:0];
event.calendar = aDefaultCalendar;
}
}
else {
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle: NSLocalizedString(@"noCalendarsKey", @"No Calendars Found")
message:NSLocalizedString(@"noCalendarMsgKey", @"noCalendarMsgKey")
delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil] autorelease];
[alert show];
}
[self initializeMenuList];
[super viewDidLoad];
}
@end