From e70b517529a19b9198f2f4cfb9a96920969e67ea Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Wed, 16 Jul 2014 21:42:12 +0200 Subject: [PATCH] Add possibility to set appearance of notices --- com.woltlab.wcf/templates/userNotice.tpl | 3 +- .../install/files/acp/templates/noticeAdd.tpl | 59 +++++++++++++++++-- .../lib/acp/form/NoticeAddForm.class.php | 49 +++++++++++++++ .../lib/acp/form/NoticeEditForm.class.php | 7 +++ wcfsetup/install/lang/de.xml | 8 +++ wcfsetup/install/lang/en.xml | 8 +++ wcfsetup/setup/db/install.sql | 1 + 7 files changed, 127 insertions(+), 8 deletions(-) diff --git a/com.woltlab.wcf/templates/userNotice.tpl b/com.woltlab.wcf/templates/userNotice.tpl index d598a6c840..783f9717c7 100644 --- a/com.woltlab.wcf/templates/userNotice.tpl +++ b/com.woltlab.wcf/templates/userNotice.tpl @@ -22,9 +22,8 @@

{lang}wcf.user.register.needActivation{/lang}

{/if} - {* todo: styling/visual appearence *} {foreach from=$__wcf->getNoticeHandler()->getVisibleNotices() item='notice'} -

+

{if $notice->isDismissible} {/if} diff --git a/wcfsetup/install/files/acp/templates/noticeAdd.tpl b/wcfsetup/install/files/acp/templates/noticeAdd.tpl index 90840419bf..891a1a3f24 100644 --- a/wcfsetup/install/files/acp/templates/noticeAdd.tpl +++ b/wcfsetup/install/files/acp/templates/noticeAdd.tpl @@ -4,6 +4,22 @@ // @@ -76,17 +92,48 @@

-
+
- + + {lang}wcf.acp.notice.showOrder.description{/lang}
+ {event name='dataFields'} + + +
+ {lang}wcf.global.settings{/lang} +
-
+
- - {lang}wcf.acp.notice.showOrder.description{/lang} + {foreach from=$availableCssClassNames item=className} + {if $className == 'custom'} + + {else} + + {/if} + {/foreach} + {if $errorField == 'cssClassName'} + + {if $errorType == 'empty'} + {lang}wcf.global.form.error.empty{/lang} + {else} + {lang}wcf.acp.notice.cssClassName.error.{@$errorType}{/lang} + {/if} + + {/if} + {lang}wcf.acp.notice.cssClassName.description{/lang} + +

{lang}wcf.acp.notice.example{/lang}

