Skip to content

Commit

Permalink
Merged recent changes from ushahidi_bugfixes; more consistent status …
Browse files Browse the repository at this point in the history
…alert implementation
  • Loading branch information
Paul Winkler committed Jun 23, 2010
2 parents aa52a30 + d004021 commit 0e91b05
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 42 deletions.
7 changes: 3 additions & 4 deletions API.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@
- (NSMutableArray *)parseIncidents:(NSData *)data;
-(NSMutableArray *)mapLocation;

- (BOOL)postIncidentWithDictionary:(NSMutableDictionary *)incidentinfo;
- (BOOL)postIncidentWithDictionary:(NSMutableDictionary *)incidentinfo andPhotoDataDictionary:(NSMutableDictionary *) photoData;
- (NSString *)postIncidentWithDictionary:(NSMutableDictionary *)incidentinfo;
- (NSString *)urlEncode:(NSString *)string;
- (BOOL)postIncidentWithDictionaryWithPhoto:(NSMutableDictionary *)incidentinfo;
- (NSString *)postIncidentWithDictionaryWithPhoto:(NSMutableDictionary *)incidentinfo;

@property (nonatomic, retain) NSString *endPoint;
@property (nonatomic, retain, readonly) NSString *errorCode;
Expand All @@ -60,4 +59,4 @@

- (NSString *)firstStringByXpath:(NSString*)xpath;

@end
@end
37 changes: 20 additions & 17 deletions API.m
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@ - (NSMutableArray *)parseIncidents: (NSData *)data {

}

- (BOOL)postIncidentWithDictionary:(NSMutableDictionary *)incidentinfo {
- (NSString*)postIncidentWithDictionary:(NSMutableDictionary *)incidentinfo {
// Returns an error message string, empty if successful.

//[[NSURLConnection alloc] initWithRequest:request delegate:self];
NSError *error;
NSURLResponse *response;
NSDictionary *results;

[app.errors removeAllObjects];

//NSString *queryURL = [NSString stringWithFormat:@"http://%@/api?task=report",app.urlString];
NSString *queryURL = [NSString stringWithFormat:@"http://%@/requests.xml",app.urlString];
Expand Down Expand Up @@ -250,18 +250,24 @@ - (BOOL)postIncidentWithDictionary:(NSMutableDictionary *)incidentinfo {
// TODO: check HTTP response status.
BOOL success = ([errorMsgs count] == 0) ? YES : NO;
// Cleanup.

//[response release];
//[results release];
for (GDataXMLElement *node in errorMsgs) {
// TODO: actually it looks like the API is only ever expected to return 1 error?
NSLog(@"Error msg from service: %@", [node stringValue]);
[app.errors addObject:[node stringValue]];
};

return success;
NSString *errorMsg = @"";
if (! success ) {
for (GDataXMLElement *node in errorMsgs) {
errorMsg = [errorMsg stringByAppendingString:[node stringValue]];
}
NSLog(@"Error msg from service: %@", errorMsg);
}

return errorMsg;

}

- (BOOL)postIncidentWithDictionaryWithPhoto:(NSMutableDictionary *)incidentinfo {
- (NSString*)postIncidentWithDictionaryWithPhoto:(NSMutableDictionary *)incidentinfo {
// Returns an error message string, empty if successful.

NSString *queryURL = [NSString stringWithFormat:@"http://%@/api?task=report",app.urlString];
//NSURL *nsurl = [NSString stringWithFormat:@"http://%@/api?task=report",app.urlString];
Expand Down Expand Up @@ -409,15 +415,12 @@ - (BOOL)postIncidentWithDictionaryWithPhoto:(NSMutableDictionary *)incidentinfo
//[results release];

if([success isEqual:@"true"])
return YES;
else
return NO;

return @"";
else {
return [[results objectForKey:@"error"] objectForKey:@"message"];
}

}
- (BOOL)postIncidentWithDictionary:(NSMutableDictionary *)incidentinfo andPhotoDataDictionary:(NSMutableDictionary *) photoData {
return NO;
}

- (NSString *)urlEncode:(NSString *)string {
return [string stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
Expand Down
5 changes: 2 additions & 3 deletions Classes/UshahidiProjAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
NSString *reports;
float tempLat,tempLng;
NSArray *arrCategory;
NSMutableArray *errors;

}

Expand All @@ -56,8 +55,8 @@
- (NSArray *)getCategories;
- (NSArray *)getAllIncidents;
-(NSArray *)getMapCentre;
-(BOOL)postData:(NSMutableDictionary *)dict;
-(BOOL)postDataWithImage:(NSMutableDictionary *)dict;
-(NSString *)postData:(NSMutableDictionary *)dict;
-(NSString *)postDataWithImage:(NSMutableDictionary *)dict;

- (NSArray *)getCategoriesByid:(int)catid;

Expand Down
6 changes: 2 additions & 4 deletions Classes/UshahidiProjAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ @implementation UshahidiProjAppDelegate
@synthesize navigationController,urlString,fname,lname,emailStr,mapView;
@synthesize dt,cat,lat,lng;
@synthesize incidentArray,imgArray,reports,mapType,mapArray,tempLat,tempLng,arrCategory;
@synthesize errors;

#pragma mark -
#pragma mark Application lifecycle
Expand All @@ -42,7 +41,6 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application {
reports = @"100";
mapType = @"Google Stardard";
urlString = @"demo.ushahidi.com";
errors = [[NSMutableArray alloc] init];
[mapType retain];
[urlString retain];

Expand Down Expand Up @@ -109,11 +107,11 @@ - (NSArray *)getAllIncidents {
return [instanceAPI allIncidents];
}

-(BOOL)postData:(NSMutableDictionary *)dict
-(NSString *)postData:(NSMutableDictionary *)dict
{
return [instanceAPI postIncidentWithDictionary:dict];
}
-(BOOL)postDataWithImage:(NSMutableDictionary *)dict
-(NSString *)postDataWithImage:(NSMutableDictionary *)dict
{
return [instanceAPI postIncidentWithDictionaryWithPhoto:dict];
}
Expand Down
33 changes: 19 additions & 14 deletions Classes/addIncident.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ -(void) save_data
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"Some Data are Missing" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok",nil];
[alert show];
}

else {

NSMutableDictionary *tempdict = [[NSMutableDictionary alloc] init];
Expand All @@ -77,29 +78,33 @@ -(void) save_data
// [tempdict setObject:data forKey:@"incident_photo"];

// Post the Data to Server
BOOL y;
if([app.imgArray count]>0 ) {
y = [app postDataWithImage:tempdict];
} else {
y = [app postData:tempdict];
NSString *errorMsg;
if([app.imgArray count]>0 )
{
errorMsg = [app postDataWithImage:tempdict];
}
else
{
errorMsg = [app postData:tempdict];
}
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"" message:@"" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
if (y){

UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"" message:@"" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
if( errorMsg == @"")
{
[alert setTitle:@"Reported!"];
textTitle.text = @"";
descriptionEditView.text = @"";
app.cat = @"";
app.cat =@"";
app.lat = @"";
app.lng = @"";
[incidentFieldsTableView reloadData];
// TODO: remove any saved draft data here?
} else {
for (NSString *err in app.errors) {
[alert setMessage:[[alert message] stringByAppendingString:err]];
}
[alert setTitle:@"Error!"];
}
[alert show];
else
{ // XXX TITLE
[alert setMessage:errorMsg];
}
[alert show];
}
}

Expand Down

0 comments on commit 0e91b05

Please sign in to comment.