From 6ca0277b5f114f6eb98e872e0536877620034502 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Thu, 18 Mar 2021 11:04:08 +0100 Subject: [PATCH] Add and use ObjectActionFunctionTemplatePlugin --- .../templates/__objectActionDeleteIcon.tpl | 5 - .../templates/__objectActionToogleIcon.tpl | 4 - syncTemplates.json | 2 - .../install/files/acp/templates/adList.tpl | 4 +- .../files/acp/templates/bbcodeList.tpl | 2 +- .../acp/templates/bbcodeMediaProviderList.tpl | 4 +- .../install/files/acp/templates/boxList.tpl | 5 +- .../acp/templates/captchaQuestionList.tpl | 4 +- .../files/acp/templates/contactSettings.tpl | 8 +- .../files/acp/templates/cronjobList.tpl | 4 +- .../devtoolsMissingLanguageItemList.tpl | 2 +- .../acp/templates/devtoolsProjectList.tpl | 2 +- .../install/files/acp/templates/tagList.tpl | 2 +- ...jectActionFunctionTemplatePlugin.class.php | 118 ++++++++++++++++++ wcfsetup/install/lang/de.xml | 11 +- wcfsetup/install/lang/en.xml | 11 +- 16 files changed, 138 insertions(+), 50 deletions(-) delete mode 100644 com.woltlab.wcf/templates/__objectActionDeleteIcon.tpl delete mode 100644 com.woltlab.wcf/templates/__objectActionToogleIcon.tpl create mode 100644 wcfsetup/install/files/lib/system/template/plugin/ObjectActionFunctionTemplatePlugin.class.php diff --git a/com.woltlab.wcf/templates/__objectActionDeleteIcon.tpl b/com.woltlab.wcf/templates/__objectActionDeleteIcon.tpl deleted file mode 100644 index 3e9817995a..0000000000 --- a/com.woltlab.wcf/templates/__objectActionDeleteIcon.tpl +++ /dev/null @@ -1,5 +0,0 @@ - diff --git a/com.woltlab.wcf/templates/__objectActionToogleIcon.tpl b/com.woltlab.wcf/templates/__objectActionToogleIcon.tpl deleted file mode 100644 index b4c22f983c..0000000000 --- a/com.woltlab.wcf/templates/__objectActionToogleIcon.tpl +++ /dev/null @@ -1,4 +0,0 @@ - diff --git a/syncTemplates.json b/syncTemplates.json index df54e5617c..4de5d1deec 100644 --- a/syncTemplates.json +++ b/syncTemplates.json @@ -33,8 +33,6 @@ "__multipleSelectionFormField", "__nonEmptyFormFieldDependency", "__numericFormField", - "__objectActionDeleteIcon", - "__objectActionToogleIcon", "__pollOptionsFormField", "__radioButtonFormField", "__ratingFormField", diff --git a/wcfsetup/install/files/acp/templates/adList.tpl b/wcfsetup/install/files/acp/templates/adList.tpl index 1d94fa77d2..d0362a7ce0 100644 --- a/wcfsetup/install/files/acp/templates/adList.tpl +++ b/wcfsetup/install/files/acp/templates/adList.tpl @@ -40,9 +40,9 @@ - {include file='__objectActionToogleIcon' object=$ad} + {objectAction action="toggle" isDisabled=$ad->isDisabled} - {include file='__objectActionDeleteIcon' objectActionConfirmMessage='wcf.acp.ad.delete.confirmMessage'} + {objectAction action="delete" objectTitle=$ad->getTitle()} {event name='itemButtons'} diff --git a/wcfsetup/install/files/acp/templates/bbcodeList.tpl b/wcfsetup/install/files/acp/templates/bbcodeList.tpl index 1a77775384..348b3cf7be 100644 --- a/wcfsetup/install/files/acp/templates/bbcodeList.tpl +++ b/wcfsetup/install/files/acp/templates/bbcodeList.tpl @@ -39,7 +39,7 @@ {if $bbcode->canDelete()} - {include file='__objectActionDeleteIcon' objectActionConfirmMessage='wcf.acp.bbcode.delete.sure'} + {objectAction action="delete" objectTitle=$bbcode->getTitle()} {else} {/if} diff --git a/wcfsetup/install/files/acp/templates/bbcodeMediaProviderList.tpl b/wcfsetup/install/files/acp/templates/bbcodeMediaProviderList.tpl index a025dd2707..65fbd31495 100644 --- a/wcfsetup/install/files/acp/templates/bbcodeMediaProviderList.tpl +++ b/wcfsetup/install/files/acp/templates/bbcodeMediaProviderList.tpl @@ -36,9 +36,9 @@ {foreach from=$objects item='mediaProvider'} - {include file='__objectActionToogleIcon' object=$mediaProvider} + {objectAction action="toggle" isDisabled=$mediaProvider->isDisabled} - {include file='__objectActionDeleteIcon' objectActionConfirmMessage='wcf.acp.bbcode.mediaProvider.delete.sure'} + {objectAction action="delete" objectTitle=$mediaProvider->getTitle()} {event name='rowButtons'} diff --git a/wcfsetup/install/files/acp/templates/boxList.tpl b/wcfsetup/install/files/acp/templates/boxList.tpl index f4855f6ed8..9edcfa28ba 100644 --- a/wcfsetup/install/files/acp/templates/boxList.tpl +++ b/wcfsetup/install/files/acp/templates/boxList.tpl @@ -117,11 +117,10 @@ {foreach from=$objects item=box} - {include file='__objectActionToogleIcon' object=$box} + {objectAction action="toggle" isDisabled=$box->isDisabled} {if $box->canDelete()} - {include file='__objectActionDeleteIcon' objectActionConfirmMessage='wcf.acp.box.delete.confirmMessage'} - + {objectAction action="delete" objectTitle=$box->name} {else} {/if} diff --git a/wcfsetup/install/files/acp/templates/captchaQuestionList.tpl b/wcfsetup/install/files/acp/templates/captchaQuestionList.tpl index 94c94f09a6..c6eb65e6e6 100644 --- a/wcfsetup/install/files/acp/templates/captchaQuestionList.tpl +++ b/wcfsetup/install/files/acp/templates/captchaQuestionList.tpl @@ -37,9 +37,9 @@ {foreach from=$objects item='question'} - {include file='__objectActionToogleIcon' object=$question} + {objectAction action="toggle" isDisabled=$question->isDisabled} - {include file='__objectActionDeleteIcon' objectActionConfirmMessage='wcf.acp.captcha.question.delete.confirmMessage'} + {objectAction action="delete" objectTitle=$question->getQuestion()} {event name='rowButtons'} diff --git a/wcfsetup/install/files/acp/templates/contactSettings.tpl b/wcfsetup/install/files/acp/templates/contactSettings.tpl index 8b41322e91..297dd6a093 100644 --- a/wcfsetup/install/files/acp/templates/contactSettings.tpl +++ b/wcfsetup/install/files/acp/templates/contactSettings.tpl @@ -50,10 +50,10 @@ {foreach from=$optionList item=option} - {include file='__objectActionToogleIcon' object=$option} + {objectAction action="toggle" isDisabled=$option->isDisabled} {if $option->canDelete()} - {include file='__objectActionDeleteIcon' objectActionConfirmMessage='wcf.acp.customOption.delete.confirmMessage'} + {objectAction action="delete" objectTitle=$option->getTitle()} {else} {/if} @@ -89,12 +89,12 @@ - {include file='__objectActionToogleIcon' object=$recipient} + {objectAction action="toggle" isDisabled=$recipient->isDisabled} {if $recipient->originIsSystem} {else} - {include file='__objectActionDeleteIcon' objectActionConfirmMessage='wcf.acp.contact.recipient.delete.confirmMessage'} + {objectAction action="delete" objectTitle=$recipient->getName()} {/if} {event name='itemButtons'} diff --git a/wcfsetup/install/files/acp/templates/cronjobList.tpl b/wcfsetup/install/files/acp/templates/cronjobList.tpl index 56d2d39147..fc102d7fbd 100644 --- a/wcfsetup/install/files/acp/templates/cronjobList.tpl +++ b/wcfsetup/install/files/acp/templates/cronjobList.tpl @@ -53,7 +53,7 @@ {if $cronjob->canBeDisabled()} - {include file='__objectActionToogleIcon' object=$cronjob} + {objectAction action="toggle" isDisabled=$cronjob->isDisabled} {else} {if !$cronjob->isDisabled} @@ -68,7 +68,7 @@ {/if} {if $cronjob->isDeletable()} - {include file='__objectActionDeleteIcon' objectActionConfirmMessage='wcf.acp.cronjob.delete.sure'} + {objectAction action="delete" objectTitle=$cronjob->getDescription()} {else} {/if} diff --git a/wcfsetup/install/files/acp/templates/devtoolsMissingLanguageItemList.tpl b/wcfsetup/install/files/acp/templates/devtoolsMissingLanguageItemList.tpl index 5c26d0db86..70c75c0efd 100644 --- a/wcfsetup/install/files/acp/templates/devtoolsMissingLanguageItemList.tpl +++ b/wcfsetup/install/files/acp/templates/devtoolsMissingLanguageItemList.tpl @@ -47,7 +47,7 @@ {foreach from=$objects item=logEntry} - {include file='__objectActionDeleteIcon' objectActionConfirmMessage='wcf.acp.devtools.missingLanguageItem.delete.confirmMessage'} + {objectAction action="delete" confirmMessage='wcf.acp.devtools.missingLanguageItem.delete.confirmMessage'} {@$logEntry->getObjectID()} diff --git a/wcfsetup/install/files/acp/templates/devtoolsProjectList.tpl b/wcfsetup/install/files/acp/templates/devtoolsProjectList.tpl index 28d6b97d85..27da5aa0e3 100644 --- a/wcfsetup/install/files/acp/templates/devtoolsProjectList.tpl +++ b/wcfsetup/install/files/acp/templates/devtoolsProjectList.tpl @@ -48,7 +48,7 @@ - {include file='__objectActionDeleteIcon' objectActionConfirmMessage='wcf.acp.devtools.project.delete.confirmMessage'} + {objectAction action="delete" objectTitle=$object->name} {@$object->getObjectID()} {$object->name} diff --git a/wcfsetup/install/files/acp/templates/tagList.tpl b/wcfsetup/install/files/acp/templates/tagList.tpl index baf60d7ebe..8799304670 100644 --- a/wcfsetup/install/files/acp/templates/tagList.tpl +++ b/wcfsetup/install/files/acp/templates/tagList.tpl @@ -74,7 +74,7 @@ - {include file='__objectActionDeleteIcon' objectActionConfirmMessage='wcf.acp.tag.delete.sure'} + {objectAction action="delete" objectTitle=$tag->getTitle()} {event name='rowButtons'} diff --git a/wcfsetup/install/files/lib/system/template/plugin/ObjectActionFunctionTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/ObjectActionFunctionTemplatePlugin.class.php new file mode 100644 index 0000000000..90685ff7c9 --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/ObjectActionFunctionTemplatePlugin.class.php @@ -0,0 +1,118 @@ + + * @package WoltLabSuite\Core\System\Template\Plugin + * @since 5.4 + */ +class ObjectActionFunctionTemplatePlugin implements IFunctionTemplatePlugin +{ + private const SUPPORTED_ACTIONS = [ + 'delete', + 'toggle', + ]; + + /** + * @inheritDoc + */ + public function execute($tagArgs, TemplateEngine $tplObj) + { + if (!isset($tagArgs['action'])) { + throw new \InvalidArgumentException("Missing 'action' argument."); + } + $action = $tagArgs['action']; + if (!in_array($action, static::SUPPORTED_ACTIONS)) { + throw new \InvalidArgumentException("Unsupported action '{$action}'."); + } + + $additionalAttributes = ''; + if (isset($tagArgs['objectId'])) { + $additionalAttributes .= " data-object-id=\"{$tagArgs['objectId']}\""; + } + $className = null; + if (isset($tagArgs['className'])) { + $additionalAttributes .= " data-object-action-class-name=\"{$tagArgs['className']}\""; + } + foreach ($tagArgs as $key => $value) { + if (\preg_match('~^parameter.+$~', $key)) { + $additionalAttributes .= sprintf( + ' data-object-action-%s="%s"', + \strtolower(\preg_replace( + '~([A-Z])~', + '-$1', + $key + )), + StringUtil::encodeHTML($value) + ); + } + } + + $language = LanguageFactory::getInstance()->getLanguage($tplObj->languageID); + + switch ($action) { + case 'delete': + if (isset($tagArgs['objectTitle'])) { + $confirmMessage = StringUtil::encodeHTML($tplObj->fetchString( + $tplObj->getCompiler()->compileString( + 'wcf.global.button.delete.confirmMessage', + $language->get('wcf.global.button.delete.confirmMessage') + )['template'], + [ + 'objectTitle' => $tagArgs['objectTitle'], + ] + )); + } + else if (isset($tagArgs['confirmMessage'])) { + $confirmMessage = StringUtil::encodeHTML($tplObj->fetchString( + $tplObj->getCompiler()->compileString( + $tagArgs['confirmMessage'], + $language->get($tagArgs['confirmMessage']) + )['template'])); + } + else { + throw new \InvalidArgumentException("Missing 'objectTitle' or 'confirmMessage' argument for 'delete' action."); + } + + $title = $language->getDynamicVariable('wcf.global.button.delete'); + + return << +HTML; + + break; + + case 'toggle': + if (!isset($tagArgs['isDisabled'])) { + throw new \InvalidArgumentException("Missing 'isDisabled' argument for 'toggle' action."); + } + + $icon = 'fa-check-square-o'; + $title = $language->getDynamicVariable('wcf.global.button.disable'); + if ($tagArgs['isDisabled']) { + $icon = 'fa-square-o'; + $title = $language->getDynamicVariable('wcf.global.button.enable'); + } + $title = StringUtil::encodeHTML($title); + + return << +HTML; + + default: + throw new \LogicException("Unreachable."); + } + } +} diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 932578f18c..9e574a7223 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -37,7 +37,6 @@ - {$ad->adName} wirklich löschen?]]> @@ -139,7 +138,6 @@ - [{$bbcode->bbcodeTag}] wirklich löschen?]]> @@ -151,7 +149,6 @@ - {$mediaProvider->title} wirklich löschen?]]> {$variable} werden durch die entsprechend benannte Untergruppe des regulären Ausdrucks ersetzt.
@@ -177,7 +174,6 @@ - {$box->name} wirklich löschen?]]> @@ -277,7 +273,6 @@ - {$question->getQuestion()} wirklich löschen?]]> @@ -289,7 +284,6 @@ - {$recipient} wirklich löschen?]]> @@ -333,7 +327,6 @@ - {$cronjob->getDescription()} wirklich löschen?]]> @@ -405,7 +398,6 @@ - {$object->name} wirklich löschen?]]> Hinweise zur Benutzung in der Entwickler-Dokumentation.]]> @@ -1807,7 +1799,6 @@ Die Datenbestände werden sorgfältig gepflegt, aber es ist nicht ausgeschlossen - {$option->getTitle()} wirklich löschen?]]> @@ -3002,7 +2993,6 @@ Kein Abschnitt darf leer sein und alle Abschnitten dürfen nur folgende Zeichen - {$tag} wirklich löschen?]]> @@ -3880,6 +3870,7 @@ Dateianhänge: + {$objectTitle} wirklich löschen?]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index ebb8428f17..29b6e4173e 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -37,7 +37,6 @@ - {$ad->adName}?]]> @@ -140,7 +139,6 @@ - [{$bbcode->bbcodeTag}]?]]> @@ -152,7 +150,6 @@ - {$mediaProvider->title}?]]> {$variable} and will be replaced with the regular expression’s matching named group.
@@ -176,7 +173,6 @@ - {$box->name}?]]> @@ -276,7 +272,6 @@ - {$question->getQuestion()}?]]> @@ -310,7 +305,6 @@ - {$cronjob->getDescription()}?]]> @@ -381,7 +375,6 @@ - {$object->name}?]]> usage instructions in the developer documentation.]]> @@ -1791,7 +1784,6 @@ The database is carefully maintained, but there will be always be a margin of er - {$option->getTitle()}?]]> @@ -2930,7 +2922,6 @@ If you have already bought the licenses for the listed apps, th - {$tag}?]]> @@ -3487,7 +3478,6 @@ Attachments: - {$recipient}?]]> @@ -3826,6 +3816,7 @@ Attachments: + {$objectTitle}?]]> -- 2.20.1