Statistics
| Branch: | Tag: | Revision:

root / Classes / ReferrerACLViewController.m @ 72744ed1

History | View | Annotate | Download (4.8 kB)

1
//
2
//  ReferrerACLViewController.m
3
//  OpenStack
4
//
5
//  Created by Mike Mayo on 12/31/10.
6
//  The OpenStack project is provided under the Apache 2.0 license.
7
//
8

    
9
#import "ReferrerACLViewController.h"
10
#import "OpenStackAccount.h"
11
#import "Container.h"
12
#import "UIViewController+Conveniences.h"
13
#import "RSTextFieldCell.h"
14
#import "ActivityIndicatorView.h"
15
#import "AccountManager.h"
16
#import "ContainerDetailViewController.h"
17

    
18

    
19
@implementation ReferrerACLViewController
20

    
21
@synthesize account, container, containerDetailViewController;
22

    
23
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
24
    return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait);
25
}
26

    
27
#pragma mark -
28
#pragma mark View lifecycle
29

    
30
- (void)viewDidLoad {
31
    [super viewDidLoad];
32
    [self addSaveButton];
33
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
34
        [self addCancelButton];
35
    }
36
    self.navigationItem.title = @"Referrer ACL";
37
}
38

    
39
- (void)viewDidAppear:(BOOL)animated {
40
    [super viewDidAppear:animated];
41
	[textField becomeFirstResponder];
42
}
43

    
44
- (void)viewWillDisappear:(BOOL)animated {
45
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
46
        [self.containerDetailViewController.tableView deselectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:4] animated:YES];
47
    }
48
}
49

    
50
#pragma mark -
51
#pragma mark Table view data source
52

    
53
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
54
    return 1;
55
}
56

    
57
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
58
    return 1;
59
}
60

    
61
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
62
    return @"The Referrer ACL is a Perl Compatible Regular Expression that must match the referrer for all content requests.";
63
}
64

    
65
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
66
    static NSString *CellIdentifier = @"ReferrerACLCell";
67
    RSTextFieldCell *cell = (RSTextFieldCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
68
    if (cell == nil) {
69
        cell = [[[RSTextFieldCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
70
        cell.modalPresentationStyle = UIModalPresentationFormSheet;
71
		textField = cell.textField;
72
		textField.clearButtonMode = UITextFieldViewModeWhileEditing;
73
        textField.delegate = self;
74
		
75
        CGRect rect = CGRectInset(cell.contentView.bounds, 23.0, 12);
76
        rect.size.height += 5; // make slightly taller to not clip the bottom of text
77
        textField.frame = rect;
78
    }    
79
    cell.textLabel.text = @"";
80
    textField.text = container.referrerACL;
81
    return cell;
82
}
83

    
84
#pragma mark -
85
#pragma mark TextFieldDelegate
86

    
87
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
88
    [self saveButtonPressed:nil];
89
    return NO;
90
}
91

    
92
#pragma mark -
93
#pragma mark Save Button
94

    
95
- (void)saveButtonPressed:(id)sender {
96
    NSString *oldACL = container.referrerACL;
97
    NSString *activityMessage = @"Saving...";
98
    activityIndicatorView = [[ActivityIndicatorView alloc] initWithFrame:[ActivityIndicatorView frameForText:activityMessage] text:activityMessage];
99
    [activityIndicatorView addToView:self.view];
100
    container.referrerACL = textField.text;
101
    [self.account.manager updateCDNContainer:container];
102
    
103
    successObserver = [[NSNotificationCenter defaultCenter] addObserverForName:@"updateCDNContainerSucceeded" object:self.container
104
                                                                         queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification* notification) 
105
       {
106
           [containerDetailViewController.tableView reloadData];
107
           [activityIndicatorView removeFromSuperviewAndRelease];
108
           [[NSNotificationCenter defaultCenter] removeObserver:successObserver];
109
           [textField resignFirstResponder];
110
           [self.navigationController popViewControllerAnimated:YES];
111
       }];
112
    
113
    failureObserver = [[NSNotificationCenter defaultCenter] addObserverForName:@"updateCDNContainerFailed" object:self.container
114
                                                                         queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification* notification) 
115
       {
116
           [activityIndicatorView removeFromSuperviewAndRelease];
117
           container.referrerACL = oldACL;
118
           textField.text = oldACL;
119
           [self alert:@"There was a problem updating this container." request:[notification.userInfo objectForKey:@"request"]];
120
           [[NSNotificationCenter defaultCenter] removeObserver:failureObserver];
121
       }];
122
}
123

    
124
#pragma mark -
125
#pragma mark Memory management
126

    
127
- (void)dealloc {
128
    [account release];
129
    [container release];
130
    [containerDetailViewController release];
131
    [super dealloc];
132
}
133

    
134
@end