Last active
August 29, 2015 14:08
-
-
Save r3trosteve/92d31de48d2ce530ab87 to your computer and use it in GitHub Desktop.
TaskDetailVC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (IBAction)submitWasPressed:(id)sender { | |
NSLog(@"I would submit a note now"); | |
NSDate *currentDay = [NSDate date]; | |
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; | |
[dateFormatter setDateFormat:@"dd-MM-yyyy"]; | |
NSString *dateString = [dateFormatter stringFromDate:currentDay]; | |
NSLog(@"%@", dateString); | |
NSString *personId = [NSString stringWithFormat:@"%@", _selectedInteraction.person] ; | |
NSString *interactionId = [NSString stringWithFormat:@"%@", _selectedInteraction.idNumber] ; | |
NSArray *interactionClosures = @[@"", @"cancel", @"close"]; | |
// NSMutableDictionary * dictInteraction = [[NSMutableDictionary alloc] init]; | |
// | |
// if ( ![_noteTextView.text isEqualToString:@""]) { | |
// [dictInteraction setObject:_noteTextView.text forKey:@"interaction[note_private]"]; | |
// } | |
// | |
// | |
// /* TODO: Enable this when API method can accept setting of status */ | |
// if ( self.status == NCInteractionDetailViewAlarm) { | |
// [dictInteraction setObject:@"alarm" forKey:@"interaction[alarm][state]"]; | |
// } else if ( self.status == NCInteractionDetailViewWarning) { | |
// [dictInteraction setObject:@"warning" forKey:@"interaction[alarm][state]"]; | |
// } | |
//[dictInteraction setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"auth_token"] forKey:@"auth_token"]; | |
// NSDictionary *params = [[NSDictionary alloc] initWithObjectsAndKeys:dictInteraction[alarm][state], @"interaction[parameters]", [[NSUserDefaults standardUserDefaults] objectForKey:@"auth_token"], @"auth_token", nil]; | |
NSString *alarmText = @"alarm"; | |
NSString *warningText = @"warning"; | |
NSDictionary *params = [[NSDictionary alloc] initWithObjectsAndKeys:alarmText, @"interaction", _noteTextView.text, @"interaction[note_private]",[[NSUserDefaults standardUserDefaults] objectForKey:@"auth_token"], @"auth_token", nil]; | |
NSLog(@"%@", params); | |
NSString *rootUrl = kInteractionsApi; | |
NSString *urlSuffix = [NSString stringWithFormat:@"/%@/interactions/%@/%@", personId, interactionId, interactionClosures[2]]; | |
NSString *url = [NSString stringWithFormat:@"%@%@", rootUrl, urlSuffix]; | |
NSLog(@"Request Url: %@", url); | |
[[NCDataSource sharedInstance] updateInteractionWithURL:url Param:params onSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { | |
NSLog(@"Updated interaction successfully."); | |
[self.selectedInteraction setState:@"closed"]; | |
[[NSNotificationCenter defaultCenter] postNotificationName:@"TaskWasClosed" object:nil]; | |
[self dissmissSelf]; | |
} onError:^(AFHTTPRequestOperation *operation, NSError *error) { | |
NSLog(@"Update interaction error."); | |
if ([_selectedInteraction.state isEqualToString:@"closed"]) { | |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Sorry, you can't update a closed Task" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; | |
[alert show]; | |
} else { | |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Sorry, we couldn't update the Task" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; | |
[alert show]; | |
} | |
}]; | |
[self dissmissSelf]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment