From 7993120486a6ea87ab85e16b3190e45dd5a06a99 Mon Sep 17 00:00:00 2001 From: Yuriy Bakhtin Date: Thu, 10 Nov 2022 17:28:55 +0400 Subject: [PATCH] Remove "regular" style of checkbox and radio (#5821) * Remove "regular" style of checkbox and radio * Update CHANGELOG-DEV.md (#5821) * Fix checkbox style on oembed confirmation * Fix test * Fix test * Fix checkbox style on widget "ContentVisibilitySelect" Co-authored-by: Lucas Bartholemy --- CHANGELOG-DEV.md | 1 + protected/humhub/config/assets-prod.php | 2 +- protected/humhub/models/UrlOembed.php | 2 +- .../widgets/views/adminDeleteModal.php | 2 - .../widgets/views/adminDeleteModal.php | 2 - .../codeception/acceptance/StreamCest.php | 7 + .../modules/ui/form/widgets/ActiveField.php | 153 ------------------ .../form/widgets/ContentVisibilitySelect.php | 2 +- static/css/flatelements.css | 108 ------------- static/js/humhub/humhub.ui.form.elements.js | 91 ----------- static/less/form.less | 85 +++++++--- static/less/oembed.less | 11 -- themes/HumHub/css/theme.css | 2 +- 13 files changed, 72 insertions(+), 396 deletions(-) diff --git a/CHANGELOG-DEV.md b/CHANGELOG-DEV.md index b9f2c86540..3eefe590b3 100644 --- a/CHANGELOG-DEV.md +++ b/CHANGELOG-DEV.md @@ -3,6 +3,7 @@ HumHub Changelog 1.13.0 (Unreleased) ------------------- +- Enh #5821: Remove "regular" style of checkbox and radio - Enh #5827: Wall menu tabs for create content forms - Enh #5808: Add a menu to remove all members of a space - Enh #5841: Possibility to show Members/Followers as list from Space about page diff --git a/protected/humhub/config/assets-prod.php b/protected/humhub/config/assets-prod.php index 9081f4989e..d7420daa32 100644 --- a/protected/humhub/config/assets-prod.php +++ b/protected/humhub/config/assets-prod.php @@ -2,7 +2,7 @@ /** * This file is generated by the "yii asset" command. * DO NOT MODIFY THIS FILE DIRECTLY. - * @version 2022-08-17 11:53:49 + * @version 2022-08-01 12:36:33 */ return [ 'app' => [ diff --git a/protected/humhub/models/UrlOembed.php b/protected/humhub/models/UrlOembed.php index 9a8f6a4629..30f06063a7 100644 --- a/protected/humhub/models/UrlOembed.php +++ b/protected/humhub/models/UrlOembed.php @@ -316,7 +316,7 @@ class UrlOembed extends ActiveRecord Html::tag('br') . Yii::t('base', 'Do you want to enable content from \'{urlPrefix}\'?', ['urlPrefix' => Html::tag('strong', $urlPrefix)]) . Html::tag('br') . - Html::tag('label', '' . Yii::t('base', 'Always allow content from this provider!')) . + Html::tag('label', ' ' . Yii::t('base', 'Always allow content from this provider!')) . Html::tag('br') . Button::info(Yii::t('base', 'Confirm'))->action('oembed.display')->sm(); diff --git a/protected/humhub/modules/comment/widgets/views/adminDeleteModal.php b/protected/humhub/modules/comment/widgets/views/adminDeleteModal.php index c9cc7c1163..90e36b68ae 100644 --- a/protected/humhub/modules/comment/widgets/views/adminDeleteModal.php +++ b/protected/humhub/modules/comment/widgets/views/adminDeleteModal.php @@ -20,8 +20,6 @@ use humhub\modules\ui\form\widgets\ActiveForm; var $messageTextarea = $('#admindeletecommentform-message'); var $notifyCheckbox = $('#admindeletecommentform-notify'); - humhub.modules.ui.form.elements.initCheckbox($notifyCheckbox); - $notifyCheckbox.on('change', function () { if($notifyCheckbox.is(':checked')) $messageTextarea.removeAttr('disabled'); diff --git a/protected/humhub/modules/content/widgets/views/adminDeleteModal.php b/protected/humhub/modules/content/widgets/views/adminDeleteModal.php index 7e75c78120..66d9ac909d 100644 --- a/protected/humhub/modules/content/widgets/views/adminDeleteModal.php +++ b/protected/humhub/modules/content/widgets/views/adminDeleteModal.php @@ -20,8 +20,6 @@ use humhub\modules\ui\form\widgets\ActiveForm; var $messageTextarea = $('#admindeletecontentform-message'); var $notifyCheckbox = $('#admindeletecontentform-notify'); - humhub.modules.ui.form.elements.initCheckbox($notifyCheckbox); - $notifyCheckbox.on('change', function () { if($notifyCheckbox.is(':checked')) $messageTextarea.removeAttr('disabled'); diff --git a/protected/humhub/modules/stream/tests/codeception/acceptance/StreamCest.php b/protected/humhub/modules/stream/tests/codeception/acceptance/StreamCest.php index 31ce26de50..9c0f4942a7 100644 --- a/protected/humhub/modules/stream/tests/codeception/acceptance/StreamCest.php +++ b/protected/humhub/modules/stream/tests/codeception/acceptance/StreamCest.php @@ -352,6 +352,13 @@ class StreamCest $I->waitForText($postTitle, null, '.s2_streamContent'); $I->amGoingTo('filter stream by date from today'); + /* + $I->jsClick('.wall-stream-filter-toggle'); + $I->waitForElementVisible($dateFromFilter); + $I->executeJS("$('" . $dateFromFilter . "').val('" . date('n/j/y') . "').change();"); + $I->waitForText($postTitle, 30, '.s2_streamContent'); + */ + $I->waitForElementVisible('.wall-stream-filter-head'); $I->click('Filter', '.wall-stream-filter-head'); $I->wait(1); diff --git a/protected/humhub/modules/ui/form/widgets/ActiveField.php b/protected/humhub/modules/ui/form/widgets/ActiveField.php index bee4ff5b14..6d0277fff4 100644 --- a/protected/humhub/modules/ui/form/widgets/ActiveField.php +++ b/protected/humhub/modules/ui/form/widgets/ActiveField.php @@ -8,8 +8,6 @@ namespace humhub\modules\ui\form\widgets; -use yii\helpers\BaseHtml; - /** * A HumHub enhanced version of [[\yii\bootstrap\ActiveField]]. * @@ -26,16 +24,6 @@ class ActiveField extends \yii\bootstrap\ActiveField */ public $preventRendering = false; - /** - * @inheritdoc - */ - public $checkboxTemplate = "
\n{beginLabel}\n{input}\n{labelTitle}\n{endLabel}\n{error}\n{hint}\n
"; - - /** - * @inheritdoc - */ - public $radioTemplate = "
\n{beginLabel}\n{input}\n{labelTitle}\n{endLabel}\n{error}\n{hint}\n
"; - /** * @inheritdoc */ @@ -92,145 +80,4 @@ class ActiveField extends \yii\bootstrap\ActiveField return parent::end(); } - - /** - * @inheritdoc - */ - public function checkbox($options = [], $enclosedByLabel = true) - { - return parent::checkbox($this->applyRegularSingleStyle($options, [ - 'inputClass' => 'regular-checkbox', - 'boxClass' => 'regular-checkbox-box', - 'template' => $this->checkboxTemplate, - ]), $enclosedByLabel); - } - - /** - * @inheritdoc - */ - public function checkboxList($items, $options = []) - { - return parent::checkboxList($items, $options)->applyRegularListStyle([ - 'type' => 'checkbox', - 'containerFindClass' => 'checkbox', - 'containerAdditionalClass' => 'regular-checkbox-container', - 'inputClass' => 'regular-checkbox', - 'boxClass' => 'regular-checkbox-box', - ]); - } - - /** - * @inheritdoc - */ - public function radio($options = [], $enclosedByLabel = true) - { - return parent::radio($this->applyRegularSingleStyle($options, [ - 'inputClass' => 'regular-radio', - 'boxClass' => 'regular-radio-button', - 'template' => $this->radioTemplate, - ]), $enclosedByLabel); - } - - /** - * @inheritdoc - */ - public function radioList($items, $options = []) - { - return parent::radioList($items, $options)->applyRegularListStyle([ - 'type' => 'radio', - 'containerFindClass' => 'radio', - 'containerAdditionalClass' => 'regular-radio-container', - 'inputClass' => 'regular-radio', - 'boxClass' => 'regular-radio-button', - ]); - } - - /** - * Apply style "regular" for single of checkbox or radio input - * - * @param array $options - * @param array $regularOptions - * @return array - */ - private function applyRegularSingleStyle(array $options, array $regularOptions): array - { - $options['class'] = isset($options['class']) ? $options['class'] . $regularOptions['inputClass'] : $regularOptions['inputClass']; - - if (!isset($options['template']) && isset($regularOptions['template'])) { - $endLabel = '{endLabel}'; - $options['template'] = str_replace($endLabel, $this->getRegularBox(array_merge($options, $regularOptions)) . $endLabel, $regularOptions['template']); - } - - return $options; - } - - /** - * Apply style "regular" for list of checkbox or radio inputs - * - * @param array $options - * @return $this - */ - private function applyRegularListStyle(array $options): self - { - if (!isset($this->parts['{input}'])) { - return $this; - } - - $regexp = '~(
[\r\n]*[\r\n]*.+?)([\r\n]*
)~im'; - - $this->parts['{input}'] = preg_replace_callback($regexp, function ($html) use($options) { - $regularOptions = []; - - $inputAttrs = $html[3]; - if (preg_match_all('/([a-z\-_]+)(="(.*?)")?/i', $inputAttrs, $m)) { - $attrs = array_combine($m[1], $m[3]); - foreach ($attrs as $attr => $value) { - if ($value === '') { - $attrs[$attr] = true; - } - } - $attrs['class'] = (isset($attrs['class']) ? $attrs['class'] . ' ' : '') . $options['inputClass']; - $inputAttrs = BaseHtml::renderTagAttributes($attrs); - - if (isset($options['boxClass'])) { - $regularOptions['boxClass'] = $options['boxClass']; - } - if (isset($attrs['disabled'])) { - $regularOptions['disabled'] = true; - } - if (isset($attrs['style'])) { - $regularOptions['style'] = $attrs['style']; - } - } - - return '
Label text - . $this->getRegularBox($regularOptions) - . $html[5]; //
- }, $this->parts['{input}']); - - return $this; - } - - /** - * HTML code to checkbox/radio for style "regular" - * - * @param array $options - * @return string - */ - private function getRegularBox(array $options = []): string - { - $checkboxOptions = []; - $checkboxOptions['class'] = $options['boxClass'] ?? 'regular-checkbox-box'; - if (!empty($options['disabled'])) { - $checkboxOptions['class'] .= ' disabled'; - } - if (isset($options['style'])) { - $checkboxOptions['style'] = $options['style']; - } - - return BaseHtml::tag('div', '', $checkboxOptions); - } } diff --git a/protected/humhub/modules/ui/form/widgets/ContentVisibilitySelect.php b/protected/humhub/modules/ui/form/widgets/ContentVisibilitySelect.php index 69a96d37d7..1f4bccdb43 100644 --- a/protected/humhub/modules/ui/form/widgets/ContentVisibilitySelect.php +++ b/protected/humhub/modules/ui/form/widgets/ContentVisibilitySelect.php @@ -88,7 +88,7 @@ class ContentVisibilitySelect extends InputWidget $this->setDefaultValue(); return - '
' . + '
' . Html::activeCheckbox($this->model, $this->attribute, $this->options) . ' exists - if ($input.parent().parent().attr('class') === "checkbox") { - $input.parent().parent().addClass('regular-checkbox-container') - .append('
'); - } - - _checkInputLabel($input); - - // Create new checkbox - var $checkbox = $('
').attr('style', $input.attr('style')); - - if ($input.is(':disabled')) { - $checkbox.addClass('disabled'); - } - - // add new checkbox element - $input.parent().append($checkbox); - - // add new class to checkbox - $input.addClass('regular-checkbox').data('form_element', $checkbox); - }; - - var initRadio = function ($input) { - if ($input.data('form_element') || $input.hasClass('regular-radio')) { - return; - } - - // Check if the standard bootstrap container
exists - if ($input.parent().parent().attr('class') === "radio") { - $input.parent().parent().addClass('regular-radio-container'); - } - - _checkInputLabel($input); - - // Create new checkbox - var $radio = $('
'); - - if ($input.is(':disabled')) { - $radio.addClass('disabled'); - } - - // add new radio element - $input.parent().append($radio); - - // add new class to checkbox - $input.addClass('regular-radio').data('form_element', $radio); - }; - - /** - * Checks the label style of $input. - * If the $input is not wrapped in a label we wrap it around a new label and use the old label text if given. - * - * @param {type} $input - * @returns {undefined} - */ - var _checkInputLabel = function ($input) { - if (!$input.parent().is('label')) { - var $parent = $input.parent(); - - var $newLabel = $('