blob: 342f03f29062077e5c546048107ab272c4bfcab3 [file] [log] [blame]
Michael Landodd603392017-07-12 00:54:52 +03001/*-
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
ys969316a9fce2020-01-19 13:50:02 +020010 *
Michael Landodd603392017-07-12 00:54:52 +030011 * http://www.apache.org/licenses/LICENSE-2.0
ys969316a9fce2020-01-19 13:50:02 +020012 *
Michael Landodd603392017-07-12 00:54:52 +030013 * 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
ys969316a9fce2020-01-19 13:50:02 +020021import { Component, DisplayModule , PropertyModel } from '../models';
22import { ComponentMetadata } from '../models/component-metadata';
Michael Landoed64b5e2017-06-09 03:19:04 +030023
24export interface IModalsHandler {
25
ys969316a9fce2020-01-19 13:50:02 +020026 openEditPropertyModal(property: PropertyModel, component: Component, filteredProperties: PropertyModel[], isPropertyOwnValue: boolean,
27 propertyOwnerType: string, propertyOwnerId: string): ng.IPromise<any>;
Michael Landoed64b5e2017-06-09 03:19:04 +030028}
29
30export class ModalsHandler implements IModalsHandler {
31
32 static '$inject' = [
33 '$uibModal',
34 '$q'
35 ];
36
ys969316a9fce2020-01-19 13:50:02 +020037 constructor(private $uibModal: ng.ui.bootstrap.IModalService,
38 private $q: ng.IQService) {
Michael Landoed64b5e2017-06-09 03:19:04 +030039 }
40
ys969316a9fce2020-01-19 13:50:02 +020041 openUpdateIconModal = (component: Component): ng.IPromise<any> => {
42 const deferred = this.$q.defer();
43 const modalOptions: ng.ui.bootstrap.IModalSettings = {
Michael Lando75aacbb2017-07-17 21:12:03 +030044 templateUrl: '../view-models/modals/icons-modal/icons-modal-view.html',
45 controller: 'Sdc.ViewModels.IconsModalViewModel',
46 size: 'sdc-auto',
47 backdrop: 'static',
48 resolve: {
ys969316a9fce2020-01-19 13:50:02 +020049 component: (): Component => {
Michael Lando75aacbb2017-07-17 21:12:03 +030050 return component;
51 }
52 }
53 };
ys969316a9fce2020-01-19 13:50:02 +020054 const modalInstance: ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
Michael Lando75aacbb2017-07-17 21:12:03 +030055 deferred.resolve(modalInstance.result);
56 return deferred.promise;
ys969316a9fce2020-01-19 13:50:02 +020057 }
Michael Landoed64b5e2017-06-09 03:19:04 +030058
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 */
ys969316a9fce2020-01-19 13:50:02 +020069 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 Landoed64b5e2017-06-09 03:19:04 +030072
ys969316a9fce2020-01-19 13:50:02 +020073 const modalOptions: ng.ui.bootstrap.IModalSettings = {
Michael Landoed64b5e2017-06-09 03:19:04 +030074 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: {
ys969316a9fce2020-01-19 13:50:02 +020080 property: (): PropertyModel => {
Michael Landoed64b5e2017-06-09 03:19:04 +030081 return property;
82 },
ys969316a9fce2020-01-19 13:50:02 +020083 component: (): Component => {
84 return component as Component;
Michael Landoed64b5e2017-06-09 03:19:04 +030085 },
ys969316a9fce2020-01-19 13:50:02 +020086 filteredProperties: (): PropertyModel[] => {
Michael Landoed64b5e2017-06-09 03:19:04 +030087 return filteredProperties;
88 },
ys969316a9fce2020-01-19 13:50:02 +020089 isPropertyValueOwner: (): boolean => {
Michael Landoed64b5e2017-06-09 03:19:04 +030090 return isPropertyValueOwner;
Michael Lando5b593492018-07-29 16:13:45 +030091 },
ys969316a9fce2020-01-19 13:50:02 +020092 propertyOwnerType: (): string => {
Michael Lando5b593492018-07-29 16:13:45 +030093 return propertyOwnerType;
94 },
ys969316a9fce2020-01-19 13:50:02 +020095 propertyOwnerId: (): string => {
Michael Lando5b593492018-07-29 16:13:45 +030096 return propertyOwnerId;
Michael Landoed64b5e2017-06-09 03:19:04 +030097 }
98 }
99 };
100
ys969316a9fce2020-01-19 13:50:02 +0200101 const modalInstance: ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
Michael Landoed64b5e2017-06-09 03:19:04 +0300102 deferred.resolve(modalInstance.result);
103 return deferred.promise;
ys969316a9fce2020-01-19 13:50:02 +0200104 }
Michael Landoed64b5e2017-06-09 03:19:04 +0300105
ys969316a9fce2020-01-19 13:50:02 +0200106 /**
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 Landoed64b5e2017-06-09 03:19:04 +0300117
ys969316a9fce2020-01-19 13:50:02 +0200118 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 Landoed64b5e2017-06-09 03:19:04 +0300142
ys969316a9fce2020-01-19 13:50:02 +0200143 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 Landoed64b5e2017-06-09 03:19:04 +0300152 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: {
ys969316a9fce2020-01-19 13:50:02 +0200158 originalProperty: (): PropertyModel => {
Michael Landoed64b5e2017-06-09 03:19:04 +0300159 return property;
160 },
ys969316a9fce2020-01-19 13:50:02 +0200161 component: (): Component => {
162 return component as Component;
Michael Landoed64b5e2017-06-09 03:19:04 +0300163 },
ys969316a9fce2020-01-19 13:50:02 +0200164 selectedModule: (): DisplayModule => {
Michael Landoed64b5e2017-06-09 03:19:04 +0300165 return selectedModule;
Michael Landoa5445102018-03-04 14:53:33 +0200166 },
ys969316a9fce2020-01-19 13:50:02 +0200167 filteredProperties: (): PropertyModel[] => {
Michael Landoa5445102018-03-04 14:53:33 +0200168 return filteredProperties;
Michael Landoed64b5e2017-06-09 03:19:04 +0300169 }
170 }
171 };
172
ys969316a9fce2020-01-19 13:50:02 +0200173 const modalInstance: ng.ui.bootstrap.IModalServiceInstance = this.$uibModal.open(modalOptions);
Michael Landoed64b5e2017-06-09 03:19:04 +0300174 deferred.resolve(modalInstance.result);
175 return deferred.promise;
ys969316a9fce2020-01-19 13:50:02 +0200176 }
Michael Landoed64b5e2017-06-09 03:19:04 +0300177
178}