import { CkeditorDropEvent } from "../File/Upload";
import { formatFilesize } from "WoltLabSuite/Core/FileUtil";
import DomChangeListener from "WoltLabSuite/Core/Dom/Change/Listener";
+import { initFragment, toggleDropdown } from "WoltLabSuite/Core/Ui/Dropdown/Simple";
type FileProcessorData = {
attachmentID: number;
return;
}
- const buttonList = document.createElement("div");
- buttonList.classList.add("attachment__item__buttons");
- buttonList.append(
- getDeleteAttachButton(fileId, (data as FileProcessorData).attachmentID, editorId, element),
- getInsertAttachBbcodeButton(
- (data as FileProcessorData).attachmentID,
- file.isImage() && file.link ? file.link : "",
- editorId,
- ),
- );
+ const extraButtons: HTMLButtonElement[] = [];
+ let insertButton: HTMLButtonElement;
if (file.isImage()) {
const thumbnail = file.thumbnails.find((thumbnail) => thumbnail.identifier === "tiny");
if (thumbnail !== undefined) {
const url = file.thumbnails.find((thumbnail) => thumbnail.identifier === "")?.link;
if (url !== undefined) {
- buttonList.append(getInsertThumbnailButton((data as FileProcessorData).attachmentID, url, editorId));
+ insertButton = getInsertThumbnailButton((data as FileProcessorData).attachmentID, url, editorId);
+
+ extraButtons.push(
+ getInsertAttachBbcodeButton((data as FileProcessorData).attachmentID, file.link ? file.link : "", editorId),
+ );
+ } else {
+ insertButton = getInsertAttachBbcodeButton(
+ (data as FileProcessorData).attachmentID,
+ file.link ? file.link : "",
+ editorId,
+ );
}
if (file.link !== undefined && file.filename !== undefined) {
DomChangeListener.trigger();
}
+ } else {
+ insertButton = getInsertAttachBbcodeButton(
+ (data as FileProcessorData).attachmentID,
+ file.isImage() && file.link ? file.link : "",
+ editorId,
+ );
+ }
+
+ const dropdownMenu = document.createElement("ul");
+ dropdownMenu.classList.add("dropdownMenu");
+ for (const button of extraButtons) {
+ const listItem = document.createElement("li");
+ listItem.append(button);
+ dropdownMenu.append(listItem);
+ }
+
+ if (dropdownMenu.childElementCount !== 0) {
+ const listItem = document.createElement("li");
+ listItem.classList.add("dropdownDivider");
+ dropdownMenu.append(listItem);
}
+ const listItem = document.createElement("li");
+ listItem.append(getDeleteAttachButton(fileId, (data as FileProcessorData).attachmentID, editorId, element));
+ dropdownMenu.append(listItem);
+
+ const moreOptions = document.createElement("button");
+ moreOptions.classList.add("button", "small", "jsTooltip");
+ moreOptions.type = "button";
+ moreOptions.title = "TODO: more options";
+ moreOptions.innerHTML = '<fa-icon name="ellipsis-vertical"></fa-icon>';
+
+ const buttonList = document.createElement("div");
+ buttonList.classList.add("attachment__item__buttons");
+ insertButton.classList.add("button", "small");
+ buttonList.append(insertButton, moreOptions);
+
element.append(buttonList);
+
+ initFragment(moreOptions, dropdownMenu);
+ moreOptions.addEventListener("click", (event) => {
+ event.stopPropagation();
+
+ toggleDropdown(moreOptions.id);
+ });
})
- .catch(() => {
+ .catch((e) => {
+ if (e instanceof Error) {
+ throw e;
+ }
+
if (file.validationError === undefined) {
return;
}
): HTMLButtonElement {
const button = document.createElement("button");
button.type = "button";
- button.classList.add("button", "small");
button.textContent = "TODO: delete";
button.addEventListener("click", () => {
function getInsertAttachBbcodeButton(attachmentId: number, url: string, editorId: string): HTMLButtonElement {
const button = document.createElement("button");
button.type = "button";
- button.classList.add("button", "small");
button.textContent = "TODO: insert";
button.addEventListener("click", () => {
function getInsertThumbnailButton(attachmentId: number, url: string, editorId: string): HTMLButtonElement {
const button = document.createElement("button");
button.type = "button";
- button.classList.add("button", "small");
button.textContent = "TODO: insert thumbnail";
button.addEventListener("click", () => {
-define(["require", "exports", "tslib", "WoltLabSuite/Core/Api/Files/DeleteFile", "../Ckeditor/Event", "WoltLabSuite/Core/FileUtil", "WoltLabSuite/Core/Dom/Change/Listener", "../File/woltlab-core-file"], function (require, exports, tslib_1, DeleteFile_1, Event_1, FileUtil_1, Listener_1) {
+define(["require", "exports", "tslib", "WoltLabSuite/Core/Api/Files/DeleteFile", "../Ckeditor/Event", "WoltLabSuite/Core/FileUtil", "WoltLabSuite/Core/Dom/Change/Listener", "WoltLabSuite/Core/Ui/Dropdown/Simple", "../File/woltlab-core-file"], function (require, exports, tslib_1, DeleteFile_1, Event_1, FileUtil_1, Listener_1, Simple_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setup = void 0;
// TODO: error handling
return;
}
- const buttonList = document.createElement("div");
- buttonList.classList.add("attachment__item__buttons");
- buttonList.append(getDeleteAttachButton(fileId, data.attachmentID, editorId, element), getInsertAttachBbcodeButton(data.attachmentID, file.isImage() && file.link ? file.link : "", editorId));
+ const extraButtons = [];
+ let insertButton;
if (file.isImage()) {
const thumbnail = file.thumbnails.find((thumbnail) => thumbnail.identifier === "tiny");
if (thumbnail !== undefined) {
}
const url = file.thumbnails.find((thumbnail) => thumbnail.identifier === "")?.link;
if (url !== undefined) {
- buttonList.append(getInsertThumbnailButton(data.attachmentID, url, editorId));
+ insertButton = getInsertThumbnailButton(data.attachmentID, url, editorId);
+ extraButtons.push(getInsertAttachBbcodeButton(data.attachmentID, file.link ? file.link : "", editorId));
+ }
+ else {
+ insertButton = getInsertAttachBbcodeButton(data.attachmentID, file.link ? file.link : "", editorId);
}
if (file.link !== undefined && file.filename !== undefined) {
const link = document.createElement("a");
Listener_1.default.trigger();
}
}
+ else {
+ insertButton = getInsertAttachBbcodeButton(data.attachmentID, file.isImage() && file.link ? file.link : "", editorId);
+ }
+ const dropdownMenu = document.createElement("ul");
+ dropdownMenu.classList.add("dropdownMenu");
+ for (const button of extraButtons) {
+ const listItem = document.createElement("li");
+ listItem.append(button);
+ dropdownMenu.append(listItem);
+ }
+ if (dropdownMenu.childElementCount !== 0) {
+ const listItem = document.createElement("li");
+ listItem.classList.add("dropdownDivider");
+ dropdownMenu.append(listItem);
+ }
+ const listItem = document.createElement("li");
+ listItem.append(getDeleteAttachButton(fileId, data.attachmentID, editorId, element));
+ dropdownMenu.append(listItem);
+ const moreOptions = document.createElement("button");
+ moreOptions.classList.add("button", "small", "jsTooltip");
+ moreOptions.type = "button";
+ moreOptions.title = "TODO: more options";
+ moreOptions.innerHTML = '<fa-icon name="ellipsis-vertical"></fa-icon>';
+ const buttonList = document.createElement("div");
+ buttonList.classList.add("attachment__item__buttons");
+ insertButton.classList.add("button", "small");
+ buttonList.append(insertButton, moreOptions);
element.append(buttonList);
+ (0, Simple_1.initFragment)(moreOptions, dropdownMenu);
+ moreOptions.addEventListener("click", (event) => {
+ event.stopPropagation();
+ (0, Simple_1.toggleDropdown)(moreOptions.id);
+ });
})
- .catch(() => {
+ .catch((e) => {
+ if (e instanceof Error) {
+ throw e;
+ }
if (file.validationError === undefined) {
return;
}
function getDeleteAttachButton(fileId, attachmentId, editorId, element) {
const button = document.createElement("button");
button.type = "button";
- button.classList.add("button", "small");
button.textContent = "TODO: delete";
button.addEventListener("click", () => {
const editor = document.getElementById(editorId);
function getInsertAttachBbcodeButton(attachmentId, url, editorId) {
const button = document.createElement("button");
button.type = "button";
- button.classList.add("button", "small");
button.textContent = "TODO: insert";
button.addEventListener("click", () => {
const editor = document.getElementById(editorId);
function getInsertThumbnailButton(attachmentId, url, editorId) {
const button = document.createElement("button");
button.type = "button";
- button.classList.add("button", "small");
button.textContent = "TODO: insert thumbnail";
button.addEventListener("click", () => {
const editor = document.getElementById(editorId);
/**
* @var array<string, ObjectType>
*/
- private array $processors;
+ private array $objectTypes;
#[\Override]
public function init(): void
{
- $this->processors = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.file');
+ $this->objectTypes = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.file');
}
public function getProcessorByName(string $objectType): ?IFileProcessor
return null;
}
- foreach ($this->processors as $objectType) {
+ foreach ($this->objectTypes as $objectType) {
if ($objectType->objectTypeID === $objectTypeID) {
return $objectType->getProcessor();
}
public function getObjectType(string $objectType): ?ObjectType
{
- return $this->processors[$objectType] ?? null;
+ return $this->objectTypes[$objectType] ?? null;
}
public function getHtmlElement(IFileProcessor $fileProcessor, array $context): string
$statement->execute($conditions->getParameters());
$thumbnailIDs = $statement->fetchAll(\PDO::FETCH_COLUMN);
- foreach ($this->processors as $processor) {
- $processor->delete($fileIDs, $thumbnailIDs);
+ foreach ($this->objectTypes as $objectType) {
+ $objectType->getProcessor()->delete($fileIDs, $thumbnailIDs);
}
}
}
}
.attachment__item__buttons {
- align-items: end;
column-gap: 5px;
display: flex;
grid-area: buttons;