Skip to content

Instantly share code, notes, and snippets.

@eugenehp
Forked from r3trosteve/gist:92d31de48d2ce530ab87
Last active August 29, 2015 14:08
Show Gist options
  • Save eugenehp/310fe2d13df362b1c7e4 to your computer and use it in GitHub Desktop.
Save eugenehp/310fe2d13df362b1c7e4 to your computer and use it in GitHub Desktop.
- (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, @"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