RulesDetailViewController.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. //
  2. // RulesDetailViewController.m
  3. // kneet2
  4. //
  5. // Created by Jason Lee on 11/30/15.
  6. // Copyright © 2015 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "RequestHandler.h"
  10. #import "RuleModel.h"
  11. #import "CustomTableView.h"
  12. #import "CustomLabel.h"
  13. #import "CustomButton.h"
  14. #import "CustomImageView.h"
  15. #import "UIImageView+WebCache.h"
  16. #import "RulesDetailViewController.h"
  17. #import "RulesConditionViewController.h"
  18. #import "DeviceModel.h"
  19. #import "RulesAddViewController.h"
  20. @implementation RulesDetailTitleTableViewCell
  21. @end
  22. @implementation RulesDetailHeaderTableViewCell
  23. @end
  24. @implementation RulesDetailTableViewCell
  25. @end
  26. @implementation RulesDetailPushTableViewCell
  27. @end
  28. @implementation RulesDetailConditionHeaderTableViewCell
  29. @end
  30. @implementation RulesDetailConditionTableViewCell
  31. @end
  32. @implementation RulesDetailExecutionTableViewCell
  33. @end
  34. @implementation RulesDetailFooterTableViewCell
  35. @end
  36. @interface RulesDetailViewController () {
  37. RuleDetailModel *_ruleDetail;
  38. NSMutableArray<ItemModel> *_triggers, *_actions, *_conditions;
  39. NSMutableArray *_arrayForHeader, *_arrayForFooter;
  40. RulesConditionViewController *_rcv;
  41. NSInteger _sectionCount;
  42. BOOL _hasDeviceAction, _hasPushAction, _hasCondition; //요일 조건 외의 조건
  43. }
  44. @end
  45. #pragma mark - Class Definition
  46. @implementation RulesDetailViewController
  47. - (void)viewDidLoad {
  48. [super viewDidLoad];
  49. // Do any additional setup after loading the view.
  50. [self initProperties];
  51. [self initUI];
  52. [self prepareViewDidLoad];
  53. }
  54. - (void)initProperties {
  55. _arrayForHeader = [[NSMutableArray alloc] init];
  56. _arrayForFooter = [[NSMutableArray alloc] init];
  57. }
  58. - (void)initUI {
  59. if (![JDFacade facade].loginUser.isHomehubOnline) {
  60. _lblTitle.text = @"홈허브 오프라인";
  61. [_lblTitle setColor:kUITextColor02 text:_lblTitle.text];
  62. return;
  63. }
  64. [self initTableViewAsDefaultStyle:_tableView];
  65. [self setThingsPopoverOptions];
  66. }
  67. - (void)prepareViewDidLoad {
  68. [self requestRuleDetail];
  69. }
  70. - (void)setThingsPopoverOptions {
  71. //set Popover Contents
  72. __weak typeof(self) weakSelf = self;
  73. _popooverOptionArray = [[NSMutableArray alloc] init];
  74. [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"새로 고침",nil),
  75. @"iconName": @"tp_01_img_bg_morepopup_icon_refresh",
  76. @"target": weakSelf,
  77. @"selector": [NSValue valueWithPointer:@selector(requestRuleDetail)]}];
  78. if ([JDFacade facade].loginUser.level > 10) {//파워유저 이상일 경우,
  79. [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"편집", @"편집"),
  80. @"iconName": @"tp_01_img_bg_morepopup_icon_group_deviceadd",
  81. @"target": weakSelf,
  82. @"selector": [NSValue valueWithPointer:@selector(editRule)]}];
  83. [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"삭제", @"삭제"),
  84. @"iconName": @"tp_01_img_bg_morepopup_icon_group_deviceadd",
  85. @"target": weakSelf,
  86. @"selector": [NSValue valueWithPointer:@selector(deleteRule)]}];
  87. }
  88. }
  89. - (void)editRule {
  90. RulesAddViewController *vc = (RulesAddViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"RulesAddViewController" storyboardName:@"Rules"];
  91. vc.refRuleDetail = _ruleDetail;
  92. [self presentViewController:vc animated:YES completion:nil];
  93. }
  94. - (void)deleteRule {
  95. [[JDFacade facade] confirmTitle:@"규칙 삭제" message:@"규칙을 삭제하시겠습니까?" completion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  96. if (buttonIndex == 0) {//OK
  97. [self requestDeleteRule];
  98. }
  99. }];
  100. }
  101. #pragma mark - Main Logic
  102. - (void)requestRuleDetail {
  103. NSString *path = [NSString stringWithFormat:API_GET_RULE_DETAIL, _refRule.homegrpRuleId];
  104. [[RequestHandler handler] sendAsyncGetRequestAPIPath:path parameters:nil modelClass:[RuleDetailModel class] completion:^(id responseObject) {
  105. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  106. return;
  107. }
  108. _ruleDetail = (RuleDetailModel *) responseObject;
  109. if (_ruleDetail) {//API 성공 ,
  110. [self setContents];
  111. }
  112. } failure:^(id errorObject) {
  113. JDErrorModel *error = (JDErrorModel *)errorObject;
  114. [[JDFacade facade] alert:error.errorMessage];
  115. }];
  116. }
  117. - (void)setDeviceValue:(NSMutableArray<ItemModel> *)items {
  118. NSArray *matchedArray = [_triggers filteredArrayUsingPredicateFormat:@"itemTypeCode == %@", ksItemSubTypeCodeDevice];
  119. for (ItemModel *item in matchedArray) {//device items
  120. for (ItemSubModel *subItem in item.subItems) {
  121. [[JDFacade facade] setRadioButtonStatus:@YES object:subItem];
  122. [[JDFacade facade] setCheckBoxStatus:@YES object:subItem];
  123. }
  124. }
  125. }
  126. - (void)setContents {
  127. _triggers = (NSMutableArray<ItemModel> *)[[NSMutableArray alloc] initWithArray:_ruleDetail.triggers];
  128. _actions = (NSMutableArray<ItemModel> *)[[NSMutableArray alloc] initWithArray:_ruleDetail.actions];
  129. _conditions = (NSMutableArray<ItemModel> *)[[NSMutableArray alloc] initWithArray:_ruleDetail.conditions];
  130. [self setDeviceValue:_triggers];
  131. [self setDeviceValue:_actions];
  132. [self setDeviceValue:_conditions];
  133. _hasDeviceAction = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeDevice];
  134. _hasPushAction = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeAppPush];
  135. _hasCondition = [_conditions objectKey:@"itemSubTypeCode" eqaulToString:ksConditionSubTypeCodeHomeMode];
  136. _hasCondition = [_conditions objectKey:@"itemSubTypeCode" eqaulToString:ksConditionSubTypeCodeDueDate] ? YES : _hasCondition;
  137. _hasCondition = [_conditions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeDevice] ? YES : _hasCondition;
  138. [_tableView reloadData];
  139. }
  140. - (void)requestDeleteRule {
  141. NSString *path = [NSString stringWithFormat:API_DELETE_RULE, _ruleDetail.homegrpRuleId];
  142. [[RequestHandler handler] sendAsyncRequestAPIPath:path method:ksHTTPRequestDELETE parameters:nil modelClass:[JDJSONModel class] showLoadingView:YES completion:^(id responseObject) {
  143. [[JDFacade facade] toast:NSLocalizedString(@"삭제되었습니다", @"삭제되었습니다")];
  144. [[JDFacade facade] gotoWishMenu:KNMenuIdRules];
  145. } failure:^(id errorObject) {
  146. JDErrorModel *error = (JDErrorModel *)errorObject;
  147. [[JDFacade facade] alert:error.errorMessage];
  148. }];
  149. }
  150. - (void)requestChangeRuleStatus {
  151. //parameters
  152. NSDictionary *parameter = @{@"status_code" : [_ruleDetail.useYn boolValue] ? @"03" : @"02"};
  153. NSString *path = [NSString stringWithFormat:API_POST_RULE_STATUS, _ruleDetail.homegrpRuleId];
  154. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  155. _ruleDetail.useYn = [_ruleDetail.useYn boolValue] ? ksNO : ksYES; //toggle
  156. if ([_ruleDetail.useYn boolValue]) {
  157. [[JDFacade facade] toast:@"규칙을 다시 시작합니다"];
  158. } else {
  159. [[JDFacade facade] toast:@"규칙을 중단합니다"];
  160. }
  161. // [self changeBtnRunStatus:[rule.useYn boolValue]];
  162. [_tableView reloadData];
  163. } failure:^(id errorObject) {
  164. JDErrorModel *error = (JDErrorModel *)errorObject;
  165. [[JDFacade facade] alert:error.errorMessage];
  166. }];
  167. }
  168. #pragma mark - UITableView DataSource & Delegate
  169. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  170. return 6;
  171. }
  172. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  173. NSInteger count = 0;
  174. if (section == 0 || section == 5) {//title
  175. count = 1;
  176. } else if (section == 1) {//triggers
  177. count = _triggers && _triggers.count ? _triggers.count : 0;
  178. } else if (section == 2) {//actions
  179. ItemModel *deviceItem = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeDevice];
  180. count = deviceItem.subItems && deviceItem.subItems.count ? deviceItem.subItems.count : 0;
  181. } else if (section == 3) {
  182. count = _hasPushAction;
  183. } else if (section == 4) {
  184. count = _hasCondition;
  185. }
  186. return count;
  187. }
  188. - (NSString *)headerTitleForSection:(NSInteger)section {
  189. NSString *title = nil;
  190. if (section == 1) {//trigger
  191. title = @"이 때가 되면";
  192. if (_triggers && _triggers.count) {
  193. ItemModel *item = _triggers[0];
  194. if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDevice]) {
  195. title = @"장치 상태가 바뀔 때";
  196. } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeTimer]) {
  197. title = @"이 시간마다";
  198. } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeHeat]) {
  199. title = @"더울때 / 추울때";
  200. } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDaylight]) {
  201. title = @"해뜰때 / 질때";
  202. }
  203. }
  204. } else if (section == 2) {//action
  205. title = @"이 장치를 실행";
  206. } else if (section == 3) {//pushes
  207. title = @"알림 메시지";
  208. }
  209. return title;
  210. }
  211. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  212. UIView *view = _arrayForHeader.count > section ? _arrayForHeader[section] : nil;
  213. if (!view) {
  214. if (section == 0 || section == 5) {//title
  215. view = [[UIView alloc] init];
  216. } else if (section == 1 || section == 2 || section == 3) {
  217. RulesDetailHeaderTableViewCell *hcell = (RulesDetailHeaderTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"HeaderCellIdentifier"];
  218. view = [[UIView alloc] initWithFrame:hcell.contentView.frame];
  219. [view addSubview:hcell];
  220. hcell.lblTitle.text = [self headerTitleForSection:section];
  221. } else if (section == 4) {//conditions
  222. RulesDetailConditionHeaderTableViewCell *hcell = (RulesDetailConditionHeaderTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"ConditionHeaderCellIdentifier"];
  223. view = [[UIView alloc] initWithFrame:hcell.contentView.frame];
  224. [view addSubview:hcell];
  225. }
  226. if (_arrayForHeader.count == section) {
  227. [_arrayForHeader insertObject:view atIndex:section];
  228. }
  229. } else {
  230. if ((section == 2 && !_hasDeviceAction) || (section == 3 && !_hasPushAction) || (section == 4 && !_hasCondition)) {
  231. view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, CGFLOAT_MIN)];
  232. } else if (section == 1 || section == 2 || section == 3) {
  233. RulesDetailHeaderTableViewCell *hcell = (RulesDetailHeaderTableViewCell *)view.subviews[0];
  234. hcell.lblTitle.text = hcell.lblTitle.text = [self headerTitleForSection:section];
  235. }
  236. }
  237. return view;
  238. }
  239. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  240. CGFloat height = 90.0f;
  241. if (section == 0 || section == 5) {
  242. height = CGFLOAT_MIN;
  243. } else if (section == 2) {
  244. height = _hasDeviceAction ? 90.0f : CGFLOAT_MIN;
  245. } else if (section == 3) {
  246. height = _hasPushAction ? 90.0f : CGFLOAT_MIN;
  247. } else if (section == 4) {
  248. height = _hasCondition ? 90.0f : CGFLOAT_MIN;
  249. }
  250. return height;
  251. }
  252. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  253. UIView *view = _arrayForFooter.count > section ? _arrayForFooter[section] : nil;
  254. if (!view) {
  255. RulesDetailFooterTableViewCell *hcell = (RulesDetailFooterTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"FooterCellIdentifier"];
  256. view = [[UIView alloc] initWithFrame:hcell.contentView.frame];
  257. [view addSubview:hcell];
  258. if (_arrayForHeader.count == section) {
  259. [_arrayForHeader insertObject:view atIndex:section];
  260. }
  261. }
  262. return view;
  263. }
  264. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  265. CGFloat height = 15.0f;
  266. if (section == 0 || section == 5) {
  267. height = CGFLOAT_MIN;
  268. } else if (section == 2) {
  269. height = _hasDeviceAction ? 15.0f : CGFLOAT_MIN;
  270. } else if (section == 3) {
  271. height = _hasPushAction ? 15.0f : CGFLOAT_MIN;
  272. } else if (section == 4) {
  273. height = _hasCondition ? 15.0f : CGFLOAT_MIN;
  274. }
  275. return height;
  276. }
  277. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  278. CGFloat height = 0.0f;
  279. NSInteger section = indexPath.section;
  280. if (section == 0) {//title
  281. height = 50;
  282. } else if (section == 1) {//triggers
  283. height = 95;
  284. } else if (section == 2) {//actions
  285. height = 95;
  286. } else if (section == 3) {//push-message
  287. ItemModel *pushItem = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeAppPush];
  288. ItemSubModel *push = pushItem.subItems[0];
  289. CGFloat width = IPHONE_WIDTH - 90;
  290. CustomLabel *lblTemp = [[CustomLabel alloc] initWithFrame:CGRectMake(0, 0, width, 30)];
  291. lblTemp.font = [UIFont systemFontOfSize:kUIFontSize02];
  292. lblTemp.numberOfLines = 0;
  293. CGFloat adjustHeight = [CommonUtil getSizeFromString:push.cmdclsValue font:lblTemp.font width:width].height;
  294. adjustHeight = adjustHeight < 30 ? 0 : adjustHeight - 30;
  295. height = 80 + adjustHeight;
  296. } else if (section == 4) {//conditions
  297. if (!_rcv) {
  298. _rcv = [CommonUtil instantiateViewControllerWithIdentifier:@"RulesConditionViewController" storyboardName:@"Rules"];
  299. [self addChildViewController:_rcv];
  300. [_rcv didMoveToParentViewController:self];
  301. }
  302. height = _rcv.tableHeight;
  303. } else if (section == 5) {//execution
  304. height = [JDFacade facade].loginUser.level == 90 ? 220.0f : 220.0f - 80.0f; //마스터만 규칙 실행 여부를 설정 가능함.
  305. }
  306. return height;
  307. }
  308. - (void)configureTriggerCell:(RulesDetailTableViewCell *)cell item:(ItemModel *)item {
  309. ItemSubModel *subItem = nil;
  310. if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDevice]) {//장치일 경우
  311. subItem = [item.subItems matchedObjectName:ksCustomRadioButtonStatus condition:YES];
  312. cell.lblItem.text = subItem.sourceName;
  313. if ([subItem.deleteYn boolValue]) {
  314. [cell.lblItem setStrikethrough:cell.lblItem.text];
  315. }
  316. cell.lblSubItem.text = subItem.sourceSubName;
  317. //노드의 액션 값을 세팅함.
  318. if (subItem.cmdclsValueList && subItem.cmdclsValueList.count) {//커맨드클래스 밸루 리스트가 있을 경우,
  319. CmdClsValueModel *cmdclsValue = [subItem.cmdclsValueList matchedObjectName:ksCustomRadioButtonStatus condition:YES];
  320. cell.lblCondition.text = [DeviceModel contentValueMsgByCmdClsCode:subItem.cmdclsCode cmdclsTypeId:(NSString *)subItem.cmdclsTypeId contentValue:cmdclsValue.cmdclsValue];
  321. } else {
  322. cell.lblCondition.text = subItem.cmdclsValueMsg;
  323. }
  324. cell.lblCondition.hidden = NO;
  325. } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeTimer]) {
  326. subItem = item.subItems && item.subItems.count ? item.subItems[0] : nil;
  327. if (subItem) {
  328. NSInteger phour = [subItem.hour integerValue];
  329. NSString *period = phour < 12 ? @"AM" : @"PM";//NSLocalizedString(@"오전", @"오전") : NSLocalizedString(@"오후", @"오후");
  330. if ([period isEqualToString:NSLocalizedString(@"오후", @"오후")]) {
  331. if (phour > 12) {
  332. phour -= 12;
  333. }
  334. }
  335. NSString *title = [NSString stringWithFormat:@"%@ %zd:%@", period, phour, subItem.minute];
  336. // NSDictionary *titleColor = @{NSForegroundColorAttributeName : kUITextColor02};
  337. cell.lblItem.text = title;
  338. cell.lblSubItem.text = [self daysOfWeekAtSubItem];
  339. cell.lblCondition.hidden = YES;
  340. }
  341. } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDaylight]) {
  342. subItem = item.subItems && item.subItems.count ? item.subItems[0] : nil;
  343. if (subItem) {
  344. NSString *title = [subItem.sourceId isEqualToString:@"sunriseUtcTime"] ? @"해뜰때" : @"해질때";
  345. cell.lblItem.text = title;
  346. cell.lblSubItem.text = [NSString stringWithFormat:@"%@ / %@", subItem.sourceName, [self daysOfWeekAtSubItem]];
  347. cell.lblCondition.hidden = YES;
  348. }
  349. } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeHeat]) {
  350. subItem = item.subItems && item.subItems.count ? item.subItems[0] : nil;
  351. if (subItem) {
  352. NSString *title = [subItem.conditionTypeCode isEqualToString:@"05"] ? @"더울때" : @"추울때";
  353. cell.lblItem.text = title;
  354. cell.lblSubItem.text = [NSString stringWithFormat:@"%@ / %@℃ / %@", subItem.sourceName, subItem.cmdclsValue, [self daysOfWeekAtSubItem]];
  355. cell.lblCondition.hidden = YES;
  356. }
  357. }
  358. [cell.imgvIcon sd_setImageWithURL:[NSURL URLWithString:subItem.imageFileName] placeholderImage:nil options:SDWebImageRefreshCached];
  359. }
  360. - (NSString *)daysOfWeekAtSubItem {
  361. NSString *daysOfWeek = ksEmptyString;
  362. ItemModel *daysCondition = [_conditions objectKey:@"itemSubTypeCode" eqaulToString:ksConditionSubTypeCodeDaysOfWeek];
  363. if (daysCondition) {
  364. ItemSubModel *subCondition = daysCondition.subItems[0];
  365. daysOfWeek = subCondition.daysOfWeek;
  366. }
  367. return daysOfWeek;
  368. }
  369. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  370. NSInteger section = indexPath.section;
  371. UITableViewCell *cell = nil;
  372. if (section == 0) {//title
  373. RulesDetailTitleTableViewCell *tcell = (RulesDetailTitleTableViewCell *)[_tableView dequeueReusableCellWithIdentifier:@"TitleCellIdentifier"];
  374. tcell.lblRuleTitle.text = _ruleDetail.ruleName;
  375. cell = tcell;
  376. } else if (section == 1) {//triggers
  377. ItemModel *item = _triggers[indexPath.row];
  378. RulesDetailTableViewCell *tcell = (RulesDetailTableViewCell *)[_tableView dequeueReusableCellWithIdentifier:@"RulesCellIdentifier"];
  379. [self configureTriggerCell:tcell item:item];
  380. cell = tcell;
  381. } else if (section == 2) {//actions - 장치일 경우,
  382. ItemModel *deviceItem = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeDevice];
  383. ItemSubModel *subItem = deviceItem.subItems[indexPath.row];
  384. RulesDetailTableViewCell *tcell = (RulesDetailTableViewCell *)[_tableView dequeueReusableCellWithIdentifier:@"RulesCellIdentifier"];
  385. tcell.lblItem.text = subItem.sourceName;
  386. if ([subItem.deleteYn boolValue]) {
  387. [tcell.lblItem setStrikethrough:tcell.lblItem.text];
  388. }
  389. tcell.lblSubItem.text = subItem.sourceSubName;
  390. tcell.lblCondition.text = subItem.cmdclsValueMsg; //노드의 액션 값을 세팅함.
  391. [tcell.imgvIcon sd_setImageWithURL:[NSURL URLWithString:subItem.imageFileName] placeholderImage:nil options:SDWebImageRefreshCached];
  392. cell = tcell;
  393. } else if (section == 3) {//actions - push-message
  394. ItemModel *pushItem = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeAppPush];
  395. ItemSubModel *subItem = pushItem.subItems[indexPath.row];
  396. RulesDetailPushTableViewCell *tcell = (RulesDetailPushTableViewCell *)[_tableView dequeueReusableCellWithIdentifier:@"PushCellIdentifier"];
  397. tcell.lblMessage.text = subItem.cmdclsValue;
  398. cell = tcell;
  399. } else if (section == 4) {//conditions
  400. RulesDetailConditionTableViewCell *tcell = (RulesDetailConditionTableViewCell *)[_tableView dequeueReusableCellWithIdentifier:@"ConditionCellIdentifier"];
  401. if (!tcell.container.subviews.count) {
  402. if ([self isViewLoaded]) {
  403. [_rcv beginAppearanceTransition:YES animated:NO];
  404. [tcell.container addSubview:_rcv.view];
  405. [_rcv endAppearanceTransition];
  406. }
  407. }
  408. tcell.constraintContainerHeight.constant = _rcv.tableHeight;
  409. _rcv.isShowingMode = YES;
  410. _rcv.conditions = _conditions;
  411. cell = tcell;
  412. } else if (section == 5) {//execution
  413. RulesDetailExecutionTableViewCell *tcell = (RulesDetailExecutionTableViewCell *)[_tableView dequeueReusableCellWithIdentifier:@"ExecutionCellIdentifier"];
  414. tcell.lblExecutionDate.text = !_ruleDetail.latestExecutionDatetime || [_ruleDetail.latestExecutionDatetime isEmptyString] ? @"-" : _ruleDetail.latestExecutionDatetime;
  415. tcell.btnUseRule.selected = [_ruleDetail.useYn boolValue];
  416. tcell.statusView.hidden = [JDFacade facade].loginUser.level < 90; //심플 유저일 경우,
  417. if (tcell.statusView.hidden) {
  418. tcell.constraintStatusViewBottom.constant = 0;
  419. tcell.constraintStatusViewHeight.constant = 0;
  420. tcell.statusView.hidden = YES;
  421. } else {//마스터일 경우,
  422. if (![tcell.btnUseRule actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  423. [tcell.btnUseRule addTarget:self action:@selector(btnUseRuleTouched:) forControlEvents:UIControlEventTouchUpInside];
  424. }
  425. }
  426. cell = tcell;
  427. }
  428. return cell;
  429. }
  430. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  431. [super tableView:tableView didSelectRowAtIndexPath:indexPath];
  432. }
  433. #pragma mark - Table Events
  434. - (void)btnUseRuleTouched:(id)sender {
  435. if ([_ruleDetail.useYn isEqualToString:ksKneetRulesDisable]) {
  436. [[JDFacade facade] toast:@"일부 장치 또는 멤버가 삭제되어 비활성 되었습니다.\n편집 후 다시 사용해주세요."];
  437. return;
  438. }
  439. [self requestChangeRuleStatus];
  440. }
  441. #pragma mark - UI Events
  442. - (IBAction)btnOptionTouched:(id)sender {
  443. [self toggleOptions:sender];
  444. }
  445. - (void)btnCloseTouched:(id)sender {
  446. [[JDFacade facade] dismissModalStack:YES completion:nil];
  447. }
  448. #pragma mark - MemoryWarning
  449. - (void)didReceiveMemoryWarning
  450. {
  451. [super didReceiveMemoryWarning];
  452. // Dispose of any resources that can be recreated.
  453. }
  454. @end