Permalink
Browse files

Move tasks between lists

  • Loading branch information...
soffes committed Aug 15, 2012
1 parent 47f46e3 commit fa4ec614ff80dd81ded4aaccab2d7d51d2324854
Showing with 39 additions and 0 deletions.
  1. +1 −0 CheddarKit/CDKHTTPClient.h
  2. +23 −0 CheddarKit/CDKHTTPClient.m
  3. +1 −0 CheddarKit/CDKTask.h
  4. +14 −0 CheddarKit/CDKTask.m
@@ -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
@@ -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
@@ -30,6 +30,7 @@
- (void)toggleCompleted;
- (BOOL)hasTag:(CDKTag *)tag;
- (BOOL)hasTags:(NSArray *)tags;
+- (void)moveToList:(CDKList *)list;
@end
View
@@ -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

0 comments on commit fa4ec61

Please sign in to comment.