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=========================================================
22 import {DataTypesService} from "app/services/data-types-service";
23 import {PropertyModel, InputPropertyBase, Component} from "app/models";
24 import {IPropertyFormBaseViewScope, PropertyFormBaseView} from "../base-property-form/property-form-base-model";
25 import {PROPERTY_TYPES} from "app/utils/constants";
27 interface ISelectDataTypeViewModelScope extends IPropertyFormBaseViewScope {
28 selectedPropertiesName:string;
29 dataTypesService:DataTypesService;
31 isTypeDataType:boolean;
36 export class SelectDataTypeViewModel extends PropertyFormBaseView {
46 'Sdc.Services.DataTypesService',
51 constructor(protected $scope:ISelectDataTypeViewModelScope,
52 protected $templateCache:ng.ITemplateCacheService,
53 protected $uibModalInstance:ng.ui.bootstrap.IModalServiceInstance,
54 protected $injector:ng.auto.IInjectorService,
55 protected originalProperty:PropertyModel,
56 protected component:Component,
57 protected filteredProperties:Array<PropertyModel>,
58 protected DataTypesService:DataTypesService,
59 private propertiesMap:Array<InputPropertyBase>,
60 private $q:ng.IQService) {
61 super($scope, $uibModalInstance, $injector, originalProperty, component, filteredProperties, DataTypesService);
63 this.$templateCache.put("select-datatype-modal-view.html", require('app/view-models/forms/property-forms/select-datatype-modal/select-datatype-modal-view.html'));
64 this.$scope.innerViewSrcUrl = "select-datatype-modal-view.html";
65 this.initChildScope();
69 save(isNeedToCloseModal):ng.IPromise<boolean> {
70 let deferred = this.$q.defer<boolean>();
71 this.$scope.property.propertiesName = this.DataTypesService.selectedPropertiesName;
72 this.$scope.property.input = this.DataTypesService.selectedInput;
73 this.$scope.property.isAlreadySelected = true;
74 this.$uibModalInstance.close(this.$scope.property);
75 deferred.resolve(true);
76 return deferred.promise;
79 private initForNotSimpleType = ():void => {
80 let property = this.$scope.property;
81 this.$scope.isTypeDataType = this.DataTypesService.isDataTypeForPropertyType(this.$scope.property);
82 if (property.type && this.$scope.simpleTypes.indexOf(property.type) == -1) {
83 if (!(property.value || property.defaultValue)) {
84 switch (property.type) {
85 case PROPERTY_TYPES.MAP:
86 this.$scope.myValue = {'': null};
88 case PROPERTY_TYPES.LIST:
89 this.$scope.myValue = [];
92 this.$scope.myValue = {};
95 this.$scope.myValue = JSON.parse(property.value || property.defaultValue);
100 //remove selection property on the modal
101 private removeSelected = ():void => {
102 this.DataTypesService.selectedPropertiesName = null;
103 this.DataTypesService.selectedInput = null;
106 private initChildScope = ():void => {
108 this.$scope.forms = {};
109 this.$scope.path = this.$scope.property.name;
110 this.$scope.isArrowsDisabled = true;
111 this.DataTypesService.alreadySelectedProperties = this.propertiesMap;
112 this.$scope.dataTypesService = this.DataTypesService;
113 this.$scope.isReadOnly = true;
114 this.initForNotSimpleType();
115 this.removeSelected();