| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- //
- // TriggerSelectPopupView.m
- // kneet2
- //
- // Created by Jason Lee on 11/23/15.
- // Copyright (c) 2015 ntels. All rights reserved.
- //
- #import "JDObject.h"
- #import "CustomLabel.h"
- #import "CustomButton.h"
- #import "CustomLabelButton.h"
- #import "TriggerSelectPopupView.h"
- #import "DeviceSelectPopupView.h"
- #import "DeviceNodePopupView.h"
- #import "TimePickerPopupView.h"
- #import "DaylightPopupView.h"
- #import "ExternHeatPopupView.h"
- @interface TriggerSelectPopupView () {
-
- NSMutableArray<ItemModel> *_checkedItems;
- }
- @end
- @implementation TriggerSelectPopupView
- - (id)initFromNib {
-
- for (UIView *view in [CommonUtil nibViews:@"TriggerSelectPopupView"]) {
- if ([view isKindOfClass:[TriggerSelectPopupView class]]) {
- self = (TriggerSelectPopupView *)view;
-
- //XIB의 경우, 현재 화면 사이즈로 맞춰줘야 함.
- self.frame = [UIScreen mainScreen].bounds;
-
- [self.imgTitleBar setImage:[UIImage imageNamed:@"img_popup_bg_head"]inset:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
-
-
- // [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
- // [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
-
-
- [self.btnCancelSingle setBackgroundImage:[UIImage imageNamed:@"img_popup_btn"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
- [self.btnCancelSingle setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
-
- //Localization
- // [self.btnConfirm setTitle:NSLocalizedString(@"확인", @"확인") forState:UIControlStateNormal];
- [self.btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
- }
- }
-
- return self;
- }
- - (void)didMoveToSuperview {
-
- }
- #pragma mark - UI Events
- - (IBAction)btnTimerTouched:(id)sender {
- ItemModel *trigger = _refTriggers && _refTriggers.count ? _refTriggers[0] : nil;
-
- BOOL isNewTrigger = !trigger.timers || !trigger.timers.count;
- ItemModel *timeTrigger = !isNewTrigger ? trigger : [[ItemModel alloc] init];
-
- TimePickerPopupView *tpopup = [[TimePickerPopupView alloc] initFromNib];
- tpopup.timeTrigger = timeTrigger;
- tpopup.refConditions = _refConditions;
-
- [tpopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
- if (buttonIndex == 0) {//OK
- if (isNewTrigger) {
- [_refTriggers addObject:timeTrigger];
- [super btnConfirmTouched:sender];
- }
- }
- }];
- }
- - (IBAction)btnDaylightTouched:(id)sender {
-
- ItemModel *trigger = _refTriggers && _refTriggers.count ? _refTriggers[0] : nil;
-
- BOOL isNewTrigger = !trigger.daylights || !trigger.daylights.count;
- ItemModel *daylightTrigger = !isNewTrigger ? trigger : [[ItemModel alloc] init];
-
- DaylightPopupView *dpopup = [[DaylightPopupView alloc] initFromNib];
- dpopup.daylightTrigger = daylightTrigger;
- dpopup.refConditions = _refConditions;
-
- [dpopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
- if (buttonIndex == 0) {//OK
- if (isNewTrigger) {
- [_refTriggers addObject:daylightTrigger];
- [super btnConfirmTouched:sender];
- }
- }
- }];
- }
- - (IBAction)btnHeatTouched:(id)sender {
-
- ItemModel *trigger = _refTriggers && _refTriggers.count ? _refTriggers[0] : nil;
-
- BOOL isNewTrigger = !trigger.heats || !trigger.heats.count;
- ItemModel *heatTrigger = !isNewTrigger ? trigger : [[ItemModel alloc] init];
-
- ExternHeatPopupView *epopup = [[ExternHeatPopupView alloc] initFromNib];
- epopup.externHeatTrigger = heatTrigger;
- epopup.refConditions = _refConditions;
-
- [epopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
- if (buttonIndex == 0) {//OK
- if (isNewTrigger) {
- [_refTriggers addObject:heatTrigger];
- [super btnConfirmTouched:sender];
- }
- }
- }];
- }
- - (IBAction)btnDeviceTouched:(id)sender {
- DeviceSelectPopupView *dpopup = [[DeviceSelectPopupView alloc] initFromNib];
- dpopup.refDevices = _refDevices;
- dpopup.typeCode = ksItemTypeCodeTrigger;
-
- [dpopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
- if (buttonIndex == 0) {//ok
- DeviceNodePopupView *npopup = [[DeviceNodePopupView alloc] initFromNib];
- npopup.refDevice = dpopup.selectedDevices[0];
- npopup.typeCode = ksItemTypeCodeTrigger;
-
- [npopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
- //action add
- if (buttonIndex == 0) {//OK
- npopup.refDevice.itemName = @"장치 상태가 바뀔 때";
- npopup.refDevice.itemSubTypeCode = ksItemSubTypeCodeDevice; //트리거 타입 설정
-
- [_refTriggers addObject:npopup.refDevice];
- [super btnConfirmTouched:sender];
- }
- }];
-
-
- //디바이스 트리거인 경우, 요일 반복 제거,
- [_refConditions enumerateObjectsUsingBlock:^(ItemModel *pCondition, NSUInteger idx, BOOL * _Nonnull stop) {
- if ([pCondition.itemSubTypeCode isEqualToString:ksConditionSubTypeCodeDaysOfWeek]) {
- [_refConditions removeObject:pCondition];
- *stop = YES;
- }
- }];
- }
- }];
- }
- - (IBAction)btnCancelTouched:(id)sender {
- [super btnCancelSingleTouched:sender];
- }
- @end
|