5 // Created by Mike Mayo on 1/17/11.
6 // Copyright 2011 __MyCompanyName__. All rights reserved.
9 #import "ErrorAlerter.h"
10 #import "LogEntryModalViewController.h"
11 #import "OpenStackRequest.h"
12 #import "UIViewController+Conveniences.h"
13 #import "APILogEntry.h"
16 @implementation ErrorAlerter
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;
23 [viewController presentModalViewController:logEntryModalViewController animated:YES];
24 [logEntryModalViewController release];
28 - (void)alert:(NSString *)message request:(OpenStackRequest *)request viewController:(UIViewController *)aViewController {
30 viewController = aViewController;
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.";
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];
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];