ScenesRegisterViewController.m 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. //
  2. // ScenesRegisterViewController.m
  3. // kneet
  4. //
  5. // Created by Jason Lee on 4/1/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. @import ObjectiveC.runtime;
  9. #import "JDObject.h"
  10. #import "RequestHandler.h"
  11. #import "SceneModel.h"
  12. #import "CustomTextField.h"
  13. #import "CustomLabel.h"
  14. #import "CustomImageView.h"
  15. #import "CustomButton.h"
  16. #import "CustomAlertView.h"
  17. #import "UIImageView+WebCache.h"
  18. #import "CustomRadioGroup.h"
  19. #import "CustomTextView.h"
  20. #import "ValidateUtil.h"
  21. #import "PredefinedDeviceViewController.h"
  22. #import "RegisterModeViewController.h"
  23. #import "RulesRegisterViewController.h"
  24. #import "ScenesRegisterViewController.h"
  25. #import "ActionPopTableView.h"
  26. #import "ScenesViewController.h"
  27. @interface ScenesRegisterViewController () <UITableViewDelegate, UITableViewDataSource> {
  28. NSString *_sceneName, *_predSceneId;
  29. NSMutableArray<ItemModel> *_actions;
  30. BOOL _isNotFirstLoading, _isCustomCreation;
  31. UIImage *_iconAction;
  32. NSMutableArray *_arrayForHeader;
  33. ActionPopTableView *_actionPopTableView;
  34. }
  35. @end
  36. #pragma mark - Class Definition
  37. @implementation ScenesRegisterViewController
  38. - (void)viewDidLoad {
  39. [super viewDidLoad];
  40. // Do any additional setup after loading the view.
  41. [self initUI];
  42. [self prepareViewDidLoad];
  43. }
  44. - (void)initUI {
  45. self.title = NSLocalizedString(@"멀티 제어 만들기",nil);
  46. _tableView.dataSource = self;
  47. _tableView.delegate = self;
  48. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  49. _tableView.backgroundColor = [UIColor clearColor];
  50. _tableView.tableFooterView = [[UIView alloc] init]; //this call table events;
  51. _isNotFirstLoading = YES;
  52. _iconAction = [UIImage imageNamed:@"tp_01_img_rule_rbox_icon_action"];
  53. //Localization
  54. [_btnComplete setTitle:NSLocalizedString(@"완성", @"완성") forState:UIControlStateNormal];
  55. [_btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
  56. }
  57. - (void)prepareViewDidLoad {
  58. _isCustomCreation = YES;
  59. if (!_tmpPredScene && !_tmpSceneDetail) {//자유롭게 만들기
  60. _predSceneId = @"0";
  61. } else {
  62. //사전 정의 씬 상세 정보 조회
  63. if (!_tmpSceneDetail) {//사전 정의 씬을 불러온 경우,
  64. _predSceneId = _tmpPredScene.predSceneId;
  65. [self requestPredefinedSceneDetail];
  66. } else {//씬을 수정하는 경우,
  67. _sceneName = _tmpSceneDetail.sceneName;
  68. _predSceneId = _tmpSceneDetail.predSceneId; //FIXME :
  69. [self setSceneDetail];
  70. }
  71. }
  72. }
  73. - (void)viewWillAppear:(BOOL)animated {
  74. [super viewWillAppear:animated];
  75. if (_isNotFirstLoading) {
  76. [_tableView reloadData];
  77. }
  78. }
  79. #pragma mark - Main Logic
  80. //자유 선택 - 커스텀 씬 생성 시 사용
  81. - (void)addItem:(ItemModel *)item {
  82. if (!_isCustomCreation)
  83. return;
  84. if (!_actions) {
  85. _actions = (NSMutableArray<ItemModel> *)[[NSMutableArray alloc] init];
  86. }
  87. if ([_actions indexOfObject:item] == NSNotFound) {
  88. [_actions addObject:item];
  89. } else {
  90. NSInteger index = [_actions indexOfObjectPassingTest:^BOOL(ItemModel *obj, NSUInteger idx, BOOL *stop) {
  91. return [item.predActionSequence isEqualToString:obj.predActionSequence];
  92. }];
  93. if (index != NSNotFound) {//동일 액션이 있을경우,
  94. [_actions replaceObjectAtIndex:index withObject:item];
  95. }
  96. }
  97. [_tableView reloadData];
  98. }
  99. - (void)requestPredefinedSceneDetail {
  100. NSString *path = [NSString stringWithFormat:API_GET_PRESCENE_DETAIL, _predSceneId];
  101. [[RequestHandler handler] sendAsyncGetRequestAPIPath:path parameters:nil modelClass:[PredefinedSceneDetailModel class] completion:^(id responseObject) {
  102. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  103. return;
  104. }
  105. PredefinedSceneDetailModel *predefinedSceneDetail = (PredefinedSceneDetailModel *) responseObject;
  106. if (predefinedSceneDetail) {//API 성공 ,
  107. if (!_tmpSceneDetail) {//생성모드일 경우,
  108. [self setPredefinedSceneDetail:predefinedSceneDetail];
  109. }
  110. // else {//수정모드일 경우,
  111. // [self matchSceneDetailWithPredefinedSceneDeatil:predefinedSceneDetail];
  112. // }
  113. }
  114. } failure:^(id errorObject) {
  115. JDErrorModel *error = (JDErrorModel *)errorObject;
  116. [[JDFacade facade] alert:error.errorMessage];
  117. }];
  118. }
  119. //각 아이템별 카운트를 설정함
  120. - (void)setPredefinedSceneDetail:(PredefinedSceneDetailModel *)predefinedSceneDetail {//각 아이템별 카운트를 설정함
  121. _actions = (NSMutableArray<ItemModel> *)[NSMutableArray arrayWithArray:predefinedSceneDetail.actions];
  122. [_tableView reloadData];
  123. }
  124. - (void)setSceneDetail {//각 아이템별 카운트를 설정함
  125. _actions = [(NSMutableArray<ItemModel> *)[NSMutableArray alloc] initWithArray:_tmpSceneDetail.actions copyItems:YES];
  126. for (ItemModel *item in _actions) {
  127. NSIndexSet *isDeleted = [item.subItems indexesOfObjectsPassingTest:^BOOL(ItemSubModel *subItem, NSUInteger idx, BOOL *stop) {
  128. return [subItem.deleteYn boolValue];
  129. }];
  130. [item.subItems removeObjectsAtIndexes:isDeleted];
  131. if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDevice]) {//디바이스일 경우,
  132. [item.predDevices removeObjectsAtIndexes:isDeleted];
  133. } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeMode]) {//모드일 경우,
  134. [item.modes removeObjectsAtIndexes:isDeleted];
  135. }
  136. }
  137. // [RulesRegisterViewController setSubItemsFromItem:_actions];
  138. }
  139. - (void)matchSceneDetailWithPredefinedSceneDeatil:(PredefinedSceneDetailModel *)predSceneDetail {
  140. [RulesRegisterViewController appendItem:_actions withPredefinedRuleItems:predSceneDetail.actions isRuleMode:NO];
  141. [_tableView reloadData];
  142. }
  143. //서브아이템 배열을 리턴함.
  144. - (NSArray *)subItemsForType:(NSArray *)subActions itemSubType:(NSString *)actionSubTypeCode {
  145. NSMutableArray *rSubItems = [[NSMutableArray alloc] init];
  146. if ([actionSubTypeCode isEqualToString:ksItemSubTypeCodeDevice]) {//디바이스일 경우,
  147. for (PredefinedDeviceModel *pdevice in subActions) {
  148. NSDictionary *rSubItem = @{@"source_id": pdevice.deviceId,
  149. @"source_sub_id": pdevice.nodeId,
  150. @"cmdcls_value": pdevice.cmdclsValue};
  151. [rSubItems addObject:rSubItem];
  152. }
  153. } else if ([actionSubTypeCode isEqualToString:ksItemSubTypeCodeMode]) {//모드일 경우,
  154. for (ModeModel *mode in subActions) {
  155. NSDictionary *rSubItem = @{@"source_id": @"VAR",
  156. @"cmdcls_value": mode.modeId};
  157. [rSubItems addObject:rSubItem];
  158. }
  159. }
  160. return rSubItems;
  161. }
  162. //아이템 배열을 리턴함.
  163. - (NSArray *)actions:(NSArray<ItemModel> *)items {
  164. //triggers, actions, conditions
  165. NSMutableArray *rItems = [[NSMutableArray alloc] init];
  166. for (ItemModel *item in items) {
  167. NSDictionary *dic = nil;
  168. NSMutableArray *subItems = [[NSMutableArray alloc] init];
  169. NSArray *pdevices = [self subItemsForType:item.predDevices itemSubType:ksItemSubTypeCodeDevice];
  170. NSArray *modes = [self subItemsForType:item.modes itemSubType:ksItemSubTypeCodeMode];
  171. if (pdevices && pdevices.count) {
  172. [subItems addObjectsFromArray:pdevices];
  173. }
  174. if (modes && modes.count) {
  175. [subItems addObjectsFromArray:modes];
  176. }
  177. if (subItems.count) {
  178. dic = @{@"pred_action_sequence": item.predActionSequence,
  179. @"item_name": item.itemName,
  180. @"item_sub_type_code": item.itemSubTypeCode,
  181. @"item_sub": subItems};
  182. [rItems addObject:dic];
  183. }
  184. }
  185. return rItems;
  186. }
  187. - (void)requestRegisterScene {
  188. NSArray *actions = [self actions:_actions];
  189. //validate
  190. // if (!triggers || !triggers.count || !triggers[@"item_sub"] || ![((NSArray *)triggers[@"item_sub"]) count]) {
  191. if (!actions || !actions.count) {
  192. [[JDFacade facade] alert:NSLocalizedString(@"액션이 없습니다", @"액션이 없습니다")];
  193. return;
  194. }
  195. //parameters
  196. NSDictionary *parameter = @{@"pred_scene_id" : _predSceneId,
  197. @"scene_name" : _sceneName,
  198. @"actions": actions ? actions : [NSNull null]};
  199. NSString *path = [NSString stringWithFormat:API_POST_SCENE];
  200. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  201. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  202. return;
  203. }
  204. JDJSONModel *result = (JDJSONModel *) responseObject;
  205. if (result) {//API 성공 ,
  206. [[JDFacade facade] toast:NSLocalizedString(@"등록되었습니다", @"등록되었습니다")];
  207. [[JDFacade facade] gotoWishMenu:KNMenuIdScenes];
  208. }
  209. } failure:^(id errorObject) {
  210. JDErrorModel *error = (JDErrorModel *)errorObject;
  211. [[JDFacade facade] alert:error.errorMessage];
  212. }];
  213. }
  214. - (void)requestModifyScene {
  215. NSArray *actions = [self actions:_actions];
  216. //validate
  217. // if (!triggers || !triggers.count || !triggers[@"item_sub"] || ![((NSArray *)triggers[@"item_sub"]) count]) {
  218. if (!actions || !actions.count) {
  219. [[JDFacade facade] alert:NSLocalizedString(@"액션이 없습니다", @"액션이 없습니다")];
  220. return;
  221. }
  222. //parameters
  223. NSDictionary *parameter = @{@"pred_scene_id" : _predSceneId,
  224. @"scene_name" : _sceneName,
  225. @"actions": actions ? actions : [NSNull null]};
  226. NSString *path = [NSString stringWithFormat:API_POST_SCENE_MODIFY, _tmpSceneDetail.homegrpSceneId];
  227. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  228. _tmpSceneDetail.sceneName = _sceneName;
  229. _tmpSceneDetail.deleteCnt = @"0";
  230. _tmpSceneDetail.actions = _actions;
  231. ScenesViewController *vc = [[JDFacade facade] viewControllerOnNaviationController:[ScenesViewController class]];
  232. [vc updateScene:_tmpSceneDetail];
  233. [[JDFacade facade] toast:NSLocalizedString(@"수정되었습니다", @"수정되었습니다")];
  234. [self.navigationController popViewControllerAnimated:YES];
  235. } failure:^(id errorObject) {
  236. JDErrorModel *error = (JDErrorModel *)errorObject;
  237. [[JDFacade facade] alert:error.errorMessage];
  238. }];
  239. }
  240. #pragma mark - UITableView DataSource & Delegate
  241. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  242. return 2;
  243. }
  244. - (NSString *)titleForSectionHeader:(NSInteger)section {
  245. NSString *title = nil;
  246. switch (section) {
  247. case 0:
  248. title = NSLocalizedString(@"무엇을 실행할까요?", @"무엇을 실행할까요?");
  249. break;
  250. case 1:
  251. title = NSLocalizedString(@"이름을 붙여주세요", @"이름을 붙여주세요");
  252. break;
  253. }
  254. return title;
  255. }
  256. - (UIImage *)imageForSection:(NSInteger)section {
  257. UIImage *image = nil;
  258. switch (section) {
  259. case 0:
  260. image = _iconAction;
  261. break;
  262. case 1:
  263. break;
  264. }
  265. return image;
  266. }
  267. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  268. UIView *view = _arrayForHeader.count > section ? _arrayForHeader[section] : nil;
  269. if (!view) {
  270. RulesCreateHeaderTableViewCell *hcell = (RulesCreateHeaderTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"HeaderCellIdentifier"];
  271. CGFloat height = [self tableView:tableView heightForHeaderInSection:section];
  272. hcell.frame = CGRectMake(0, 0, IPHONE_WIDTH, height);
  273. if (section == 0) {
  274. hcell.imgvTop.hidden = YES;
  275. hcell.constraintHeaderTitleTop.constant = 10;
  276. }
  277. view = [[UIView alloc] initWithFrame:hcell.frame];
  278. [view addSubview:hcell];
  279. hcell.lblHeaderTitle.text = [self titleForSectionHeader:section];
  280. [_arrayForHeader insertObject:view atIndex:section];
  281. }
  282. return view;
  283. }
  284. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  285. if (section == 0) {
  286. return 65.0f;
  287. }
  288. return 72.0f;
  289. }
  290. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  291. return 0.01f;
  292. }
  293. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  294. NSInteger count = 0;
  295. if (section == 1) {//title cell
  296. count = 1;
  297. } else if (section == 0) {//actions
  298. count = _actions.count + _isCustomCreation;
  299. }
  300. return count;
  301. }
  302. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  303. CGFloat height = 0;
  304. if (indexPath.section == 0) {
  305. //calcualate subItemsText
  306. NSArray *items = _actions;
  307. if (indexPath.row == _actions.count) {//자유롭게 만들기 셀 (액션 추가)
  308. height = 60.0f;
  309. } else {//추가된 액션 표현.
  310. ItemModel *item = items[indexPath.row];
  311. CGFloat adjustHeight = [RulesRegisterViewController heightForSubItems:item isTrigger:NO];
  312. adjustHeight = adjustHeight > 0 ? adjustHeight + 15 + 20 : adjustHeight; //label top, bottom margin
  313. height = 60 + adjustHeight;
  314. }
  315. } else if (indexPath.section == 1) {//씬 이름입력
  316. height = 89;
  317. }
  318. return height;
  319. }
  320. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  321. UITableViewCell *cell = nil;
  322. // NSLog(@"%s\n %zd", __PRETTY_FUNCTION__, indexPath.row);
  323. if (indexPath.section == 1) {//타이틀 셀
  324. RulesCreateTitleTableViewCell *tcell = [tableView dequeueReusableCellWithIdentifier:@"TitleCellIdentifier"];
  325. if (tcell == nil) {
  326. tcell = [[RulesCreateTitleTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TitleCellIdentifier"];
  327. }
  328. tcell.txtRuleTitle.text = [tcell.txtRuleTitle.text isEmptyString] ? _sceneName : tcell.txtRuleTitle.text;
  329. tcell.lblRuleTitle.text = [tcell.txtRuleTitle.text isEmptyString] ? @"입력" : tcell.txtRuleTitle.text;
  330. cell = tcell;
  331. } else {//액션즈 셀
  332. RulesCreateTableViewCell *tcell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
  333. if (tcell == nil) {
  334. tcell = [[RulesCreateTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CellIdentifier"];
  335. }
  336. UIImage *bgImage = [UIImage imageNamed:@"tp_01_img_rule_rbox_bg"];
  337. tcell.constraintImgvBgHeight.constant = 55.0f;
  338. [tcell.imgvBg setImage:bgImage];
  339. if (indexPath.row == _actions.count) {//자유롭게 만들기 셀 (액션 추가)
  340. tcell.lblItemName.text = NSLocalizedString(@"자유 선택", @"자유 선택");
  341. tcell.lblSubItems.hidden = YES;
  342. tcell.lineview.hidden = tcell.btnDeleteSubItems.hidden = tcell.lblSubItems.hidden;
  343. } else {//추가된 액션
  344. NSArray *items = _actions;
  345. ItemModel *item = items[indexPath.row];
  346. [RulesRegisterViewController fillCell:tcell item:item isTrigger:NO];
  347. tcell.btnDeleteSubItems.value = item;
  348. if (![tcell.btnDeleteSubItems actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  349. [tcell.btnDeleteSubItems addTarget:self action:@selector(btnDeleteSubItemsTouched:) forControlEvents:UIControlEventTouchUpInside];
  350. }
  351. }
  352. tcell.imgvItem.image = [self imageForSection:indexPath.section];
  353. cell = tcell;
  354. }
  355. return cell;
  356. }
  357. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  358. if (indexPath.section == 1) {//title cell //텍스트필드를 원상태로 되돌림
  359. RulesCreateTitleTableViewCell *cell = (RulesCreateTitleTableViewCell *)[_tableView cellForRowAtIndexPath:indexPath];
  360. [cell setSelected:YES animated:YES];
  361. return;
  362. } else {
  363. NSIndexPath *ip = [NSIndexPath indexPathForItem:0 inSection:1]; //텍스트필드를 원상태로 되돌림
  364. RulesCreateTitleTableViewCell *cell = (RulesCreateTitleTableViewCell *)[_tableView cellForRowAtIndexPath:ip];
  365. if (!cell.txtRuleTitle.hidden && [cell.txtRuleTitle isFirstResponder]) {
  366. [cell.txtRuleTitle resignFirstResponder];
  367. }
  368. }
  369. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  370. if (indexPath.row == _actions.count) {//자유롭게 만들기 셀 (액션 추가)
  371. //FIXME : 매번 로드를 해야되는가?
  372. if (!_actionPopTableView) {
  373. _actionPopTableView = [[ActionPopTableView alloc] initFromNib];
  374. }
  375. _actionPopTableView.actions = _actions;
  376. [_actionPopTableView.tableView scrollsToTop];
  377. [_actionPopTableView show];
  378. } else {//사전 정의 액션, 수정 모드, 추가된 액션
  379. NSArray *items = _actions;
  380. ItemModel *item = items[indexPath.row];
  381. UIViewController *vc = nil;
  382. if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDevice]) {//디바이스일 경우,
  383. PredefinedDeviceViewController *dvc = (PredefinedDeviceViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"PredefinedDeviceViewController" storyboardName:@"Rules"];
  384. dvc.title = [self titleForSectionHeader:indexPath.section];
  385. dvc.predSceneId = _predSceneId;
  386. dvc.tmpItem = item;
  387. vc = dvc;
  388. } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeMode]) {//모드일 경우,
  389. RegisterModeViewController *mvc = (RegisterModeViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"RegisterModeViewController" storyboardName:@"Rules"];
  390. mvc.title = [self titleForSectionHeader:indexPath.section];
  391. mvc.tmpItem = item;
  392. vc = mvc;
  393. }
  394. [self.navigationController pushViewController:vc animated:YES];
  395. }
  396. }
  397. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  398. // Remove seperator inset
  399. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  400. [cell setSeparatorInset:UIEdgeInsetsZero];
  401. }
  402. // Prevent the cell from inheriting the Table View's margin settings
  403. if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
  404. [cell setPreservesSuperviewLayoutMargins:NO];
  405. }
  406. // Explictly set your cell's layout margins
  407. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  408. [cell setLayoutMargins:UIEdgeInsetsZero];
  409. }
  410. }
  411. #pragma mark - UI Events
  412. - (void)resetAllCheckbox {
  413. // [_tableView enumarateTableViewCellsUsingBlock:^(UITableViewCell *cell) {
  414. // ProductTableViewCell *pcell = (ProductTableViewCell *)cell;
  415. // pcell.chkSelect.checked = NO;
  416. // }];
  417. }
  418. - (void)btnCancelSceneTouched:(id)sender {
  419. [self.navigationController popViewControllerAnimated:YES];
  420. }
  421. - (void)btnDeleteSubItemsTouched:(id)sender {
  422. CustomButton *btnDeleteSubItems = (CustomButton *)sender;
  423. ItemModel *action = btnDeleteSubItems.value;
  424. action.predDevices = nil;
  425. action.cnt = @"0";
  426. [_actions removeObject:btnDeleteSubItems.value];
  427. [_tableView reloadData];
  428. }
  429. - (void)btnCompleteSceneTouched:(id)sender {
  430. [self.view endEditing:YES];
  431. //1.Validate Title
  432. RulesCreateTitleTableViewCell *tcell = (RulesCreateTitleTableViewCell *)[_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]]; //마지막 섹션
  433. if (tcell && ![ValidateUtil validateTextfiled:tcell.txtRuleTitle type:ValidateTypeNull title:NSLocalizedString(@"이름", @"이름")]) {
  434. return;
  435. }
  436. if (!_tmpSceneDetail && !tcell) {
  437. [[JDFacade facade] alert:NSLocalizedString(@"이름을 입력하세요", @"이름을 입력하세요")];
  438. return;
  439. }
  440. _sceneName = !tcell ? _sceneName : tcell.txtRuleTitle.text;
  441. if (!_tmpSceneDetail) {//생성
  442. [self requestRegisterScene];
  443. } else {//수정
  444. [self requestModifyScene];
  445. }
  446. }
  447. #pragma mark - MemoryWarning
  448. - (void)didReceiveMemoryWarning
  449. {
  450. [super didReceiveMemoryWarning];
  451. // Dispose of any resources that can be recreated.
  452. }
  453. @end