40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
|
import { AlertOptions } from "@ionic/angular";
|
||
|
import { Observable } from "rxjs";
|
||
|
import { StoragehubService } from "src/app/storagehub.service";
|
||
|
import { WSItem } from "../ws-item";
|
||
|
import { Action } from "./action";
|
||
|
|
||
|
export class DeleteAction extends Action {
|
||
|
|
||
|
override getAlertOptions(item: WSItem, storagehub: StoragehubService, reload: Function): AlertOptions {
|
||
|
var title = item.getTitle();
|
||
|
var options: AlertOptions = {
|
||
|
header: `Are you sure to delete item ${title} ?`,
|
||
|
buttons: [{
|
||
|
text: 'No',
|
||
|
role: 'cancel'
|
||
|
},
|
||
|
{
|
||
|
text: 'Yes',
|
||
|
handler: () => {
|
||
|
this.actionHandler(item, storagehub).subscribe(
|
||
|
() => reload()
|
||
|
);
|
||
|
}
|
||
|
}]
|
||
|
};
|
||
|
return options;
|
||
|
|
||
|
}
|
||
|
actionHandler(data: WSItem, storagehub: StoragehubService): Observable<any> {
|
||
|
return storagehub.deleteItem(data.item.id);
|
||
|
}
|
||
|
|
||
|
getName(): string {
|
||
|
return "Delete";
|
||
|
}
|
||
|
getActionType(): string | undefined {
|
||
|
return "destructive";
|
||
|
}
|
||
|
|
||
|
}
|