root / Classes / AddContainerViewController.m @ c2940e36
History | View | Annotate | Download (3.7 kB)
1 |
// |
---|---|
2 |
// AddContainerViewController.m |
3 |
// OpenStack |
4 |
// |
5 |
// Created by Mike Mayo on 12/8/10. |
6 |
// The OpenStack project is provided under the Apache 2.0 license. |
7 |
// |
8 |
|
9 |
#import "AddContainerViewController.h" |
10 |
#import "UIViewController+Conveniences.h" |
11 |
#import "ContainersViewController.h" |
12 |
#import "OpenStackAccount.h" |
13 |
#import "Container.h" |
14 |
#import "AccountManager.h" |
15 |
#import "RSTextFieldCell.h" |
16 |
#import "APICallback.h" |
17 |
#import "ActivityIndicatorView.h" |
18 |
|
19 |
@implementation AddContainerViewController |
20 |
|
21 |
@synthesize containersViewController, account; |
22 |
|
23 |
#pragma mark - View lifecycle |
24 |
|
25 |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { |
26 |
return ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait); |
27 |
} |
28 |
|
29 |
- (void)viewDidLoad { |
30 |
[super viewDidLoad]; |
31 |
self.navigationItem.title = @"Add Container"; |
32 |
[self addCancelButton]; |
33 |
[self addSaveButton]; |
34 |
} |
35 |
|
36 |
- (void)viewDidAppear:(BOOL)animated { |
37 |
[super viewDidAppear:animated]; |
38 |
[textField becomeFirstResponder]; |
39 |
} |
40 |
|
41 |
#pragma mark - Memory management |
42 |
|
43 |
- (void)dealloc { |
44 |
[containersViewController release]; |
45 |
[account release]; |
46 |
[super dealloc]; |
47 |
} |
48 |
|
49 |
#pragma mark - UITableViewDataSource |
50 |
|
51 |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
52 |
return 1; |
53 |
} |
54 |
|
55 |
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section { |
56 |
return @"A container is a storage compartment for your files and provides a way for you to organize your data. Containers are similar to folders, but cannot be nested."; |
57 |
} |
58 |
|
59 |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
60 |
static NSString *cellIdentifier = @"ContainerNameCell"; |
61 |
RSTextFieldCell *cell = (RSTextFieldCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier]; |
62 |
if (cell == nil) { |
63 |
cell = [[[RSTextFieldCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier] autorelease]; |
64 |
cell.modalPresentationStyle = UIModalPresentationFormSheet; |
65 |
textField = cell.textField; |
66 |
textField.delegate = self; |
67 |
textField.clearButtonMode = UITextFieldViewModeWhileEditing; |
68 |
} |
69 |
cell.textLabel.text = @"Name"; |
70 |
return cell; |
71 |
} |
72 |
|
73 |
#pragma mark - UITextFieldDelegate |
74 |
|
75 |
- (BOOL)textFieldShouldReturn:(UITextField *)textField { |
76 |
[self saveButtonPressed:nil]; |
77 |
return NO; |
78 |
} |
79 |
|
80 |
#pragma mark - Button handlers |
81 |
|
82 |
- (void)saveButtonPressed:(id)sender { |
83 |
if ([textField.text isEqualToString:@""]) { |
84 |
[self alert:@"Container Name Required" message:@"Please enter a container name."]; |
85 |
} else { |
86 |
[textField resignFirstResponder]; |
87 |
__block ActivityIndicatorView *activityIndicatorView = [ActivityIndicatorView activityIndicatorViewWithText:@"Creating container..." |
88 |
andAddToView:self.view]; |
89 |
Container *container = [[Container alloc] init]; |
90 |
container.name = textField.text; |
91 |
[[self.account.manager createContainer:container] |
92 |
success:^(OpenStackRequest *request) { |
93 |
[self.containersViewController.tableView reloadData]; |
94 |
[activityIndicatorView stopAnimatingAndRemoveFromSuperview]; |
95 |
[self dismissModalViewControllerAnimated:YES]; |
96 |
[container release]; |
97 |
} |
98 |
failure:^(OpenStackRequest *request) { |
99 |
[activityIndicatorView stopAnimatingAndRemoveFromSuperview]; |
100 |
[self alert:@"There was a problem creating your container." request:request]; |
101 |
[container release]; |
102 |
}]; |
103 |
} |
104 |
} |
105 |
|
106 |
@end |