ScenesRegisterViewController.m 21 KB

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