mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.8 KiB
69 lines
1.8 KiB
/*
|
|
* Squidex Headless CMS
|
|
*
|
|
* @license
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
|
|
*/
|
|
|
|
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
|
import { FormBuilder } from '@angular/forms';
|
|
|
|
import {
|
|
AssetFolderDto,
|
|
AssetsState,
|
|
RenameAssetFolderForm
|
|
} from '@app/shared/internal';
|
|
|
|
@Component({
|
|
selector: 'sqx-asset-folder-form',
|
|
styleUrls: ['./asset-folder-form.component.scss'],
|
|
templateUrl: './asset-folder-form.component.html',
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
|
})
|
|
export class AssetFolderFormComponent implements OnInit {
|
|
@Output()
|
|
public complete = new EventEmitter();
|
|
|
|
@Input()
|
|
public assetFolder: AssetFolderDto;
|
|
|
|
public editForm = new RenameAssetFolderForm(this.formBuilder);
|
|
|
|
constructor(
|
|
private readonly assetsState: AssetsState,
|
|
private readonly formBuilder: FormBuilder
|
|
) {
|
|
}
|
|
|
|
public ngOnInit() {
|
|
if (this.assetFolder) {
|
|
this.editForm.load(this.assetFolder);
|
|
}
|
|
}
|
|
|
|
public emitComplete() {
|
|
this.complete.emit();
|
|
}
|
|
|
|
public createAssetFolder() {
|
|
const value = this.editForm.submit();
|
|
|
|
if (value) {
|
|
if (this.assetFolder) {
|
|
this.assetsState.updateAssetFolder(this.assetFolder, value)
|
|
.subscribe(() => {
|
|
this.emitComplete();
|
|
}, error => {
|
|
this.editForm.submitFailed(error);
|
|
});
|
|
} else {
|
|
this.assetsState.createAssetFolder(value.folderName)
|
|
.subscribe(() => {
|
|
this.emitComplete();
|
|
}, error => {
|
|
this.editForm.submitFailed(error);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|