Skip to content

Commit 9e546bd

Browse files
committed
Deprecate functions no longer required in the FormBuilder for quotes.
Implement new class `IWysiwygTabFormContainer` which contains an icon for display and the information of an internal name
1 parent 0ac017b commit 9e546bd

File tree

16 files changed

+269
-176
lines changed

16 files changed

+269
-176
lines changed

com.woltlab.wcf/templates/shared_wysiwygFormField.tpl

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,3 @@
1414
*}>{$field->getValue()}</textarea>
1515

1616
{include file='shared_wysiwyg' wysiwygSelector=$field->getPrefixedId()}
17-
18-
{if $field->supportsQuotes()}
19-
<script data-relocate="true">
20-
// Bootstrap for window.__wcf_bc_eventHandler
21-
require(['WoltLabSuite/Core/Bootstrap'], function(Bootstrap) {
22-
{include file='shared_messageQuoteManager' wysiwygSelector=$field->getPrefixedId() supportPaste=true}
23-
24-
{if $field->getQuoteData() !== null}
25-
var quoteHandler = new WCF.Message.Quote.Handler(
26-
$quoteManager,
27-
'{$field->getQuoteData('actionClass')|encodeJS}',
28-
'{$field->getQuoteData('objectType')}',
29-
'{$field->getQuoteData('selectors')[container]}',
30-
'{$field->getQuoteData('selectors')[messageBody]}',
31-
'{$field->getQuoteData('selectors')[messageContent]}',
32-
true
33-
);
34-
35-
elData(elById('{@$field->getPrefixedId()|encodeJS}'), 'quote-handler', quoteHandler);
36-
{/if}
37-
});
38-
</script>
39-
{/if}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<div id="{$container->getPrefixedId()|encodeJS}Container"{*
2+
*} class="messageTabMenuContent messageTabMenuContent--quotes"></div>
3+
4+
<script data-relocate="true">
5+
require(["WoltLabSuite/Core/Component/Quote/List"], ({ setup }) => {
6+
setup("{$container->getWysiwygId()|encodeJS}", "{$container->getPrefixedId()|encodeJS}Container");
7+
});
8+
</script>
9+
10+
{include file='shared_formContainerDependencies'}
11+
12+
<script data-relocate="true">
13+
require(['WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/WysiwygTab'], ({ WysiwygTab }) => {
14+
new WysiwygTab('{$container->getPrefixedId()|encodeJS}Container', '{$container->getName()|encodeJS}', '{$container->getWysiwygId()|encodeJS}');
15+
});
16+
</script>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<div id="{$container->getPrefixedId()}Container"{*
2+
*}{if !$container->getClasses()|empty} class="{implode from=$container->getClasses() item='class' glue=' '}{$class}{/implode}"{/if}{*
3+
*}{foreach from=$container->getAttributes() key='attributeName' item='attributeValue'} {$attributeName}="{$attributeValue}"{/foreach}{*
4+
*}{if !$container->checkDependencies()} hidden{/if}{*
5+
*}>
6+
{include file='shared_formContainerChildren'}
7+
</div>
8+
9+
{include file='shared_formContainerDependencies'}
10+
11+
<script data-relocate="true">
12+
require(['WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/WysiwygTab'], ({ WysiwygTab }) => {
13+
new WysiwygTab('{$container->getPrefixedId()|encodeJS}Container', '{$container->getName()|encodeJS}', '{$container->getWysiwygId()|encodeJS}');
14+
});
15+
</script>

com.woltlab.wcf/templates/shared_wysiwygTabMenuFormContainer.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<ul>
77
{foreach from=$container item='child'}
88
{if $child->isAvailable()}
9-
<li data-name="{$child->getPrefixedId()|rawurlencode}Container"{if !$child->checkDependencies()} hidden{/if}>
9+
<li data-name="{$child->getName()}"{if !$child->checkDependencies()} hidden{/if}>
1010
<button type="button">
1111
{if $child->getIcon()}{icon name=$child->getIcon()}{/if}
1212
<span>{@$child->getLabel()}</span>

