2 // ResizeServerViewController.m
5 // Created by Mike Mayo on 2/9/10.
6 // The OpenStack project is provided under the Apache 2.0 license.
9 #import "ResizeServerViewController.h"
10 #import "ServerViewController.h"
11 #import "UIViewController+Conveniences.h"
12 #import "OpenStackAccount.h"
15 #import "AccountManager.h"
18 @implementation ResizeServerViewController
20 @synthesize account, server;
23 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
24 return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait);
28 #pragma mark Button Handlers
30 -(void)saveButtonPressed:(id)sender {
31 [self.account.manager resizeServer:self.server flavor:selectedFlavor];
32 [serverViewController showToolbarActivityMessage:@"Resizing server..."];
33 [self dismissModalViewControllerAnimated:YES];
34 [serverViewController.tableView deselectRowAtIndexPath:[NSIndexPath indexPathForRow:kResize inSection:kActions] animated:YES];
38 #pragma mark View lifecycle
40 - (void)viewWillAppear:(BOOL)animated {
41 [super viewWillAppear:animated];
42 selectedFlavor = self.server.flavor;
43 [tableView reloadData];
47 #pragma mark Table view data source
49 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
53 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
54 return [self.account.flavors count];
57 - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
58 return [self.account.provider isRackspace] ? @"Resizes will be charged or credited a prorated amount based upon the difference in cost and the number of days remaining in your billing cycle." : @"";
61 // Customize the appearance of table view cells.
62 - (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
64 static NSString *CellIdentifier = @"Cell";
66 UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
68 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
71 // Configure the cell...
72 Flavor *flavor = [self.account.sortedFlavors objectAtIndex:indexPath.row];
73 cell.textLabel.text = flavor.name;
74 cell.detailTextLabel.text = [NSString stringWithFormat:@"%iMB RAM, %iGB Disk", flavor.ram, flavor.disk];
76 if (flavor.identifier == selectedFlavor.identifier) {
77 cell.accessoryType = UITableViewCellAccessoryCheckmark;
79 cell.accessoryType = UITableViewCellAccessoryNone;
86 #pragma mark Table view delegate
88 - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
89 selectedFlavor = [self.account.sortedFlavors objectAtIndex:indexPath.row];
90 [aTableView deselectRowAtIndexPath:indexPath animated:YES];
91 [NSTimer scheduledTimerWithTimeInterval:0.35 target:aTableView selector:@selector(reloadData) userInfo:nil repeats:NO];
95 #pragma mark Memory management