Michael Lando | dd60339 | 2017-07-12 00:54:52 +0300 | [diff] [blame] | 1 | /*- |
| 2 | * ============LICENSE_START======================================================= |
| 3 | * SDC |
| 4 | * ================================================================================ |
| 5 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
| 6 | * ================================================================================ |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 10 | * |
Michael Lando | dd60339 | 2017-07-12 00:54:52 +0300 | [diff] [blame] | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 12 | * |
Michael Lando | dd60339 | 2017-07-12 00:54:52 +0300 | [diff] [blame] | 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | * ============LICENSE_END========================================================= |
| 19 | */ |
| 20 | |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 21 | import { Component, DisplayModule , PropertyModel } from '../models'; |
| 22 | import { ComponentMetadata } from '../models/component-metadata'; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 23 | |
| 24 | export interface IModalsHandler { |
| 25 | |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 26 | openEditPropertyModal(property: PropertyModel, component: Component, filteredProperties: PropertyModel[], isPropertyOwnValue: boolean, |
| 27 | propertyOwnerType: string, propertyOwnerId: string): ng.IPromise<any>; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | export class ModalsHandler implements IModalsHandler { |
| 31 | |
| 32 | static '$inject' = [ |
| 33 | '$uibModal', |
| 34 | '$q' |
| 35 | ]; |
| 36 | |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 37 | constructor(private $uibModal: ng.ui.bootstrap.IModalService, |
| 38 | private $q: ng.IQService) { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 39 | } |
| 40 | |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 41 | openUpdateIconModal = (component: Component): ng.IPromise<any> => { |
| 42 | const deferred = this.$q.defer(); |
| 43 | const modalOptions: ng.ui.bootstrap.IModalSettings = { |
Michael Lando | 75aacbb | 2017-07-17 21:12:03 +0300 | [diff] [blame] | 44 | templateUrl: '../view-models/modals/icons-modal/icons-modal-view.html', |
| 45 | controller: 'Sdc.ViewModels.IconsModalViewModel', |
| 46 | size: 'sdc-auto', |
| 47 | backdrop: 'static', |
| 48 | resolve: { |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 49 | component: (): Component => { |
Michael Lando | 75aacbb | 2017-07-17 21:12:03 +0300 | [diff] [blame] | 50 | return component; |
| 51 | } |
| 52 | } |
| 53 | }; |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 54 | const modalInstance: ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions); |
Michael Lando | 75aacbb | 2017-07-17 21:12:03 +0300 | [diff] [blame] | 55 | deferred.resolve(modalInstance.result); |
| 56 | return deferred.promise; |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 57 | } |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 58 | |
| 59 | /** |
| 60 | * |
| 61 | * This function openes up the edit property modal |
| 62 | * |
| 63 | * @param property - the property to edit |
| 64 | * @param component - the component who is the owner of the property |
| 65 | * @param filteredProperties - the filtered properties list to scroll between in the edit modal |
| 66 | * @param isPropertyValueOwner - boolean telling if the component is eligible of editing the property |
| 67 | * @returns {IPromise<T>} - Promise telling if the modal has opened or not |
| 68 | */ |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 69 | openEditPropertyModal = (property: PropertyModel, component: Component | ComponentMetadata, filteredProperties: PropertyModel[], |
| 70 | isPropertyValueOwner: boolean, propertyOwnerType: string, propertyOwnerId: string): ng.IPromise<any> => { |
| 71 | const deferred = this.$q.defer(); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 72 | |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 73 | const modalOptions: ng.ui.bootstrap.IModalSettings = { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 74 | templateUrl: '../view-models/forms/property-forms/component-property-form/property-form-view.html', |
| 75 | controller: 'Sdc.ViewModels.PropertyFormViewModel', |
| 76 | size: 'sdc-l', |
| 77 | backdrop: 'static', |
| 78 | keyboard: false, |
| 79 | resolve: { |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 80 | property: (): PropertyModel => { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 81 | return property; |
| 82 | }, |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 83 | component: (): Component => { |
| 84 | return component as Component; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 85 | }, |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 86 | filteredProperties: (): PropertyModel[] => { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 87 | return filteredProperties; |
| 88 | }, |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 89 | isPropertyValueOwner: (): boolean => { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 90 | return isPropertyValueOwner; |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 91 | }, |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 92 | propertyOwnerType: (): string => { |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 93 | return propertyOwnerType; |
| 94 | }, |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 95 | propertyOwnerId: (): string => { |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 96 | return propertyOwnerId; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | }; |
| 100 | |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 101 | const modalInstance: ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 102 | deferred.resolve(modalInstance.result); |
| 103 | return deferred.promise; |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 104 | } |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 105 | |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 106 | /** |
| 107 | * |
| 108 | * This function openes up the edit property modal |
| 109 | * |
| 110 | * @param property - the property to edit |
| 111 | * @param filteredProperties - the filtered properties list to scroll between in the edit modal |
| 112 | * @param isPropertyValueOwner - boolean telling if the component is eligible of editing the property |
| 113 | * @returns {IPromise<T>} - Promise telling if the modal has opened or not |
| 114 | */ |
| 115 | newOpenEditPropertyModal = (property: PropertyModel, filteredProperties: PropertyModel[], isPropertyValueOwner: boolean, propertyOwnerType: string, propertyOwnerId: string): ng.IPromise<any> => { |
| 116 | const deferred = this.$q.defer(); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 117 | |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 118 | const modalOptions: ng.ui.bootstrap.IModalSettings = { |
| 119 | templateUrl: '../view-models/forms/property-forms/component-property-form/property-form-view.html', |
| 120 | controller: 'Sdc.ViewModels.PropertyFormViewModel', |
| 121 | size: 'sdc-l', |
| 122 | backdrop: 'static', |
| 123 | keyboard: false, |
| 124 | resolve: { |
| 125 | property: (): PropertyModel => { |
| 126 | return property; |
| 127 | }, |
| 128 | filteredProperties: (): PropertyModel[] => { |
| 129 | return filteredProperties; |
| 130 | }, |
| 131 | isPropertyValueOwner: (): boolean => { |
| 132 | return isPropertyValueOwner; |
| 133 | }, |
| 134 | propertyOwnerType: (): string => { |
| 135 | return propertyOwnerType; |
| 136 | }, |
| 137 | propertyOwnerId: (): string => { |
| 138 | return propertyOwnerId; |
| 139 | } |
| 140 | } |
| 141 | }; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 142 | |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 143 | const modalInstance: ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions); |
| 144 | deferred.resolve(modalInstance.result); |
| 145 | return deferred.promise; |
| 146 | } |
| 147 | |
| 148 | openEditModulePropertyModal = (property: PropertyModel, component: Component, selectedModule: DisplayModule, filteredProperties: PropertyModel[]): ng.IPromise<any> => { |
| 149 | const deferred = this.$q.defer(); |
| 150 | |
| 151 | const modalOptions: ng.ui.bootstrap.IModalSettings = { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 152 | templateUrl: '../view-models/forms/property-forms/base-property-form/property-form-base-view.html', |
| 153 | controller: 'Sdc.ViewModels.ModulePropertyView', |
| 154 | size: 'sdc-l', |
| 155 | backdrop: 'static', |
| 156 | keyboard: false, |
| 157 | resolve: { |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 158 | originalProperty: (): PropertyModel => { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 159 | return property; |
| 160 | }, |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 161 | component: (): Component => { |
| 162 | return component as Component; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 163 | }, |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 164 | selectedModule: (): DisplayModule => { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 165 | return selectedModule; |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 166 | }, |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 167 | filteredProperties: (): PropertyModel[] => { |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 168 | return filteredProperties; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 169 | } |
| 170 | } |
| 171 | }; |
| 172 | |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 173 | const modalInstance: ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 174 | deferred.resolve(modalInstance.result); |
| 175 | return deferred.promise; |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 176 | } |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 177 | |
| 178 | } |