Skip to content

Commit

Permalink
Merge branch 'sankam-nikolya-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
unclead committed Mar 7, 2017
2 parents 5256627 + 619f770 commit f7e5a4b
Show file tree
Hide file tree
Showing 16 changed files with 837 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Yii2 multiple input change log
==============================

2.6.0
=====

- PR#132: Implemented `Sortting` (sankam-nikolya)
- PR#132: fixed if attribute is set and hasProperty return false (sankam-nikolya)

2.5.0
=====

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Yii2 widget for handle multiple inputs for an attribute of model and tabular inp
[![License](https://poser.pugx.org/unclead/yii2-multiple-input/license)](https://packagist.org/packages/unclead/yii2-multiple-input)

##Latest release
The latest stable version of the extension is v2.5.0 Follow the [instruction](./UPGRADE.md) for upgrading from previous versions
The latest stable version of the extension is v2.6.0 Follow the [instruction](./UPGRADE.md) for upgrading from previous versions

##Installation
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"yii2 tabular input"
],
"type": "yii2-extension",
"version": "2.5.0",
"version": "2.6.0",
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/unclead/yii2-multiple-input/issues?state=open",
Expand Down
3 changes: 2 additions & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ use unclead\multipleinput\MultipleInput;
'allowEmptyList' => false,
'enableGuessTitle' => true,
'min' => 2, // should be at least 2 rows
'addButtonPosition' => MultipleInput::POS_HEADER // show add button in the header
'addButtonPosition' => MultipleInput::POS_HEADER, // show add button in the header
'sortable' => true, // optional. user can change order of rows
])
->label(false);
?>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jquery.multipleInput",
"version": "2.5.0",
"version": "2.6.0",
"description": "jQuery multipleInput",
"scripts": {
"build": "npm install && (gulp || node node_modules/gulp/bin/gulp.js)"
Expand Down
23 changes: 21 additions & 2 deletions src/MultipleInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ class MultipleInput extends InputWidget
*/
public $form;

/**
* @var bool allow sorting.
* @internal this property is used when need to allow sorting rows.
*/
public $sortable = false;

/**
* Initialization.
*
Expand Down Expand Up @@ -155,7 +161,7 @@ protected function initData()
}

if ($this->model instanceof Model) {
$data = $this->model->hasProperty($this->attribute)
$data = ($this->model->hasProperty($this->attribute) || isset($this->model->{$this->attribute}))
? ArrayHelper::getValue($this->model, $this->attribute, [])
: [];

Expand Down Expand Up @@ -207,6 +213,18 @@ public function run()
*/
private function createRenderer()
{
if($this->sortable) {
$drag = [
'name' => 'drag',
'type' => MultipleInputColumn::TYPE_DRAGCOLUMN,
'headerOptions' => [
'style' => 'width: 20px;',
]
];

array_unshift($this->columns, $drag);
}

$config = [
'id' => $this->getId(),
'columns' => $this->columns,
Expand All @@ -219,7 +237,8 @@ private function createRenderer()
'addButtonPosition' => $this->addButtonPosition,
'rowOptions' => $this->rowOptions,
'context' => $this,
'form' => $this->form
'form' => $this->form,
'sortable' => $this->sortable
];

if ($this->removeButtonOptions !== null) {
Expand Down
9 changes: 8 additions & 1 deletion src/TabularInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ class TabularInput extends Widget
*/
public $form;

/**
* @var bool allow sorting.
* @internal this property is used when need to allow sorting rows.
*/
public $sortable = false;

/**
* Initialization.
*
Expand Down Expand Up @@ -158,7 +164,8 @@ private function createRenderer()
'rowOptions' => $this->rowOptions,
'addButtonPosition' => $this->addButtonPosition,
'context' => $this,
'form' => $this->form
'form' => $this->form,
'sortable' => $this->sortable
];

if ($this->removeButtonOptions !== null) {
Expand Down
2 changes: 1 addition & 1 deletion src/assets/MultipleInputAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class MultipleInputAsset extends AssetBundle
{
public $css = [
'css/multiple-input.css'
YII_DEBUG ? 'css/multiple-input.css' : 'css/multiple-input.min.css'
];

public $js = [];
Expand Down
33 changes: 33 additions & 0 deletions src/assets/MultipleInputSortableAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* @link https://github.com/unclead/yii2-multiple-input
* @copyright Copyright (c) 2014 unclead
* @license https://github.com/unclead/yii2-multiple-input/blob/master/LICENSE.md
*/

namespace unclead\multipleinput\assets;

use yii\web\AssetBundle;

/**
* Class MultipleInputAsset
* @package unclead\multipleinput\assets
*/
class MultipleInputSortableAsset extends AssetBundle
{
public $sourcePath = __DIR__ . '/src/';

public $css = [
YII_DEBUG ? 'css/sorting.css' : 'css/sorting.min.css'
];

public $js = [
YII_DEBUG ? 'js/jquery-sortable.js' : 'js/jquery-sortable.min.js'
];

public $depends = [
'unclead\multipleinput\assets\MultipleInputAsset',
];

}
1 change: 1 addition & 0 deletions src/assets/src/css/multiple-input.min.css

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

42 changes: 42 additions & 0 deletions src/assets/src/css/sorting.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.drag-handle,
.dragging,
.dragging * {
cursor: move !important;
}

.dragged {
position: absolute;
top: 0;
opacity: .5;
z-index: 2000;
}

.drag-handle {
opacity: .5;
padding: 7.5px;
}

.drag-handle:hover {
opacity: 1;
}

tr.placeholder {
display: block;
background: red;
position: relative;
margin: 0;
padding: 0;
border: none;
}

tr.placeholder:before {
content: "";
position: absolute;
width: 0;
height: 0;
border: 5px solid transparent;
border-left-color: red;
margin-top: -5px;
left: -5px;
border-right: none;
}
1 change: 1 addition & 0 deletions src/assets/src/css/sorting.min.css

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

Loading

0 comments on commit f7e5a4b

Please sign in to comment.