diff --git a/ts/WoltLabSuite/WebComponent/woltlab-core-label-picker.ts b/ts/WoltLabSuite/WebComponent/woltlab-core-label-picker.ts index 755f2100f86..ca397fb914d 100644 --- a/ts/WoltLabSuite/WebComponent/woltlab-core-label-picker.ts +++ b/ts/WoltLabSuite/WebComponent/woltlab-core-label-picker.ts @@ -30,8 +30,7 @@ throw new Error("Expected a non empty list of labels."); } - // TODO: This HTML is duplicated in `set selected()` - const emptyLabel = `${window.WoltLabLanguage.getPhrase("wcf.label.none")}`; + const emptyLabel = this.#getHtmlForNoneLabel(); this.#button.type = "button"; this.#button.classList.add("dropdownToggle"); @@ -84,8 +83,7 @@ } if (this.selected) { - // TODO: This is _slightly_ awkward. - this.selected = this.selected!; + this.#updateValue(this.selected); } } @@ -107,12 +105,7 @@ set selected(selected: number) { this.setAttribute("selected", selected.toString()); - this.#button.innerHTML = - this.#labels.get(selected) || - `${window.WoltLabLanguage.getPhrase("wcf.label.none")}`; - if (this.#formValue !== undefined) { - this.#formValue.value = selected.toString(); - } + this.#updateValue(selected); } get selected(): number | undefined { @@ -152,6 +145,17 @@ get required(): boolean { return this.hasAttribute("required"); } + + #getHtmlForNoneLabel(): string { + return `${window.WoltLabLanguage.getPhrase("wcf.label.none")}`; + } + + #updateValue(labelId: number): void { + this.#button.innerHTML = this.#labels.get(labelId) || this.#getHtmlForNoneLabel(); + if (this.#formValue !== undefined) { + this.#formValue.value = labelId.toString(); + } + } } window.customElements.define("woltlab-core-label-picker", WoltlabCoreLabelPickerElement); diff --git a/wcfsetup/install/files/js/WoltLabSuite/WebComponent.min.js b/wcfsetup/install/files/js/WoltLabSuite/WebComponent.min.js index 49f468276d2..50832cf6c4a 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/WebComponent.min.js +++ b/wcfsetup/install/files/js/WoltLabSuite/WebComponent.min.js @@ -60,7 +60,7 @@ Expecting `+Z.join(", ")+", got '"+(this.terminals_[E]||E)+"'":ae="Parse error o time::after { content: " (" attr(title) ")"; } - }`,L.append(C)}g&&(this.#e.dateTime=p.toISOString(),this.#e.title=b.DateAndTime.format(p));let y;if(this.static)y=this.#e.title;else if(xt?y=this.#t(L,0):p.getTime()>a?y=this.#t(L,-1):y=L.map(W=>W.value).join(""):y=b.DateAndTime.format(p)}else y=b.Date.format(p);y=y.charAt(0).toUpperCase()+y.slice(1),this.#e.textContent=y}#t(g,p){return g.map(y=>y.type==="weekday"?b.TodayOrYesterday.format(p,"day"):y.value).join("")}}window.customElements.define("woltlab-core-date-time",q);let S=()=>{document.querySelectorAll("woltlab-core-date-time").forEach(h=>h.refresh(!1))},z,P=()=>{z=window.setInterval(()=>{i(),S()},6e4)};document.addEventListener("DOMContentLoaded",()=>P(),{once:!0}),document.addEventListener("visibilitychange",()=>{document.hidden?window.clearInterval(z):(S(),P())})}{class e extends HTMLElement{#a;#e;#t=new Map;constructor(){super(),this.#a=document.createElement("button")}connectedCallback(){if(this.hasAttribute("labels")&&(this.#t=new Map(JSON.parse(this.getAttribute("labels"))),this.removeAttribute("labels")),this.#t.size===0)throw new Error("Expected a non empty list of labels.");let l=`${window.WoltLabLanguage.getPhrase("wcf.label.none")}`;this.#a.type="button",this.#a.classList.add("dropdownToggle"),this.#a.innerHTML=l,this.#a.addEventListener("click",a=>{a.preventDefault();let i=new CustomEvent("showPicker");this.dispatchEvent(i)}),this.#a.id=this.id,this.removeAttribute("id"),this.append(this.#a);let c=document.createElement("ul");c.classList.add("scrollableDropdownMenu");for(let[a,i]of this.#t)c.append(this.#s(a,i));if(!this.required){let a=document.createElement("li");a.classList.add("dropdownDivider"),c.append(a,this.#s(0,l))}let t=document.createElement("ul");t.classList.add("dropdownMenu"),t.append(c),this.append(t),this.classList.add("dropdown"),this.closest("form")!==null?(this.#e===void 0&&(this.#e=document.createElement("input"),this.#e.type="hidden",this.#e.name=`labelIDs[${this.dataset.groupId}]`,this.append(this.#e)),this.#e.value=(this.selected||0).toString()):this.#e?.remove(),this.selected&&(this.selected=this.selected)}#s(l,c){let t=document.createElement("button");t.type="button",t.dataset.labelId=l.toString(),t.innerHTML=c,t.addEventListener("click",()=>{this.selected=l});let a=document.createElement("li");return a.append(t),a}set selected(l){this.setAttribute("selected",l.toString()),this.#a.innerHTML=this.#t.get(l)||`${window.WoltLabLanguage.getPhrase("wcf.label.none")}`,this.#e!==void 0&&(this.#e.value=l.toString())}get selected(){let l=parseInt(this.getAttribute("selected"));if(!Number.isNaN(l))return l}set disabled(l){l?this.setAttribute("disabled",""):this.removeAttribute("disabled"),this.#a.disabled=l,this.#e&&(this.#e.disabled=l)}get disabled(){return this.hasAttribute("disabled")}set required(l){l?this.setAttribute("required",""):this.removeAttribute("required")}get required(){return this.hasAttribute("required")}}window.customElements.define("woltlab-core-label-picker",e)}{let r=[24,48,96];class l extends HTMLElement{#a;#e;connectedCallback(){this.#a===void 0&&this.#t()}attributeChangedCallback(t,a,i){if(t==="size"){let d=parseInt(i||"");if(!r.includes(d)){let b=parseInt(a||"");r.includes(b)||(b=24),this.setAttribute(t,b.toString())}}}#t(){this.classList.add("loading-indicator"),this.hasAttribute("size")||this.setAttribute("size",24 .toString()),this.#a=document.createElement("fa-icon"),this.#a.size=this.size,this.#a.setIcon("spinner"),this.#e=document.createElement("span"),this.#e.classList.add("loading-indicator__text"),this.#e.textContent=window.WoltLabLanguage.getPhrase("wcf.global.loading"),this.#e.hidden=this.hideText;let t=document.createElement("div");t.classList.add("loading-indicator__wrapper"),t.append(this.#a,this.#e),this.append(t)}get size(){return parseInt(this.getAttribute("size"))}set size(t){if(!r.includes(t))throw new TypeError(`The size ${t} is unrecognized, permitted values are ${r.join(", ")}.`);this.setAttribute("size",t.toString()),this.#a&&(this.#a.size=t)}get hideText(){return this.hasAttribute("hide-text")}set hideText(t){t?this.setAttribute("hide-text",""):this.removeAttribute("hide-text"),this.#e&&(this.#e.hidden=t)}static get observedAttributes(){return["size"]}}window.customElements.define("woltlab-core-loading-indicator",l)}{let e,r=()=>(e===void 0&&(e=window.matchMedia("(max-width: 544px)")),e);class l extends HTMLElement{#a="pagination";connectedCallback(){this.#e(),r().addEventListener("change",()=>this.#e())}#e(){if(this.innerHTML="",this.count<2)return;this.classList.add(`${this.#a}__wrapper`);let t=this.#t();this.append(t);let a=this.#s();a&&t.append(a);let i=document.createElement("ul");i.classList.add(`${this.#a}__list`),t.append(i),i.append(this.#l(1)),this.page>this.thresholdForEllipsis+1&&i.append(this.#i()),this.#f().forEach(b=>{i.append(b)}),this.count-this.page>this.thresholdForEllipsis&&i.append(this.#i()),i.append(this.#l(this.count));let d=this.#o();d&&t.append(d)}#t(){let t=document.createElement("nav");return t.setAttribute("role","navigation"),t.setAttribute("aria-label",window.WoltLabLanguage.getPhrase("wcf.page.pagination")),t.classList.add(this.#a),t}#s(){if(this.page===1)return;let t=document.createElement("div");t.classList.add(`${this.#a}__prev`);let a=this.#r(this.page-1);a instanceof HTMLAnchorElement&&(a.rel="prev"),a.title=window.WoltLabLanguage.getPhrase("wcf.global.page.previous"),a.classList.add("jsTooltip"),t.append(a);let i=document.createElement("fa-icon");return i.setIcon("arrow-left"),a.append(i),t}#o(){if(this.page===this.count)return;let t=document.createElement("div");t.classList.add(`${this.#a}__next`);let a=this.#r(this.page+1);a instanceof HTMLAnchorElement&&(a.rel="next"),a.title=window.WoltLabLanguage.getPhrase("wcf.global.page.next"),a.classList.add("jsTooltip"),t.append(a);let i=document.createElement("fa-icon");return i.setIcon("arrow-right"),a.append(i),t}#r(t){let a,i=this.getLinkUrl(t);return i?(a=document.createElement("a"),a.href=i):(a=document.createElement("button"),a.type="button",this.page===t?a.disabled=!0:a.addEventListener("click",()=>{this.#n(t)})),a.classList.add(`${this.#a}__link`),a}#l(t){let a=document.createElement("li");a.classList.add(`${this.#a}__item`);let i=this.#r(t);return i.setAttribute("aria-label",window.WoltLabLanguage.getPhrase("wcf.page.pageNo",{pageNo:t})),t===this.page&&(i.setAttribute("aria-current","page"),i.classList.add(`${this.#a}__link--current`)),i.textContent=t.toLocaleString(document.documentElement.lang),a.append(i),a}#f(){let t=[],a,i;r().matches?(a=this.page,i=this.page):(a=this.page-1,a===3&&a--,i=this.page+1,i===this.count-2&&i++);for(let d=a;d<=i;d++)d<=1||d>=this.count||t.push(this.#l(d));return t}#i(){let t=document.createElement("li");t.classList.add(`${this.#a}__item`,`${this.#a}__item--ellipsis`);let a=document.createElement("button");return a.type="button",a.title=window.WoltLabLanguage.getPhrase("wcf.page.jumpTo"),a.classList.add("pagination__link","jsTooltip"),a.innerHTML="⋯",a.addEventListener("click",()=>{this.dispatchEvent(new CustomEvent("jumpToPage"))}),t.append(a),t}get thresholdForEllipsis(){return r().matches?1:3}getLinkUrl(t){if(!this.url)return"";let a=new URL(this.url);return a.search+=a.search!==""?"&":"?",a.search+=new URLSearchParams([["pageNo",t.toString()]]).toString(),a.toString()}jumpToPage(t){let a=this.getLinkUrl(t);a?window.location.href=a:this.#n(t)}#n(t){let a=new CustomEvent("switchPage",{cancelable:!0,detail:t});this.dispatchEvent(a),a.defaultPrevented||(this.page=t)}get count(){return this.hasAttribute("count")?parseInt(this.getAttribute("count")):0}set count(t){this.setAttribute("count",t.toString()),this.#e()}get page(){return this.hasAttribute("page")?parseInt(this.getAttribute("page")):1}set page(t){this.setAttribute("page",t.toString()),this.#e()}get url(){return this.getAttribute("url")}set url(t){this.setAttribute("url",t),this.#e()}}window.customElements.define("woltlab-core-pagination",l)}{class e extends HTMLElement{connectedCallback(){this.setData(this.#e(),this.#t())}setData(l,c){this.#a(l,c)}get objectId(){return parseInt(this.getAttribute("object-id"))}get objectType(){return this.getAttribute("object-type")}#a(l,c){if(this.innerHTML="",!l.size)return;let t=document.createElement("button");t.classList.add("reactionSummary","jsTooltip"),t.title=window.WoltLabLanguage.getPhrase("wcf.reactions.summary.listReactions"),t.addEventListener("click",()=>{this.dispatchEvent(new Event("showDetails"))}),this.append(t),l.forEach((a,i)=>{let d=document.createElement("span");d.classList.add("reactionCountButton"),i===c&&d.classList.add("selected");let b=document.createElement("span");b.innerHTML=window.REACTION_TYPES[i].renderedIcon,d.append(b);let k=document.createElement("span");k.classList.add("reactionCount"),k.textContent=a.toString(),d.append(k),t.append(d)})}#e(){let l=JSON.parse(this.getAttribute("data"));return this.removeAttribute("data"),new Map(l)}#t(){return parseInt(this.getAttribute("selected-reaction"))}}window.customElements.define("woltlab-core-reaction-summary",e)}window.WoltLabLanguage=ne;window.WoltLabTemplate=V;window.HTMLParsedElement=pe;})(); + }`,L.append(C)}g&&(this.#e.dateTime=p.toISOString(),this.#e.title=b.DateAndTime.format(p));let y;if(this.static)y=this.#e.title;else if(xt?y=this.#t(L,0):p.getTime()>a?y=this.#t(L,-1):y=L.map(W=>W.value).join(""):y=b.DateAndTime.format(p)}else y=b.Date.format(p);y=y.charAt(0).toUpperCase()+y.slice(1),this.#e.textContent=y}#t(g,p){return g.map(y=>y.type==="weekday"?b.TodayOrYesterday.format(p,"day"):y.value).join("")}}window.customElements.define("woltlab-core-date-time",q);let S=()=>{document.querySelectorAll("woltlab-core-date-time").forEach(h=>h.refresh(!1))},z,P=()=>{z=window.setInterval(()=>{i(),S()},6e4)};document.addEventListener("DOMContentLoaded",()=>P(),{once:!0}),document.addEventListener("visibilitychange",()=>{document.hidden?window.clearInterval(z):(S(),P())})}{class e extends HTMLElement{#a;#e;#t=new Map;constructor(){super(),this.#a=document.createElement("button")}connectedCallback(){if(this.hasAttribute("labels")&&(this.#t=new Map(JSON.parse(this.getAttribute("labels"))),this.removeAttribute("labels")),this.#t.size===0)throw new Error("Expected a non empty list of labels.");let l=this.#l();this.#a.type="button",this.#a.classList.add("dropdownToggle"),this.#a.innerHTML=l,this.#a.addEventListener("click",a=>{a.preventDefault();let i=new CustomEvent("showPicker");this.dispatchEvent(i)}),this.#a.id=this.id,this.removeAttribute("id"),this.append(this.#a);let c=document.createElement("ul");c.classList.add("scrollableDropdownMenu");for(let[a,i]of this.#t)c.append(this.#r(a,i));if(!this.required){let a=document.createElement("li");a.classList.add("dropdownDivider"),c.append(a,this.#r(0,l))}let t=document.createElement("ul");t.classList.add("dropdownMenu"),t.append(c),this.append(t),this.classList.add("dropdown"),this.closest("form")!==null?(this.#e===void 0&&(this.#e=document.createElement("input"),this.#e.type="hidden",this.#e.name=`labelIDs[${this.dataset.groupId}]`,this.append(this.#e)),this.#e.value=(this.selected||0).toString()):this.#e?.remove(),this.selected&&this.#s(this.selected)}#r(l,c){let t=document.createElement("button");t.type="button",t.dataset.labelId=l.toString(),t.innerHTML=c,t.addEventListener("click",()=>{this.selected=l});let a=document.createElement("li");return a.append(t),a}set selected(l){this.setAttribute("selected",l.toString()),this.#s(l)}get selected(){let l=parseInt(this.getAttribute("selected"));if(!Number.isNaN(l))return l}set disabled(l){l?this.setAttribute("disabled",""):this.removeAttribute("disabled"),this.#a.disabled=l,this.#e&&(this.#e.disabled=l)}get disabled(){return this.hasAttribute("disabled")}set required(l){l?this.setAttribute("required",""):this.removeAttribute("required")}get required(){return this.hasAttribute("required")}#l(){return`${window.WoltLabLanguage.getPhrase("wcf.label.none")}`}#s(l){this.#a.innerHTML=this.#t.get(l)||this.#l(),this.#e!==void 0&&(this.#e.value=l.toString())}}window.customElements.define("woltlab-core-label-picker",e)}{let r=[24,48,96];class l extends HTMLElement{#a;#e;connectedCallback(){this.#a===void 0&&this.#t()}attributeChangedCallback(t,a,i){if(t==="size"){let d=parseInt(i||"");if(!r.includes(d)){let b=parseInt(a||"");r.includes(b)||(b=24),this.setAttribute(t,b.toString())}}}#t(){this.classList.add("loading-indicator"),this.hasAttribute("size")||this.setAttribute("size",24 .toString()),this.#a=document.createElement("fa-icon"),this.#a.size=this.size,this.#a.setIcon("spinner"),this.#e=document.createElement("span"),this.#e.classList.add("loading-indicator__text"),this.#e.textContent=window.WoltLabLanguage.getPhrase("wcf.global.loading"),this.#e.hidden=this.hideText;let t=document.createElement("div");t.classList.add("loading-indicator__wrapper"),t.append(this.#a,this.#e),this.append(t)}get size(){return parseInt(this.getAttribute("size"))}set size(t){if(!r.includes(t))throw new TypeError(`The size ${t} is unrecognized, permitted values are ${r.join(", ")}.`);this.setAttribute("size",t.toString()),this.#a&&(this.#a.size=t)}get hideText(){return this.hasAttribute("hide-text")}set hideText(t){t?this.setAttribute("hide-text",""):this.removeAttribute("hide-text"),this.#e&&(this.#e.hidden=t)}static get observedAttributes(){return["size"]}}window.customElements.define("woltlab-core-loading-indicator",l)}{let e,r=()=>(e===void 0&&(e=window.matchMedia("(max-width: 544px)")),e);class l extends HTMLElement{#a="pagination";connectedCallback(){this.#e(),r().addEventListener("change",()=>this.#e())}#e(){if(this.innerHTML="",this.count<2)return;this.classList.add(`${this.#a}__wrapper`);let t=this.#t();this.append(t);let a=this.#r();a&&t.append(a);let i=document.createElement("ul");i.classList.add(`${this.#a}__list`),t.append(i),i.append(this.#i(1)),this.page>this.thresholdForEllipsis+1&&i.append(this.#n()),this.#f().forEach(b=>{i.append(b)}),this.count-this.page>this.thresholdForEllipsis&&i.append(this.#n()),i.append(this.#i(this.count));let d=this.#l();d&&t.append(d)}#t(){let t=document.createElement("nav");return t.setAttribute("role","navigation"),t.setAttribute("aria-label",window.WoltLabLanguage.getPhrase("wcf.page.pagination")),t.classList.add(this.#a),t}#r(){if(this.page===1)return;let t=document.createElement("div");t.classList.add(`${this.#a}__prev`);let a=this.#s(this.page-1);a instanceof HTMLAnchorElement&&(a.rel="prev"),a.title=window.WoltLabLanguage.getPhrase("wcf.global.page.previous"),a.classList.add("jsTooltip"),t.append(a);let i=document.createElement("fa-icon");return i.setIcon("arrow-left"),a.append(i),t}#l(){if(this.page===this.count)return;let t=document.createElement("div");t.classList.add(`${this.#a}__next`);let a=this.#s(this.page+1);a instanceof HTMLAnchorElement&&(a.rel="next"),a.title=window.WoltLabLanguage.getPhrase("wcf.global.page.next"),a.classList.add("jsTooltip"),t.append(a);let i=document.createElement("fa-icon");return i.setIcon("arrow-right"),a.append(i),t}#s(t){let a,i=this.getLinkUrl(t);return i?(a=document.createElement("a"),a.href=i):(a=document.createElement("button"),a.type="button",this.page===t?a.disabled=!0:a.addEventListener("click",()=>{this.#o(t)})),a.classList.add(`${this.#a}__link`),a}#i(t){let a=document.createElement("li");a.classList.add(`${this.#a}__item`);let i=this.#s(t);return i.setAttribute("aria-label",window.WoltLabLanguage.getPhrase("wcf.page.pageNo",{pageNo:t})),t===this.page&&(i.setAttribute("aria-current","page"),i.classList.add(`${this.#a}__link--current`)),i.textContent=t.toLocaleString(document.documentElement.lang),a.append(i),a}#f(){let t=[],a,i;r().matches?(a=this.page,i=this.page):(a=this.page-1,a===3&&a--,i=this.page+1,i===this.count-2&&i++);for(let d=a;d<=i;d++)d<=1||d>=this.count||t.push(this.#i(d));return t}#n(){let t=document.createElement("li");t.classList.add(`${this.#a}__item`,`${this.#a}__item--ellipsis`);let a=document.createElement("button");return a.type="button",a.title=window.WoltLabLanguage.getPhrase("wcf.page.jumpTo"),a.classList.add("pagination__link","jsTooltip"),a.innerHTML="⋯",a.addEventListener("click",()=>{this.dispatchEvent(new CustomEvent("jumpToPage"))}),t.append(a),t}get thresholdForEllipsis(){return r().matches?1:3}getLinkUrl(t){if(!this.url)return"";let a=new URL(this.url);return a.search+=a.search!==""?"&":"?",a.search+=new URLSearchParams([["pageNo",t.toString()]]).toString(),a.toString()}jumpToPage(t){let a=this.getLinkUrl(t);a?window.location.href=a:this.#o(t)}#o(t){let a=new CustomEvent("switchPage",{cancelable:!0,detail:t});this.dispatchEvent(a),a.defaultPrevented||(this.page=t)}get count(){return this.hasAttribute("count")?parseInt(this.getAttribute("count")):0}set count(t){this.setAttribute("count",t.toString()),this.#e()}get page(){return this.hasAttribute("page")?parseInt(this.getAttribute("page")):1}set page(t){this.setAttribute("page",t.toString()),this.#e()}get url(){return this.getAttribute("url")}set url(t){this.setAttribute("url",t),this.#e()}}window.customElements.define("woltlab-core-pagination",l)}{class e extends HTMLElement{connectedCallback(){this.setData(this.#e(),this.#t())}setData(l,c){this.#a(l,c)}get objectId(){return parseInt(this.getAttribute("object-id"))}get objectType(){return this.getAttribute("object-type")}#a(l,c){if(this.innerHTML="",!l.size)return;let t=document.createElement("button");t.classList.add("reactionSummary","jsTooltip"),t.title=window.WoltLabLanguage.getPhrase("wcf.reactions.summary.listReactions"),t.addEventListener("click",()=>{this.dispatchEvent(new Event("showDetails"))}),this.append(t),l.forEach((a,i)=>{let d=document.createElement("span");d.classList.add("reactionCountButton"),i===c&&d.classList.add("selected");let b=document.createElement("span");b.innerHTML=window.REACTION_TYPES[i].renderedIcon,d.append(b);let k=document.createElement("span");k.classList.add("reactionCount"),k.textContent=a.toString(),d.append(k),t.append(d)})}#e(){let l=JSON.parse(this.getAttribute("data"));return this.removeAttribute("data"),new Map(l)}#t(){return parseInt(this.getAttribute("selected-reaction"))}}window.customElements.define("woltlab-core-reaction-summary",e)}window.WoltLabLanguage=ne;window.WoltLabTemplate=V;window.HTMLParsedElement=pe;})(); /** * Handles the low level management of language items. * diff --git a/wcfsetup/install/files/lib/data/article/category/ArticleCategory.class.php b/wcfsetup/install/files/lib/data/article/category/ArticleCategory.class.php index 1268d6fecbc..bb54373887f 100644 --- a/wcfsetup/install/files/lib/data/article/category/ArticleCategory.class.php +++ b/wcfsetup/install/files/lib/data/article/category/ArticleCategory.class.php @@ -12,6 +12,7 @@ use wcf\system\category\CategoryHandler; use wcf\system\category\CategoryPermissionHandler; use wcf\system\label\LabelHandler; +use wcf\system\label\LabelPicker; use wcf\system\request\LinkHandler; use wcf\system\user\object\watch\UserObjectWatchHandler; use wcf\system\user\storage\UserStorageHandler; @@ -195,6 +196,13 @@ public function getLabelGroups(string $permission = 'canSetLabel'): array return []; } + /** + * Returns all label pickers that have been assigned to one or more + * accessible category. + * + * @return LabelPicker[] + * @since 6.1 + */ public static function getLabelPickers(): array { $labelGroupsToCategories = ArticleCategoryLabelCacheBuilder::getInstance()->getData();