RulesDetailViewController.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. //
  2. // RulesDetailViewController.m
  3. // kneet
  4. //
  5. // Created by Jason Lee on 3/18/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. @import ObjectiveC.runtime;
  9. #import "JDObject.h"
  10. #import "RequestHandler.h"
  11. #import "RuleModel.h"
  12. #import "CustomCheckBox.h"
  13. #import "CustomLabel.h"
  14. #import "CustomImageView.h"
  15. #import "CustomAlertView.h"
  16. #import "CustomTextView.h"
  17. #import "RulesRegisterViewController.h"
  18. #import "RulesDetailViewController.h"
  19. #import "DeviceModel.h"
  20. #import "RulesViewController.h"
  21. @implementation RulesDetailTitleViewCell
  22. - (void)awakeFromNib {
  23. self.backgroundColor = [UIColor clearColor];
  24. }
  25. @end
  26. @interface RulesDetailTableViewCell () <CustomTextViewDelegate> {
  27. }
  28. @property (weak, nonatomic) ItemModel *item;
  29. @end
  30. @implementation RulesDetailTableViewCell
  31. - (void)awakeFromNib {
  32. self.backgroundColor = [UIColor clearColor];
  33. }
  34. @end
  35. @implementation RulesDetailActivationViewCell
  36. - (void)awakeFromNib {
  37. self.backgroundColor = [UIColor clearColor];
  38. _lblRunTitle.text = NSLocalizedString(@"규칙 활성화", @"규칙 활성화");
  39. }
  40. @end
  41. @implementation RulesDetailDisableViewCell
  42. - (void)awakeFromNib {
  43. self.backgroundColor = [UIColor clearColor];
  44. _lblDesc.text = NSLocalizedString(@"일부 장치 또는 멤버가 삭제되어 비활성 되었습니다\n편집 후 다시 사용해주세요", @"일부 장치 또는 멤버가 삭제되어 비활성 되었습니다\n편집 후 다시 사용해주세요");
  45. }
  46. @end
  47. @interface RulesDetailViewController () <UITableViewDataSource, UITableViewDelegate> {
  48. RuleDetailModel *_ruleDetail;
  49. NSInteger _triggerCount, _actionCount, _conditionCount;
  50. BOOL _isNotFirstLoading;
  51. UIImage *_iconTrigger, *_iconAction;
  52. UIImage *_btnRunBgImageNormal, *_btnRunBgImageHighlight;
  53. CustomButton *_btnRun;
  54. NSMutableArray *_arrayForHeader;
  55. BOOL _testToggle; //for debug
  56. }
  57. @end
  58. #pragma mark - Class Definition
  59. @implementation RulesDetailViewController
  60. - (void)viewDidLoad {
  61. [super viewDidLoad];
  62. // Do any additional setup after loading the view.
  63. [self initUI];
  64. [self prepareViewDidLoad];
  65. }
  66. - (void)initUI {
  67. _tableView.dataSource = self;
  68. _tableView.delegate = self;
  69. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  70. _tableView.backgroundColor = [UIColor clearColor];
  71. _tableView.tableFooterView = [[UIView alloc] init]; //this call table events;
  72. _iconTrigger = [UIImage imageNamed:@"tp_01_img_rule_rbox_icon_trigger"];
  73. _iconAction = [UIImage imageNamed:@"tp_01_img_rule_rbox_icon_action"];
  74. _btnRunBgImageNormal = [UIImage imageNamed:@"tp_01_img_control_switch_onoff_on"];
  75. _btnRunBgImageHighlight = [UIImage imageNamed:@"tp_01_img_control_switch_onoff_off"];
  76. if ([JDFacade facade].loginHomeGroup.level <= 10) {//심플멤버일 경우,
  77. _constraintActionTabHeight.constant = 0;
  78. }
  79. //Localization
  80. [_btnEdit setTitle:NSLocalizedString(@"편집", @"편집") forState:UIControlStateNormal];
  81. [_btnDelete setTitle:NSLocalizedString(@"삭제", @"삭제") forState:UIControlStateNormal];
  82. }
  83. - (void)prepareViewDidLoad {
  84. //룰 상세 조회
  85. // [self requestRuleDetail];
  86. }
  87. - (void)viewWillAppear:(BOOL)animated {
  88. [super viewWillAppear:animated];
  89. self.title = NSLocalizedString(@"홈 규칙 상세",nil);
  90. [self performSelector:@selector(requestRuleDetail) withObject:nil afterDelay:0.0f];
  91. }
  92. #pragma mark - Main Logic
  93. - (void)requestRuleDetail {
  94. //parameters
  95. NSString *path = [NSString stringWithFormat:API_GET_RULE_DETAIL, _rule.homegrpRuleId];
  96. [[RequestHandler handler] sendAsyncGetRequestAPIPath:path parameters:nil modelClass:[RuleDetailModel class] completion:^(id responseObject) {
  97. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  98. return;
  99. }
  100. _ruleDetail = (RuleDetailModel *) responseObject;
  101. if (_ruleDetail) {//API 성공 ,
  102. [self setRuleDetailContents];
  103. }
  104. } failure:^(id errorObject) {
  105. JDErrorModel *error = (JDErrorModel *)errorObject;
  106. [[JDFacade facade] alert:error.errorMessage];
  107. }];
  108. }
  109. + (void)cloneSubItemsForItemSubType:(NSArray<ItemModel> *)items conditions:(NSArray<ItemModel> *)conditions {
  110. for (ItemModel *item in items) {
  111. if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDevice]) {//디바이스일 경우,
  112. item.predDevices = (NSMutableArray<PredefinedDeviceModel> *)[[NSMutableArray alloc] init];
  113. for (ItemSubModel *subItem in item.subItems) {
  114. PredefinedDeviceModel *pdevice = [[PredefinedDeviceModel alloc] initWithSubItem:subItem];
  115. [item.predDevices addObject:pdevice];
  116. if ([pdevice isEqual:item.predDevices.firstObject]) {
  117. pdevice.conditions = (NSMutableArray<ItemModel> *)[[NSMutableArray alloc] initWithArray:conditions];
  118. }
  119. }
  120. } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeMode]) {//모드일 경우,
  121. item.modes = (NSMutableArray<ModeModel> *)[[NSMutableArray alloc] init];
  122. for (ItemSubModel *subItem in item.subItems) {
  123. ModeModel *mode = [[ModeModel alloc] initWithSubItem:subItem];
  124. [item.modes addObject:mode];
  125. if ([mode isEqual:item.modes.firstObject]) {
  126. mode.conditions = (NSMutableArray<ItemModel> *)[[NSMutableArray alloc] initWithArray:conditions];;
  127. }
  128. }
  129. } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeAppPush]) {//푸시일 경우,
  130. item.pushes = (NSMutableArray<ItemSubModel> *)[[NSMutableArray alloc] initWithArray:item.subItems];
  131. for (ItemSubModel *subItem in item.pushes) {
  132. if ([subItem isEqual:item.subItems.firstObject]) {
  133. subItem.conditions = (NSMutableArray<ItemModel> *)[[NSMutableArray alloc] initWithArray:conditions];;
  134. }
  135. }
  136. } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeTimer]) {//타이머일 경우,
  137. item.timers = (NSMutableArray<ItemSubModel> *)[[NSMutableArray alloc] initWithArray:item.subItems];
  138. for (ItemSubModel *subItem in item.timers) {
  139. if ([subItem isEqual:item.subItems.firstObject]) {
  140. subItem.conditions = (NSMutableArray<ItemModel> *)[[NSMutableArray alloc] initWithArray:conditions];;
  141. }
  142. }
  143. } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeGeoFencing]) {//지오펜싱일 경우,
  144. item.mobileDevices = [(NSMutableArray<DeviceModel> *)[NSMutableArray alloc] init];
  145. for (ItemSubModel *subItem in item.subItems) {
  146. DeviceModel *device = [[DeviceModel alloc] initWithSubItem:subItem];
  147. [item.mobileDevices addObject:device];
  148. if ([device isEqual:item.mobileDevices.firstObject]) {
  149. device.conditions = (NSMutableArray<ItemModel> *)[[NSMutableArray alloc] initWithArray:conditions];
  150. }
  151. }
  152. }
  153. }
  154. }
  155. - (void)setRuleDetailContents {
  156. _triggerCount = _ruleDetail.triggers && _ruleDetail.triggers.count ? _ruleDetail.triggers.count : 0;
  157. _actionCount = _ruleDetail.actions && _ruleDetail.actions.count ? _ruleDetail.actions.count : 0;
  158. _conditionCount = _ruleDetail.conditions && _ruleDetail.conditions.count ? _ruleDetail.conditions.count : 0;
  159. //트리거에 컨디션을 넣어줘야함.
  160. [RulesDetailViewController cloneSubItemsForItemSubType:_ruleDetail.triggers conditions:_ruleDetail.conditions];
  161. [RulesDetailViewController cloneSubItemsForItemSubType:_ruleDetail.actions conditions:nil];
  162. [_tableView reloadData];
  163. }
  164. - (void)requestChangeRuleStatus:(NSString *)statusCode {
  165. //parameters
  166. NSDictionary *parameter = @{@"status_code" : statusCode};
  167. NSString *path = [NSString stringWithFormat:API_POST_RULE_STATUS, _ruleDetail.homegrpRuleId];
  168. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  169. _ruleDetail.useYn = [_ruleDetail.useYn boolValue] ? ksNO : ksYES; //toggle
  170. [self changeBtnRunStatus:[_ruleDetail.useYn boolValue]];
  171. [[JDFacade facade] toast:NSLocalizedString(@"변경되었습니다", @"변경되었습니다")];
  172. RulesViewController *vc = [[JDFacade facade] viewControllerOnNaviationController:[RulesViewController class]];
  173. [vc updateRule:_ruleDetail];
  174. } failure:^(id errorObject) {
  175. JDErrorModel *error = (JDErrorModel *)errorObject;
  176. [[JDFacade facade] alert:error.errorMessage];
  177. }];
  178. }
  179. - (void)requestDeleteRule {
  180. NSString *path = [NSString stringWithFormat:API_DELETE_RULE, _ruleDetail.homegrpRuleId];
  181. [[RequestHandler handler] sendAsyncRequestAPIPath:path method:ksHTTPRequestDELETE parameters:nil modelClass:[JDJSONModel class] showLoadingView:YES completion:^(id responseObject) {
  182. [[JDFacade facade] toast:NSLocalizedString(@"삭제되었습니다", @"삭제되었습니다")];
  183. [[JDFacade facade] gotoWishMenu:KNMenuIdRules];
  184. } failure:^(id errorObject) {
  185. JDErrorModel *error = (JDErrorModel *)errorObject;
  186. [[JDFacade facade] alert:error.errorMessage];
  187. }];
  188. }
  189. #pragma mark - UITableView DataSource & Delegate
  190. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  191. return 4 + ([_ruleDetail.useYn isEqualToString:ksKneetRulesDisable] ? 1 : 0);
  192. }
  193. - (NSString *)titleForSectionHeader:(NSInteger)section {
  194. NSString *title = nil;
  195. switch (section) {
  196. case 1:
  197. title = NSLocalizedString(@"언제 실행할까요?", @"언제 실행할까요?");
  198. break;
  199. case 2:
  200. title = NSLocalizedString(@"무엇을 실행할까요?", @"무엇을 실행할까요?");
  201. break;
  202. }
  203. return title;
  204. }
  205. - (UIImage *)imageForSection:(NSInteger)section {
  206. UIImage *image = nil;
  207. switch (section) {
  208. case 1:
  209. image = _iconTrigger;
  210. break;
  211. case 2:
  212. image = _iconAction;
  213. break;
  214. }
  215. return image;
  216. }
  217. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  218. UIView *view = _arrayForHeader.count > section ? _arrayForHeader[section] : nil;
  219. if (!view) {
  220. RulesCreateHeaderTableViewCell *hcell = (RulesCreateHeaderTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"HeaderCellIdentifier"];
  221. CGFloat height = [self tableView:tableView heightForHeaderInSection:section];
  222. hcell.frame = CGRectMake(0, 0, IPHONE_WIDTH, height);
  223. if (section == 0) {//titleCell
  224. hcell.imgvTop.hidden = YES;
  225. hcell.constraintHeaderTitleTop.constant = 10;
  226. }
  227. view = [[UIView alloc] initWithFrame:hcell.frame];
  228. [view addSubview:hcell];
  229. hcell.lblHeaderTitle.text = [self titleForSectionHeader:section];
  230. [_arrayForHeader insertObject:view atIndex:section];
  231. }
  232. return view;
  233. }
  234. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  235. if (section == 1 || section == 2) {//trigger & actions
  236. return 72.0f;
  237. }
  238. return 0.01f;
  239. }
  240. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  241. return 0.01f;
  242. }
  243. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  244. NSInteger count = 1;
  245. if (section == 1) {//triggers
  246. count = _triggerCount;
  247. } else if (section == 2) {//actions
  248. count = _actionCount;
  249. }
  250. return count;
  251. }
  252. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  253. CGFloat height = 0;
  254. if (indexPath.section == 0) {//title
  255. height = 80;
  256. } else if (indexPath.section == 1 || indexPath.section == 2) {//triggers & actions
  257. //calcualate subItemsText
  258. NSArray *items = nil;
  259. if (indexPath.section == 1) {
  260. items = _ruleDetail.triggers;
  261. } else if (indexPath.section == 2) {
  262. items = _ruleDetail.actions;
  263. }
  264. ItemModel *item = items[indexPath.row];
  265. CGFloat adjustHeight = [RulesRegisterViewController heightForSubItems:item isTrigger:indexPath.section == 1];
  266. adjustHeight = adjustHeight > 0 ? adjustHeight + 15 + 20 : adjustHeight;
  267. height = 60 + adjustHeight;
  268. } else if (indexPath.section == 3) {//activation
  269. height = 90.0f;
  270. } else if (indexPath.section == 4) {//disable
  271. height = 52.0f;
  272. }
  273. return height;
  274. }
  275. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  276. UITableViewCell *cell = nil;
  277. if (indexPath.section == 0) {
  278. RulesDetailTitleViewCell *tcell = [tableView dequeueReusableCellWithIdentifier:@"TitleCellIdentifier"];
  279. if (tcell == nil) {
  280. tcell = [[RulesDetailTitleViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TitleCellIdentifier"];
  281. }
  282. tcell.lblRuleTitle.text = _ruleDetail.ruleName;
  283. tcell.lblRuleOwner.text = [NSString stringWithFormat:@"by %@", _ruleDetail.nickname];
  284. cell = tcell;
  285. } else if (indexPath.section == 3) {//액션 셀
  286. RulesDetailActivationViewCell *tcell = [tableView dequeueReusableCellWithIdentifier:@"ActivationCellIdentifier"];
  287. if (tcell == nil) {
  288. tcell = [[RulesDetailActivationViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ActivationCellIdentifier"];
  289. }
  290. tcell.selectionStyle = UITableViewCellSelectionStyleNone;
  291. if (!_btnRun) {
  292. _btnRun = tcell.btnRun;
  293. }
  294. [self changeBtnRunStatus:[_ruleDetail.useYn boolValue]];
  295. if (![tcell.btnRun actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  296. [tcell.btnRun addTarget:self action:@selector(btnRunRuleTouched:) forControlEvents:UIControlEventTouchUpInside];
  297. }
  298. cell = tcell;
  299. } else if (indexPath.section == 4) {//disable
  300. cell = [tableView dequeueReusableCellWithIdentifier:@"DisableCellIdentifier"];
  301. } else {
  302. RulesDetailTableViewCell *tcell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
  303. if (tcell == nil) {
  304. tcell = [[RulesDetailTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CellIdentifier"];
  305. }
  306. NSArray *items = nil;
  307. if (indexPath.section == 1) {
  308. items = _ruleDetail.triggers;
  309. } else if (indexPath.section == 2) {
  310. items = _ruleDetail.actions;
  311. }
  312. ItemModel *item = items[indexPath.row];
  313. [RulesRegisterViewController fillCell:tcell item:item isTrigger:indexPath.section == 1];
  314. tcell.imgvItem.image = [self imageForSection:indexPath.section];
  315. cell = tcell;
  316. }
  317. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  318. return cell;
  319. }
  320. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  321. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  322. }
  323. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  324. // Remove seperator inset
  325. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  326. [cell setSeparatorInset:UIEdgeInsetsZero];
  327. }
  328. // Prevent the cell from inheriting the Table View's margin settings
  329. if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
  330. [cell setPreservesSuperviewLayoutMargins:NO];
  331. }
  332. // Explictly set your cell's layout margins
  333. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  334. [cell setLayoutMargins:UIEdgeInsetsZero];
  335. }
  336. }
  337. #pragma mark - UI Events
  338. - (void)changeBtnRunStatus:(BOOL)isRun {
  339. if (!isRun) {
  340. [_btnRun setTitle:@"Off" forState:UIControlStateNormal];
  341. _btnRun.titleEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
  342. _btnRun.rectForCapBackground = CGRectMake(40, 0, 0, 30);
  343. [_btnRun setBackgroundImage:_btnRunBgImageHighlight forState:UIControlStateNormal];
  344. [_btnRun setBackgroundImage:_btnRunBgImageNormal forState:UIControlStateHighlighted];
  345. } else {
  346. [_btnRun setTitle:@"On" forState:UIControlStateNormal];
  347. _btnRun.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
  348. _btnRun.rectForCapBackground = CGRectMake(30, 0, 0, 40);
  349. [_btnRun setBackgroundImage:_btnRunBgImageNormal forState:UIControlStateNormal];
  350. [_btnRun setBackgroundImage:_btnRunBgImageHighlight forState:UIControlStateHighlighted];
  351. }
  352. }
  353. - (void)btnRunRuleTouched:(id)sender {
  354. if ([_ruleDetail.useYn isEqualToString:ksKneetRulesDisable]) {
  355. [[JDFacade facade] toast:NSLocalizedString(@"일부 장치 또는 멤버가 삭제되어 비활성 되었습니다\n편집 후 다시 사용해주세요", @"일부 장치 또는 멤버가 삭제되어 비활성 되었습니다\n편집 후 다시 사용해주세요")];
  356. return;
  357. }
  358. BOOL isRun = [_ruleDetail.useYn boolValue];
  359. [self requestChangeRuleStatus:isRun ? @"03" : @"02"];
  360. // _testToggle = !_testToggle;
  361. // if (_testToggle) {
  362. // [[LocationHandler handler] checkIn];
  363. // } else {
  364. // [[LocationHandler handler] checkOut];
  365. // }
  366. }
  367. - (void)gotoModifyRule {
  368. RulesRegisterViewController *vc = (RulesRegisterViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"RulesRegisterViewController" storyboardName:@"Rules"];
  369. vc.tmpRuleDetail = _ruleDetail;
  370. PredefinedRuleDetailModel *tmpRuleDetail = [[PredefinedRuleDetailModel alloc] initWithDictionary:
  371. @{@"triggers":@[
  372. @{@"pred_rule_id":@"0", @"pred_item_sequence": @"1", @"item_sub_type_code": ksItemSubTypeCodeTimer, @"item_type_code": @"01", @"item_name":NSLocalizedString(@"특정 시간에", @"특정 시간에")},
  373. @{@"pred_rule_id":@"0", @"pred_item_sequence": @"1", @"item_sub_type_code": ksItemSubTypeCodeGeoFencing, @"item_type_code": @"01", @"item_name":NSLocalizedString(@"귀가 또는 외출 시", @"귀가 또는 외출 시")},
  374. @{@"pred_rule_id":@"0", @"pred_item_sequence": @"1", @"item_sub_type_code": ksItemSubTypeCodeMode, @"item_type_code": @"01", @"item_name":NSLocalizedString(@"홈 모드가 바뀔 때", @"홈 모드가 바뀔 때")},
  375. @{@"pred_rule_id":@"0", @"pred_item_sequence": @"1", @"item_sub_type_code": ksItemSubTypeCodeDevice, @"item_type_code": @"01", @"item_name":NSLocalizedString(@"집에 변화가 일어날 때", @"집에 변화가 일어날 때")}
  376. ]} error:nil];
  377. vc.tmpPredRuleDetail = tmpRuleDetail;
  378. [self.navigationController pushViewController:vc animated:YES];
  379. }
  380. - (IBAction)btnEditTouched:(id)sender {
  381. if ([_ruleDetail.useYn isEqualToString:ksKneetRulesDisable]) {//삭제된 장치가 있을 경우,
  382. NSMutableString *deletedDevices = [[NSMutableString alloc] init];
  383. for (ItemModel *item in _ruleDetail.actions) {
  384. if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDevice]) {//디바이스일 경우,
  385. for (PredefinedDeviceModel *pdevice in item.predDevices) {
  386. if ([pdevice.deleteYn boolValue]) {//삭제된 장치를 추가
  387. NSString *prefix = [deletedDevices isEmptyString] ? @"" : @", ";
  388. [deletedDevices appendFormat:@"%@%@", prefix, pdevice.deviceName];
  389. }
  390. }
  391. } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeGeoFencing]) {//지오펜싱일 경우,
  392. for (DeviceModel *device in item.mobileDevices) {
  393. if ([device.deleteYn boolValue]) {//삭제된 장치를 추가
  394. NSString *prefix = [deletedDevices isEmptyString] ? @"" : @", ";
  395. [deletedDevices appendFormat:@"%@%@(%@)", prefix, device.nickname, device.deviceName];
  396. }
  397. }
  398. }
  399. }
  400. for (ItemModel *item in _ruleDetail.actions) {
  401. if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDevice]) {//디바이스일 경우,
  402. for (PredefinedDeviceModel *pdevice in item.predDevices) {
  403. if ([pdevice.deleteYn boolValue]) {//삭제된 장치를 추가
  404. NSString *prefix = [deletedDevices isEmptyString] ? @"" : @", ";
  405. [deletedDevices appendFormat:@"%@%@", prefix, pdevice.deviceName];
  406. }
  407. }
  408. } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeAppPush]) {//푸시일 경우,
  409. for (ItemSubModel *push in item.pushes) {
  410. if ([push.deleteYn boolValue]) {//삭제된 장치를 추가
  411. NSString *prefix = [deletedDevices isEmptyString] ? @"" : @", ";
  412. [deletedDevices appendFormat:@"%@%@", prefix, push.sourceName];
  413. }
  414. }
  415. }
  416. }
  417. NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"삭제된 장치 또는 멤버를 정리 후 진행합니다\n\n%@", @"삭제된 장치 또는 멤버를 정리 후 진행합니다\n\n%@"), deletedDevices];
  418. CustomAlertView *alert = [[CustomAlertView alloc] initWithTitle:NSLocalizedString(@"알림", @"알림") message:msg delegate:nil OKButtonTitle:NSLocalizedString(@"확인", @"확인") cancelButtonTitle:NSLocalizedString(@"취소", @"취소")];
  419. [alert showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  420. if (buttonIndex == 0) {//OK
  421. [self gotoModifyRule];
  422. }
  423. }];
  424. return;
  425. }
  426. [self gotoModifyRule];
  427. }
  428. - (IBAction)btnDeleteTouched:(id)sender {
  429. NSString *messge = NSLocalizedString(@"삭제하시겠습니까?", @"삭제하시겠습니까?");
  430. CustomAlertView *alert = [[CustomAlertView alloc] initWithTitle:NSLocalizedString(@"알림", @"알림") message:messge delegate:self OKButtonTitle:NSLocalizedString(@"삭제", @"삭제") cancelButtonTitle:NSLocalizedString(@"취소", @"취소")];
  431. [alert showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  432. if (buttonIndex == 0) {
  433. [self requestDeleteRule];
  434. }
  435. }];
  436. }
  437. #pragma mark - MemoryWarning
  438. - (void)didReceiveMemoryWarning
  439. {
  440. [super didReceiveMemoryWarning];
  441. // Dispose of any resources that can be recreated.
  442. }
  443. @end