TriggerSelectPopupView.m 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. NSLog(@"_refTriggers : %@", _refTriggers);
  56. [super btnConfirmTouched:sender];
  57. }
  58. }
  59. }];
  60. }
  61. - (IBAction)btnDaylightTouched:(id)sender {
  62. ItemModel *trigger = _refTriggers && _refTriggers.count ? _refTriggers[0] : nil;
  63. BOOL isNewTrigger = !trigger.daylights || !trigger.daylights.count;
  64. ItemModel *daylightTrigger = !isNewTrigger ? trigger : [[ItemModel alloc] init];
  65. DaylightPopupView *dpopup = [[DaylightPopupView alloc] initFromNib];
  66. dpopup.daylightTrigger = daylightTrigger;
  67. dpopup.refConditions = _refConditions;
  68. [dpopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  69. if (buttonIndex == 0) {//OK
  70. if (isNewTrigger) {
  71. [_refTriggers addObject:daylightTrigger];
  72. [super btnConfirmTouched:sender];
  73. }
  74. }
  75. }];
  76. }
  77. - (IBAction)btnHeatTouched:(id)sender {
  78. ItemModel *trigger = _refTriggers && _refTriggers.count ? _refTriggers[0] : nil;
  79. BOOL isNewTrigger = !trigger.heats || !trigger.heats.count;
  80. ItemModel *heatTrigger = !isNewTrigger ? trigger : [[ItemModel alloc] init];
  81. ExternHeatPopupView *epopup = [[ExternHeatPopupView alloc] initFromNib];
  82. epopup.externHeatTrigger = heatTrigger;
  83. epopup.refConditions = _refConditions;
  84. [epopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  85. if (buttonIndex == 0) {//OK
  86. if (isNewTrigger) {
  87. NSLog(@"heatTrigger : %@", heatTrigger);
  88. [_refTriggers addObject:heatTrigger];
  89. [super btnConfirmTouched:sender];
  90. }
  91. }
  92. }];
  93. }
  94. - (IBAction)btnDeviceTouched:(id)sender {
  95. DeviceSelectPopupView *dpopup = [[DeviceSelectPopupView alloc] initFromNib];
  96. dpopup.refDevices = _refDevices;
  97. dpopup.typeCode = ksItemTypeCodeTrigger;
  98. [dpopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  99. if (buttonIndex == 0) {//ok
  100. DeviceNodePopupView *npopup = [[DeviceNodePopupView alloc] initFromNib];
  101. npopup.refDevice = dpopup.selectedDevices[0];
  102. npopup.typeCode = ksItemTypeCodeTrigger;
  103. [npopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  104. //action add
  105. if (buttonIndex == 0) {//OK
  106. npopup.refDevice.itemName = @"장치 상태가 바뀔 때";
  107. npopup.refDevice.itemSubTypeCode = ksItemSubTypeCodeDevice; //트리거 타입 설정
  108. [_refTriggers addObject:npopup.refDevice];
  109. [super btnConfirmTouched:sender];
  110. }
  111. }];
  112. //디바이스 트리거인 경우, 요일 반복 제거,
  113. [_refConditions enumerateObjectsUsingBlock:^(ItemModel *pCondition, NSUInteger idx, BOOL * _Nonnull stop) {
  114. if ([pCondition.itemSubTypeCode isEqualToString:ksConditionSubTypeCodeDaysOfWeek]) {
  115. [_refConditions removeObject:pCondition];
  116. *stop = YES;
  117. }
  118. }];
  119. }
  120. }];
  121. }
  122. - (IBAction)btnCancelTouched:(id)sender {
  123. [super btnCancelSingleTouched:sender];
  124. }
  125. @end