diff --git a/Blog/Base.lproj/Main.storyboard b/Blog/Base.lproj/Main.storyboard index cf639c9..27cdf83 100644 --- a/Blog/Base.lproj/Main.storyboard +++ b/Blog/Base.lproj/Main.storyboard @@ -43,6 +43,12 @@ + + + + + + @@ -98,6 +104,8 @@ + + diff --git a/Blog/EditorViewController.m b/Blog/EditorViewController.m index 9b7f860..0e11609 100644 --- a/Blog/EditorViewController.m +++ b/Blog/EditorViewController.m @@ -18,6 +18,7 @@ @property (nonatomic, weak) IBOutlet UILabel *titleView; @property (nonatomic, weak) IBOutlet UITextView *textView; @property (nonatomic, weak) IBOutlet UIToolbar *toolbar; +@property (nonatomic, weak) IBOutlet UIBarButtonItem *publishBarButtonItem; @property (strong, nonatomic) Post *modifiedPost; @property (strong, nonatomic) PMKPromise *savePromise; @@ -54,6 +55,7 @@ [self.toolbar.items enumerateObjectsUsingBlock:^(UIBarButtonItem *item, NSUInteger idx, BOOL *stop) { item.enabled = toolbarEnabled; }]; + self.publishBarButtonItem.title = self.modifiedPost.draft ? @"Publish" : @"Unpublish"; } - (void)configureTitleView { @@ -151,6 +153,28 @@ self.modifiedPost = [self.modifiedPost copyWithURL:url]; } +- (IBAction)publishOrUnpublish:(id)sender { + // TODO: prevent changes while publishing + [self savePost].then(^{ + PMKPromise *promise = nil; + Post *post = self.modifiedPost; + if (post.draft) { + promise = [self.blogController requestPublishDraftWithPath:post.path]; + } + else { + promise = [self.blogController requestUnpublishPostWithPath:post.path]; + } + promise.then(^(Post *post) { + self.post = post; + self.modifiedPost = post; + [self configureView]; + if (self.postUpdatedBlock) { + self.postUpdatedBlock(post); + } + }); + }); +} + - (IBAction)presentChangeTitle:(id)sender { if (self.presentedViewController) { return;