SignUpQuizSetViewController.m 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. //
  2. // SignUpQuizSetViewController.m
  3. // OneCable
  4. //
  5. // Created by nComz on 2017. 5. 22..
  6. // Copyright © 2017년 ntels. All rights reserved.
  7. //
  8. #import "SignUpQuizSetViewController.h"
  9. #import "CustomTextField.h"
  10. #import "CustomDatePopupView.h"
  11. #import "RequestHandler.h"
  12. #import "ImageUtil.h"
  13. /**
  14. 해당 메뉴는 마스터만 출력
  15. **/
  16. @interface SignUpQuizSetViewController () <CustomTextFieldDelegate> {
  17. DataSelectListModel *_quizList;
  18. DataSelectModel *_selectedQuiz;
  19. CustomDatePopupView *_popDate;
  20. NSString *answer;
  21. }
  22. @end
  23. @implementation SignUpQuizSetViewController
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. [self initUI];
  27. }
  28. - (void)viewWillAppear:(BOOL)animated {
  29. [super viewWillAppear:animated];
  30. [self requestInviteQuizList];
  31. }
  32. - (void)initUI {
  33. [self.navigationController.navigationBar setHidden:YES];
  34. self.navigationController.interactivePopGestureRecognizer.enabled = NO;
  35. [_lblStep setColor:kUITextColor03 text:[NSString stringWithFormat:@"%@", @"/ 5"]];
  36. answer = @"";
  37. _btnNext.enabled = NO;
  38. [self showDirectInputArea:NO];
  39. _txtQuizSelect.delegate = self;
  40. _txtSelfQuiz.delegate = self;
  41. _txtQuizSelect.keyboardType = UIKeyboardTypeDefault;
  42. _txtQuizSelect.returnKeyType = UIReturnKeyDone;
  43. _txtQuizSelect.placeholder = @"퀴즈를 선택하세요.";
  44. }
  45. -(void)showDirectInputArea:(BOOL)isShow
  46. {
  47. _viewSelfQuiz.hidden = !isShow;
  48. if(_viewSelfQuiz.isHidden){
  49. _viewHeight.constant = 0;
  50. } else{
  51. _viewHeight.constant = 177.0f;
  52. }
  53. }
  54. - (void)updateUI {
  55. _btnNext.enabled = [self isValidRequestInfo];
  56. if (_selectedQuiz != nil) {
  57. QuizModel *info = (QuizModel *)_selectedQuiz.value;
  58. [self showDirectInputArea:[info isUserEditQuiz]];
  59. _txtQuizSelect.text = _selectedQuiz.title;
  60. } else {
  61. [self showDirectInputArea:NO];
  62. }
  63. }
  64. - (void)requestInviteQuizList {
  65. NSString *path = [NSString stringWithFormat:API_POST_HOMEGROUP_INVITE_QUIZ];
  66. [[RequestHandler handler] sendAsyncGetRequestAPIPath:path parameters:nil modelClass:[QuizListModel class] completion:^(id responseObject) {
  67. QuizListModel *quizList = (QuizListModel *)responseObject;
  68. NSLog(@"Response : %@", responseObject);
  69. _quizList = [[DataSelectListModel alloc] init];
  70. _quizList.title = @"퀴즈 선택";
  71. for (QuizModel *info in quizList.quizList) {
  72. DataSelectModel *data = [[DataSelectModel alloc] init];
  73. data.title = info.quiz;
  74. data.value = info;
  75. [_quizList.list addObject:data];
  76. }
  77. } failure:^(id errorObject) {
  78. JDErrorModel *error = (JDErrorModel *)errorObject;
  79. [[JDFacade facade] alert:error.errorMessage];
  80. }];
  81. }
  82. - (void)requestQuizUpdate{
  83. QuizModel *quizInfo = (QuizModel *)_selectedQuiz.value;
  84. NSLog(@"Quiz Info : %@", quizInfo);
  85. NSString *quiz = quizInfo.quiz;
  86. if (quizInfo.isUserEditQuiz) {
  87. quiz = [_txtSelfQuiz.text trim];
  88. }
  89. //parameters
  90. NSDictionary *parameter = @{@"type": @"quiz" ,
  91. @"quiz": quiz,
  92. @"quiz_id":quizInfo.quizId,
  93. @"status_code":quizInfo.statusCode,
  94. @"answer":answer};
  95. NSString *path = [[JDFacade facade] getUrlWithCustGroupIDAndMemberID:API_POST_MEMBER_UPDATE];
  96. [[RequestHandler handler] sendAsyncPutRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  97. // [JDFacade facade].loginUser.quiz = quiz;
  98. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"IDSetViewController" storyboardName:@"SignUp"];
  99. [self.navigationController pushViewController:vc animated:YES];
  100. } failure:^(id errorObject) {
  101. JDErrorModel *error = (JDErrorModel *)errorObject;
  102. [[JDFacade facade] alert:error.errorMessage];
  103. }];
  104. }
  105. -(void)showQuizList{
  106. [[JDFacade facade] selectDatas:self listInfo:_quizList completion:^(DataSelectModel *seleced) {
  107. _selectedQuiz = seleced;
  108. _txtQuizSelect.text = _selectedQuiz.title;
  109. [self updateUI];
  110. }];
  111. }
  112. - (IBAction)btnCancelTouched:(id)sender {
  113. [self dismissViewControllerAnimated:YES completion:nil];
  114. }
  115. - (IBAction)btnNextTouched:(id)sender {
  116. // TODO : 퀴즈 업데이트? cust,group id 없음
  117. // [self requestQuizUpdate];
  118. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"IDSetViewController" storyboardName:@"SignUp"];
  119. [self.navigationController pushViewController:vc animated:YES];
  120. }
  121. - (IBAction)btnInputQuizTouched:(id)sender {
  122. if (_popDate == nil) {
  123. _popDate = [[CustomDatePopupView alloc] initWithTitle:@"정답 날짜 입력"];
  124. }
  125. [_popDate showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  126. if (buttonIndex == 0) {//OK
  127. NSLog(@"Input Date : %@%@%@", _popDate.txtYear.text, _popDate.txtMonth.text, _popDate.txtDay.text);
  128. NSString *date = [NSString stringWithFormat:@"%@%@%@",_popDate.txtYear.text,_popDate.txtMonth.text,_popDate.txtDay.text];
  129. answer = date;
  130. if ([date isEqualToString:@""]) {
  131. [_btnInputQuizAnswer setTitle:[CommonUtil currentDate2] forState:UIControlStateNormal];
  132. answer = [CommonUtil currentDate3];
  133. } else {
  134. NSString *date = [NSString stringWithFormat:@"%@ / %@ / %@",_popDate.txtYear.text,_popDate.txtMonth.text,_popDate.txtDay.text];
  135. [_btnInputQuizAnswer setTitle:date forState:UIControlStateNormal];
  136. }
  137. [_btnInputQuizAnswer setBackgroundImage:[UIImage imageNamed:@"img_input_round_bg_active"] forState:UIControlStateNormal];
  138. [_btnInputQuizAnswer setTitleColor:kUITextColor01 forState:UIControlStateNormal];
  139. }
  140. }];
  141. }
  142. - (BOOL)isValidRequestInfo {
  143. BOOL result = YES;
  144. QuizModel *quizInfo = (_selectedQuiz != nil) ? (QuizModel *)_selectedQuiz.value : nil;
  145. if (result && quizInfo == nil)
  146. {
  147. result = NO;
  148. }
  149. if (result && quizInfo.isUserEditQuiz)
  150. {
  151. if ([[_txtSelfQuiz.text trim] isEmptyString])
  152. {
  153. result = NO;
  154. }
  155. }
  156. return result;
  157. }
  158. -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
  159. if ([textField isEqual:_txtQuizSelect]) {
  160. [self showQuizList];
  161. return NO;
  162. }
  163. return YES;
  164. }
  165. - (void)textFieldDidEndEditing:(UITextField *)textField{
  166. if (_txtSelfQuiz.text.length > 0) {
  167. UIImage *active = [ImageUtil stretchedImage:[UIImage imageNamed:@"img_input_round_bg_active"] expectSize:CGSizeMake(_txtSelfQuiz.frame.size.width, _txtSelfQuiz.frame.size.height)];
  168. [_txtSelfQuiz setBackground:active];
  169. _btnNext.enabled = YES;
  170. } else {
  171. _btnNext.enabled = NO;
  172. }
  173. }
  174. - (void)didReceiveMemoryWarning {
  175. [super didReceiveMemoryWarning];
  176. }
  177. @end