@web-atoms/core
Version:
53 lines (43 loc) • 1.6 kB
text/typescript
import { App } from "../../../../App";
import { AtomBinder } from "../../../../core/AtomBinder";
import { BindableProperty } from "../../../../core/BindableProperty";
import { Inject } from "../../../../di/Inject";
import { AtomViewModel, Validate } from "../../../../view-model/AtomViewModel";
import { WindowService } from "../../../../web/services/WindowService";
export interface IMovie {
label: string;
value?: string;
category: string;
}
export class MovieListViewModel extends AtomViewModel {
public movies: IMovie[] = [
{ label: "First", category: "None" },
{ label: "True Lies", category: "Action" },
{ label: "Jurassic Park", category: "Adventure" },
{ label: "Big", category: "Kids" },
{ label: "Inception", category: "Suspense" },
{ label: "Last", category: "None" },
];
public selectedMovie: IMovie;
constructor(
app: App,
private windowService: WindowService) {
super(app);
}
public get errorSelectedMovie(): string {
return this.selectedMovie ? "" : "Please select any movie";
}
public onItemClick(data: IMovie): void {
this.selectedMovie = data;
}
public async onDelete(data: IMovie): Promise<any> {
if (! (await this.windowService.confirm("Are you sure you want to delete?", "Confirm"))) {
return;
}
AtomBinder.removeItem(this.movies, data);
await this.windowService.alert("Movie deleted successfully.");
}
}