UI changes.
[pithos-ios] / Classes / ErrorAlerter.m
1 //
2 //  ErrorAlerter.m
3 //  OpenStack
4 //
5 //  Created by Mike Mayo on 1/17/11.
6 //  Copyright 2011 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "ErrorAlerter.h"
10 #import "LogEntryModalViewController.h"
11 #import "OpenStackRequest.h"
12 #import "UIViewController+Conveniences.h"
13 #import "APILogEntry.h"
14
15
16 @implementation ErrorAlerter
17
18 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
19     if (buttonIndex == 1) { // details button
20         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
21             logEntryModalViewController.modalPresentationStyle = UIModalPresentationFormSheet;
22         }                
23         [viewController presentModalViewController:logEntryModalViewController animated:YES];
24         [logEntryModalViewController release];
25     }
26 }
27
28 - (void)alert:(NSString *)message request:(OpenStackRequest *)request viewController:(UIViewController *)aViewController {
29     
30     viewController = aViewController;
31
32     NSString *title = @"Error";
33     if (request.responseStatusCode == 0) {
34         title = @"Connection Error";
35         message = @"Please check your connection or API URL and try again.";
36     }
37
38     logEntryModalViewController = [[LogEntryModalViewController alloc] initWithNibName:@"LogEntryModalViewController" bundle:nil];
39     logEntryModalViewController.logEntry = [[[APILogEntry alloc] initWithRequest:request] autorelease];
40     logEntryModalViewController.requestDescription = [logEntryModalViewController.logEntry requestDescription];
41     logEntryModalViewController.responseDescription = [logEntryModalViewController.logEntry responseDescription];
42     logEntryModalViewController.requestMethod = [logEntryModalViewController.logEntry requestMethod];
43     logEntryModalViewController.url = [[logEntryModalViewController.logEntry url] description];
44     
45     // present an alert with a Details button to show the API log entry
46     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Details", nil];
47     [alert show];
48     [alert release];        
49 }
50
51
52 @end