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 } 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): 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): 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;
101 const modalInstance: ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
102 deferred.resolve(modalInstance.result);
103 return deferred.promise;
108 * This function openes up the edit property modal
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
115 newOpenEditPropertyModal = (property: PropertyModel, filteredProperties: PropertyModel[], isPropertyValueOwner: boolean, propertyOwnerType: string, propertyOwnerId: string): ng.IPromise<any> => {
116 const deferred = this.$q.defer();
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',
125 property: (): PropertyModel => {
128 filteredProperties: (): PropertyModel[] => {
129 return filteredProperties;
131 isPropertyValueOwner: (): boolean => {
132 return isPropertyValueOwner;
134 propertyOwnerType: (): string => {
135 return propertyOwnerType;
137 propertyOwnerId: (): string => {
138 return propertyOwnerId;
143 const modalInstance: ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
144 deferred.resolve(modalInstance.result);
145 return deferred.promise;
148 openEditModulePropertyModal = (property: PropertyModel, component: Component, selectedModule: DisplayModule, filteredProperties: PropertyModel[]): ng.IPromise<any> => {
149 const deferred = this.$q.defer();
151 const modalOptions: ng.ui.bootstrap.IModalSettings = {
152 templateUrl: '../view-models/forms/property-forms/base-property-form/property-form-base-view.html',
153 controller: 'Sdc.ViewModels.ModulePropertyView',
158 originalProperty: (): PropertyModel => {
161 component: (): Component => {
162 return component as Component;
164 selectedModule: (): DisplayModule => {
165 return selectedModule;
167 filteredProperties: (): PropertyModel[] => {
168 return filteredProperties;
173 const modalInstance: ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
174 deferred.resolve(modalInstance.result);
175 return deferred.promise;