ChangeNamePopupView.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // ChangeNamePopupView.m
  3. // kneet2
  4. //
  5. // Created by Jason Lee on 10/12/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "RequestHandler.h"
  10. #import "JDJSONModel.h"
  11. #import "CustomLabel.h"
  12. #import "CustomTextField.h"
  13. #import "ValidateUtil.h"
  14. #import "ChangeNamePopupView.h"
  15. @interface ChangeNamePopupView () <CustomTextFieldDelegate>
  16. {
  17. }
  18. @end
  19. @implementation ChangeNamePopupView
  20. - (id)initFromNib {
  21. for (UIView *view in [CommonUtil nibViews:@"ChangeNamePopupView"]) {
  22. if ([view isKindOfClass:[ChangeNamePopupView class]]) {
  23. self = (ChangeNamePopupView *)view;
  24. //XIB의 경우, 현재 화면 사이즈로 맞춰줘야 함.
  25. self.frame = [UIScreen mainScreen].bounds;
  26. self.lblTitle.text = NSLocalizedString(@"이름변경", @"이름변경");
  27. _txtNickname.keyboardType = UIKeyboardTypeDefault;
  28. _txtNickname.returnKeyType = UIReturnKeyDone;
  29. //Localization
  30. [self.btnConfirm setTitle:NSLocalizedString(@"확인", @"확인") forState:UIControlStateNormal];
  31. [self.btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
  32. }
  33. }
  34. return self;
  35. }
  36. - (void)didMoveToSuperview {
  37. if (!self.superview) {
  38. return;
  39. }
  40. _txtNickname.customTextFieldSuperview = CustomTextFieldSuperviewIsPopupContentView;
  41. }
  42. #pragma mark - Main Logic
  43. - (void)requestChangeNickname {
  44. //parameters
  45. NSDictionary *parameter = @{@"nickname": _txtNickname.text};
  46. NSString *path = [NSString stringWithFormat:API_POST_MEMBER_UPDATE, [JDFacade facade].loginUser.memberId, @"name"];
  47. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  48. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  49. return;
  50. }
  51. JDJSONModel *result = (JDJSONModel *) responseObject;
  52. if (result) {//API 성공 ,
  53. [[JDFacade facade] toast:NSLocalizedString(@"이름이 변경되었습니다", nil)];
  54. [JDFacade facade].loginUser.nickname = _txtNickname.text;
  55. [super btnConfirmTouched:nil];
  56. }
  57. } failure:^(id errorObject) {
  58. JDErrorModel *error = (JDErrorModel *)errorObject;
  59. [[JDFacade facade] alert:error.errorMessage];
  60. }];
  61. }
  62. #pragma mark - UI Events
  63. - (IBAction)btnConfirmTouched:(id)sender {
  64. //validate
  65. if (![ValidateUtil validateTextfiled:_txtNickname type:ValidateTypeNickname title:NSLocalizedString(@"이름", @"이름")]) {
  66. return;
  67. }
  68. [self requestChangeNickname];
  69. }
  70. #pragma mark - CustomTextField
  71. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  72. if ([textField isEqual:_txtNickname]) {
  73. [self btnConfirmTouched:nil];
  74. }
  75. return YES;
  76. }
  77. @end