2020#import " ActionSheetDatePicker.h"
2121#import " TaskDescriptionViewController.h"
2222#import " WebViewController.h"
23+ #import " ProjectToChooseListViewController.h"
2324
2425@interface EditTaskViewController ()<TTTAttributedLabelDelegate>
2526@property (strong , nonatomic ) UITableView *myTableView;
@@ -45,26 +46,14 @@ - (void)viewDidLoad
4546{
4647 [super viewDidLoad ];
4748 // Do any additional setup after loading the view.
48- switch (_myTask.handleType ) {
49- case TaskHandleTypeAdd:{
50- _myCopyTask = [Task taskWithTask: _myTask];
51- _myCopyTask.handleType = TaskHandleTypeAdd;
52- }
53- break ;
54- case TaskHandleTypeEdit:{
55- _myCopyTask = [Task taskWithTask: _myTask];
56-
57- // 评论
58- _myMsgInputView = [UIMessageInputView messageInputViewWithType: UIMessageInputViewContentTypeTask];
59- _myMsgInputView.isAlwaysShow = YES ;
60- _myMsgInputView.delegate = self;
61-
62- [self queryToRefreshTaskDetail ];
63-
64- }
65- break ;
66- default :
67- break ;
49+ _myCopyTask = [Task taskWithTask: _myTask];
50+ if (_myTask.handleType == TaskHandleTypeEdit) {
51+ // 评论
52+ _myMsgInputView = [UIMessageInputView messageInputViewWithType: UIMessageInputViewContentTypeTask];
53+ _myMsgInputView.isAlwaysShow = YES ;
54+ _myMsgInputView.delegate = self;
55+
56+ [self queryToRefreshTaskDetail ];
6857 }
6958 [self configTitle ];
7059
@@ -103,15 +92,17 @@ - (void)viewDidLoad
10392 RACObserve (self , myCopyTask.task_description.markdown)] reduce: ^id (NSString *content, User *owner, NSNumber *priority, NSNumber *status, NSString *deadline){
10493 @strongify (self);
10594 BOOL enabled = ![self .myCopyTask isSameToTask: self .myTask];
106- if (self.myCopyTask .handleType == TaskEditTypeAdd && self.myCopyTask .content .length <= 0 ) {
107- enabled = NO ;
95+ if (self.myCopyTask .handleType > TaskHandleTypeEdit) {
96+ enabled = ([self .myCopyTask.content trimWhitespace ].length > 0 &&
97+ self.myCopyTask .project != nil &&
98+ self.myCopyTask .owner != nil );
10899 }
109100 return @(enabled);
110101 }];
111102}
112103
113104- (void )configTitle {
114- if (_myTask.handleType == TaskEditTypeAdd ) {
105+ if (_myTask.handleType > TaskHandleTypeEdit ) {
115106 self.title = @" 创建任务" ;
116107 }else {
117108 self.title = _myTask.project .name ;
@@ -202,7 +193,7 @@ - (void)doneBtnClicked{
202193 if (_myCopyTask.isRequesting ) {
203194 return ;
204195 }
205- if (_myCopyTask.handleType == TaskHandleTypeAdd ) {
196+ if (_myCopyTask.handleType > TaskHandleTypeEdit ) {
206197 if (!_myCopyTask.content || _myCopyTask.content .length <= 0 ) {
207198 return ;
208199 }
@@ -211,7 +202,7 @@ - (void)doneBtnClicked{
211202 _myCopyTask.isRequesting = NO ;
212203 if (data) {
213204 if (_taskChangedBlock) {
214- _taskChangedBlock (_myTask, TaskEditTypeAdd );
205+ _taskChangedBlock ();
215206 }
216207 [self .navigationController popViewControllerAnimated: YES ];
217208 }
@@ -227,7 +218,7 @@ - (void)doneBtnClicked{
227218 _myTask.owner = _myCopyTask.owner ;
228219 _myTask.status = _myCopyTask.status ;
229220 if (_taskChangedBlock) {
230- _taskChangedBlock (_myTask, TaskEditTypeModify );
221+ _taskChangedBlock ();
231222 }
232223 [self .navigationController popViewControllerAnimated: YES ];
233224 }else {
@@ -247,7 +238,7 @@ - (void)deleteTask:(Task *)toDelete{
247238 toDelete.isRequesting = NO ;
248239 if (data) {
249240 if (_taskChangedBlock) {
250- _taskChangedBlock (_myTask, TaskEditTypeAdd );
241+ _taskChangedBlock ();
251242 }
252243 [self .navigationController popViewControllerAnimated: YES ];
253244 }
@@ -289,14 +280,15 @@ - (void)deleteComment:(TaskComment *)comment{
289280}
290281#pragma mark Table M
291282- (NSInteger )numberOfSectionsInTableView : (UITableView *)tableView {
292- return (self.myCopyTask .handleType == TaskEditTypeAdd )? 2 : 3 ;
283+ return (self.myCopyTask .handleType > TaskHandleTypeEdit )? 2 : 3 ;
293284}
294285- (NSInteger )tableView : (UITableView *)tableView numberOfRowsInSection : (NSInteger )section {
295286 NSInteger row = 0 ;
296287 if (section == 0 ) {
297288 row = 2 ;
298289 }else if (section == 1 ){
299- row = (self.myCopyTask .handleType == TaskHandleTypeAdd)? 3 : 4 ;
290+ TaskHandleType handleType = self.myCopyTask .handleType ;
291+ row = handleType == TaskHandleTypeEdit? 4 : handleType == TaskHandleTypeAddWithProject? 3 : 4 ;
300292 }else {
301293 row = self.myCopyTask .activityList .count ;
302294 }
@@ -337,7 +329,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
337329 }else {
338330 TaskDescriptionCell *cell = [tableView dequeueReusableCellWithIdentifier: kCellIdentifier_TaskDescriptionCell forIndexPath: indexPath];
339331 NSString *titleStr;
340- if (_myCopyTask.handleType == TaskEditTypeAdd ) {
332+ if (_myCopyTask.handleType > TaskHandleTypeEdit ) {
341333 titleStr = @" 添加描述" ;
342334 }else {
343335 titleStr = _myCopyTask.has_description .boolValue ? @" 查看描述" : @" 补充描述" ;
@@ -356,7 +348,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
356348 }
357349 }else if (indexPath.section == 1 ){
358350 LeftImage_LRTextCell *cell = [tableView dequeueReusableCellWithIdentifier: kCellIdentifier_LeftImage_LRText forIndexPath: indexPath];
359- [cell setObj: _myCopyTask type: indexPath.row];
351+ LeftImage_LRTextCellType cellType = _myCopyTask.handleType == TaskHandleTypeAddWithoutProject? indexPath.row : indexPath.row +1 ;
352+ [cell setObj: _myCopyTask type: cellType];
360353 cell.backgroundColor = kColorTableBG ;
361354 [tableView addLineforPlainCell: cell forRowAtIndexPath: indexPath withLeftSpace: 60 ];
362355 return cell;
@@ -449,23 +442,39 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
449442// [self goToDescriptionVC];
450443// }
451444 }else if (indexPath.section == 1 ){
452- if (indexPath.row == LeftImage_LRTextCellTypeTaskOwner) {
445+ LeftImage_LRTextCellType cellType = _myCopyTask.handleType == TaskHandleTypeAddWithoutProject? indexPath.row : indexPath.row +1 ;
446+ if (cellType == LeftImage_LRTextCellTypeTaskProject) {
447+ ProjectToChooseListViewController *vc = [[ProjectToChooseListViewController alloc ] init ];
448+ vc.projectChoosedBlock = ^(Project *project){
449+ ESStrongSelf;
450+ _self.myCopyTask .project = project;
451+ _self.myCopyTask .owner = nil ;// 更换新的执行人
452+ [_self.myTableView reloadData ];
453+ };
454+ [self .navigationController pushViewController: vc animated: YES ];
455+
456+ NSLog (@" haimeizuo" );
457+ }else if (cellType == LeftImage_LRTextCellTypeTaskOwner) {
458+ if (_myCopyTask.project == nil ) {
459+ [self showHudTipStr: @" 需要选定所属项目先~" ];
460+ return ;
461+ }
453462 ProjectMemberListViewController *vc = [[ProjectMemberListViewController alloc ] init ];
454463 [vc setFrame: self .view.bounds project: _myCopyTask.project type: ProMemTypeTaskOwner refreshBlock: nil selectBlock: ^(ProjectMember *member) {
455464 ESStrongSelf;
456465 _self.myCopyTask .owner = member.user ;// 更换新的执行人
457466 [_self.myTableView reloadData ];
458467 } cellBtnBlock: nil ];
459468 [self .navigationController pushViewController: vc animated: YES ];
460- }else if (indexPath. row == LeftImage_LRTextCellTypeTaskPriority){
469+ }else if (cellType == LeftImage_LRTextCellTypeTaskPriority){
461470 ValueListViewController *vc = [[ValueListViewController alloc ] init ];
462471 [vc setTitle: @" 优先级" valueList: kTaskPrioritiesDisplay defaultSelectIndex: _myCopyTask.priority.intValue type: ValueListTypeTaskPriority selectBlock: ^(NSInteger index) {
463472 ESStrongSelf;
464473 _self.myCopyTask .priority = [NSNumber numberWithInteger: index];// 更换新的任务优先级
465474 [_self.myTableView reloadData ];
466475 }];
467476 [self .navigationController pushViewController: vc animated: YES ];
468- }else if (indexPath. row == LeftImage_LRTextCellTypeTaskDeadline){
477+ }else if (cellType == LeftImage_LRTextCellTypeTaskDeadline){
469478 NSDate *curDate = _myCopyTask.deadline_date ? _myCopyTask.deadline_date : [NSDate date ];
470479 ESStrongSelf;
471480 ActionSheetDatePicker *picker = [[ActionSheetDatePicker alloc ] initWithTitle: nil datePickerMode: UIDatePickerModeDate selectedDate: curDate doneBlock: ^(ActionSheetDatePicker *picker, NSDate *selectedDate, id origin) {
@@ -483,7 +492,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
483492 NSForegroundColorAttributeName : [UIColor colorWithHexString: @" 0x666666" ]} forState: UIControlStateNormal];
484493 [picker setCancelButton: barButton];
485494 [picker showActionSheetPicker ];
486- }else if (indexPath. row == LeftImage_LRTextCellTypeTaskStatus){
495+ }else if (cellType == LeftImage_LRTextCellTypeTaskStatus){
487496 ValueListViewController *vc = [[ValueListViewController alloc ] init ];
488497 [vc setTitle: @" 阶段" valueList: @[@" 未完成" , @" 已完成" ] defaultSelectIndex: _myCopyTask.status.intValue-1 type: ValueListTypeTaskStatus selectBlock: ^(NSInteger index) {
489498 ESStrongSelf;
0 commit comments