11//
2- // AddTopicViewController .m
2+ // EditTopicViewController .m
33// Coding_iOS
44//
55// Created by 王 原闯 on 14-8-27.
66// Copyright (c) 2014年 Coding. All rights reserved.
77//
88
9- #import " AddTopicViewController .h"
9+ #import " EditTopicViewController .h"
1010#import " ProjectTopic.h"
1111#import " Coding_NetAPIManager.h"
1212#import " EaseMarkdownTextView.h"
1313#import " WebContentManager.h"
1414
15- @interface AddTopicViewController ()<UIWebViewDelegate>
16- @property (strong , nonatomic ) ProjectTopic *myProTopic;
15+ @interface EditTopicViewController ()<UIWebViewDelegate>
1716
1817
1918@property (strong , nonatomic ) UISegmentedControl *segmentedControl;
@@ -29,7 +28,7 @@ @interface AddTopicViewController ()<UIWebViewDelegate>
2928
3029@end
3130
32- @implementation AddTopicViewController
31+ @implementation EditTopicViewController
3332
3433- (id )initWithNibName : (NSString *)nibNameOrNil bundle : (NSBundle *)nibBundleOrNil
3534{
@@ -45,8 +44,6 @@ - (void)viewDidLoad
4544 [super viewDidLoad ];
4645 // Do any additional setup after loading the view.
4746
48- self.myProTopic = [ProjectTopic topicWithPro: self .curProject];
49-
5047 if (!_segmentedControl) {
5148 _segmentedControl = ({
5249 UISegmentedControl *segmentedControl = [[UISegmentedControl alloc ] initWithItems: @[@" 编辑" , @" 预览" ]];
@@ -68,7 +65,7 @@ - (void)viewDidLoad
6865 self.navigationItem .titleView = _segmentedControl;
6966 }
7067
71- [self .navigationItem setRightBarButtonItem: [UIBarButtonItem itemWithBtnTitle: @" 完成" target: self action: @selector (saveBtnClicked )] animated: YES ];
68+ [self .navigationItem setRightBarButtonItem: [UIBarButtonItem itemWithBtnTitle: self .type == TopicEditTypeFeedBack? @" 发送 " : @" 完成" target: self action: @selector (saveBtnClicked )] animated: YES ];
7269 self.navigationItem .rightBarButtonItem .enabled = NO ;
7370
7471
@@ -82,7 +79,6 @@ - (void)viewDidLoad
8279 }];
8380
8481 self.curIndex = 0 ;
85-
8682}
8783
8884- (void )didReceiveMemoryWarning
@@ -145,8 +141,8 @@ - (void)loadEditView{
145141 make.edges .equalTo (self.view );
146142 }];
147143 [_inputTitleView mas_makeConstraints: ^(MASConstraintMaker *make) {
148- make.top .equalTo (_editView.mas_top ).offset (20 .0 );
149- make.height .mas_equalTo (20 );
144+ make.top .equalTo (_editView.mas_top ).offset (10 .0 );
145+ make.height .mas_equalTo (30 );
150146
151147 make.left .equalTo (_editView).offset (kPaddingLeftWidth );
152148 make.right .equalTo (_editView).offset (-kPaddingLeftWidth );
@@ -163,14 +159,18 @@ - (void)loadEditView{
163159 }];
164160
165161 // 内容
162+ @weakify (self);
166163 RAC (self.navigationItem .rightBarButtonItem , enabled) = [RACSignal combineLatest: @[self .inputTitleView.rac_textSignal, self .inputContentView.rac_textSignal] reduce: ^id (NSString *title, NSString *content){
164+ @strongify (self);
167165 BOOL enabled = ([title stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet ]].length > 0
168- && [content stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet ]].length > 0 );
166+ && [content stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet ]].length > 0
167+ && ![title isEqualToString: self .myProTopic.mdTitle]
168+ && ![content isEqualToString: self .myProTopic.mdContent]);
169169 return @(enabled);
170170 }];
171- _inputTitleView.placeholder = @" 讨论标题" ;
171+ _inputTitleView.placeholder = self. type == TopicEditTypeFeedBack? @" 反馈标题 " : @" 讨论标题" ;
172172 [_inputTitleView setValue: [UIColor lightGrayColor ] forKeyPath: @" _placeholderLabel.textColor" ];
173- _inputContentView.placeholder = @" 讨论内容" ;
173+ _inputContentView.placeholder = self. type == TopicEditTypeFeedBack? @" 反馈内容 " : @" 讨论内容" ;
174174 }
175175 _editView.hidden = NO ;
176176 _preview.hidden = YES ;
@@ -206,7 +206,7 @@ - (void)loadPreview{
206206}
207207
208208- (void )previewLoadMDData {
209- NSString *mdStr = [NSString stringWithFormat: @" # %@ \n\n %@ " , _inputTitleView.text, _inputContentView.text];
209+ NSString *mdStr = [NSString stringWithFormat: @" # %@ \n %@ " , _inputTitleView.text, _inputContentView.text];
210210 [_activityIndicator startAnimating ];
211211
212212 @weakify (self);
@@ -221,23 +221,37 @@ - (void)previewLoadMDData{
221221#pragma mark nav_btn
222222
223223- (void )saveBtnClicked {
224- self.myProTopic .title = _inputTitleView.text ;
225- self.myProTopic .content = _inputContentView.text ;
226-
227- if (_myProTopic.title .length <= 0 || _myProTopic.htmlMedia .contentOrigional <= 0 ) {
228- kTipAlert (@" 至少写点什么吖" );
229- return ;
224+ self.myProTopic .mdTitle = _inputTitleView.text ;
225+ self.myProTopic .mdContent = _inputContentView.text ;
226+ if (self.type == TopicEditTypeModify) {
227+ self.navigationItem .rightBarButtonItem .enabled = NO ;
228+ @weakify (self);
229+ [[Coding_NetAPIManager sharedManager ] request_ModifyProjectTpoic: self .myProTopic andBlock: ^(id data, NSError *error) {
230+ @strongify (self);
231+ self.navigationItem .rightBarButtonItem .enabled = YES ;
232+ if (data) {
233+ if (self.topicChangedBlock ) {
234+ self.topicChangedBlock (data, self.type );
235+ }
236+ [self .navigationController popViewControllerAnimated: YES ];
237+ }
238+ }];
239+ }else {
240+ self.navigationItem .rightBarButtonItem .enabled = NO ;
241+ @weakify (self);
242+ [[Coding_NetAPIManager sharedManager ] request_AddProjectTpoic: self .myProTopic andBlock: ^(id data, NSError *error) {
243+ @strongify (self);
244+ self.navigationItem .rightBarButtonItem .enabled = YES ;
245+ if (data) {
246+ if (self.topicChangedBlock ) {
247+ self.topicChangedBlock (data, self.type );
248+ }
249+ [self .navigationController popViewControllerAnimated: YES ];
250+ }
251+ }];
230252 }
231- self.navigationItem .rightBarButtonItem .enabled = NO ;
232- [[Coding_NetAPIManager sharedManager ] request_AddProjectTpoic: self .myProTopic andBlock: ^(id data, NSError *error) {
233- self.navigationItem .rightBarButtonItem .enabled = YES ;
234- if (data) {
235- self.myProTopic = data;
236- [self .navigationController popViewControllerAnimated: YES ];
237- }
238- }];
239- }
240253
254+ }
241255
242256#pragma mark UIWebViewDelegate
243257- (BOOL )webView : (UIWebView *)webView shouldStartLoadWithRequest : (NSURLRequest *)request navigationType : (UIWebViewNavigationType)navigationType {
0 commit comments