TriggerSelectPopupView.m 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //
  2. // TriggerSelectPopupView.m
  3. // kneet2
  4. //
  5. // Created by Jason Lee on 11/23/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "CustomLabel.h"
  10. #import "CustomButton.h"
  11. #import "CustomLabelButton.h"
  12. #import "TriggerSelectPopupView.h"
  13. #import "DeviceSelectPopupView.h"
  14. #import "DeviceNodePopupView.h"
  15. #import "TimePickerPopupView.h"
  16. #import "DaylightPopupView.h"
  17. #import "ExternHeatPopupView.h"
  18. @interface TriggerSelectPopupView () {
  19. NSMutableArray<ItemModel> *_checkedItems;
  20. }
  21. @end
  22. @implementation TriggerSelectPopupView
  23. - (id)initFromNib {
  24. for (UIView *view in [CommonUtil nibViews:@"TriggerSelectPopupView"]) {
  25. if ([view isKindOfClass:[TriggerSelectPopupView class]]) {
  26. self = (TriggerSelectPopupView *)view;
  27. //XIB의 경우, 현재 화면 사이즈로 맞춰줘야 함.
  28. self.frame = [UIScreen mainScreen].bounds;
  29. [self.imgTitleBar setImage:[UIImage imageNamed:@"img_popup_bg_head"]inset:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  30. // [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  31. // [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  32. [self.btnCancelSingle setBackgroundImage:[UIImage imageNamed:@"img_popup_btn"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  33. [self.btnCancelSingle setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  34. //Localization
  35. // [self.btnConfirm setTitle:NSLocalizedString(@"확인", @"확인") forState:UIControlStateNormal];
  36. [self.btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
  37. }
  38. }
  39. return self;
  40. }
  41. - (void)didMoveToSuperview {
  42. }
  43. #pragma mark - UI Events
  44. - (IBAction)btnTimerTouched:(id)sender {
  45. ItemModel *trigger = _refTriggers && _refTriggers.count ? _refTriggers[0] : nil;
  46. BOOL isNewTrigger = !trigger.timers || !trigger.timers.count;
  47. ItemModel *timeTrigger = !isNewTrigger ? trigger : [[ItemModel alloc] init];
  48. TimePickerPopupView *tpopup = [[TimePickerPopupView alloc] initFromNib];
  49. tpopup.timeTrigger = timeTrigger;
  50. tpopup.refConditions = _refConditions;
  51. [tpopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  52. if (buttonIndex == 0) {//OK
  53. if (isNewTrigger) {
  54. [_refTriggers addObject:timeTrigger];
  55. [super btnConfirmTouched:sender];
  56. }
  57. }
  58. }];
  59. }
  60. - (IBAction)btnDaylightTouched:(id)sender {
  61. ItemModel *trigger = _refTriggers && _refTriggers.count ? _refTriggers[0] : nil;
  62. BOOL isNewTrigger = !trigger.daylights || !trigger.daylights.count;
  63. ItemModel *daylightTrigger = !isNewTrigger ? trigger : [[ItemModel alloc] init];
  64. DaylightPopupView *dpopup = [[DaylightPopupView alloc] initFromNib];
  65. dpopup.daylightTrigger = daylightTrigger;
  66. dpopup.refConditions = _refConditions;
  67. [dpopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  68. if (buttonIndex == 0) {//OK
  69. if (isNewTrigger) {
  70. [_refTriggers addObject:daylightTrigger];
  71. [super btnConfirmTouched:sender];
  72. }
  73. }
  74. }];
  75. }
  76. - (IBAction)btnHeatTouched:(id)sender {
  77. ItemModel *trigger = _refTriggers && _refTriggers.count ? _refTriggers[0] : nil;
  78. BOOL isNewTrigger = !trigger.heats || !trigger.heats.count;
  79. ItemModel *heatTrigger = !isNewTrigger ? trigger : [[ItemModel alloc] init];
  80. ExternHeatPopupView *epopup = [[ExternHeatPopupView alloc] initFromNib];
  81. epopup.externHeatTrigger = heatTrigger;
  82. epopup.refConditions = _refConditions;
  83. [epopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  84. if (buttonIndex == 0) {//OK
  85. if (isNewTrigger) {
  86. NSLog(@"heatTrigger : %@", heatTrigger);
  87. [_refTriggers addObject:heatTrigger];
  88. [super btnConfirmTouched:sender];
  89. }
  90. }
  91. }];
  92. }
  93. - (IBAction)btnDeviceTouched:(id)sender {
  94. DeviceSelectPopupView *dpopup = [[DeviceSelectPopupView alloc] initFromNib];
  95. dpopup.refDevices = _refDevices;
  96. dpopup.typeCode = ksItemTypeCodeTrigger;
  97. [dpopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  98. if (buttonIndex == 0) {//ok
  99. DeviceNodePopupView *npopup = [[DeviceNodePopupView alloc] initFromNib];
  100. npopup.refDevice = dpopup.selectedDevices[0];
  101. npopup.typeCode = ksItemTypeCodeTrigger;
  102. [npopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  103. //action add
  104. if (buttonIndex == 0) {//OK
  105. npopup.refDevice.itemName = @"장치 상태가 바뀔 때";
  106. npopup.refDevice.itemSubTypeCode = ksItemSubTypeCodeDevice; //트리거 타입 설정
  107. [_refTriggers addObject:npopup.refDevice];
  108. [super btnConfirmTouched:sender];
  109. }
  110. }];
  111. //디바이스 트리거인 경우, 요일 반복 제거,
  112. [_refConditions enumerateObjectsUsingBlock:^(ItemModel *pCondition, NSUInteger idx, BOOL * _Nonnull stop) {
  113. if ([pCondition.itemSubTypeCode isEqualToString:ksConditionSubTypeCodeDaysOfWeek]) {
  114. [_refConditions removeObject:pCondition];
  115. *stop = YES;
  116. }
  117. }];
  118. }
  119. }];
  120. }
  121. - (IBAction)btnCancelTouched:(id)sender {
  122. [super btnCancelSingleTouched:sender];
  123. }
  124. @end