RulesConditionHomeModePopupView.m 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. //
  2. // RulesConditionHomeModePopupView.m
  3. // kneet2
  4. //
  5. // Created by Jason Lee on 11/25/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 "CustomTableView.h"
  13. #import "CustomButton.h"
  14. #import "CustomCheckBox.h"
  15. #import "ImageUtil.h"
  16. #import "RulesConditionHomeModePopupView.h"
  17. @implementation RulesConditionHomeModeTableViewCell
  18. @end
  19. @interface RulesConditionHomeModePopupView () <UITableViewDataSource, UITableViewDelegate> {
  20. NSMutableArray<ModeModel> *_modeList;
  21. BOOL _isNotFirstLoading;
  22. UIImage *_bgCellImage1, *_bgCellImage2;
  23. NSMutableArray<ItemModel> *_checkedItems;
  24. }
  25. @end
  26. @implementation RulesConditionHomeModePopupView
  27. - (id)initFromNib {
  28. for (UIView *view in [CommonUtil nibViews:@"RulesConditionHomeModePopupView"]) {
  29. if ([view isKindOfClass:[RulesConditionHomeModePopupView class]]) {
  30. self = (RulesConditionHomeModePopupView *)view;
  31. //XIB의 경우, 현재 화면 사이즈로 맞춰줘야 함.
  32. self.frame = [UIScreen mainScreen].bounds;
  33. [self initTableViewAsDefaultStyle:_tableView];
  34. UINib *nib = [UINib nibWithNibName:@"RulesConditionHomeModeTableViewCell" bundle:nil];
  35. [_tableView registerNib:nib forCellReuseIdentifier:@"ModeCellIdentifier"];
  36. //Localization
  37. [self.btnConfirm setTitle:NSLocalizedString(@"확인", @"확인") forState:UIControlStateNormal];
  38. [self.btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
  39. UIEdgeInsets insets = UIEdgeInsetsMake(4, 4, 4, 4);
  40. _bgCellImage1 = [ImageUtil resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch img:[UIImage imageNamed:@"tp_01_img_list_bg_01"]];
  41. _bgCellImage2 = [ImageUtil resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch img:[UIImage imageNamed:@"tp_01_img_list_bg_02"]];
  42. }
  43. }
  44. return self;
  45. }
  46. - (void)initTableViewAsDefaultStyle:(CustomTableView *)tableView {
  47. tableView.dataSource = self;
  48. tableView.delegate = self;
  49. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  50. tableView.backgroundColor = [UIColor clearColor];
  51. tableView.tableFooterView = [[UIView alloc] init]; //this call table events;
  52. }
  53. - (void)didMoveToSuperview {
  54. [self requestHomeModes];
  55. }
  56. - (void)setCondition:(ItemModel *)condition {
  57. _condition = condition;
  58. if (_condition.itemSubTypeCode && [_condition.itemSubTypeCode isEqualToString:ksConditionSubTypeCodeHomeMode]) {
  59. //set values.
  60. } else {
  61. _condition.itemName = @"이 홈모드에서만";
  62. _condition.itemSubTypeCode = ksConditionSubTypeCodeHomeMode;
  63. }
  64. }
  65. #pragma mark - Main Logic
  66. - (void)requestHomeModes {
  67. NSString *path = API_GET_DASHBOARD_MODE_LIST;
  68. [[RequestHandler handler] sendAsyncGetRequestAPIPath:path parameters:nil modelClass:[ModeListModel class] completion:^(id responseObject) {
  69. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  70. return;
  71. }
  72. ModeListModel *fetchedModeList = (ModeListModel *)responseObject;
  73. if (fetchedModeList && fetchedModeList.list && fetchedModeList.list.count) {//API 성공 ,
  74. _modeList = (NSMutableArray<ModeModel> *)[[NSMutableArray alloc] initWithArray:fetchedModeList.list];
  75. // for (ModeModel *mode in _tmpItem.modes) {
  76. // [_modeList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
  77. //
  78. // ModeModel *cmode = (ModeModel *)obj;
  79. // if ([mode.modeId isEqualToString:cmode.modeId]) {//동일한 모드일 경우, 저장된 모드로 교체함
  80. // [_modeList replaceObjectAtIndex:idx withObject:mode];
  81. // *stop = YES;
  82. // }
  83. // }];
  84. // }
  85. // for (ModeModel *mode in _tmpItem.modes) {
  86. //
  87. // NSInteger indx = [_modeList indexOfObjectPassingTest:^BOOL(ModeModel *obj, NSUInteger idx, BOOL *stop) {
  88. // return [mode.modeId isEqualToString:obj.modeId];
  89. // }];
  90. //
  91. // if (indx != NSNotFound) {
  92. // ModeModel *tmodel = _modeList[indx];
  93. //
  94. // [[KNFacade facade] setRadioButtonStatus:@YES object:tmodel];
  95. // // id radioStatus = [[KNFacade facade] getRadioButtonStatus:mode];
  96. // // if (radioStatus) {
  97. // // }
  98. // }
  99. // }
  100. // [self setModeContents];
  101. [_tableView reloadData];
  102. }
  103. } failure:^(id errorObject) {
  104. JDErrorModel *error = (JDErrorModel *)errorObject;
  105. [[JDFacade facade] alert:error.errorMessage];
  106. }];
  107. }
  108. #pragma mark - UITableView DataSource & Delegate
  109. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  110. return 1;
  111. }
  112. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  113. return _modeList ? _modeList.count : 0;
  114. }
  115. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  116. CGFloat height = 95.0f;
  117. return height;
  118. }
  119. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  120. ModeModel *mode = _modeList[indexPath.row];
  121. RulesConditionHomeModeTableViewCell *tcell = (RulesConditionHomeModeTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"ModeCellIdentifier"];
  122. tcell.lblMode.text = mode.modeName;
  123. // tcell.chkSelect.delegate = self;
  124. tcell.chkSelect.value = mode;
  125. tcell.chkSelect.checked = [tcell.chkSelect getCheckStatusFromValue];
  126. return tcell;
  127. }
  128. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  129. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  130. RulesConditionHomeModeTableViewCell *tcell = (RulesConditionHomeModeTableViewCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath];
  131. [tcell.chkSelect checkBoxClicked];
  132. [_tableView reloadData];
  133. }
  134. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  135. // Remove seperator inset
  136. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  137. [cell setSeparatorInset:UIEdgeInsetsZero];
  138. }
  139. // Prevent the cell from inheriting the Table View's margin settings
  140. if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
  141. [cell setPreservesSuperviewLayoutMargins:NO];
  142. }
  143. // Explictly set your cell's layout margins
  144. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  145. [cell setLayoutMargins:UIEdgeInsetsZero];
  146. }
  147. }
  148. #pragma mark - UI Events
  149. - (IBAction)btnConfirmTouched:(id)sender {
  150. //validate & set values
  151. NSMutableString *modeValues = [[NSMutableString alloc] init];
  152. NSMutableString *modeValueMsgs = [[NSMutableString alloc] init];
  153. for (ModeModel *mode in _modeList) {
  154. if ([[[JDFacade facade] getCheckBoxStatus:mode] boolValue]) {
  155. NSString *prefix = [modeValues isEmptyString] ? ksEmptyString : @",";
  156. NSString *prefix2 = [modeValues isEmptyString] ? ksEmptyString : @" / ";
  157. [modeValues appendFormat:@"%@%@", prefix, mode.modeId];
  158. [modeValueMsgs appendFormat:@"%@%@", prefix2, mode.modeName];
  159. }
  160. }
  161. if ([modeValues isEmptyString]) {
  162. [[JDFacade facade] alert:NSLocalizedString(@"선택된 항목이 없습니다", @"선택된 항목이 없습니다")];
  163. return;
  164. }
  165. ItemSubModel *subCondition = nil;
  166. if (_condition.subItems && _condition.subItems.count) {
  167. subCondition = _condition.subItems[0];
  168. } else {
  169. subCondition = [[ItemSubModel alloc] init];
  170. _condition.subItems = (NSMutableArray<ItemSubModel> *)[[NSMutableArray alloc] init];
  171. [_condition.subItems addObject:subCondition];
  172. }
  173. subCondition.sourceId = @"VAR";
  174. subCondition.conditionTypeCode = @"01";
  175. subCondition.cmdclsValue = modeValues;
  176. subCondition.cmdclsValueMsg = modeValueMsgs;
  177. [super btnConfirmTouched:sender];
  178. }
  179. @end