|
|
@@ -0,0 +1,231 @@
|
|
|
+//
|
|
|
+// SignUpQuizSetViewController.m
|
|
|
+// OneCable
|
|
|
+//
|
|
|
+// Created by nComz on 2017. 5. 22..
|
|
|
+// Copyright © 2017년 ntels. All rights reserved.
|
|
|
+//
|
|
|
+
|
|
|
+#import "SignUpQuizSetViewController.h"
|
|
|
+#import "CustomTextField.h"
|
|
|
+#import "CustomDatePopupView.h"
|
|
|
+#import "RequestHandler.h"
|
|
|
+#import "ImageUtil.h"
|
|
|
+
|
|
|
+/**
|
|
|
+ 해당 메뉴는 마스터만 출력
|
|
|
+ **/
|
|
|
+@interface SignUpQuizSetViewController () <CustomTextFieldDelegate> {
|
|
|
+
|
|
|
+ DataSelectListModel *_quizList;
|
|
|
+ DataSelectModel *_selectedQuiz;
|
|
|
+ CustomDatePopupView *_popDate;
|
|
|
+ NSString *answer;
|
|
|
+}
|
|
|
+
|
|
|
+@end
|
|
|
+
|
|
|
+@implementation SignUpQuizSetViewController
|
|
|
+
|
|
|
+- (void)viewDidLoad {
|
|
|
+ [super viewDidLoad];
|
|
|
+
|
|
|
+ [self initUI];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)viewWillAppear:(BOOL)animated {
|
|
|
+ [super viewWillAppear:animated];
|
|
|
+ [self requestInviteQuizList];
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+- (void)initUI {
|
|
|
+ [self.navigationController.navigationBar setHidden:YES];
|
|
|
+ self.navigationController.interactivePopGestureRecognizer.enabled = NO;
|
|
|
+
|
|
|
+ [_lblStep setColor:kUITextColor03 text:[NSString stringWithFormat:@"%@", @"/ 5"]];
|
|
|
+
|
|
|
+ answer = @"";
|
|
|
+ _btnNext.enabled = NO;
|
|
|
+ [self showDirectInputArea:NO];
|
|
|
+
|
|
|
+ _txtQuizSelect.delegate = self;
|
|
|
+ _txtSelfQuiz.delegate = self;
|
|
|
+
|
|
|
+ _txtQuizSelect.keyboardType = UIKeyboardTypeDefault;
|
|
|
+ _txtQuizSelect.returnKeyType = UIReturnKeyDone;
|
|
|
+
|
|
|
+ _txtQuizSelect.placeholder = @"퀴즈를 선택하세요.";
|
|
|
+}
|
|
|
+
|
|
|
+-(void)showDirectInputArea:(BOOL)isShow
|
|
|
+{
|
|
|
+ _viewSelfQuiz.hidden = !isShow;
|
|
|
+
|
|
|
+ if(_viewSelfQuiz.isHidden){
|
|
|
+ _viewHeight.constant = 0;
|
|
|
+ } else{
|
|
|
+ _viewHeight.constant = 177.0f;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)updateUI {
|
|
|
+ _btnNext.enabled = [self isValidRequestInfo];
|
|
|
+
|
|
|
+ if (_selectedQuiz != nil) {
|
|
|
+ QuizModel *info = (QuizModel *)_selectedQuiz.value;
|
|
|
+ [self showDirectInputArea:[info isUserEditQuiz]];
|
|
|
+ _txtQuizSelect.text = _selectedQuiz.title;
|
|
|
+ } else {
|
|
|
+ [self showDirectInputArea:NO];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)requestInviteQuizList {
|
|
|
+
|
|
|
+ NSString *path = [NSString stringWithFormat:API_POST_HOMEGROUP_INVITE_QUIZ];
|
|
|
+
|
|
|
+ [[RequestHandler handler] sendAsyncGetRequestAPIPath:path parameters:nil modelClass:[QuizListModel class] completion:^(id responseObject) {
|
|
|
+
|
|
|
+ QuizListModel *quizList = (QuizListModel *)responseObject;
|
|
|
+
|
|
|
+ NSLog(@"Response : %@", responseObject);
|
|
|
+ _quizList = [[DataSelectListModel alloc] init];
|
|
|
+ _quizList.title = @"퀴즈 선택";
|
|
|
+
|
|
|
+ for (QuizModel *info in quizList.quizList) {
|
|
|
+ DataSelectModel *data = [[DataSelectModel alloc] init];
|
|
|
+ data.title = info.quiz;
|
|
|
+ data.value = info;
|
|
|
+ [_quizList.list addObject:data];
|
|
|
+ }
|
|
|
+
|
|
|
+ } failure:^(id errorObject) {
|
|
|
+ JDErrorModel *error = (JDErrorModel *)errorObject;
|
|
|
+ [[JDFacade facade] alert:error.errorMessage];
|
|
|
+ }];
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+- (void)requestQuizUpdate{
|
|
|
+ QuizModel *quizInfo = (QuizModel *)_selectedQuiz.value;
|
|
|
+ NSLog(@"Quiz Info : %@", quizInfo);
|
|
|
+
|
|
|
+ NSString *quiz = quizInfo.quiz;
|
|
|
+ if (quizInfo.isUserEditQuiz) {
|
|
|
+ quiz = [_txtSelfQuiz.text trim];
|
|
|
+ }
|
|
|
+
|
|
|
+ //parameters
|
|
|
+ NSDictionary *parameter = @{@"type": @"quiz" ,
|
|
|
+ @"quiz": quiz,
|
|
|
+ @"quiz_id":quizInfo.quizId,
|
|
|
+ @"status_code":quizInfo.statusCode,
|
|
|
+ @"answer":answer};
|
|
|
+
|
|
|
+ NSString *path = [[JDFacade facade] getUrlWithCustGroupIDAndMemberID:API_POST_MEMBER_UPDATE];
|
|
|
+
|
|
|
+ [[RequestHandler handler] sendAsyncPutRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
|
|
|
+
|
|
|
+// [JDFacade facade].loginUser.quiz = quiz;
|
|
|
+ UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"IDSetViewController" storyboardName:@"SignUp"];
|
|
|
+
|
|
|
+ [self.navigationController pushViewController:vc animated:YES];
|
|
|
+
|
|
|
+ } failure:^(id errorObject) {
|
|
|
+ JDErrorModel *error = (JDErrorModel *)errorObject;
|
|
|
+ [[JDFacade facade] alert:error.errorMessage];
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+-(void)showQuizList{
|
|
|
+ [[JDFacade facade] selectDatas:self listInfo:_quizList completion:^(DataSelectModel *seleced) {
|
|
|
+ _selectedQuiz = seleced;
|
|
|
+ _txtQuizSelect.text = _selectedQuiz.title;
|
|
|
+ [self updateUI];
|
|
|
+
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+- (IBAction)btnCancelTouched:(id)sender {
|
|
|
+ [self dismissViewControllerAnimated:YES completion:nil];
|
|
|
+}
|
|
|
+
|
|
|
+- (IBAction)btnNextTouched:(id)sender {
|
|
|
+// TODO : 퀴즈 업데이트? cust,group id 없음
|
|
|
+// [self requestQuizUpdate];
|
|
|
+ UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"IDSetViewController" storyboardName:@"SignUp"];
|
|
|
+
|
|
|
+ [self.navigationController pushViewController:vc animated:YES];
|
|
|
+}
|
|
|
+
|
|
|
+- (IBAction)btnInputQuizTouched:(id)sender {
|
|
|
+ if (_popDate == nil) {
|
|
|
+ _popDate = [[CustomDatePopupView alloc] initWithTitle:@"정답 날짜 입력"];
|
|
|
+ }
|
|
|
+
|
|
|
+ [_popDate showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
|
|
|
+ if (buttonIndex == 0) {//OK
|
|
|
+ NSLog(@"Input Date : %@%@%@", _popDate.txtYear.text, _popDate.txtMonth.text, _popDate.txtDay.text);
|
|
|
+
|
|
|
+ NSString *date = [NSString stringWithFormat:@"%@%@%@",_popDate.txtYear.text,_popDate.txtMonth.text,_popDate.txtDay.text];
|
|
|
+
|
|
|
+ answer = date;
|
|
|
+ if ([date isEqualToString:@""]) {
|
|
|
+ [_btnInputQuizAnswer setTitle:[CommonUtil currentDate2] forState:UIControlStateNormal];
|
|
|
+ answer = [CommonUtil currentDate3];
|
|
|
+ } else {
|
|
|
+ NSString *date = [NSString stringWithFormat:@"%@ / %@ / %@",_popDate.txtYear.text,_popDate.txtMonth.text,_popDate.txtDay.text];
|
|
|
+ [_btnInputQuizAnswer setTitle:date forState:UIControlStateNormal];
|
|
|
+ }
|
|
|
+ [_btnInputQuizAnswer setBackgroundImage:[UIImage imageNamed:@"img_input_round_bg_active"] forState:UIControlStateNormal];
|
|
|
+ [_btnInputQuizAnswer setTitleColor:kUITextColor01 forState:UIControlStateNormal];
|
|
|
+ }
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+- (BOOL)isValidRequestInfo {
|
|
|
+ BOOL result = YES;
|
|
|
+ QuizModel *quizInfo = (_selectedQuiz != nil) ? (QuizModel *)_selectedQuiz.value : nil;
|
|
|
+
|
|
|
+ if (result && quizInfo == nil)
|
|
|
+ {
|
|
|
+ result = NO;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (result && quizInfo.isUserEditQuiz)
|
|
|
+ {
|
|
|
+ if ([[_txtSelfQuiz.text trim] isEmptyString])
|
|
|
+ {
|
|
|
+ result = NO;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
|
|
|
+ if ([textField isEqual:_txtQuizSelect]) {
|
|
|
+ [self showQuizList];
|
|
|
+ return NO;
|
|
|
+ }
|
|
|
+ return YES;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)textFieldDidEndEditing:(UITextField *)textField{
|
|
|
+ if (_txtSelfQuiz.text.length > 0) {
|
|
|
+
|
|
|
+ UIImage *active = [ImageUtil stretchedImage:[UIImage imageNamed:@"img_input_round_bg_active"] expectSize:CGSizeMake(_txtSelfQuiz.frame.size.width, _txtSelfQuiz.frame.size.height)];
|
|
|
+ [_txtSelfQuiz setBackground:active];
|
|
|
+ _btnNext.enabled = YES;
|
|
|
+ } else {
|
|
|
+ _btnNext.enabled = NO;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)didReceiveMemoryWarning {
|
|
|
+ [super didReceiveMemoryWarning];
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+@end
|