RulesViewController.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. //
  2. // RulesViewController.m
  3. // kneet
  4. //
  5. // Created by Jason Lee on 3/18/15.
  6. // Copyright (c) 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 "CustomImageView.h"
  14. #import "JYRefreshController.h"
  15. #import "UIImageView+WebCache.h"
  16. #import "ImageUtil.h"
  17. #import "RulesViewController.h"
  18. #import "CustomCheckBox.h"
  19. #import "RulesDetailViewController.h"
  20. #import "RulesAddViewController.h"
  21. #import "CustomLabelButton.h"
  22. #import "HomeMemberViewController.h"
  23. #import "CustomSwitch.h"
  24. #define kfRulesTableViewCellHeight 101.0f
  25. @implementation RulesTableViewCell
  26. @end
  27. @implementation RulesCreateTableViewCell
  28. @end
  29. @interface RulesViewController () <UITableViewDataSource, UITableViewDelegate> {
  30. NSMutableArray<RuleModel> *_ruleList;
  31. NSString *_pagingType, *_pagingId;
  32. UIImage *_stateImageRun, *_stateImageStop;
  33. UIImage *_btnImageRun, *_btnImageStop;
  34. BOOL _isNotFirstLoading, _isDeleteMode;
  35. }
  36. @property (strong, nonatomic) JYPullToRefreshController *refreshController;
  37. @end
  38. #pragma mark - Class Definition
  39. @implementation RulesViewController
  40. - (void)viewDidLoad {
  41. [super viewDidLoad];
  42. // _ruleList = (NSMutableArray<RuleModel> *)[[NSMutableArray alloc] init];
  43. [self initUI];
  44. [self prepareViewDidLoad];
  45. }
  46. - (void)viewWillAppear:(BOOL)animated {
  47. [super viewWillAppear:animated];
  48. // if (_isNotFirstLoading) {
  49. [self performSelector:@selector(requestRules) withObject:nil afterDelay:0.0f];
  50. // }
  51. }
  52. - (void)initUI {
  53. //initialize tableview
  54. [self initTableViewAsDefaultStyle:_tableView];
  55. [_btnClose setHidden:YES];
  56. [_btnOption setHidden:NO];
  57. _btnImageRun = [UIImage imageNamed:@"img_rule_list_playbtn_active"];
  58. _btnImageStop = [UIImage imageNamed:@"img_rule_list_playbtn_disable"];
  59. _stateImageRun = [UIImage imageNamed:@"common_bullet_circle_red"];
  60. _stateImageStop = [UIImage imageNamed:@"common_bullet_circle_gray"];
  61. _tableView.backgroundColor = [UIColor clearColor];
  62. //[self setThingsPopoverOptions];
  63. [self setMoreBtnArray];
  64. [self initRefreshController];
  65. }
  66. - (void)initRefreshController {
  67. //set refresh controls
  68. __weak typeof(self) weakSelf = self;
  69. self.refreshController = [[JYPullToRefreshController alloc] initWithScrollView:self.tableView];
  70. self.refreshController.pullToRefreshHandleAction = ^{
  71. [weakSelf requestRules];
  72. };
  73. }
  74. - (void)setThingsPopoverOptions {
  75. // //set Popover Contents
  76. // __weak typeof(self) weakSelf = self;
  77. // _popooverOptionArray = [[NSMutableArray alloc] init];
  78. //
  79. // [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"새로고침",nil),
  80. // @"iconName": @"img_bg_morepopup_icon_refresh",
  81. // @"target": weakSelf,
  82. // @"selector": [NSValue valueWithPointer:@selector(refreshRuleList)]}];
  83. //
  84. // if ([JDFacade facade].loginUser.level > 10) {//파워유저 이상일 경우,
  85. // [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"만들기", @"만들기"),
  86. // @"iconName": @"img_bg_morepopup_icon_edit",
  87. // @"target": weakSelf,
  88. // @"selector": [NSValue valueWithPointer:@selector(addNewRule)]}];
  89. //
  90. // [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"삭제", @"삭제"),
  91. // @"iconName": @"img_bg_morepopup_icon_del",
  92. // @"target": weakSelf,
  93. // @"selector": [NSValue valueWithPointer:@selector(toggleEditMode)]}];
  94. // }
  95. }
  96. - (void)setMoreBtnArray {
  97. _moreBtnArray = [NSMutableArray array];
  98. // if (![[JDFacade facade].loginUser hasHomeHub]) {
  99. // [_btnOption setHidden:YES];
  100. // }
  101. if([[JDFacade facade].loginUser.gradeCode isEqualToString:KNEET_MEMBER_MASTER]) {
  102. for (int i = 0; i < 3; i++) {
  103. MoreBtnModel *btnModel;
  104. switch (i) {
  105. case 0:
  106. btnModel = [[MoreBtnModel alloc] initWithTyep:Add isEnable:YES];
  107. break;
  108. case 1:
  109. btnModel = [[MoreBtnModel alloc] initWithTyep:Del isEnable:_ruleList.count > 0];
  110. break;
  111. case 2:
  112. btnModel = [[MoreBtnModel alloc] initWithTyep:Refresh isEnable:YES];
  113. break;
  114. default:
  115. break;
  116. }
  117. [_moreBtnArray addObject:btnModel];
  118. }
  119. }
  120. else {
  121. MoreBtnModel *btnModel = [[MoreBtnModel alloc] initWithTyep:Refresh isEnable:YES];
  122. [_moreBtnArray addObject:btnModel];
  123. }
  124. }
  125. - (void)prepareViewDidLoad {
  126. [self updateTitle];
  127. [self performSelector:@selector(requestRules) withObject:nil afterDelay:0.0f];
  128. }
  129. - (void)updateHomeHubStatusToRules {
  130. [self updateTitle];
  131. }
  132. - (void)refreshRuleList {
  133. _pagingId = nil;
  134. _pagingType = nil;
  135. if (_ruleList && _ruleList.count) {
  136. [_ruleList removeAllObjects];
  137. }
  138. [self performSelector:@selector(requestRules) withObject:nil afterDelay:0.0f];
  139. }
  140. - (void)addNewRule {
  141. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"RulesAddViewController" storyboardName:@"Rules"];
  142. [self presentViewController:vc animated:YES completion:nil];
  143. }
  144. - (void)toggleEditMode {
  145. _isDeleteMode = !_isDeleteMode;
  146. [_btnClose setHidden:!_isDeleteMode];
  147. [_btnOption setHidden:_isDeleteMode];
  148. if (_isDeleteMode) {
  149. _lblTitle.text = @"규칙 삭제";
  150. _imgvHubAlert.hidden = YES;
  151. } else {
  152. [self updateTitle];
  153. }
  154. [_tableView reloadData];
  155. // _constraintEditModeRight.constant = _isDeleteMode ? 0 : -_editModeView.width;
  156. //
  157. // [UIView animateWithDuration:kfAnimationDur animations:^{
  158. // [self.view layoutIfNeeded];
  159. // }];
  160. }
  161. #pragma mark - Main Logic
  162. //- (void)requestRuleListRecently {
  163. //
  164. // RuleModel *firstRule = [_ruleList firstObject];
  165. // _pagingType = ksListPagingTypeUpward;
  166. // _pagingId = firstRule.ruleId;
  167. //
  168. // [self performSelector:@selector(requestRules) withObject:nil afterDelay:0.0f];
  169. //}
  170. //
  171. //- (void)requestRuleListOlder {
  172. //
  173. // RuleModel *lastRule = [_ruleList lastObject];
  174. // _pagingType = ksListPagingTypeDownward;
  175. // _pagingId = lastRule.ruleId;
  176. //
  177. // [self performSelector:@selector(requestRules) withObject:nil afterDelay:0.0f];
  178. //}
  179. - (void)requestRules {
  180. if (![JDFacade facade].loginUser.hasHomeHub) {
  181. return;
  182. }
  183. NSString *path = [[JDFacade facade] getUrlWithCustAndGroupID:API_GET_RULE aditional:@""];
  184. [[RequestHandler handler] sendAsyncGetRequestAPIPath:path parameters:nil modelClass:[RuleListModel class] completion:^(id responseObject) {
  185. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  186. return;
  187. }
  188. RuleListModel *fetchedRuleList = (RuleListModel *)responseObject;
  189. if (fetchedRuleList && fetchedRuleList.rules ) {//API 성공,
  190. _ruleList = [fetchedRuleList.rules mutableCopy];
  191. if (!_ruleList.count) {//이미 로드된 데이터가 있을 경우는 출력하지 않음.
  192. _lblConnectHub.text = @"등록된 규칙이 없습니다";
  193. _imgvConnectHub.image = [UIImage imageNamed:@"img_1depth_nodevice"];
  194. }
  195. }
  196. [self updateTitle];
  197. [self setMoreBtnArray];
  198. [_tableView reloadData];
  199. //refresh controller
  200. if (self.refreshController && self.refreshController.refreshState == JYRefreshStateLoading) {
  201. [self.refreshController stopRefreshWithAnimated:YES completion:nil];
  202. }
  203. if (!_isNotFirstLoading) {
  204. _isNotFirstLoading = YES;
  205. }
  206. } failure:^(id errorObject) {
  207. JDErrorModel *error = (JDErrorModel *)errorObject;
  208. [[JDFacade facade] alert:error.errorMessage];
  209. }];
  210. }
  211. - (void)requestChangeRuleStatus:(RuleModel *)rule {
  212. //parameters
  213. NSDictionary *parameter = @{@"status_code" : [rule.useYn isEqualToString:@"Y"] ? @"03" : @"02"};
  214. NSArray *arr = @[rule.ruleId];
  215. NSString *path = [[JDFacade facade] getUrlWithCustAndGroupID:API_PUT_RULE_STATUS arguments:arr];
  216. [[RequestHandler handler] sendAsyncPutRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  217. rule.useYn = [rule.useYn boolValue] ? ksNO : ksYES; //toggle
  218. if ([rule.useYn boolValue]) {
  219. [[JDFacade facade] toast:@"규칙을 다시 시작합니다"];
  220. } else {
  221. [[JDFacade facade] toast:@"규칙을 중단합니다"];
  222. }
  223. // [self changeBtnRunStatus:[rule.useYn boolValue]];
  224. [self updateTitle];
  225. [_tableView reloadData];
  226. } failure:^(id errorObject) {
  227. JDErrorModel *error = (JDErrorModel *)errorObject;
  228. [[JDFacade facade] alert:error.errorMessage];
  229. }];
  230. }
  231. - (void)requestDeleteRule:(RuleModel *)rule {
  232. NSArray *arr = @[rule.ruleId];
  233. NSString *path = [[JDFacade facade] getUrlWithCustAndGroupID:API_DELETE_RULE arguments:arr];
  234. [[RequestHandler handler] sendAsyncRequestAPIPath:path
  235. method:ksHTTPRequestDELETE
  236. parameters:nil
  237. modelClass:[JDJSONModel class]
  238. showLoadingView:YES
  239. completion:^(id responseObject) {
  240. [[JDFacade facade] toast:@"규칙을 삭제했습니다"];
  241. [_ruleList removeObject:rule];
  242. [self toggleEditMode];
  243. [self updateTitle];
  244. [_tableView reloadData];
  245. } failure:^(id errorObject) {
  246. JDErrorModel *error = (JDErrorModel *)errorObject;
  247. [[JDFacade facade] alert:error.errorMessage];
  248. }];
  249. }
  250. - (void)updateRule:(RuleModel *)rule {
  251. for (RuleModel *tmpRule in _ruleList) {
  252. if ([rule.homegrpRuleId isEqualToString:tmpRule.homegrpRuleId]) {
  253. tmpRule.ruleName = rule.ruleName;
  254. tmpRule.useYn = rule.useYn;
  255. break;
  256. }
  257. }
  258. [_tableView reloadData];
  259. }
  260. - (void)updateTitle {
  261. if (_isDeleteMode) {
  262. return;
  263. }
  264. NSInteger inactiveCount = [_ruleList filteredArrayUsingPredicateFormat:@"SELF.useYn != %@", ksYES].count;
  265. NSInteger activeCount = _ruleList.count > inactiveCount ? _ruleList.count - inactiveCount : inactiveCount - _ruleList.count;
  266. _lblTitle.text = [NSString stringWithFormat:@"적용 %zd / 미적용 %zd", activeCount, inactiveCount];
  267. if (![JDFacade facade].loginUser.hasHomeHub) {//홈허브 아이디가 없는 경우,
  268. [_mainView bringSubviewToFront:_addHubContainerView];
  269. _addHubContainerView.hidden = NO;
  270. _tableView.hidden = YES;
  271. _btnOption.hidden = YES;
  272. if (![JDFacade facade].loginUser.homegrpId) {//연결한 적이 없음
  273. _lblConnectHub.text = @"초대를 받아서\n시작해 보세요";
  274. _imgvHubAlert.hidden = YES;
  275. _imgvConnectHub.image = [UIImage imageNamed:@"img_1depth_invitation"];
  276. _lblLeaveAccount.hidden = YES;
  277. _lblSimpleMemberInfo.hidden = YES;
  278. } else {//홈허브가 삭제됨.
  279. _lblTitle.text = @"홈허브 삭제됨";
  280. _imgvHubAlert.hidden = NO;
  281. _lblConnectHub.text = @"홈허브를 다시 연결하려면\n고객센터에 문의해주세요";
  282. _imgvConnectHub.image = [UIImage imageNamed:@"img_things_homehub_img_hubdelete_cscenter"];
  283. if ([JDFacade facade].loginUser.level < 90) {//일반 유저일 경우,
  284. _imgvConnectHub.image = [UIImage imageNamed:@"img_things_homehub_img_hubdelete_wait"];
  285. _lblLeaveAccount.hidden = NO;
  286. _lblSimpleMemberInfo.hidden = NO;
  287. [_lblLeaveAccount setUnderLine:_lblLeaveAccount.text];
  288. if (!_lblLeaveAccount.touchHandler) {
  289. [_lblLeaveAccount addTouchEventHandler:^(id label) {
  290. [self leaveHomegroup];
  291. }];
  292. }
  293. }
  294. }
  295. } else {
  296. if (![JDFacade facade].loginUser.isHomehubOnline) {
  297. _imgvHubAlert.hidden = NO;
  298. _lblTitle.text = @"홈허브 오프라인";
  299. [_lblTitle setColor:kUITextColor01 text:_lblTitle.text];
  300. } else {
  301. _imgvHubAlert.hidden = YES;
  302. }
  303. [_mainView bringSubviewToFront:_tableView];
  304. _addHubContainerView.hidden = YES;
  305. _tableView.hidden = NO;
  306. _btnOption.hidden = NO;
  307. }
  308. //활성/비활성 업데이트
  309. if ([_lblTitle.text rangeOfString:@"활성"].location != NSNotFound) {
  310. [_lblTitle setColor:kUITextColor02 text:[NSString stringWithFormat:@"%zd", activeCount]];
  311. [_lblTitle setColor:kUITextColor03 text:[NSString stringWithFormat:@"비활성 %zd", inactiveCount]];
  312. }
  313. }
  314. - (void)leaveHomegroup {
  315. HomeMemberViewController *vc = [[HomeMemberViewController alloc] init];
  316. [vc leaveHomegroup];
  317. }
  318. #pragma mark - UITableView DataSource & Delegate
  319. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  320. NSInteger auth = [JDFacade facade].loginUser.level == 90 && !_isDeleteMode;
  321. NSInteger count = _ruleList.count > 0 ? 1 + auth : 1;
  322. return count;
  323. }
  324. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  325. NSInteger count = 1;
  326. if (_ruleList.count > 0 && section == 0) {//규칙이 있을 경우,
  327. count = _ruleList.count;
  328. }
  329. return count;
  330. }
  331. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  332. CGFloat height = kfRulesTableViewCellHeight;
  333. NSInteger section = indexPath.section;
  334. if (_ruleList.count > 0 && section == 0) {//규칙이 있을 경우,
  335. height = 77.0f;
  336. } else if (_ruleList.count > 0 && section == 1) {
  337. height = 135.0f;
  338. } else {
  339. height = IPHONE_HEIGHT - kfNavigationBarHeight - 55.0f; //header, tabbar
  340. }
  341. // if (indexPath.row == _ruleList.count) {
  342. // height = _ruleList.count ? 190.0f : IPHONE_HEIGHT - kfNavigationBarHeight;
  343. // _tableView.scrollEnabled = _ruleList.count;
  344. // }
  345. return height;
  346. }
  347. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  348. NSInteger section = indexPath.section;
  349. UITableViewCell *rcell = nil;
  350. if (_ruleList.count > 0 && section == 0) {//규칙이 있을 경우,
  351. RulesTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
  352. RuleModel *rule = _ruleList[indexPath.row];
  353. cell.lblRuleName.text = rule.ruleName;
  354. cell.switchRulePlay.hidden = _isDeleteMode || [JDFacade facade].loginUser.level < 90;
  355. cell.switchRulePlay.on = EQUALS(rule.useYn, @"Y");
  356. cell.btnDelete.hidden = !_isDeleteMode;
  357. // [cell.imgvTrigger sd_setImageWithURL:[NSURL URLWithString:rule.imageFileName] placeholderImage:nil options:SDWebImageRefreshCached];
  358. NSString *imgName = [CommonUtil getImageNameFormUrlString:rule.imageFileName];
  359. imgName = EQUALS(rule.useYn, @"Y") ? imgName : [NSString stringWithFormat:@"%@_disable",imgName];
  360. cell.imgvTrigger.image = [UIImage imageNamed:imgName];
  361. cell.switchRulePlay.tag = indexPath.row;
  362. cell.btnDelete.value = rule;
  363. if (![cell.switchRulePlay actionsForTarget:self forControlEvent:UIControlEventValueChanged]) {
  364. [cell.switchRulePlay addTarget:self action:@selector(changeSwitch:) forControlEvents:UIControlEventValueChanged];
  365. }
  366. if (![cell.btnDelete actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  367. [cell.btnDelete addTarget:self action:@selector(btnDeleteTouched:) forControlEvents:UIControlEventTouchUpInside];
  368. }
  369. rcell = cell;
  370. }
  371. else {
  372. RulesCreateTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AddCellIdentifier"];
  373. if (![cell.btnAdd actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  374. [cell.btnAdd addTarget:self action:@selector(addNewRule) forControlEvents:UIControlEventTouchUpInside];
  375. }
  376. rcell = cell;
  377. }
  378. return rcell;
  379. }
  380. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  381. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  382. NSInteger section = indexPath.section;
  383. if (indexPath.row == _ruleList.count || section > 0) {
  384. return;
  385. }
  386. if (!_isDeleteMode) {//go to detail
  387. //goto rule details
  388. RulesDetailViewController *vc = (RulesDetailViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"RulesDetailViewController" storyboardName:@"Rules"];
  389. vc.refRule = _ruleList[indexPath.row];
  390. [self presentViewController:vc animated:YES completion:nil];
  391. }
  392. }
  393. #pragma mark - TableView UI Events
  394. - (void)changeSwitch:(id)sender {
  395. UISwitch *sw = sender;
  396. RuleModel *rule = _ruleList[sw.tag];
  397. if ([rule.useYn isEqualToString:ksKneetRulesDisable]) {//규칙 비활성화 일 경우,
  398. NSString *msg = [NSString stringWithFormat:@"삭제된 장치로 인해 \"%@\"규칙을 적용할 수 없습니다.",rule.ruleName];
  399. CustomAlertView *alert = [[CustomAlertView alloc] initWithTitle:@"알림"
  400. message:msg
  401. delegate:nil
  402. OKButtonTitle:@"편집"
  403. cancelButtonTitle:@"취소"];
  404. [alert showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  405. if (buttonIndex == 0) {//OK
  406. dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{//RUN to background thread
  407. NSArray *arr = @[rule.ruleId];
  408. NSString *path = [[JDFacade facade] getUrlWithCustAndGroupID:API_GET_RULE_DETAIL arguments:arr];
  409. RuleDetailModel *ruleDetail = [[RequestHandler handler] sendSyncGetRequestAPIPath:path parameters:nil modelClass:[RuleDetailModel class] showLoadingView:YES];
  410. RulesAddViewController *vc = (RulesAddViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"RulesAddViewController" storyboardName:@"Rules"];
  411. vc.refRuleDetail = ruleDetail;
  412. dispatch_async(dispatch_get_main_queue(), ^{
  413. [self presentViewController:vc animated:YES completion:nil];
  414. });
  415. });
  416. }
  417. }];
  418. }
  419. else {
  420. [self requestChangeRuleStatus:rule];
  421. }
  422. }
  423. //- (void)btnRulePlayTouched:(id)sender {
  424. // CustomButton *btnRulePlay = (CustomButton *)sender;
  425. //
  426. // RuleModel *rule = btnRulePlay.value;
  427. // if ([rule.useYn isEqualToString:ksKneetRulesDisable]) {//규칙 비활성화 일 경우,
  428. //
  429. // CustomAlertView *alert = [[CustomAlertView alloc] initWithTitle:@"알림" message:@"일부 장치가 삭제되었습니다.\n편집 후 실행하세요." delegate:nil OKButtonTitle:@"편집" cancelButtonTitle:@"취소"];
  430. // [alert showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  431. // if (buttonIndex == 0) {//OK
  432. //
  433. // dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{//RUN to background thread
  434. //
  435. // NSString *path = [NSString stringWithFormat:API_GET_RULE_DETAIL, rule.homegrpRuleId];
  436. // RuleDetailModel *ruleDetail = [[RequestHandler handler] sendSyncGetRequestAPIPath:path parameters:nil modelClass:[RuleDetailModel class] showLoadingView:YES];
  437. //
  438. // RulesAddViewController *vc = (RulesAddViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"RulesAddViewController" storyboardName:@"Rules"];
  439. // vc.refRuleDetail = ruleDetail;
  440. //
  441. // dispatch_async(dispatch_get_main_queue(), ^{
  442. // [self presentViewController:vc animated:YES completion:nil];
  443. // });
  444. // });
  445. // }
  446. // }];
  447. // } else {
  448. // [self requestChangeRuleStatus:rule];
  449. // }
  450. //}
  451. - (void)btnDeleteTouched:(id)sender {
  452. [[JDFacade facade] confirmTitle:@"규칙 삭제"
  453. message:@"규칙을 삭제하시겠습니까?"
  454. completion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  455. if (buttonIndex == 0) {//OK
  456. CustomButton *btnDelete = (CustomButton *)sender;
  457. RuleModel *rule = btnDelete.value;
  458. [self requestDeleteRule:rule];
  459. }
  460. }];
  461. }
  462. #pragma mark - UI Events
  463. - (IBAction)btnOptionTouched:(id)sender {
  464. //[self toggleOptions:sender];
  465. [self toggleOptionsWithArray:sender btnArray:_moreBtnArray];
  466. }
  467. - (IBAction)btnCloseTouched:(id)sender {
  468. [self toggleEditMode];
  469. }
  470. - (IBAction)btnCloseOnEditModeTouched:(id)sender {
  471. [self toggleEditMode];
  472. }
  473. #pragma mark - MemoryWarning
  474. - (void)didReceiveMemoryWarning
  475. {
  476. [super didReceiveMemoryWarning];
  477. // Dispose of any resources that can be recreated.
  478. }
  479. #pragma mark - MoreButtonDelegate
  480. -(void)moreBtnAction:(id)sender
  481. {
  482. NSInteger tag = [(UIButton *)sender tag];
  483. NSLog(@"MoreBtn Action : %li", (long)tag);
  484. switch (tag) {
  485. case Add:
  486. {
  487. [self addNewRule];
  488. }
  489. break;
  490. case Del:
  491. {
  492. [self toggleEditMode];
  493. }
  494. break;
  495. case Refresh:
  496. {
  497. }
  498. break;
  499. default:
  500. break;
  501. }
  502. }
  503. @end