+
+
+ +
+
+
+
@@ -108,7 +155,7 @@ {/if} - {event name='dataFields'} + {event name='settingsFields'}
{event name='fieldsets'} diff --git a/wcfsetup/install/files/lib/acp/form/NoticeAddForm.class.php b/wcfsetup/install/files/lib/acp/form/NoticeAddForm.class.php index 4b85e30ced..529e96f940 100644 --- a/wcfsetup/install/files/lib/acp/form/NoticeAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/NoticeAddForm.class.php @@ -7,6 +7,7 @@ use wcf\form\AbstractForm; use wcf\system\condition\ConditionHandler; use wcf\system\exception\UserInputException; use wcf\system\language\I18nHandler; +use wcf\system\Regex; use wcf\system\WCF; use wcf\util\StringUtil; @@ -26,6 +27,30 @@ class NoticeAddForm extends AbstractForm { */ public $activeMenuItem = 'wcf.acp.menu.link.notice.add'; + /** + * list pf pre-defined CSS class names + * @var array + */ + public $availableCssClassNames = array( + 'info', + 'warning', + 'error', + + 'custom' + ); + + /** + * name of the chosen CSS class name + * @var string + */ + public $cssClassName = ''; + + /** + * custom CSS class name + * @var string + */ + public $customCssClassName = ''; + /** * grouped notice condition object types * @var array @@ -77,6 +102,9 @@ class NoticeAddForm extends AbstractForm { WCF::getTPL()->assign(array( 'action' => 'add', + 'availableCssClassNames' => $this->availableCssClassNames, + 'cssClassName' => $this->cssClassName, + 'customCssClassName' => $this->customCssClassName, 'isDisabled' => $this->isDisabled, 'isDismissible' => $this->isDismissible, 'groupedConditionObjectTypes' => $this->groupedConditionObjectTypes, @@ -121,6 +149,8 @@ class NoticeAddForm extends AbstractForm { I18nHandler::getInstance()->readValues(); + if (isset($_POST['cssClassName'])) $this->cssClassName = StringUtil::trim($_POST['cssClassName']); + if (isset($_POST['customCssClassName'])) $this->customCssClassName = StringUtil::trim($_POST['customCssClassName']); if (isset($_POST['isDisabled'])) $this->isDisabled = 1; if (isset($_POST['isDismissible'])) $this->isDismissible = 1; if (isset($_POST['noticeName'])) $this->noticeName = StringUtil::trim($_POST['noticeName']); @@ -158,6 +188,7 @@ class NoticeAddForm extends AbstractForm { $this->objectAction = new NoticeAction(array(), 'create', array( 'data' => array_merge($this->additionalFields, array( + 'cssClassName' => $this->cssClassName == 'custom' ? $this->customCssClassName : $this->cssClassName, 'isDisabled' => $this->isDisabled, 'isDismissible' => $this->isDismissible, 'notice' => I18nHandler::getInstance()->isPlainValue('notice') ? I18nHandler::getInstance()->getValue('notice') : '', @@ -196,6 +227,8 @@ class NoticeAddForm extends AbstractForm { $this->saved(); // reset values + $this->cssClassName = ''; + $this->customCssClassName = ''; $this->isDisabled = 0; $this->isDismissible = 0; $this->noticeName = ''; @@ -229,6 +262,22 @@ class NoticeAddForm extends AbstractForm { } } + // validate class name + if (empty($this->cssClassName)) { + throw new UserInputException('cssClassName'); + } + else if (!in_array($this->cssClassName, $this->availableCssClassNames)) { + throw new UserInputException('cssClassName', 'notValid'); + } + else if ($this->cssClassName == 'custom') { + if (empty($this->cssClassName)) { + throw new UserInputException('cssClassName'); + } + if (!Regex::compile('^-?[_a-zA-Z]+[_a-zA-Z0-9-]+$')->match($this->customCssClassName)) { + throw new UserInputException('cssClassName', 'notValid'); + } + } + foreach ($this->groupedConditionObjectTypes as $groupedObjectTypes) { foreach ($groupedObjectTypes as $objectTypes) { if (is_array($objectTypes)) { diff --git a/wcfsetup/install/files/lib/acp/form/NoticeEditForm.class.php b/wcfsetup/install/files/lib/acp/form/NoticeEditForm.class.php index b45489b196..efbe7b5ab3 100644 --- a/wcfsetup/install/files/lib/acp/form/NoticeEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/NoticeEditForm.class.php @@ -67,6 +67,12 @@ class NoticeEditForm extends NoticeAddForm { if (empty($_POST)) { I18nHandler::getInstance()->setOptions('notice', 1, $this->notice->notice, 'wcf.notice.notice.notice\d+'); + $this->cssClassName = $this->notice->cssClassName; + if (!in_array($this->cssClassName, $this->availableCssClassNames)) { + $this->customCssClassName = $this->cssClassName; + $this->cssClassName = 'custom'; + } + $this->isDisabled = $this->notice->isDisabled; $this->isDismissible = $this->notice->isDismissible; $this->noticeName = $this->notice->noticeName; @@ -126,6 +132,7 @@ class NoticeEditForm extends NoticeAddForm { $this->objectAction = new NoticeAction(array($this->notice), 'update', array( 'data' => array_merge($this->additionalFields, array( + 'cssClassName' => $this->cssClassName == 'custom' ? $this->customCssClassName : $this->cssClassName, 'isDisabled' => $this->isDisabled, 'isDismissible' => $this->isDismissible, 'notice' => I18nHandler::getInstance()->isPlainValue('notice') ? I18nHandler::getInstance()->getValue('notice') : 'wcf.notice.notice.notice'.$this->notice->noticeID, diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 7b3763e096..b7a76552d3 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -648,6 +648,12 @@ + + + + + + @@ -658,6 +664,7 @@ + @@ -2072,6 +2079,7 @@ Fehler sind beispielsweise: + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 4205787ccf..0d127944ed 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -647,6 +647,12 @@ Examples for medium ID detection: + + + + + + @@ -657,6 +663,7 @@ Examples for medium ID detection: + @@ -2040,6 +2047,7 @@ Errors are: + diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index d425ce9717..9075e2585a 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -542,6 +542,7 @@ CREATE TABLE wcf1_notice ( noticeName VARCHAR(255) NOT NULL, notice MEDIUMTEXT, noticeUseHtml TINYINT(1) NOT NULL DEFAULT 0, + cssClassName VARCHAR(255) NOT NULL DEFAULT 'info', showOrder INT(10) NOT NULL DEFAULT 0, isDisabled TINYINT(1) NOT NULL DEFAULT 0, isDismissible TINYINT(1) NOT NULL DEFAULT 0 -- 2.20.1