SignUpQuizSetViewController.m 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. #import "IDSetViewController.h"
  14. /**
  15. 해당 메뉴는 마스터만 출력
  16. **/
  17. @interface SignUpQuizSetViewController () <CustomTextFieldDelegate,dismissPopupViewDelegate> {
  18. DataSelectListModel *_quizList; // 퀴즈 목록 모델
  19. DataSelectModel *_selectedQuiz; // 선택 한 퀴즈
  20. CustomDatePopupView *_popDate; // 정답 입력 팝업
  21. NSString *answer; // 입력한 정답
  22. }
  23. @end
  24. @implementation SignUpQuizSetViewController
  25. @synthesize signUpModel;
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. [self initUI];
  29. }
  30. // 퀴즈 목록을 가져옴
  31. - (void)viewWillAppear:(BOOL)animated {
  32. [super viewWillAppear:animated];
  33. [self requestQuizList];
  34. }
  35. // UI 설정
  36. - (void)initUI {
  37. [self.navigationController.navigationBar setHidden:YES];
  38. self.navigationController.interactivePopGestureRecognizer.enabled = NO;
  39. signUpModel = [[SignUpModel alloc]init];
  40. [_lblStep setColor:kUITextColor03 text:[NSString stringWithFormat:@"%@", @"/ 5"]];
  41. answer = @"";
  42. _btnNext.enabled = NO;
  43. [self showDirectInputArea:NO];
  44. _txtQuizSelect.delegate = self;
  45. _txtSelfQuiz.delegate = self;
  46. _txtQuizSelect.keyboardType = UIKeyboardTypeDefault;
  47. _txtQuizSelect.returnKeyType = UIReturnKeyDone;
  48. _txtSelfQuiz.keyboardType = UIKeyboardTypeDefault;
  49. _txtSelfQuiz.returnKeyType = UIReturnKeyDone;
  50. _txtQuizSelect.placeholder = @"퀴즈 선택";
  51. }
  52. // 선택입력,사용자 입력 여부에 따라 뷰 높이 값 설정
  53. -(void)showDirectInputArea:(BOOL)isShow
  54. {
  55. _viewSelfQuiz.hidden = !isShow;
  56. if(_viewSelfQuiz.isHidden){
  57. _viewHeight.constant = 0;
  58. } else{
  59. _viewHeight.constant = 177.0f;
  60. }
  61. }
  62. // 다음 버튼 활성화 여부 및 선택한 퀴즈 입력 설정
  63. - (void)updateUI {
  64. _btnNext.enabled = [self isValidRequestInfo];
  65. if (_selectedQuiz != nil) {
  66. QuizModel *info = (QuizModel *)_selectedQuiz.value;
  67. [self showDirectInputArea:[info isUserEditQuiz]];
  68. _txtQuizSelect.text = _selectedQuiz.title;
  69. } else {
  70. [self showDirectInputArea:NO];
  71. }
  72. }
  73. // 퀴즈 목록 요청
  74. - (void)requestQuizList {
  75. NSString *path = [NSString stringWithFormat:API_POST_HOMEGROUP_INVITE_QUIZ];
  76. [[RequestHandler handler] sendAsyncGetRequestAPIPath:path parameters:nil modelClass:[QuizListModel class] completion:^(id responseObject) {
  77. QuizListModel *quizList = (QuizListModel *)responseObject;
  78. //NSLog(@"Response : %@", responseObject);
  79. _quizList = [[DataSelectListModel alloc] init];
  80. _quizList.title = @"퀴즈 선택";
  81. for (QuizModel *info in quizList.quizList) {
  82. DataSelectModel *data = [[DataSelectModel alloc] init];
  83. data.title = info.quiz;
  84. data.value = info;
  85. [_quizList.list addObject:data];
  86. }
  87. } failure:^(id errorObject) {
  88. JDErrorModel *error = (JDErrorModel *)errorObject;
  89. [[JDFacade facade] alert:error.errorMessage];
  90. }];
  91. }
  92. // 사용자가 입력한 퀴즈 저장 후 아이디,비밀번호 설정 메뉴로 이동
  93. - (void)masterQuizSet{
  94. QuizModel *quizInfo = (QuizModel *)_selectedQuiz.value;
  95. NSLog(@"Quiz Info : %@", quizInfo);
  96. NSString *quiz = quizInfo.quiz;
  97. if (quizInfo.isUserEditQuiz) {
  98. quiz = [_txtSelfQuiz.text trim];
  99. }
  100. SignUpModel *signUpInfo = [[SignUpModel alloc]init];
  101. signUpInfo = signUpModel;
  102. signUpInfo.quiz = quiz;
  103. signUpInfo.quizId = quizInfo.quizId;
  104. signUpInfo.statusCode = quizInfo.statusCode;
  105. signUpInfo.answer = answer;
  106. signUpInfo.phone = _phoneNum;
  107. IDSetViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"IDSetViewController" storyboardName:@"SignUp"];
  108. vc.signUpModel = signUpInfo;
  109. [self.navigationController pushViewController:vc animated:YES];
  110. }
  111. // 퀴즈 목록가져온 후 선택한 퀴즈 입력 설정
  112. -(void)showQuizList{
  113. [[JDFacade facade] selectDatas:self listInfo:_quizList completion:^(DataSelectModel *seleced) {
  114. _selectedQuiz = seleced;
  115. _txtQuizSelect.text = _selectedQuiz.title;
  116. [self updateUI];
  117. }];
  118. }
  119. // 메뉴 닫기
  120. - (IBAction)btnCancelTouched:(id)sender {
  121. [self dismissViewControllerAnimated:YES completion:nil];
  122. }
  123. // 다음 버튼 터치시 사용자가 입력한 퀴즈 저장 후 메뉴이동
  124. - (IBAction)btnNextTouched:(id)sender {
  125. [self masterQuizSet];
  126. }
  127. // 정답 날짜 입력 팝업 출력 및 입력한 날짜 가져옴
  128. - (IBAction)btnInputQuizTouched:(id)sender {
  129. if (_popDate == nil) {
  130. _popDate = [[CustomDatePopupView alloc] initWithTitle:@"정답 날짜 입력"];
  131. _popDate.delegate = self;
  132. }
  133. [_popDate showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  134. if (buttonIndex == 0) {//OK
  135. NSLog(@"Input Date : %@%@%@", _popDate.txtYear.text, _popDate.txtMonth.text, _popDate.txtDay.text);
  136. NSString *date = [NSString stringWithFormat:@"%@%@%@",_popDate.txtYear.text,_popDate.txtMonth.text,_popDate.txtDay.text];
  137. answer = date;
  138. if ([date isEqualToString:@""]) {
  139. [_btnInputQuizAnswer setTitle:[CommonUtil currentDate2] forState:UIControlStateNormal];
  140. answer = [CommonUtil currentDate3];
  141. NSLog(@"Current Date : %@",answer);
  142. } else {
  143. NSString *date = [NSString stringWithFormat:@"%@ / %@ / %@",_popDate.txtYear.text,_popDate.txtMonth.text,_popDate.txtDay.text];
  144. [_btnInputQuizAnswer setTitle:date forState:UIControlStateNormal];
  145. }
  146. [_btnInputQuizAnswer setBackgroundImage:[UIImage imageNamed:@"img_input_round_bg_active"] forState:UIControlStateNormal];
  147. [_btnInputQuizAnswer setTitleColor:kUITextColor01 forState:UIControlStateNormal];
  148. }
  149. }];
  150. }
  151. // (delegate) 팝업이 꺼졌을 경우 호출
  152. - (void)dismissPopupView{
  153. _btnNext.enabled = [self isValidRequestInfo];
  154. if ([[_btnInputQuizAnswer titleForState:UIControlStateNormal] isEqualToString:_btnInputQuizAnswer.placeHolder])
  155. {
  156. _btnNext.enabled = NO;
  157. }
  158. }
  159. // 다음버튼 활성화 여부 체크
  160. - (BOOL)isValidRequestInfo {
  161. BOOL result = YES;
  162. QuizModel *quizInfo = (_selectedQuiz != nil) ? (QuizModel *)_selectedQuiz.value : nil;
  163. if (result && quizInfo == nil)
  164. {
  165. result = NO;
  166. }
  167. if (result && quizInfo.isUserEditQuiz)
  168. {
  169. if ([[_txtSelfQuiz.text trim] isEmptyString])
  170. {
  171. result = NO;
  172. }
  173. }
  174. if ([_btnInputQuizAnswer.titleLabel.text isEqualToString:@"정답 날짜 입력"])
  175. {
  176. result = NO;
  177. }
  178. return result;
  179. }
  180. // 퀴즈선택 TextField 터치시 퀴즈 목록 출력
  181. -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
  182. if ([textField isEqual:_txtQuizSelect]) {
  183. [self showQuizList];
  184. return NO;
  185. }
  186. return YES;
  187. }
  188. // 입력 된 퀴즈 여부에 따라 다음버튼 활성화 설정
  189. - (void)textFieldDidEndEditing:(UITextField *)textField{
  190. _btnNext.enabled = _txtSelfQuiz.text.length > 0;
  191. if ([_btnInputQuizAnswer.titleLabel.text isEqualToString:@"정답 날짜 입력"])
  192. {
  193. _btnNext.enabled = NO;
  194. }
  195. }
  196. // TextField Done 버튼 설정
  197. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  198. [textField resignFirstResponder];
  199. return YES;
  200. }
  201. - (void)didReceiveMemoryWarning {
  202. [super didReceiveMemoryWarning];
  203. }
  204. @end