| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624 |
- //
- // RulesDetailViewController.m
- // kneet2
- //
- // Created by Jason Lee on 11/30/15.
- // Copyright © 2015 ntels. All rights reserved.
- //
- #import "JDObject.h"
- #import "RequestHandler.h"
- #import "RuleModel.h"
- #import "CustomTableView.h"
- #import "CustomLabel.h"
- #import "CustomButton.h"
- #import "CustomImageView.h"
- #import "UIImageView+WebCache.h"
- #import "RulesDetailViewController.h"
- #import "RulesConditionViewController.h"
- #import "DeviceModel.h"
- #import "RulesAddViewController.h"
- @implementation RulesDetailTitleTableViewCell
- @end
- @implementation RulesDetailHeaderTableViewCell
- @end
- @implementation RulesDetailTableViewCell
- @end
- @implementation RulesDetailPushTableViewCell
- @end
- @implementation RulesDetailConditionHeaderTableViewCell
- @end
- @implementation RulesDetailConditionTableViewCell
- @end
- @implementation RulesDetailExecutionTableViewCell
- @end
- @implementation RulesDetailFooterTableViewCell
- @end
- @interface RulesDetailViewController () {
- RuleDetailModel *_ruleDetail;
-
- NSMutableArray<ItemModel> *_triggers, *_actions, *_conditions;
- NSMutableArray *_arrayForHeader, *_arrayForFooter;
-
- RulesConditionViewController *_rcv;
-
- NSInteger _sectionCount;
- BOOL _hasDeviceAction, _hasPushAction, _hasCondition; //요일 조건 외의 조건
- }
- @end
- #pragma mark - Class Definition
- @implementation RulesDetailViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- [self initProperties];
- [self initUI];
- [self prepareViewDidLoad];
- }
- - (void)initProperties {
- _arrayForHeader = [[NSMutableArray alloc] init];
- _arrayForFooter = [[NSMutableArray alloc] init];
- }
- - (void)initUI {
-
- if (![JDFacade facade].loginUser.isHomehubOnline) {
- _lblTitle.text = @"홈허브 오프라인";
- [_lblTitle setColor:kUITextColor02 text:_lblTitle.text];
- return;
- }
-
- [self initTableViewAsDefaultStyle:_tableView];
- [self setThingsPopoverOptions];
- }
- - (void)prepareViewDidLoad {
- [self requestRuleDetail];
- }
- - (void)setThingsPopoverOptions {
- //set Popover Contents
- __weak typeof(self) weakSelf = self;
- _popooverOptionArray = [[NSMutableArray alloc] init];
-
- [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"새로 고침",nil),
- @"iconName": @"tp_01_img_bg_morepopup_icon_refresh",
- @"target": weakSelf,
- @"selector": [NSValue valueWithPointer:@selector(requestRuleDetail)]}];
-
- if ([JDFacade facade].loginUser.level > 10) {//파워유저 이상일 경우,
- [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"편집", @"편집"),
- @"iconName": @"tp_01_img_bg_morepopup_icon_group_deviceadd",
- @"target": weakSelf,
- @"selector": [NSValue valueWithPointer:@selector(editRule)]}];
-
- [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"삭제", @"삭제"),
- @"iconName": @"tp_01_img_bg_morepopup_icon_group_deviceadd",
- @"target": weakSelf,
- @"selector": [NSValue valueWithPointer:@selector(deleteRule)]}];
- }
- }
- - (void)editRule {
- RulesAddViewController *vc = (RulesAddViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"RulesAddViewController" storyboardName:@"Rules"];
- vc.refRuleDetail = _ruleDetail;
-
- [self presentViewController:vc animated:YES completion:nil];
- }
- - (void)deleteRule {
-
- [[JDFacade facade] confirmTitle:@"규칙 삭제" message:@"규칙을 삭제하시겠습니까?" completion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
- if (buttonIndex == 0) {//OK
- [self requestDeleteRule];
- }
- }];
- }
- #pragma mark - Main Logic
- - (void)requestRuleDetail {
-
- NSString *path = [NSString stringWithFormat:API_GET_RULE_DETAIL, _refRule.homegrpRuleId];
-
- [[RequestHandler handler] sendAsyncGetRequestAPIPath:path parameters:nil modelClass:[RuleDetailModel class] completion:^(id responseObject) {
- if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
- return;
- }
-
- _ruleDetail = (RuleDetailModel *) responseObject;
-
- if (_ruleDetail) {//API 성공 ,
- [self setContents];
- }
- } failure:^(id errorObject) {
- JDErrorModel *error = (JDErrorModel *)errorObject;
- [[JDFacade facade] alert:error.errorMessage];
- }];
- }
- - (void)setDeviceValue:(NSMutableArray<ItemModel> *)items {
- NSArray *matchedArray = [_triggers filteredArrayUsingPredicateFormat:@"itemTypeCode == %@", ksItemSubTypeCodeDevice];
-
- for (ItemModel *item in matchedArray) {//device items
- for (ItemSubModel *subItem in item.subItems) {
- [[JDFacade facade] setRadioButtonStatus:@YES object:subItem];
- [[JDFacade facade] setCheckBoxStatus:@YES object:subItem];
- }
- }
- }
- - (void)setContents {
- _triggers = (NSMutableArray<ItemModel> *)[[NSMutableArray alloc] initWithArray:_ruleDetail.triggers];
- _actions = (NSMutableArray<ItemModel> *)[[NSMutableArray alloc] initWithArray:_ruleDetail.actions];
- _conditions = (NSMutableArray<ItemModel> *)[[NSMutableArray alloc] initWithArray:_ruleDetail.conditions];
-
- [self setDeviceValue:_triggers];
- [self setDeviceValue:_actions];
- [self setDeviceValue:_conditions];
-
- _hasDeviceAction = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeDevice];
- _hasPushAction = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeAppPush];
-
- _hasCondition = [_conditions objectKey:@"itemSubTypeCode" eqaulToString:ksConditionSubTypeCodeHomeMode];
- _hasCondition = [_conditions objectKey:@"itemSubTypeCode" eqaulToString:ksConditionSubTypeCodeDueDate] ? YES : _hasCondition;
- _hasCondition = [_conditions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeDevice] ? YES : _hasCondition;
-
- [_tableView reloadData];
- }
- - (void)requestDeleteRule {
-
- NSString *path = [NSString stringWithFormat:API_DELETE_RULE, _ruleDetail.homegrpRuleId];
-
- [[RequestHandler handler] sendAsyncRequestAPIPath:path method:ksHTTPRequestDELETE parameters:nil modelClass:[JDJSONModel class] showLoadingView:YES completion:^(id responseObject) {
-
- [[JDFacade facade] toast:NSLocalizedString(@"삭제되었습니다", @"삭제되었습니다")];
- [[JDFacade facade] gotoWishMenu:KNMenuIdRules];
-
- } failure:^(id errorObject) {
- JDErrorModel *error = (JDErrorModel *)errorObject;
- [[JDFacade facade] alert:error.errorMessage];
- }];
- }
- - (void)requestChangeRuleStatus {
- //parameters
- NSDictionary *parameter = @{@"status_code" : [_ruleDetail.useYn boolValue] ? @"03" : @"02"};
-
- NSString *path = [NSString stringWithFormat:API_POST_RULE_STATUS, _ruleDetail.homegrpRuleId];
-
- [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
-
- _ruleDetail.useYn = [_ruleDetail.useYn boolValue] ? ksNO : ksYES; //toggle
-
- if ([_ruleDetail.useYn boolValue]) {
- [[JDFacade facade] toast:@"규칙을 다시 시작합니다"];
- } else {
- [[JDFacade facade] toast:@"규칙을 중단합니다"];
- }
- // [self changeBtnRunStatus:[rule.useYn boolValue]];
-
- [_tableView reloadData];
- } failure:^(id errorObject) {
- JDErrorModel *error = (JDErrorModel *)errorObject;
- [[JDFacade facade] alert:error.errorMessage];
- }];
- }
- #pragma mark - UITableView DataSource & Delegate
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 6;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- NSInteger count = 0;
- if (section == 0 || section == 5) {//title
- count = 1;
-
- } else if (section == 1) {//triggers
- count = _triggers && _triggers.count ? _triggers.count : 0;
-
- } else if (section == 2) {//actions
- ItemModel *deviceItem = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeDevice];
- count = deviceItem.subItems && deviceItem.subItems.count ? deviceItem.subItems.count : 0;
-
- } else if (section == 3) {
- count = _hasPushAction;
-
- } else if (section == 4) {
- count = _hasCondition;
- }
-
- return count;
- }
- - (NSString *)headerTitleForSection:(NSInteger)section {
- NSString *title = nil;
-
- if (section == 1) {//trigger
- title = @"이 때가 되면";
- if (_triggers && _triggers.count) {
- ItemModel *item = _triggers[0];
-
- if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDevice]) {
- title = @"장치 상태가 바뀔 때";
- } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeTimer]) {
- title = @"이 시간마다";
- } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeHeat]) {
- title = @"더울때 / 추울때";
- } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDaylight]) {
- title = @"해뜰때 / 질때";
- }
- }
-
- } else if (section == 2) {//action
- title = @"이 장치를 실행";
- } else if (section == 3) {//pushes
- title = @"알림 메시지";
- }
- return title;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
-
- UIView *view = _arrayForHeader.count > section ? _arrayForHeader[section] : nil;
- if (!view) {
-
- if (section == 0 || section == 5) {//title
- view = [[UIView alloc] init];
- } else if (section == 1 || section == 2 || section == 3) {
-
- RulesDetailHeaderTableViewCell *hcell = (RulesDetailHeaderTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"HeaderCellIdentifier"];
- view = [[UIView alloc] initWithFrame:hcell.contentView.frame];
- [view addSubview:hcell];
-
- hcell.lblTitle.text = [self headerTitleForSection:section];
-
- } else if (section == 4) {//conditions
- RulesDetailConditionHeaderTableViewCell *hcell = (RulesDetailConditionHeaderTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"ConditionHeaderCellIdentifier"];
-
- view = [[UIView alloc] initWithFrame:hcell.contentView.frame];
- [view addSubview:hcell];
- }
-
- if (_arrayForHeader.count == section) {
- [_arrayForHeader insertObject:view atIndex:section];
- }
- } else {
-
- if ((section == 2 && !_hasDeviceAction) || (section == 3 && !_hasPushAction) || (section == 4 && !_hasCondition)) {
- view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, CGFLOAT_MIN)];
-
- } else if (section == 1 || section == 2 || section == 3) {
- RulesDetailHeaderTableViewCell *hcell = (RulesDetailHeaderTableViewCell *)view.subviews[0];
- hcell.lblTitle.text = hcell.lblTitle.text = [self headerTitleForSection:section];
-
- }
- }
-
- return view;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- CGFloat height = 90.0f;
- if (section == 0 || section == 5) {
- height = CGFLOAT_MIN;
- } else if (section == 2) {
- height = _hasDeviceAction ? 90.0f : CGFLOAT_MIN;
- } else if (section == 3) {
- height = _hasPushAction ? 90.0f : CGFLOAT_MIN;
- } else if (section == 4) {
- height = _hasCondition ? 90.0f : CGFLOAT_MIN;
- }
- return height;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
-
- UIView *view = _arrayForFooter.count > section ? _arrayForFooter[section] : nil;
- if (!view) {
- RulesDetailFooterTableViewCell *hcell = (RulesDetailFooterTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"FooterCellIdentifier"];
- view = [[UIView alloc] initWithFrame:hcell.contentView.frame];
- [view addSubview:hcell];
-
- if (_arrayForHeader.count == section) {
- [_arrayForHeader insertObject:view atIndex:section];
- }
- }
-
- return view;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- CGFloat height = 15.0f;
- if (section == 0 || section == 5) {
- height = CGFLOAT_MIN;
- } else if (section == 2) {
- height = _hasDeviceAction ? 15.0f : CGFLOAT_MIN;
- } else if (section == 3) {
- height = _hasPushAction ? 15.0f : CGFLOAT_MIN;
- } else if (section == 4) {
- height = _hasCondition ? 15.0f : CGFLOAT_MIN;
- }
- return height;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- CGFloat height = 0.0f;
- NSInteger section = indexPath.section;
-
- if (section == 0) {//title
- height = 50;
-
- } else if (section == 1) {//triggers
- height = 95;
-
- } else if (section == 2) {//actions
- height = 95;
-
- } else if (section == 3) {//push-message
-
- ItemModel *pushItem = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeAppPush];
- ItemSubModel *push = pushItem.subItems[0];
-
- CGFloat width = IPHONE_WIDTH - 90;
- CustomLabel *lblTemp = [[CustomLabel alloc] initWithFrame:CGRectMake(0, 0, width, 30)];
- lblTemp.font = [UIFont systemFontOfSize:kUIFontSize02];
- lblTemp.numberOfLines = 0;
-
- CGFloat adjustHeight = [CommonUtil getSizeFromString:push.cmdclsValue font:lblTemp.font width:width].height;
- adjustHeight = adjustHeight < 30 ? 0 : adjustHeight - 30;
-
- height = 80 + adjustHeight;
-
- } else if (section == 4) {//conditions
- if (!_rcv) {
- _rcv = [CommonUtil instantiateViewControllerWithIdentifier:@"RulesConditionViewController" storyboardName:@"Rules"];
-
- [self addChildViewController:_rcv];
- [_rcv didMoveToParentViewController:self];
- }
-
- height = _rcv.tableHeight;
-
- } else if (section == 5) {//execution
- height = [JDFacade facade].loginUser.level == 90 ? 220.0f : 220.0f - 80.0f; //마스터만 규칙 실행 여부를 설정 가능함.
- }
-
- return height;
- }
- - (void)configureTriggerCell:(RulesDetailTableViewCell *)cell item:(ItemModel *)item {
-
- ItemSubModel *subItem = nil;
- if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDevice]) {//장치일 경우
- subItem = [item.subItems matchedObjectName:ksCustomRadioButtonStatus condition:YES];
-
- cell.lblItem.text = subItem.sourceName;
- if ([subItem.deleteYn boolValue]) {
- [cell.lblItem setStrikethrough:cell.lblItem.text];
- }
- cell.lblSubItem.text = subItem.sourceSubName;
-
- //노드의 액션 값을 세팅함.
- if (subItem.cmdclsValueList && subItem.cmdclsValueList.count) {//커맨드클래스 밸루 리스트가 있을 경우,
- CmdClsValueModel *cmdclsValue = [subItem.cmdclsValueList matchedObjectName:ksCustomRadioButtonStatus condition:YES];
- cell.lblCondition.text = [DeviceModel contentValueMsgByCmdClsCode:subItem.cmdclsCode cmdclsTypeId:(NSString *)subItem.cmdclsTypeId contentValue:cmdclsValue.cmdclsValue];
- } else {
- cell.lblCondition.text = subItem.cmdclsValueMsg;
- }
- cell.lblCondition.hidden = NO;
-
- } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeTimer]) {
-
- subItem = item.subItems && item.subItems.count ? item.subItems[0] : nil;
- if (subItem) {
- NSInteger phour = [subItem.hour integerValue];
- NSString *period = phour < 12 ? @"AM" : @"PM";//NSLocalizedString(@"오전", @"오전") : NSLocalizedString(@"오후", @"오후");
-
- if ([period isEqualToString:NSLocalizedString(@"오후", @"오후")]) {
- if (phour > 12) {
- phour -= 12;
- }
- }
-
- NSString *title = [NSString stringWithFormat:@"%@ %zd:%@", period, phour, subItem.minute];
-
- // NSDictionary *titleColor = @{NSForegroundColorAttributeName : kUITextColor02};
- cell.lblItem.text = title;
- cell.lblSubItem.text = [self daysOfWeekAtSubItem];
-
- cell.lblCondition.hidden = YES;
- }
- } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDaylight]) {
-
- subItem = item.subItems && item.subItems.count ? item.subItems[0] : nil;
- if (subItem) {
- NSString *title = [subItem.sourceId isEqualToString:@"sunriseUtcTime"] ? @"해뜰때" : @"해질때";
-
- cell.lblItem.text = title;
- cell.lblSubItem.text = [NSString stringWithFormat:@"%@ / %@", subItem.sourceName, [self daysOfWeekAtSubItem]];
-
- cell.lblCondition.hidden = YES;
- }
- } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeHeat]) {
-
- subItem = item.subItems && item.subItems.count ? item.subItems[0] : nil;
- if (subItem) {
- NSString *title = [subItem.conditionTypeCode isEqualToString:@"05"] ? @"더울때" : @"추울때";
-
- cell.lblItem.text = title;
- cell.lblSubItem.text = [NSString stringWithFormat:@"%@ / %@℃ / %@", subItem.sourceName, subItem.cmdclsValue, [self daysOfWeekAtSubItem]];
-
- cell.lblCondition.hidden = YES;
- }
- }
-
- [cell.imgvIcon sd_setImageWithURL:[NSURL URLWithString:subItem.imageFileName] placeholderImage:nil options:SDWebImageRefreshCached];
- }
- - (NSString *)daysOfWeekAtSubItem {
-
- NSString *daysOfWeek = ksEmptyString;
- ItemModel *daysCondition = [_conditions objectKey:@"itemSubTypeCode" eqaulToString:ksConditionSubTypeCodeDaysOfWeek];
- if (daysCondition) {
- ItemSubModel *subCondition = daysCondition.subItems[0];
- daysOfWeek = subCondition.daysOfWeek;
- }
- return daysOfWeek;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- NSInteger section = indexPath.section;
-
- UITableViewCell *cell = nil;
-
- if (section == 0) {//title
- RulesDetailTitleTableViewCell *tcell = (RulesDetailTitleTableViewCell *)[_tableView dequeueReusableCellWithIdentifier:@"TitleCellIdentifier"];
- tcell.lblRuleTitle.text = _ruleDetail.ruleName;
-
- cell = tcell;
-
- } else if (section == 1) {//triggers
- ItemModel *item = _triggers[indexPath.row];
-
- RulesDetailTableViewCell *tcell = (RulesDetailTableViewCell *)[_tableView dequeueReusableCellWithIdentifier:@"RulesCellIdentifier"];
-
- [self configureTriggerCell:tcell item:item];
-
- cell = tcell;
- } else if (section == 2) {//actions - 장치일 경우,
-
- ItemModel *deviceItem = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeDevice];
- ItemSubModel *subItem = deviceItem.subItems[indexPath.row];
-
- RulesDetailTableViewCell *tcell = (RulesDetailTableViewCell *)[_tableView dequeueReusableCellWithIdentifier:@"RulesCellIdentifier"];
- tcell.lblItem.text = subItem.sourceName;
- if ([subItem.deleteYn boolValue]) {
- [tcell.lblItem setStrikethrough:tcell.lblItem.text];
- }
-
- tcell.lblSubItem.text = subItem.sourceSubName;
- tcell.lblCondition.text = subItem.cmdclsValueMsg; //노드의 액션 값을 세팅함.
-
- [tcell.imgvIcon sd_setImageWithURL:[NSURL URLWithString:subItem.imageFileName] placeholderImage:nil options:SDWebImageRefreshCached];
-
- cell = tcell;
-
- } else if (section == 3) {//actions - push-message
-
- ItemModel *pushItem = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeAppPush];
- ItemSubModel *subItem = pushItem.subItems[indexPath.row];
-
- RulesDetailPushTableViewCell *tcell = (RulesDetailPushTableViewCell *)[_tableView dequeueReusableCellWithIdentifier:@"PushCellIdentifier"];
- tcell.lblMessage.text = subItem.cmdclsValue;
-
- cell = tcell;
-
- } else if (section == 4) {//conditions
- RulesDetailConditionTableViewCell *tcell = (RulesDetailConditionTableViewCell *)[_tableView dequeueReusableCellWithIdentifier:@"ConditionCellIdentifier"];
-
- if (!tcell.container.subviews.count) {
- if ([self isViewLoaded]) {
- [_rcv beginAppearanceTransition:YES animated:NO];
- [tcell.container addSubview:_rcv.view];
- [_rcv endAppearanceTransition];
- }
- }
-
- tcell.constraintContainerHeight.constant = _rcv.tableHeight;
-
- _rcv.isShowingMode = YES;
- _rcv.conditions = _conditions;
-
- cell = tcell;
- } else if (section == 5) {//execution
- RulesDetailExecutionTableViewCell *tcell = (RulesDetailExecutionTableViewCell *)[_tableView dequeueReusableCellWithIdentifier:@"ExecutionCellIdentifier"];
-
- tcell.lblExecutionDate.text = !_ruleDetail.latestExecutionDatetime || [_ruleDetail.latestExecutionDatetime isEmptyString] ? @"-" : _ruleDetail.latestExecutionDatetime;
- tcell.btnUseRule.selected = [_ruleDetail.useYn boolValue];
-
- tcell.statusView.hidden = [JDFacade facade].loginUser.level < 90; //심플 유저일 경우,
- if (tcell.statusView.hidden) {
- tcell.constraintStatusViewBottom.constant = 0;
- tcell.constraintStatusViewHeight.constant = 0;
- tcell.statusView.hidden = YES;
-
- } else {//마스터일 경우,
- if (![tcell.btnUseRule actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
- [tcell.btnUseRule addTarget:self action:@selector(btnUseRuleTouched:) forControlEvents:UIControlEventTouchUpInside];
- }
- }
-
- cell = tcell;
- }
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- [super tableView:tableView didSelectRowAtIndexPath:indexPath];
- }
- #pragma mark - Table Events
- - (void)btnUseRuleTouched:(id)sender {
- if ([_ruleDetail.useYn isEqualToString:ksKneetRulesDisable]) {
- [[JDFacade facade] toast:@"일부 장치 또는 멤버가 삭제되어 비활성 되었습니다.\n편집 후 다시 사용해주세요."];
- return;
- }
-
- [self requestChangeRuleStatus];
- }
- #pragma mark - UI Events
- - (IBAction)btnOptionTouched:(id)sender {
- [self toggleOptions:sender];
- }
- - (void)btnCloseTouched:(id)sender {
- [[JDFacade facade] dismissModalStack:YES completion:nil];
- }
- #pragma mark - MemoryWarning
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
|