Skip to content

Commit

Permalink
Fix #183: Enhancements to support Bootstrap v5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Sep 1, 2021
1 parent 724f713 commit b1782cc
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 41 deletions.
8 changes: 8 additions & 0 deletions CHANGE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Change Log: `yii2-detail-view`
==============================

## Version 1.8.4

**Date:** 01-Sep-2021

- (enh #183): Enhancements to support Bootstrap v5.x
- (enh #179): Update Hungarian Translations.
- (enh #176): Correct container identifier.

## Version 1.8.3

**Date:** 15-May-2020
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014 - 2020, Kartik Visweswaran
Copyright (c) 2014 - 2021, Kartik Visweswaran
Krajee.com
All rights reserved.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
],
"require": {
"kartik-v/yii2-dialog": "~1.0",
"kartik-v/yii2-widget-activeform": ">=1.5.7"
"kartik-v/yii2-widget-activeform": ">=1.6.0"
},
"autoload": {
"psr-4": {
Expand Down
60 changes: 30 additions & 30 deletions src/DetailView.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
/**
* @package yii2-detail-view
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2020
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @version 1.8.3
*/

namespace kartik\detail;

use Closure;
use Exception;
use kartik\base\BootstrapInterface;
use kartik\base\Config;
use kartik\base\TranslationTrait;
use kartik\base\WidgetTrait;
use kartik\base\PluginAssetBundle;
use kartik\dialog\Dialog;
use ReflectionException;
use Yii;
use yii\base\Arrayable;
use yii\base\InvalidConfigException;
Expand Down Expand Up @@ -778,7 +780,7 @@ public function init()

/**
* @inheritdoc
* @throws \ReflectionException
* @throws ReflectionException
*/
public function run()
{
Expand All @@ -795,17 +797,17 @@ protected function initWidget()
$this->_msgCat = 'kvdetail';
$this->pluginName = 'kvDetailView';
$this->initBsVersion();
$isBs4 = $this->isBs4();
if ($isBs4) {
$notBs3 = !$this->isBs(3);
if ($notBs3) {
Html::addCssClass($this->container, 'kv-container-bs4');
}
if ($this->enableEditMode) {
/**
* @var ActiveForm $formClass
* @var string|ActiveForm $formClass
*/
$formClass = $this->formClass;
$activeForm = ActiveForm::class;
if (!is_subclass_of($formClass, $activeForm) && $formClass !== $activeForm) {
if (!is_subclass_of($formClass, $activeForm) && $formClass != $activeForm) {
throw new InvalidConfigException("Form class '{$formClass}' must exist and extend from '{$activeForm}'.");
}
$this->validateDisplay();
Expand Down Expand Up @@ -837,8 +839,8 @@ protected function initWidget()

/**
* Prepares and runs the detail view widget
* @throws \ReflectionException
* @throws \Exception
* @throws ReflectionException
* @throws Exception
*/
protected function runWidget()
{
Expand All @@ -860,12 +862,12 @@ protected function runWidget()

$this->registerAssets();
$output = $this->renderDetailView();
if (is_array($this->panel) && !empty($this->panel) && $this->panel !== false) {
if (is_array($this->panel) && !empty($this->panel)) {
$output = $this->renderPanel($output);
}
$output = strtr(Html::tag('div', $this->mainTemplate, $this->container), ['{detail}' => $output]);
Html::addCssClass($this->viewButtonsContainer, 'kv-buttons-1');
$buttons = Html::tag('span', $this->renderButtons(1), $this->viewButtonsContainer);
$buttons = Html::tag('span', $this->renderButtons(), $this->viewButtonsContainer);
if ($this->enableEditMode) {
Html::addCssClass($this->editButtonsContainer, 'kv-buttons-2');
$buttons .= Html::tag('span', $this->renderButtons(2), $this->editButtonsContainer);
Expand All @@ -883,7 +885,7 @@ protected function runWidget()

/**
* Initializes and renders alert container block
* @throws \Exception
* @throws Exception
*/
protected function renderAlertBlock()
{
Expand All @@ -901,7 +903,7 @@ protected function renderAlertBlock()
Html::addCssStyle($this->alertContainerOptions, 'display:none;');
}
$out = Html::beginTag('div', $this->alertContainerOptions);
$alertWidgetClass = $this->isBs4() ? 'yii\bootstrap4\Alert' : 'yii\bootstrap\Alert';
$alertWidgetClass = !$this->isBs(3) ? 'yii\bootstrap4\Alert' : 'yii\bootstrap\Alert';
foreach ($flashes as $type => $message) {
if (!isset($this->alertMessageSettings[$type])) {
continue;
Expand Down Expand Up @@ -1059,9 +1061,10 @@ protected function renderAttributeItem($attribute)
/**
* Checks if a bootstrap grid column class has been added to the container
*
* @param array $container
* @param array $container
*
* @return boolean
* @throws Exception
*/
protected static function hasGridCol($container = [])
{
Expand All @@ -1088,7 +1091,7 @@ protected static function hasGridCol($container = [])
* @param array $config the attribute config
*
* @return mixed
* @throws \yii\base\InvalidConfigException
* @throws InvalidConfigException
*/
protected function renderFormAttribute($config)
{
Expand Down Expand Up @@ -1173,7 +1176,7 @@ protected function getPanelType()
* Sets the grid panel layout based on the [[template]] and [[panel]] settings.
* @param string $items
* @return string
* @throws InvalidConfigException
* @throws InvalidConfigException|Exception
*/
protected function renderPanel($items)
{
Expand All @@ -1195,20 +1198,20 @@ protected function renderPanel($items)
$panelBefore = '';
$panelAfter = '';
$panelFooter = '';
$isBs4 = $this->isBs4();
$notBs3 = !$this->isBs(3);
if (isset($this->panelCssPrefix)) {
static::initCss($options, $this->panelCssPrefix . $type);
} else {
$this->addCssClass($options, self::BS_PANEL);
Html::addCssClass($options, $isBs4 ? "border-{$type}" : "panel-{$type}");
Html::addCssClass($options, $notBs3 ? "border-{$type}" : "panel-{$type}");
}
if ($after === false && $footer === false) {
Html::addCssClass($this->container, 'kv-flat-b');
}
$titleTag = ArrayHelper::remove($titleOptions, 'tag', ($isBs4 ? 'h5' : 'h3'));
static::initCss($titleOptions, $isBs4 ? 'm-0' : $this->getCssClass(self::BS_PANEL_TITLE));
$titleTag = ArrayHelper::remove($titleOptions, 'tag', ($notBs3 ? 'h5' : 'h3'));
static::initCss($titleOptions, $notBs3 ? 'm-0' : $this->getCssClass(self::BS_PANEL_TITLE));
if ($heading !== false) {
$color = $isBs4 ? ($type === 'default' ? ' bg-light' : " text-white bg-{$type}") : '';
$color = $notBs3 ? ($type === 'default' ? ' bg-light' : " text-white bg-{$type}") : '';
static::initCss($headingOptions, $this->getCssClass(self::BS_PANEL_HEADING) . $color);
$panelHeading = Html::tag('div', $this->panelHeadingTemplate, $headingOptions);
}
Expand Down Expand Up @@ -1296,17 +1299,17 @@ protected function renderButton($type)
*
* @param string $type the button type
* @param string $iconBs3 the bootstrap 3 icon suffix name
* @param string $iconBs4 the bootstrap 4 icon suffix name
* @param string $iconNotBs3 the non bootstrap 3 icon suffix name
* @param string $title the title to display on hover
*
* @return string
* @throws InvalidConfigException
* @throws InvalidConfigException|Exception
*/
protected function getDefaultButton($type, $iconBs3, $iconBs4, $title)
protected function getDefaultButton($type, $iconBs3, $iconNotBs3, $title)
{
$buttonOptions = $type . 'Options';
$options = $this->$buttonOptions;
$css = $this->getDefaultIconPrefix() . ($this->isBs4() ? $iconBs4 : $iconBs3);
$css = $this->getDefaultIconPrefix() . (!$this->isBs(3) ? $iconNotBs3 : $iconBs3);
$label = ArrayHelper::remove($options, 'label', '<i class="' . $css . '"></i>');
if (empty($options['class'])) {
$options['class'] = 'kv-action-btn';
Expand All @@ -1332,7 +1335,7 @@ protected function getDefaultButton($type, $iconBs3, $iconBs4, $title)

/**
* Register assets
* @throws \Exception
* @throws Exception
*/
protected function registerAssets()
{
Expand Down Expand Up @@ -1369,9 +1372,6 @@ protected function registerAssets()
'dialogLib' => ArrayHelper::getValue($this->krajeeDialogSettings, 'libName', 'krajeeDialog'),
];
$id = 'jQuery("#' . $this->container['id'] . '")';
if ($this->enableEditMode) {
$options['mode'] = $this->mode;
}
$this->registerPlugin($this->pluginName, $id);
if ($this->tooltips) {
PluginAssetBundle::registerBundle($view, $this->bsVersion);
Expand Down Expand Up @@ -1426,8 +1426,8 @@ protected function parseAttributeItem($attribute)
}
$attribute = [
'attribute' => $matches[1],
'format' => isset($matches[3]) ? $matches[3] : 'text',
'label' => isset($matches[5]) ? $matches[5] : null,
'format' => $matches[3] ?? 'text',
'label' => $matches[5] ?? null,
];
}
if (!is_array($attribute)) {
Expand Down
2 changes: 1 addition & 1 deletion src/DetailViewAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @package yii2-detail-view
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2020
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @version 1.8.3
*/

Expand Down
4 changes: 2 additions & 2 deletions src/assets/css/kv-detail-view.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*!
* @package yii2-detail-view
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2020
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @version 1.8.3
*
* Styles for yii2-detail-view extension
*
* Author: Kartik Visweswaran
* Copyright: 2014 - 2020, Kartik Visweswaran, Krajee.com
* Copyright: 2014 - 2021, Kartik Visweswaran, Krajee.com
* For more JQuery plugins visit http://plugins.krajee.com
* For more Yii related demos visit http://demos.krajee.com
*/
Expand Down
4 changes: 2 additions & 2 deletions src/assets/css/kv-detail-view.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/assets/js/kv-detail-view.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*!
* @package yii2-detail-view
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2020
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2021
* @version 1.8.3
*
* Client extension for the yii2-detail-view extension
*
* Author: Kartik Visweswaran
* Copyright: 2014 - 2020, Kartik Visweswaran, Krajee.com
* Copyright: 2014 - 2021, Kartik Visweswaran, Krajee.com
* For more JQuery plugins visit http://plugins.krajee.com
* For more Yii related demos visit http://demos.krajee.com
*/
Expand Down
4 changes: 2 additions & 2 deletions src/assets/js/kv-detail-view.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b1782cc

Please sign in to comment.