InvitationAnswerViewController.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // InvitationAnswerViewController.m
  3. // kneet2
  4. //
  5. // Created by Jason Lee on 10/21/15.
  6. // Copyright © 2015 ntels. All rights reserved.
  7. //
  8. #import "InvitationAnswerViewController.h"
  9. #import "InvitationAnswerPopupView.h"
  10. #import "RequestHandler.h"
  11. #import "LoginModel.h"
  12. #import "InvitationListViewController.h"
  13. @interface InvitationAnswerViewController () {
  14. InvitationAnswerPopupView *_apopup;
  15. }
  16. @end
  17. #pragma mark - Class Definition
  18. @implementation InvitationAnswerViewController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. // Do any additional setup after loading the view.
  22. [self initUI];
  23. [self prepareViewDidLoad];
  24. }
  25. - (void)initUI {
  26. }
  27. - (void)prepareViewDidLoad {
  28. }
  29. #pragma mark - Main Logic
  30. - (void)requestJoinInvitation:(InvitationModel *)invitation {
  31. //parameters
  32. NSDictionary *parameter = @{@"homegrp_id": invitation.homegrpId,
  33. @"authorization_reply": invitation.sdate,
  34. @"status_code": ksYES};
  35. NSString *path = [NSString stringWithFormat:API_POST_HOMEGROUP_MEMBER_INVITATIONS];
  36. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  37. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  38. return;
  39. }
  40. JDJSONModel *result = (JDJSONModel *) responseObject;
  41. if (result) {//API 성공 ,
  42. NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"축하합니다!\n[%@] 멤버가 되었습니다.", @"축하합니다!\n[%@] 멤버가 되었습니다."), invitation.homegrpName];
  43. [[JDFacade facade] alert:msg completionHander:^{
  44. [[JDFacade facade] dismissModalStack:YES completion:nil];
  45. }];
  46. }
  47. } failure:^(id errorObject) {//답변이 틀린 경우,
  48. JDErrorModel *error = (JDErrorModel *)errorObject;
  49. if ([error.errorCode isEqualToString:@"400-102"]) {//답변이
  50. if ([error.errorCount integerValue] < 3) {//답변이 1,2회 틀린 경우,
  51. [[JDFacade facade] alert:error.errorMessage completionHander:^{
  52. [self popInvitationAnswer:invitation];
  53. }];
  54. } else {//답변이 3회 틀린 경우,
  55. [[JDFacade facade] alert:error.errorMessage completionHander:^{
  56. [self dismissViewControllerAnimated:YES completion:^{
  57. InvitationListViewController *vc = (InvitationListViewController *)[JDFacade facade].currentViewController;
  58. if ([vc isKindOfClass:[InvitationListViewController class]]) {
  59. [vc requestInvitationList];
  60. }
  61. }];
  62. }];
  63. }
  64. } else {
  65. [[JDFacade facade] alert:error.errorMessage];
  66. }
  67. }];
  68. }
  69. - (void)popInvitationAnswer:(InvitationModel *)invitation {
  70. //pop
  71. if (!_apopup) {
  72. _apopup = [[InvitationAnswerPopupView alloc] initFromNib];
  73. }
  74. _apopup.invitation = invitation;
  75. [_apopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  76. if (buttonIndex == 0) {//OK
  77. invitation.sdate = _apopup.selectedDate;
  78. [self requestJoinInvitation:invitation];
  79. }
  80. }];
  81. }
  82. #pragma mark - UI Events
  83. - (IBAction)btnAnswerTouched:(id)sender {
  84. [self popInvitationAnswer:_invitation];
  85. }
  86. - (IBAction)btnCloseTouched:(id)sender {
  87. [self dismissViewControllerAnimated:YES completion:nil];
  88. }
  89. #pragma mark - MemoryWarning
  90. - (void)didReceiveMemoryWarning
  91. {
  92. [super didReceiveMemoryWarning];
  93. // Dispose of any resources that can be recreated.
  94. }
  95. @end