Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move tasks between lists

  • Loading branch information...
commit fa4ec614ff80dd81ded4aaccab2d7d51d2324854 1 parent 47f46e3
@soffes soffes authored
View
1  CheddarKit/CDKHTTPClient.h
@@ -44,5 +44,6 @@ typedef void (^CDKHTTPClientFailure)(AFJSONRequestOperation *operation, NSError
- (void)sortTasks:(NSArray *)tasks inList:(CDKList *)list success:(CDKHTTPClientSuccess)success failure:(CDKHTTPClientFailure)failure;
- (void)archiveAllTasksInList:(CDKList *)list success:(CDKHTTPClientSuccess)success failure:(CDKHTTPClientFailure)failure;
- (void)archiveCompletedTasksInList:(CDKList *)list success:(CDKHTTPClientSuccess)success failure:(CDKHTTPClientFailure)failure;
+- (void)moveTask:(CDKTask *)task toList:(CDKList *)list success:(CDKHTTPClientSuccess)success failure:(CDKHTTPClientFailure)failure;
@end
View
23 CheddarKit/CDKHTTPClient.m
@@ -455,6 +455,29 @@ - (void)archiveCompletedTasksInList:(CDKList *)list success:(CDKHTTPClientSucces
}
+- (void)moveTask:(CDKTask *)task toList:(CDKList *)list success:(CDKHTTPClientSuccess)success failure:(CDKHTTPClientFailure)failure {
+ NSString *path = [NSString stringWithFormat:@"tasks/%@/move", task.remoteID];
+ NSDictionary *params = [[NSDictionary alloc] initWithObjectsAndKeys:
+ list.remoteID, @"task[list_id]",
+ nil];
+ [self putPath:path parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
+ __weak NSManagedObjectContext *context = [CDKTask mainContext];
+ [context performBlockAndWait:^{
+ [task unpackDictionary:responseObject];
+ [task save];
+ }];
+
+ if (success) {
+ success((AFJSONRequestOperation *)operation, responseObject);
+ }
+ } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
+ if (failure) {
+ failure((AFJSONRequestOperation *)operation, error);
+ }
+ }];
+}
+
+
#pragma mark - Authentication
- (void)_userChanged:(NSNotification *)notification {
View
1  CheddarKit/CDKTask.h
@@ -30,6 +30,7 @@
- (void)toggleCompleted;
- (BOOL)hasTag:(CDKTag *)tag;
- (BOOL)hasTags:(NSArray *)tags;
+- (void)moveToList:(CDKList *)list;
@end
View
14 CheddarKit/CDKTask.m
@@ -174,4 +174,18 @@ - (BOOL)hasTags:(NSArray *)tags {
return YES;
}
+
+- (void)moveToList:(CDKList *)list {
+ CDKList *oldList = self.list;
+ self.list = list;
+ [self save];
+
+ [[CDKHTTPClient sharedClient] moveTask:self toList:list success:nil failure:^(AFJSONRequestOperation *operation, NSError *error) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ self.list = oldList;
+ [self save];
+ });
+ }];
+}
+
@end
Please sign in to comment.
Something went wrong with that request. Please try again.