ts/WoltLabSuite/Core/Component/Message/MessageTabMenu.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ class TabMenu {
8787
}
8888
}
8989

90+
isHiddenTab(tabName: string): boolean {
91+
const tab = this.#tabs.find((element) => element.dataset.name === tabName);
92+
if (tab === undefined) {
93+
return true;
94+
}
95+
96+
return tab.hidden;
97+
}
98+
9099
setTabCounter(tabName: string, value: number): void {
91100
const tab = this.#tabs.find((element) => element.dataset.name === tabName);
92101
if (tab === undefined) {

ts/WoltLabSuite/Core/Component/Quote/List.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ class QuoteList {
2929
#editor: HTMLElement;
3030
#editorId: string;
3131

32-
constructor(editorId: string, editor: HTMLElement) {
32+
constructor(editorId: string, editor: HTMLElement, containerId?: string) {
3333
this.#editorId = editorId;
3434
this.#editor = editor;
35-
this.#container = document.getElementById(`quotes_${editorId}`)!;
35+
this.#container = document.getElementById(containerId ? containerId : `quotes_${editorId}`)!;
3636
if (this.#container === null) {
3737
throw new Error(`The quotes container for '${editorId}' does not exist.`);
3838
}
@@ -134,7 +134,7 @@ export function refreshQuoteLists() {
134134
}
135135
}
136136

137-
export function setup(editorId: string): void {
137+
export function setup(editorId: string, containerId?: string): void {
138138
if (quoteLists.has(editorId)) {
139139
return;
140140
}
@@ -146,7 +146,7 @@ export function setup(editorId: string): void {
146146

147147
listenToCkeditor(editor).ready(({ ckeditor }) => {
148148
if (ckeditor.features.quoteBlock) {
149-
quoteLists.set(editorId, new QuoteList(editorId, editor));
149+
quoteLists.set(editorId, new QuoteList(editorId, editor, containerId));
150150
}
151151

152152
if (ckeditor.isVisible()) {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Container visibility handler implementation for a wysiwyg tab menu tab that, in addition to the
3+
* tab itself, also handles the visibility of the tab menu list item.
4+
*
5+
* @author Olaf Braun
6+
* @copyright 2001-2025 WoltLab GmbH
7+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
8+
* @since 6.2
9+
*/
10+
11+
import Abstract from "./Abstract";
12+
import * as DependencyManager from "../Manager";
13+
import { getTabMenu } from "WoltLabSuite/Core/Component/Message/MessageTabMenu";
14+
15+
export class WysiwygTab extends Abstract {
16+
readonly #tabName: string;
17+
readonly #wysiwygId: string;
18+
19+
constructor(containerId: string, tabName: string, wysiwygId: string) {
20+
super(containerId);
21+
22+
this.#tabName = tabName;
23+
this.#wysiwygId = wysiwygId;
24+
}
25+
26+
public checkContainer(): void {
27+
// only consider containers that have not been hidden by their own dependencies
28+
if (DependencyManager.isHiddenByDependencies(this._container)) {
29+
return;
30+
}
31+
32+
const containerIsVisible = !this._container.hidden;
33+
const tabMenu = getTabMenu(this.#wysiwygId)!;
34+
const containerShouldBeVisible = tabMenu.isHiddenTab(this.#tabName);
35+
36+
if (containerIsVisible !== containerShouldBeVisible) {
37+
if (containerShouldBeVisible) {
38+
tabMenu?.showTab(this.#tabName);
39+
} else {
40+
tabMenu?.hideTab(this.#tabName);
41+
}
42+
43+
// Check containers again to make sure parent containers can react to changing the visibility
44+
// of this container.
45+
DependencyManager.checkContainers();
46+
}
47+
}
48+
}

wcfsetup/install/files/js/WoltLabSuite/Core/Component/Message/MessageTabMenu.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wcfsetup/install/files/js/WoltLabSuite/Core/Component/Quote/List.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/WysiwygTab.js

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)