multi-project/projects/app/_modules/pages/sections/add/add-section.component.ts

57 lines
1.4 KiB
TypeScript

import {Component, Input} from '@angular/core';
import {FormsService, ObjectsService} from "@app/_services";
@Component({
selector: 'add-section',
templateUrl: 'add-section.component.html',
styleUrls: ['add-section.component.scss']
})
export class AddSectionComponent {
@Input() page: any;
@Input() ord: number;
@Input() modelType: string;
public types = <any>[];
public ddVisible = false;
constructor(private formsService: FormsService, private objectsService: ObjectsService) {
}
ngOnInit() {
this.fetchTypes();
}
fetchTypes() {
this.objectsService.fetchType('page-section', {include: 'children.children.children.children'}).subscribe(res => {
this.types = res.data?.children?.data;
this.types = this.types.map(item => {
item.parent = item?.children?.data?.length > 0;
item.showChilren = false;
return item;
});
});
}
add(type: string) {
this.types = this.types.map(item => {
item.showChilren = false;
return item;
});
let attach = {modelType: this.modelType, modelId: this.page.id, group: 'sections', ord: this.ord};
this.formsService.createObject(type, {extraProps: {attach: attach}});
this.hideDD();
}
toggleDD() {
this.ddVisible = !this.ddVisible;
}
hideDD() {
this.ddVisible = false;
}
subClick(type){
type.showChilren = !type.showChilren;
}
}