2 import {DataTypesService} from "app/services/data-types-service";
3 import {PropertyModel, InputPropertyBase, Component} from "app/models";
4 import {IPropertyFormBaseViewScope, PropertyFormBaseView} from "../base-property-form/property-form-base-model";
5 import {PROPERTY_TYPES} from "app/utils/constants";
7 interface ISelectDataTypeViewModelScope extends IPropertyFormBaseViewScope {
8 selectedPropertiesName:string;
9 dataTypesService:DataTypesService;
11 isTypeDataType:boolean;
16 export class SelectDataTypeViewModel extends PropertyFormBaseView {
26 'Sdc.Services.DataTypesService',
31 constructor(protected $scope:ISelectDataTypeViewModelScope,
32 protected $templateCache:ng.ITemplateCacheService,
33 protected $uibModalInstance:ng.ui.bootstrap.IModalServiceInstance,
34 protected $injector:ng.auto.IInjectorService,
35 protected originalProperty:PropertyModel,
36 protected component:Component,
37 protected filteredProperties:Array<PropertyModel>,
38 protected DataTypesService:DataTypesService,
39 private propertiesMap:Array<InputPropertyBase>,
40 private $q:ng.IQService) {
41 super($scope, $uibModalInstance, $injector, originalProperty, component, filteredProperties, DataTypesService);
43 this.$templateCache.put("select-datatype-modal-view.html", require('app/view-models/forms/property-forms/select-datatype-modal/select-datatype-modal-view.html'));
44 this.$scope.innerViewSrcUrl = "select-datatype-modal-view.html";
45 this.initChildScope();
49 save(isNeedToCloseModal):ng.IPromise<boolean> {
50 let deferred = this.$q.defer();
51 this.$scope.property.propertiesName = this.DataTypesService.selectedPropertiesName;
52 this.$scope.property.input = this.DataTypesService.selectedInput;
53 this.$scope.property.isAlreadySelected = true;
54 this.$uibModalInstance.close(this.$scope.property);
55 deferred.resolve(true);
56 return deferred.promise;
59 private initForNotSimpleType = ():void => {
60 let property = this.$scope.property;
61 this.$scope.isTypeDataType = this.DataTypesService.isDataTypeForPropertyType(this.$scope.property);
62 if (property.type && this.$scope.simpleTypes.indexOf(property.type) == -1) {
63 if (!(property.value || property.defaultValue)) {
64 switch (property.type) {
65 case PROPERTY_TYPES.MAP:
66 this.$scope.myValue = {'': null};
68 case PROPERTY_TYPES.LIST:
69 this.$scope.myValue = [];
72 this.$scope.myValue = {};
75 this.$scope.myValue = JSON.parse(property.value || property.defaultValue);
80 //remove selection property on the modal
81 private removeSelected = ():void => {
82 this.DataTypesService.selectedPropertiesName = null;
83 this.DataTypesService.selectedInput = null;
86 private initChildScope = ():void => {
88 this.$scope.forms = {};
89 this.$scope.path = this.$scope.property.name;
90 this.$scope.isArrowsDisabled = true;
91 this.DataTypesService.alreadySelectedProperties = this.propertiesMap;
92 this.$scope.dataTypesService = this.DataTypesService;
93 this.$scope.isReadOnly = true;
94 this.initForNotSimpleType();
95 this.removeSelected();