Skip to content

Commit

Permalink
Upgrade to release v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Oct 19, 2014
1 parent cf7dd4d commit dd62f15
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 19 deletions.
8 changes: 8 additions & 0 deletions CHANGE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
version 1.2.0
=============
**Date:** 2014-10-19

- enh #13: Improve hide of elements and remove fade delay at initialization
- enh #14: Add various container properties to configure HTML options
- enh # 15: Refactor and optimize client code

version 1.1.0
=============
**Date:** 2014-07-15
Expand Down
59 changes: 52 additions & 7 deletions DetailView.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @copyright Copyright © Kartik Visweswaran, Krajee.com, 2013
* @package yii2-detail-view
* @version 1.0.0
* @version 1.2.0
*/

namespace kartik\detail;
Expand Down Expand Up @@ -295,6 +295,26 @@ class DetailView extends \yii\widgets\DetailView
*/
public $buttons2 = '{view} {save}';

/**
* @var array the HTML attributes for the container displaying the VIEW mode attributes.
*/
public $viewAttributeContainer = [];

/**
* @var array the HTML attributes for the container displaying the EDIT mode attributes.
*/
public $editAttributeContainer = [];

/**
* @var array the HTML attributes for the container displaying the VIEW mode buttons.
*/
public $viewButtonsContainer = [];

/**
* @var array the HTML attributes for the container displaying the EDIT mode buttons.
*/
public $editButtonsContainer = [];

/**
* @var array the HTML attributes for the view button. This will toggle the view from edit mode to view mode.
* The following special options are recognized:
Expand Down Expand Up @@ -348,6 +368,7 @@ public function init()
static::validateAttribute($attribute);
}
Html::addCssClass($this->options, 'detail-view');
$this->validateDisplay();
if ($this->bootstrap) {
Html::addCssClass($this->options, 'table');
if ($this->hover) {
Expand Down Expand Up @@ -379,6 +400,25 @@ public function init()
$this->registerAssets();
}

/**
* Validates the display of correct attributes and buttons
* at initialization based on mode
*/
protected function validateDisplay()
{
$none = 'display:none';
if ($this->mode === self::MODE_VIEW) {
Html::addCssStyle($this->editAttributeContainer, $none);
Html::addCssStyle($this->editButtonsContainer, $none);
} else {
Html::addCssStyle($this->viewAttributeContainer, $none);
Html::addCssStyle($this->viewButtonsContainer, $none);
}
}

/**
* Initialization for i18n translations
*/
public function initI18N()
{
Yii::setAlias('@kvdetail', dirname(__FILE__));
Expand All @@ -391,7 +431,6 @@ public function initI18N()
}
Yii::$app->i18n->translations['kvdetail'] = $this->i18n;
}

/**
* Renders the detail view.
* This is the main entry of the whole detail view rendering.
Expand All @@ -403,11 +442,13 @@ public function run()
$output = $this->renderPanel($output);
}
$output = strtr($this->mainTemplate, [
'{detail}' => '<div id="' . $this->container['id'] . '">' . $output . '</div>'
'{detail}' => Html::tag('div', $output, $this->container)
]);
Html::addCssClass($this->viewButtonsContainer, 'kv-buttons-1');
Html::addCssClass($this->editButtonsContainer, 'kv-buttons-2');
echo strtr($output, [
'{buttons}' => '<span class="kv-buttons-1">' . $this->renderButtons(1) .
'</span> <span class="kv-buttons-2 kv-hide">' . $this->renderButtons(2) . '</span>'
'{buttons}' => Html::tag('span', $this->renderButtons(1), $this->viewButtonsContainer) .
Html::tag('span', $this->renderButtons(2), $this->editButtonsContainer)
]);
ActiveForm::end();
}
Expand All @@ -422,10 +463,12 @@ public function run()
protected function renderAttribute($attribute, $index)
{
$dispAttr = $this->formatter->format($attribute['value'], $attribute['format']);
$output = '<div class="kv-attribute">' . $dispAttr . "</div>\n";
Html::addCssClass($this->viewAttributeContainer, 'kv-attribute');
Html::addCssClass($this->editAttributeContainer, 'kv-form-attribute');
$output = Html::tag('div', $dispAttr, $this->viewAttributeContainer) . "\n";
if ($this->enableEditMode) {
$editInput = (!empty($attribute['displayOnly']) && $attribute['displayOnly']) ? $dispAttr : $this->renderFormAttribute($attribute);
$output .= '<div class="kv-form-attribute kv-hide">' . $editInput . '</div>';
$output .= Html::tag('div', $editInput, $this->editAttributeContainer);
}
if (is_string($this->template)) {
return strtr($this->template, [
Expand All @@ -438,6 +481,8 @@ protected function renderAttribute($attribute, $index)
}

/**
* Renders the main detail view widget
*
* @return string the detail view content
*/
protected function renderDetailView()
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ may be updated when you install or update this extension. You may need to lock y
for extension break if you do not wish to auto update dependencies.

### Latest Release
The latest version of the extension is release v1.1.0. Refer the [CHANGE LOG](https://github.com/kartik-v/yii2-detail-view/blob/master/CHANGE.md) for details of various releases.
The latest version of the extension is release v1.2.0. Refer the [CHANGE LOG](https://github.com/kartik-v/yii2-detail-view/blob/master/CHANGE.md) for details of various releases.

### Demo
You can see detailed [documentation](http://demos.krajee.com/detail-view) and [demonstration](http://demos.krajee.com/detail-view-demo) on usage of the extension.
Expand Down
5 changes: 1 addition & 4 deletions assets/css/kv-detail-view.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014
* @version 1.0.0
* @version 1.2.0
*
* Styles for yii2-detail-view extension
*
Expand All @@ -9,9 +9,6 @@
* For more JQuery plugins visit http://plugins.krajee.com
* For more Yii related demos visit http://demos.krajee.com
*/
.kv-hide {
display:none;
}
.kv-form-attribute .help-block {
margin-bottom: -15px;
}
4 changes: 2 additions & 2 deletions assets/css/kv-detail-view.min.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014
* @version 1.0.0
* @version 1.2.0
*
* Styles for yii2-detail-view extension
*
Expand All @@ -9,4 +9,4 @@
* For more JQuery plugins visit http://plugins.krajee.com
* For more Yii related demos visit http://demos.krajee.com
*/
.kv-hide{display:none}.kv-form-attribute .help-block{margin-bottom: -15px}
.kv-form-attribute .help-block{margin-bottom: -15px}
5 changes: 2 additions & 3 deletions assets/js/kv-detail-view.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014
* @version 1.0.0
* @version 1.2.0
*
* Client extension for the yii2-detail-view extension
*
Expand All @@ -24,7 +24,7 @@
constructor: KvDetailView,
init: function () {
var self = this;
self.setMode(self.mode);
self.initElements();
self.$btnUpdate.on('click', function (e) {
self.setMode('edit');
});
Expand All @@ -50,7 +50,6 @@
self.$buttons1.fadeIn(t);
});
}
self.initElements();
},
initElements: function () {
var self = this;
Expand Down
4 changes: 2 additions & 2 deletions 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 dd62f15

Please sign in to comment.