RulesTriggerOptionViewController.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. //
  2. // RulesTriggerOptionViewController.m
  3. // kneet
  4. //
  5. // Created by Jason Lee on 5/11/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "ItemModel.h"
  10. #import "DatePickerButton.h"
  11. #import "TimePickerButton.h"
  12. #import "CustomButton.h"
  13. #import "CustomCheckBox.h"
  14. #import "DaysPopupView.h"
  15. #import "ModePopTableView.h"
  16. #import "ExternHeatPopupView.h"
  17. #import "RulesTriggerOptionViewController.h"
  18. #define kfTriggerOptionTableViewCellHeight 60.0f
  19. @interface RulesTriggerOptionViewController () {
  20. NSInteger _rowCount;
  21. UIImage *_imageBtnNormal, *_imageBtnDisable;
  22. DaysPopupView *_daysPopupView;
  23. ModePopTableView *_modePopTableView;
  24. ExternHeatPopupView *_externHeatPopView;
  25. }
  26. @end
  27. #pragma mark - Class Definition
  28. @implementation RulesTriggerOptionViewController
  29. - (void)viewDidLoad {
  30. [super viewDidLoad];
  31. // Do any additional setup after loading the view.
  32. [self initUI];
  33. [self prepareViewDidLoad];
  34. }
  35. - (void)initUI {
  36. self.tableView.scrollEnabled = NO;
  37. self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
  38. self.tableView.separatorColor = kUILineColor2;
  39. self.tableView.backgroundColor = [UIColor clearColor];
  40. self.tableView.tableFooterView = [[UIView alloc] init]; //this call table events;
  41. CGRect sr = self.view.frame;
  42. sr.size.width = IPHONE_WIDTH;
  43. self.view.frame = sr;
  44. _imageBtnNormal = [UIImage imageNamed:@"tp_01_img_input_bg_02"];
  45. _imageBtnDisable = [UIImage imageNamed:@"tp_01_img_input_bg_02_disable"];
  46. _btnDueDateFrom.date = [NSDate date];
  47. _btnDueDateFrom.placeHolder = _btnDueDateFrom.dateString;
  48. [_btnDueDateTo setTitle:ksEmptyString forState:UIControlStateNormal];
  49. // _btnDueDateTo.date = [NSDate date];
  50. // _btnDueDateTo.placeHolder = _btnDueDateTo.dateString;
  51. [_btnDueTimeFrom setHour:9 minute:0];
  52. _btnDueTimeFrom.placeHolder = _btnDueTimeFrom.timeString;
  53. [_btnDueTimeTo setTitle:ksEmptyString forState:UIControlStateNormal];
  54. // [_btnDueTimeTo setHour:10 minute:0];
  55. // _btnDueTimeTo.placeHolder = _btnDueTimeTo.timeString;
  56. [_btnDueDateFrom setBackgroundImage:_imageBtnDisable forState:UIControlStateNormal];
  57. [_btnDueDateTo setBackgroundImage:_imageBtnDisable forState:UIControlStateNormal];
  58. [_btnDaysOfWeek setBackgroundImage:_imageBtnDisable forState:UIControlStateNormal];
  59. [_btnDueTimeFrom setBackgroundImage:_imageBtnDisable forState:UIControlStateNormal];
  60. [_btnDueTimeTo setBackgroundImage:_imageBtnDisable forState:UIControlStateNormal];
  61. [_btnModes setBackgroundImage:_imageBtnDisable forState:UIControlStateNormal];
  62. [_btnExternHeat setBackgroundImage:_imageBtnDisable forState:UIControlStateNormal];
  63. [_chkDueDate setTitle:NSLocalizedString(@"기간", @"기간") forState:UIControlStateNormal];
  64. [_chkDaysOfWeek setTitle:NSLocalizedString(@"요일", @"요일") forState:UIControlStateNormal];
  65. [_chkDueTime setTitle:NSLocalizedString(@"시간", @"시간") forState:UIControlStateNormal];
  66. [_chkModes setTitle:NSLocalizedString(@"홈 모드", @"홈 모드") forState:UIControlStateNormal];
  67. [_chkExternHeat setTitle:NSLocalizedString(@"지역온도", @"지역온도") forState:UIControlStateNormal];
  68. // _modes = (NSMutableArray<ModeModel> *)[[NSMutableArray alloc] init];
  69. }
  70. - (void)prepareViewDidLoad {
  71. ItemSubModel *subItem = nil;
  72. if ([_tmpItem.itemSubTypeCode isEqualToString:ksItemSubTypeCodeMode]) {//홈모드일 경우,
  73. _rowCount = 4;
  74. if (_tmpItem.modes && _tmpItem.modes.count) {
  75. subItem = _tmpItem.modes && _tmpItem.modes.count ? _tmpItem.modes[0] : nil;
  76. }
  77. } else if ([_tmpItem.itemSubTypeCode isEqualToString:ksItemSubTypeCodeTimer]) {//타이머일 경우,
  78. _rowCount = 4;
  79. if (_tmpItem.timers && _tmpItem.timers.count) {
  80. subItem = _tmpItem.timers && _tmpItem.timers.count ? _tmpItem.timers[0] : nil;
  81. }
  82. } else {
  83. if ([_tmpItem.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDevice]) {//디바이스일 경우,
  84. subItem = _tmpItem.predDevices && _tmpItem.predDevices.count ? _tmpItem.predDevices[0] : nil;
  85. } if ([_tmpItem.itemSubTypeCode isEqualToString:ksItemSubTypeCodeGeoFencing]) {//지오펜싱일 경우,
  86. subItem = _tmpItem.mobileDevices && _tmpItem.mobileDevices.count ? _tmpItem.mobileDevices[0] : nil;
  87. }
  88. _rowCount = 5;
  89. }
  90. for (ItemModel *condition in subItem.conditions) {
  91. if ([condition.itemSubTypeCode isEqualToString:ksConditionSubTypeCodeDueDate]) {//기간
  92. _dueDateCondition = condition;
  93. ItemSubModel *subCondition = _dueDateCondition.subItems[0];
  94. NSArray *darray = [subCondition.cmdclsValue componentsSeparatedByString:@"~"];
  95. //from
  96. [_btnDueDateFrom setTitle:darray[0] forState:UIControlStateNormal];
  97. if (darray.count > 1) {//to
  98. [_btnDueDateTo setTitle:darray[1] forState:UIControlStateNormal];
  99. }
  100. _chkDueDate.checked = YES;
  101. [_btnDueDateFrom setBackgroundImage:_imageBtnNormal forState:UIControlStateNormal];
  102. [_btnDueDateTo setBackgroundImage:_imageBtnNormal forState:UIControlStateNormal];
  103. } else if ([condition.itemSubTypeCode isEqualToString:ksConditionSubTypeCodeDaysOfWeek]) {//요일
  104. _daysOfWeekCondition = condition;
  105. ItemSubModel *subCondition = _daysOfWeekCondition.subItems[0];
  106. _chkDaysOfWeek.checked = YES;
  107. [_btnDaysOfWeek setTitle:subCondition.cmdclsValueMsg forState:UIControlStateNormal];
  108. [_btnDaysOfWeek setBackgroundImage:_imageBtnNormal forState:UIControlStateNormal];
  109. } else if ([condition.itemSubTypeCode isEqualToString:ksConditionSubTypeCodeDueTime]) {//시간
  110. _dueTimeCondition = condition;
  111. ItemSubModel *subCondition = _dueTimeCondition.subItems[0];
  112. NSArray *darray = [subCondition.cmdclsValue componentsSeparatedByString:@"~"];
  113. //from
  114. [_btnDueTimeFrom setTitle:darray[0] forState:UIControlStateNormal];
  115. if (darray.count > 1) {//to
  116. [_btnDueTimeTo setTitle:darray[1] forState:UIControlStateNormal];
  117. }
  118. _chkDueTime.checked = YES;
  119. [_btnDueTimeFrom setBackgroundImage:_imageBtnNormal forState:UIControlStateNormal];
  120. [_btnDueTimeTo setBackgroundImage:_imageBtnNormal forState:UIControlStateNormal];
  121. } else if ([condition.itemSubTypeCode isEqualToString:ksConditionSubTypeCodeHomeMode]) {//홈모드
  122. _homeModeCondition = condition;
  123. ItemSubModel *subCondition = _homeModeCondition.subItems[0];
  124. _chkModes.checked = YES;
  125. [_btnModes setTitle:subCondition.cmdclsValueMsg forState:UIControlStateNormal];
  126. [_btnModes setBackgroundImage:_imageBtnNormal forState:UIControlStateNormal];
  127. } else if ([condition.itemSubTypeCode isEqualToString:ksConditionSubTypeCodeExternHeat]) {//바깥온도
  128. _exterHeatCondition = condition;
  129. ItemSubModel *subCondition = _exterHeatCondition.subItems[0];
  130. _chkExternHeat.checked = YES;
  131. [_btnExternHeat setTitle:subCondition.cmdclsValueMsg forState:UIControlStateNormal];
  132. [_btnExternHeat setBackgroundImage:_imageBtnNormal forState:UIControlStateNormal];
  133. }
  134. }
  135. }
  136. - (void)viewDidAppear:(BOOL)animated {
  137. [super viewDidAppear:animated];
  138. }
  139. #pragma mark - Main Logic
  140. - (BOOL)hasCondition {
  141. return _chkDueDate.checked || _chkDaysOfWeek.checked || _chkDueTime.checked || _chkModes.checked || _chkExternHeat.checked;
  142. }
  143. - (NSMutableArray<ItemModel> *)conditions {
  144. _conditions = [(NSMutableArray<ItemModel> *)[NSMutableArray alloc] init];
  145. //기간
  146. if (_chkDueDate.checked) {
  147. if (!self.dueDateCondition)
  148. return nil;
  149. [_conditions addObject:self.dueDateCondition];
  150. }
  151. //요일
  152. if (_chkDaysOfWeek.checked) {
  153. if (!self.daysOfWeekCondition)
  154. return nil;
  155. [_conditions addObject:self.daysOfWeekCondition];
  156. }
  157. //시간 조건
  158. if (_chkDueTime.checked) {
  159. if (!self.dueTimeCondition)
  160. return nil;
  161. [_conditions addObject:self.dueTimeCondition];
  162. }
  163. //홈모드
  164. if (_chkModes.checked) {
  165. if (!self.homeModeCondition)
  166. return nil;
  167. [_conditions addObject:self.homeModeCondition];
  168. }
  169. //지역온도모드
  170. if (_chkExternHeat.checked) {
  171. if (!self.exterHeatCondition)
  172. return nil;
  173. [_conditions addObject:self.exterHeatCondition];
  174. }
  175. return _conditions;
  176. }
  177. - (ItemModel *)dueDateCondition {
  178. _dueDateCondition = nil;
  179. if (_chkDueDate.checked) {
  180. _dueDateCondition = [[ItemModel alloc] init];
  181. _dueDateCondition.itemName = NSLocalizedString(@"기간", @"기간");
  182. _dueDateCondition.itemSubTypeCode = ksConditionSubTypeCodeDueDate;
  183. ItemSubModel *subCondtion = [[ItemSubModel alloc] init];
  184. subCondtion.conditionTypeCode = @"09";
  185. if ([[_btnDueDateTo titleForState:UIControlStateNormal] isEmptyString]) {
  186. subCondtion.cmdclsValue = [NSString stringWithFormat:@"%@", _btnDueDateFrom.dateString];
  187. subCondtion.dueDate = [NSString stringWithFormat:@"%@", _btnDueDateFrom.formatString];
  188. } else {
  189. subCondtion.cmdclsValue = [NSString stringWithFormat:@"%@~%@", _btnDueDateFrom.dateString, _btnDueDateTo.dateString];
  190. subCondtion.dueDate = [NSString stringWithFormat:@"%@ ~ %@", _btnDueDateFrom.formatString, _btnDueDateTo.formatString];
  191. }
  192. _dueDateCondition.subItems = (NSMutableArray<ItemSubModel> *)[[NSMutableArray alloc] initWithObjects:subCondtion, nil];
  193. }
  194. return _dueDateCondition;
  195. }
  196. //- (NSString *)dueDate {
  197. // _dueDate = nil;
  198. // if (_chkDueDate.checked) {
  199. // if (!_btnDueDateTo.value) {
  200. // _dueDate = [NSString stringWithFormat:@"%@", _btnDueDateFrom.dateString];
  201. // } else {
  202. // _dueDate = [NSString stringWithFormat:@"%@ ~ %@", _btnDueDateFrom.dateString, _btnDueDateTo.dateString];
  203. // }
  204. // }
  205. // return _dueDate;
  206. //}
  207. //
  208. //
  209. //- (NSString *)dueDateCommandClassValue {
  210. // _dueDateCommandClassValue = nil;
  211. // if (_chkDueDate.checked) {
  212. // if (!_btnDueDateTo.value) {
  213. // _dueDateCommandClassValue = [NSString stringWithFormat:@"%@", _btnDueDateFrom.formatString];
  214. // } else {
  215. // _dueDateCommandClassValue = [NSString stringWithFormat:@"%@ ~ %@", _btnDueDateFrom.formatString, _btnDueDateTo.formatString];
  216. // }
  217. // }
  218. // return _dueDateCommandClassValue;
  219. //}
  220. - (ItemModel *)daysOfWeekCondition {
  221. if (_chkDaysOfWeek.checked && _daysPopupView) {
  222. _daysOfWeekCondition = _daysPopupView.condition;
  223. }
  224. if (!_daysOfWeekCondition && _chkDaysOfWeek.checked) {
  225. [[JDFacade facade] alert:NSLocalizedString(@"요일을 선택해주세요", @"요일을 선택해주세요")];
  226. }
  227. return _daysOfWeekCondition;
  228. }
  229. //- (NSString *)daysOfWeek {
  230. // _daysOfWeek = nil;
  231. // if (_chkDaysOfWeek.checked) {
  232. // _daysOfWeek = _daysPopupView ? _daysPopupView.daysOfWeek : nil;
  233. // }
  234. // return _daysOfWeek;
  235. //}
  236. //
  237. //- (NSString *)daysOfWeekCommandClassValue {
  238. // _daysOfWeekCommandClassValue = nil;
  239. // if (_chkDaysOfWeek.checked) {
  240. // _daysOfWeekCommandClassValue = _daysPopupView ? _daysPopupView.commandClassValue : nil;
  241. // }
  242. // return _daysOfWeekCommandClassValue;
  243. //}
  244. - (ItemModel *)dueTimeCondition {
  245. _dueTimeCondition = nil;
  246. if (_chkDueTime.checked) {
  247. _dueTimeCondition = [[ItemModel alloc] init];
  248. _dueTimeCondition.itemName = NSLocalizedString(@"시간", @"시간");
  249. _dueTimeCondition.itemSubTypeCode = ksConditionSubTypeCodeDueTime;
  250. ItemSubModel *subCondtion = [[ItemSubModel alloc] init];
  251. subCondtion.conditionTypeCode = @"09";
  252. if ([[_btnDueTimeTo titleForState:UIControlStateNormal] isEmptyString]) {
  253. subCondtion.cmdclsValue = [NSString stringWithFormat:@"%@", _btnDueTimeFrom.timeString];
  254. subCondtion.dueTime = [NSString stringWithFormat:@"%@", [CommonUtil formattedTime2:_btnDueTimeFrom.timeString]];
  255. } else {
  256. subCondtion.cmdclsValue = [NSString stringWithFormat:@"%@~%@", _btnDueTimeFrom.timeString, _btnDueTimeTo.timeString];
  257. subCondtion.dueTime = [NSString stringWithFormat:@"%@ ~ %@", [CommonUtil formattedTime2:_btnDueTimeFrom.timeString], [CommonUtil formattedTime2:_btnDueTimeTo.timeString]];
  258. }
  259. _dueTimeCondition.subItems = (NSMutableArray<ItemSubModel> *)[[NSMutableArray alloc] initWithObjects:subCondtion, nil];
  260. }
  261. return _dueTimeCondition;
  262. }
  263. //- (NSString *)dueTime {
  264. // _dueTime = nil;
  265. // if (_chkDueTime.checked) {
  266. //
  267. // if (!_btnDueTimeTo.value) {
  268. // _dueTime = [NSString stringWithFormat:@"%@", _btnDueTimeFrom.timeString];
  269. // } else {
  270. // _dueTime = [NSString stringWithFormat:@"%@ ~ %@", _btnDueTimeFrom.timeString, _btnDueTimeTo.timeString];
  271. // }
  272. // }
  273. // return _dueDate;
  274. //}
  275. //
  276. //- (NSString *)dueTimeCommandClassValue {
  277. // _dueTime = nil;
  278. // if (_chkDueTime.checked) {
  279. //
  280. // if (!_btnDueTimeTo.value) {
  281. // _dueTime = [NSString stringWithFormat:@"%@", _btnDueTimeFrom.timeString];
  282. // } else {
  283. // _dueTime = [NSString stringWithFormat:@"%@ ~ %@", _btnDueTimeFrom.timeString, _btnDueTimeTo.timeString];
  284. // }
  285. // }
  286. // return _dueDate;
  287. //}
  288. - (ItemModel *)homeModeCondition {
  289. if (_chkModes.checked && _modePopTableView) {
  290. _homeModeCondition = _modePopTableView.condition;
  291. }
  292. if (!_homeModeCondition && _chkModes.checked) {
  293. [[JDFacade facade] alert:NSLocalizedString(@"홈모드를 선택해주세요", @"홈모드를 선택해주세요")];
  294. }
  295. return _homeModeCondition;
  296. }
  297. - (ItemModel *)exterHeatCondition {
  298. if (_chkExternHeat.checked && _externHeatPopView) {
  299. _exterHeatCondition = _externHeatPopView.condition;
  300. }
  301. if (!_exterHeatCondition && _chkExternHeat.checked) {
  302. [[JDFacade facade] alert:NSLocalizedString(@"지역온도를 선택해주세요", @"지역온도를 선택해주세요")];
  303. }
  304. return _exterHeatCondition;
  305. }
  306. - (CGFloat)heightForTriggerOptions
  307. {
  308. return _rowCount * kfTriggerOptionTableViewCellHeight;
  309. }
  310. #pragma mark - UITableView Delegate
  311. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  312. return 1;
  313. }
  314. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  315. return _rowCount;
  316. }
  317. - (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
  318. {
  319. return [super tableView:tableView indentationLevelForRowAtIndexPath:indexPath];
  320. }
  321. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  322. NSIndexPath *tmpIndexPath = indexPath;
  323. if ([_tmpItem.itemSubTypeCode isEqualToString:ksItemSubTypeCodeTimer]) {
  324. if (indexPath.row >= 2) {
  325. tmpIndexPath = [NSIndexPath indexPathForRow:indexPath.row + 1 inSection:indexPath.section];
  326. }
  327. } else if ([_tmpItem.itemSubTypeCode isEqualToString:ksItemSubTypeCodeMode]) {
  328. if (indexPath.row >= 3) {
  329. tmpIndexPath = [NSIndexPath indexPathForRow:indexPath.row + 1 inSection:indexPath.section];
  330. }
  331. }
  332. UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:tmpIndexPath];
  333. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  334. return cell;
  335. }
  336. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  337. // Remove seperator inset
  338. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  339. [cell setSeparatorInset:UIEdgeInsetsZero];
  340. }
  341. // Prevent the cell from inheriting the Table View's margin settings
  342. if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
  343. [cell setPreservesSuperviewLayoutMargins:NO];
  344. }
  345. // Explictly set your cell's layout margins
  346. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  347. [cell setLayoutMargins:UIEdgeInsetsZero];
  348. }
  349. }
  350. #pragma mark - UI Events
  351. - (IBAction)chkDueDateTouched:(id)sender
  352. {
  353. CustomCheckBox *chk = (CustomCheckBox *)sender;
  354. UIImage *image = !chk.checked ? _imageBtnNormal : _imageBtnDisable;
  355. if (!chk.checked) {
  356. [_btnDueDateTo setTitle:ksEmptyString forState:UIControlStateNormal];
  357. }
  358. [_btnDueDateFrom setBackgroundImage:image forState:UIControlStateNormal];
  359. [_btnDueDateTo setBackgroundImage:image forState:UIControlStateNormal];
  360. }
  361. - (IBAction)chkDaysTouched:(id)sender
  362. {
  363. CustomCheckBox *chk = (CustomCheckBox *)sender;
  364. UIImage *image = !chk.checked ? _imageBtnNormal : _imageBtnDisable;
  365. [_btnDaysOfWeek setBackgroundImage:image forState:UIControlStateNormal];
  366. }
  367. - (IBAction)chkDueTimeTouched:(id)sender
  368. {
  369. CustomCheckBox *chk = (CustomCheckBox *)sender;
  370. UIImage *image = !chk.checked ? _imageBtnNormal : _imageBtnDisable;
  371. if (!chk.checked) {
  372. [_btnDueTimeTo setTitle:ksEmptyString forState:UIControlStateNormal];
  373. }
  374. [_btnDueTimeFrom setBackgroundImage:image forState:UIControlStateNormal];
  375. [_btnDueTimeTo setBackgroundImage:image forState:UIControlStateNormal];
  376. }
  377. - (IBAction)chkModesTouched:(id)sender
  378. {
  379. CustomCheckBox *chk = (CustomCheckBox *)sender;
  380. UIImage *image = !chk.checked ? _imageBtnNormal : _imageBtnDisable;
  381. [_btnModes setBackgroundImage:image forState:UIControlStateNormal];
  382. }
  383. - (IBAction)chkExternHeatTouched:(id)sender
  384. {
  385. CustomCheckBox *chk = (CustomCheckBox *)sender;
  386. UIImage *image = !chk.checked ? _imageBtnNormal : _imageBtnDisable;
  387. [_btnExternHeat setBackgroundImage:image forState:UIControlStateNormal];
  388. }
  389. //buttons
  390. - (IBAction)btnDueDateFromTouched:(id)sender
  391. {
  392. CustomButton *btn = (CustomButton *)sender;
  393. [btn setBackgroundImage:_imageBtnNormal forState:UIControlStateNormal];
  394. _chkDueDate.checked = YES;
  395. }
  396. - (IBAction)btnDueDateToTouched:(id)sender
  397. {
  398. CustomButton *btn = (CustomButton *)sender;
  399. [btn setBackgroundImage:_imageBtnNormal forState:UIControlStateNormal];
  400. [_btnDueDateFrom setBackgroundImage:_imageBtnNormal forState:UIControlStateNormal];
  401. _chkDueDate.checked = YES;
  402. }
  403. - (IBAction)btnDaysToTouched:(id)sender
  404. {
  405. CustomButton *btn = (CustomButton *)sender;
  406. [btn setBackgroundImage:_imageBtnNormal forState:UIControlStateNormal];
  407. _chkDaysOfWeek.checked = YES;
  408. if (!_daysPopupView) {
  409. _daysPopupView = [[DaysPopupView alloc] initFromNib];
  410. }
  411. _daysPopupView.condition = _daysOfWeekCondition;
  412. [_daysPopupView showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  413. if (buttonIndex == 0) {//선택
  414. _daysOfWeekCondition = _daysPopupView.condition;
  415. [_btnDaysOfWeek setTitle:_daysPopupView.daysOfWeek forState:UIControlStateNormal];
  416. }
  417. }];
  418. }
  419. - (IBAction)btnDueTimeFromToTouched:(id)sender
  420. {
  421. CustomButton *btn = (CustomButton *)sender;
  422. [btn setBackgroundImage:_imageBtnNormal forState:UIControlStateNormal];
  423. _chkDueTime.checked = YES;
  424. }
  425. - (IBAction)btnDueTimeToTouched:(id)sender
  426. {
  427. CustomButton *btn = (CustomButton *)sender;
  428. [btn setBackgroundImage:_imageBtnNormal forState:UIControlStateNormal];
  429. [_btnDueTimeTo setBackgroundImage:_imageBtnNormal forState:UIControlStateNormal];
  430. _chkDueTime.checked = YES;
  431. }
  432. - (IBAction)btnModesTouched:(id)sender
  433. {
  434. CustomButton *btn = (CustomButton *)sender;
  435. [btn setBackgroundImage:_imageBtnNormal forState:UIControlStateNormal];
  436. _chkModes.checked = YES;
  437. if (!_modePopTableView) {
  438. _modePopTableView = [[ModePopTableView alloc] initFromNib];
  439. }
  440. _modePopTableView.condition = _homeModeCondition;
  441. [_modePopTableView showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  442. if (buttonIndex == 0) {//선택
  443. _homeModeCondition = _modePopTableView.condition;
  444. [_btnModes setTitle:_modePopTableView.homeModes forState:UIControlStateNormal];
  445. }
  446. }];
  447. }
  448. - (IBAction)btnExternHeatTouched:(id)sender
  449. {
  450. CustomButton *btn = (CustomButton *)sender;
  451. [btn setBackgroundImage:_imageBtnNormal forState:UIControlStateNormal];
  452. _chkExternHeat.checked = YES;
  453. if (!_externHeatPopView) {
  454. _externHeatPopView = [[ExternHeatPopupView alloc] initFromNib];
  455. }
  456. _externHeatPopView.condition = _exterHeatCondition;
  457. [_externHeatPopView showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  458. if (buttonIndex == 0) {//선택
  459. _exterHeatCondition = _externHeatPopView.condition;
  460. [_btnExternHeat setTitle:_externHeatPopView.externHeat forState:UIControlStateNormal];
  461. }
  462. }];
  463. }
  464. #pragma mark - MemoryWarning
  465. - (void)didReceiveMemoryWarning
  466. {
  467. [super didReceiveMemoryWarning];
  468. // Dispose of any resources that can be recreated.
  469. }
  470. @end