diff --git a/public/assets/pages/filespage/thing.js b/public/assets/pages/filespage/thing.js index f6f0ec48..3c86ffcb 100644 --- a/public/assets/pages/filespage/thing.js +++ b/public/assets/pages/filespage/thing.js @@ -11,6 +11,14 @@ import { addSelection, isSelected, clearSelection } from "./state_selection.js"; import { mv as mv$ } from "./model_files.js"; import { mv as mvVL, withVirtualLayer } from "./model_virtual_layer.js"; +import rxjs from "../../lib/rx.js"; +import { rm as rm$ } from "./model_files.js"; +import { rm as rmVL } from "./model_virtual_layer.js"; +import { basename } from "../../lib/path.js"; +import t from "../../locales/index.js"; +import { createModal } from "../../components/modal.js"; +import componentDelete from "./modal_delete.js"; + const mv = (from, to) => withVirtualLayer( mv$(from, to), mvVL(from, to), @@ -149,6 +157,27 @@ export function createThing({ return $thing; } + let $action = $thing.querySelector(".component_action"); + $action.innerHTML = ``; + $action.onclick = (e) => { + e.preventDefault(); + e.stopPropagation(); + const rm = (...paths) => withVirtualLayer( + rm$(...paths), + rmVL(...paths), + ); + return rxjs.from(componentDelete( + createModal({ + withButtonsRight: t("OK"), + withButtonsLeft: t("CANCEL"), + }), + basename(path).substr(0, 15), + )).pipe( + rxjs.mergeMap(() => rm(path)), + rxjs.tap(() => window.dispatchEvent(new KeyboardEvent("keydown", { keyCode: 27 }))), + ).subscribe(); + }; + const checked = isSelected(n); if (permissions && permissions.can_move !== false) $thing.setAttribute("draggable", "true"); $thing.classList.add(checked ? "selected" : "not-selected");