2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 import { Component, DisplayModule , PropertyModel, InputFEModel } from '../models';
22 import { ComponentMetadata } from '../models/component-metadata';
24 export interface IModalsHandler {
26 openEditPropertyModal(property: PropertyModel, component: Component, filteredProperties: PropertyModel[], isPropertyOwnValue: boolean,
27 propertyOwnerType: string, propertyOwnerId: string, isViewOnly?: boolean): ng.IPromise<any>;
30 export class ModalsHandler implements IModalsHandler {
37 constructor(private $uibModal: ng.ui.bootstrap.IModalService,
38 private $q: ng.IQService) {
41 openUpdateIconModal = (component: Component): ng.IPromise<any> => {
42 const deferred = this.$q.defer();
43 const modalOptions: ng.ui.bootstrap.IModalSettings = {
44 templateUrl: '../view-models/modals/icons-modal/icons-modal-view.html',
45 controller: 'Sdc.ViewModels.IconsModalViewModel',
49 component: (): Component => {
54 const modalInstance: ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
55 deferred.resolve(modalInstance.result);
56 return deferred.promise;
61 * This function openes up the edit property modal
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
69 openEditPropertyModal = (property: PropertyModel, component: Component | ComponentMetadata, filteredProperties: PropertyModel[],
70 isPropertyValueOwner: boolean, propertyOwnerType: string, propertyOwnerId: string, isViewOnly: boolean = false): ng.IPromise<any> => {
71 const deferred = this.$q.defer();
73 const modalOptions: ng.ui.bootstrap.IModalSettings = {
74 templateUrl: '../view-models/forms/property-forms/component-property-form/property-form-view.html',
75 controller: 'Sdc.ViewModels.PropertyFormViewModel',
80 property: (): PropertyModel => {
83 component: (): Component => {
84 return component as Component;
86 filteredProperties: (): PropertyModel[] => {
87 return filteredProperties;
89 isPropertyValueOwner: (): boolean => {
90 return isPropertyValueOwner;
92 propertyOwnerType: (): string => {
93 return propertyOwnerType;
95 propertyOwnerId: (): string => {
96 return propertyOwnerId;
98 isViewOnly: (): boolean => {
101 inputProperty: (): InputFEModel => {
107 const modalInstance: ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
108 deferred.resolve(modalInstance.result);
109 return deferred.promise;
114 * This function openes up the edit property modal
116 * @param property - the property to edit
117 * @param filteredProperties - the filtered properties list to scroll between in the edit modal
118 * @param isPropertyValueOwner - boolean telling if the component is eligible of editing the property
119 * @returns {IPromise<T>} - Promise telling if the modal has opened or not
121 newOpenEditPropertyModal = (property: PropertyModel, filteredProperties: PropertyModel[], isPropertyValueOwner: boolean, propertyOwnerType: string, propertyOwnerId: string, component: Component, inputProperty: InputFEModel): ng.IPromise<any> => {
122 const deferred = this.$q.defer();
124 const modalOptions: ng.ui.bootstrap.IModalSettings = {
125 templateUrl: '../view-models/forms/property-forms/component-property-form/property-form-view.html',
126 controller: 'Sdc.ViewModels.PropertyFormViewModel',
131 property: (): PropertyModel => {
134 filteredProperties: (): PropertyModel[] => {
135 return filteredProperties;
137 isPropertyValueOwner: (): boolean => {
138 return isPropertyValueOwner;
140 propertyOwnerType: (): string => {
141 return propertyOwnerType;
143 propertyOwnerId: (): string => {
144 return propertyOwnerId;
146 isViewOnly: (): boolean => {
149 component: (): Component => {
150 return component as Component;
152 inputProperty: (): InputFEModel => {
153 return inputProperty;
158 const modalInstance: ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
159 deferred.resolve(modalInstance.result);
160 return deferred.promise;
163 openEditModulePropertyModal = (property: PropertyModel, component: Component, selectedModule: DisplayModule, filteredProperties: PropertyModel[]): ng.IPromise<any> => {
164 const deferred = this.$q.defer();
166 const modalOptions: ng.ui.bootstrap.IModalSettings = {
167 templateUrl: '../view-models/forms/property-forms/base-property-form/property-form-base-view.html',
168 controller: 'Sdc.ViewModels.ModulePropertyView',
173 originalProperty: (): PropertyModel => {
176 component: (): Component => {
177 return component as Component;
179 selectedModule: (): DisplayModule => {
180 return selectedModule;
182 filteredProperties: (): PropertyModel[] => {
183 return filteredProperties;
188 const modalInstance: ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
189 deferred.resolve(modalInstance.result);
190 return deferred.promise;