Navigation Menu

Skip to content

Commit

Permalink
Extending handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
execut committed Feb 15, 2019
1 parent e1fc674 commit 49d2fd9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
22 changes: 14 additions & 8 deletions action/adapter/gridView/handler/Model.php
Expand Up @@ -40,19 +40,25 @@ public function run() {
$arguments[] = ['id' => $ids];
if (is_array($method)) {
$class = $method[0];
$count = $class::$method(...$arguments);
$result = $class::$method(...$arguments);
} else if (is_callable($method)) {
$count = $method(...$arguments);
$result = $method(...$arguments);
} else {
$count = $class::$method(...$arguments);
$result = $class::$method(...$arguments);
}

$response = new \execut\actions\action\Response();
$flashes = [
'kv-detail-success' => strtr($this->successMessage, ['#' => $count]),
];
$response->content = \yii::$app->response->redirect($this->getReferer());
$response->flashes = $flashes;
if (is_array($result)) {
$response->format = 'json';
$response->content = $result;
} else {
$count = $result;
$flashes = [
'kv-detail-success' => strtr($this->successMessage, ['#' => $count]),
];
$response->content = \yii::$app->response->redirect($this->getReferer());
$response->flashes = $flashes;
}

return $response;
}
Expand Down
6 changes: 6 additions & 0 deletions widgets/HandlersButton.php
Expand Up @@ -9,6 +9,7 @@
namespace execut\actions\widgets;

use execut\yii\jui\Widget;
use yii\bootstrap\Modal;
use yii\helpers\Html;
use yii\helpers\Url;

Expand All @@ -33,6 +34,11 @@ public function run()
'idAttribute' => $this->idAttribute,
];
$this->registerWidget();
Modal::begin([
'header' => '<h3 class="modal-title"><i class="glyphicon glyphicon-trash"></i> Исправьте ошибки</h3>',
'id' => $this->id . '-modal',
]);
Modal::end();
return Html::tag('i', '', [
'id' => $this->id,
'class' => 'btn btn-' . $this->type . ' glyphicon glyphicon-' . $this->icon,
Expand Down
16 changes: 15 additions & 1 deletion widgets/assets/HandlersButton.js
Expand Up @@ -10,6 +10,7 @@
var t = this,
el = t.element;
t._gridEl = $(t.options.gridSelector);
t._modalEl = $('#' + el.attr('id') + '-modal');
},
_initEvents: function () {
var t = this,
Expand All @@ -28,7 +29,20 @@
url += '&' + t.options.idAttribute + '[]=' + selectedIds[key];
}

$.get(url);
$.get(url, function (r) {
var resultError = [];
for (var modelName in r) {
for (var attribute in r[modelName]) {
for (var errorKey in r[modelName][attribute]) {
var error = r[modelName][attribute][errorKey];
resultError[resultError.length] = modelName + ': ' + error;
}
}
}

t._modalEl.find('.modal-body').html(resultError.join('<br>'));
t._modalEl.modal('show');
});
}
});
},
Expand Down
2 changes: 1 addition & 1 deletion widgets/assets/HandlersButton.min.js

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

0 comments on commit 49d2fd9

Please sign in to comment.