Skip to content

Commit

Permalink
prepare for release
Browse files Browse the repository at this point in the history
  • Loading branch information
mdmunir committed Nov 3, 2014
1 parent 08bc41a commit 3d25997
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 30 deletions.
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,42 @@
yii2-widgets
============

Yii2 widgets
Installation
------------

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require mdmsoft//yii2-format-converter "*"
```

or add

```
"mdmsoft//yii2-format-converter": "*"
```

to the require section of your `composer.json` file.

Usage
-----

# TabularInput Widget

```php
<?=
TabularInput::widget([
'id' => 'detail-grid',
'allModels' => $details,
'modelClass' => OrderItem::className(),
'options' => ['tag' => 'tbody'],
'itemOptions' => ['tag' => 'tr'],
'itemView' => '_item_detail',
'clientOptions' => [
'afterAddRow' => new JsExpresion("..."),
]
]);
?>
```
14 changes: 11 additions & 3 deletions TabularInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
/**
* Description of TabularInput
*
* @author Misbahul D Munir (mdmunir) <misbahuldmunir@gmail.com>
* @author Misbahul D Munir <misbahuldmunir@gmail.com>
* @since 1.0
*/
class TabularInput extends Widget
{
Expand Down Expand Up @@ -148,16 +149,23 @@ public function renderItem($model, $key, $index)
}
}

/**
* Register script
*/
protected function registerClientScript()
{
$id = $this->options['id'];
$options = Json::encode($this->getClientOptions());
$view = $this->getView();
list(,$publish) = $view->assetManager->publish('@mdm/widgets/assets');
$view->registerJsFile($publish . '/mdm.tabularInput.js', ['depends'=>['yii\web\JqueryAsset']]);
list(, $publish) = $view->assetManager->publish('@mdm/widgets/assets');
$view->registerJsFile($publish . '/mdm.tabularInput.js', ['depends' => ['yii\web\JqueryAsset']]);
$view->registerJs("jQuery('#$id').mdmTabularInput($options);");
}

/**
* Get client options
* @return array
*/
protected function getClientOptions()
{
$result = array_merge($this->clientOptions, [
Expand Down
20 changes: 17 additions & 3 deletions assets/mdm.tabularInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
initRow: undefined,
afterAddRow: undefined,
afterInit: undefined,
beforeDelete: undefined,
btnDelSelector: '[data-action=\'delete\']',
serialSelector: '.serial',
btnAddSelector: undefined,
};

var listData = {
};

var methods = {
init: function(options) {
return this.each(function() {
Expand All @@ -51,8 +52,7 @@
$(document)
.off('click.mdmTabularInput', btnDelSel)
.on('click.mdmTabularInput', btnDelSel, function(event) {
$(this).closest(rowSelector).remove();
$e.mdmTabularInput('rearrage');
$e.mdmTabularInput('deleteRow',$(this).closest(rowSelector));
event.preventDefault();
return false;
});
Expand Down Expand Up @@ -99,6 +99,20 @@
$e.mdmTabularInput('rearrage');
return $row;
},
deleteRow: function($row) {
var $e = $(this);
var id = $e.prop('id');
var settings = $.extend({}, defaults, options || {});
listData[id] = {settings: settings};
if (!$row instanceof jQuery) {
var rowSelector = "#" + id + " > " + settings.itemTag;
$row = $(rowSelector).eq($row);
}
if (settings.beforeDelete === undefined || settings.beforeDelete.call(this, $row) !== false) {
$row.remove();
$e.mdmTabularInput('rearrage');
}
},
getSelectedRows: function() {
var $e = $(this);
var settings = listData[$e.prop('id')].settings;
Expand Down
51 changes: 28 additions & 23 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
{
"name": "mdmsoft/yii2-widgets",
"description": "Widgets for Yii2",
"keywords": ["yii", "widgets", "tabular input"],
"type": "yii2-extension",
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/mdmsoft/yii2-widgets/issues",
"source": "https://github.com/mdmsoft/yii2-widgets"
},
"authors": [
{
"name": "Misbahul Munir",
"email": "misbahuldmunir@gmail.com"
}
],
"require": {
"yiisoft/yii2": "*"
},
"autoload": {
"psr-4": {
"mdm\\widgets\\": ""
}
}
"name": "mdmsoft/yii2-widgets",
"description": "Widgets for Yii2",
"keywords": ["yii", "widgets", "tabular input"],
"type": "yii2-extension",
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/mdmsoft/yii2-widgets/issues",
"source": "https://github.com/mdmsoft/yii2-widgets"
},
"authors": [
{
"name": "Misbahul Munir",
"email": "misbahuldmunir@gmail.com"
}
],
"require": {
"yiisoft/yii2": "~2.0"
},
"autoload": {
"psr-4": {
"mdm\\widgets\\": ""
}
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
}
}

0 comments on commit 3d25997

Please sign in to comment.