[SDC-31] add mising script got Comformance fix
[sdc.git] / catalog-ui / src / app / models / property-fe-model.ts
1 import {SchemaPropertyGroupModel, SchemaProperty} from './aschema-property';
2 import { PROPERTY_DATA } from 'app/utils';
3 import { FilterPropertiesAssignmentData, PropertyBEModel } from 'app/models';
4
5 export class PropertyFEModel extends PropertyBEModel {
6     public static filterData:FilterPropertiesAssignmentData;
7     childrenProperties: Array<PropertyFEModel>;
8     expandedChildPropertyId: string;
9     isAllChildrenLevelsCalculated: boolean;
10     isDataType: boolean;
11     isDisabled: boolean;
12     isSelected: boolean;
13     isSimpleType: boolean;
14     parent: PropertyFEModel;
15     treeNodeId: string;
16     valueObjectRef: any;
17     private _derivedFromSimpleTypeName:string;
18     get derivedFromSimpleTypeName():string {
19         return this._derivedFromSimpleTypeName;
20     }
21     set derivedFromSimpleTypeName(derivedFromSimpleTypeName:string) {
22         this._derivedFromSimpleTypeName = derivedFromSimpleTypeName;
23     }
24
25     constructor(property?: PropertyBEModel);
26     constructor(name: string, type: string, treeNodeId: string, parent: PropertyFEModel, valueObjectRef: any, schema?: SchemaPropertyGroupModel);
27     constructor(nameOrPropertyObj?: string | PropertyBEModel, type?: string, treeNodeId?: string, parent?: PropertyFEModel, valueObjectRef?: any, schema?: SchemaPropertyGroupModel) {
28
29         super(typeof nameOrPropertyObj === 'string' ? null : nameOrPropertyObj);
30
31         if (typeof nameOrPropertyObj === 'string') {
32             this.name = nameOrPropertyObj;
33             this.type = type;
34             this.treeNodeId = treeNodeId;
35             this.parent = parent;
36             this.valueObjectRef = valueObjectRef;
37             this.value = this.value || this.defaultValue;
38             if(schema){
39                 this.schema = new SchemaPropertyGroupModel(new SchemaProperty(schema.property));
40             }
41         }
42         this.isSimpleType = PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.type) > -1;
43         this.isDataType = PROPERTY_DATA.TYPES.indexOf(this.type) == -1;
44         this.setNonDeclared();
45     }
46
47
48     public setNonDeclared = (): void => {
49         this.isSelected = false;
50         this.isDisabled = false;
51     }
52
53     public setAsDeclared = (): void => {
54         this.isSelected = true;
55         this.isDisabled = true;
56     }
57
58     //For expand-collapse functionality
59     public updateExpandedChildPropertyId = (childPropertyId: string): void => {
60         this.expandedChildPropertyId = (this.expandedChildPropertyId == childPropertyId) ? '' : childPropertyId;
61     }
62
63     public convertToServerObject: Function = (): any => { //TODO: Idan, Rachel, Nechama: Decide what we need to do here
64         // let serverObject = {};
65         // let mapData = {
66         //     'type': this.type,
67         //     'required': this.required || false,
68         //     'defaultValue': this.defaultValue != '' && this.defaultValue != '[]' && this.defaultValue != '{}' ? this.defaultValue : null,
69         //     'description': this.description,
70         //     'isPassword': this.password || false,
71         //     'schema': this.schema,
72         //     'name': this.name
73         // };
74         // serverObject[this.name] = mapData;
75
76         //return JSON.stringify(serverObject);
77     };
78 }