Skip to content

Commit

Permalink
Refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
z-song committed Apr 16, 2019
1 parent 03896d5 commit 38a1242
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 57 deletions.
21 changes: 11 additions & 10 deletions src/Form/Tools.php
Expand Up @@ -210,9 +210,12 @@ protected function renderView()
*/
protected function renderDelete()
{
$deleteConfirm = trans('admin.delete_confirm');
$confirm = trans('admin.confirm');
$cancel = trans('admin.cancel');
$trans = [
'delete_confirm' => trans('admin.delete_confirm'),
'confirm' => trans('admin.confirm'),
'cancel' => trans('admin.cancel'),
'delete' => trans('admin.delete'),
];

$class = uniqid();

Expand All @@ -221,13 +224,13 @@ protected function renderDelete()
$('.{$class}-delete').unbind('click').click(function() {
swal({
title: "$deleteConfirm",
title: "{$trans['delete_confirm']}",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "$confirm",
confirmButtonText: "{$trans['confirm']}",
showLoaderOnConfirm: true,
cancelButtonText: "$cancel",
cancelButtonText: "{$trans['cancel']}",
preConfirm: function() {
return new Promise(function(resolve) {
$.ajax({
Expand Down Expand Up @@ -259,14 +262,12 @@ protected function renderDelete()
SCRIPT;

$delete = trans('admin.delete');

Admin::script($script);

return <<<HTML
<div class="btn-group pull-right" style="margin-right: 5px">
<a href="javascript:void(0);" class="btn btn-sm btn-danger {$class}-delete" title="{$delete}">
<i class="fa fa-trash"></i><span class="hidden-xs"> {$delete}</span>
<a href="javascript:void(0);" class="btn btn-sm btn-danger {$class}-delete" title="{$trans['delete']}">
<i class="fa fa-trash"></i><span class="hidden-xs"> {$trans['delete']}</span>
</a>
</div>
HTML;
Expand Down
14 changes: 8 additions & 6 deletions src/Grid/Displayers/Actions.php
Expand Up @@ -205,9 +205,11 @@ protected function renderDelete()

protected function setupDeleteScript()
{
$deleteConfirm = trans('admin.delete_confirm');
$confirm = trans('admin.confirm');
$cancel = trans('admin.cancel');
$trans = [
'delete_confirm' => trans('admin.delete_confirm'),
'confirm' => trans('admin.confirm'),
'cancel' => trans('admin.cancel'),
];

$script = <<<SCRIPT
Expand All @@ -216,13 +218,13 @@ protected function setupDeleteScript()
var id = $(this).data('id');
swal({
title: "$deleteConfirm",
title: "{$trans['delete_confirm']}",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "$confirm",
confirmButtonText: "{$trans['confirm']}",
showLoaderOnConfirm: true,
cancelButtonText: "$cancel",
cancelButtonText: "{$trans['cancel']}",
preConfirm: function() {
return new Promise(function(resolve) {
$.ajax({
Expand Down
14 changes: 8 additions & 6 deletions src/Grid/Tools/BatchDelete.php
Expand Up @@ -14,9 +14,11 @@ public function __construct($title)
*/
public function script()
{
$deleteConfirm = trans('admin.delete_confirm');
$confirm = trans('admin.confirm');
$cancel = trans('admin.cancel');
$trans = [
'delete_confirm' => trans('admin.delete_confirm'),
'confirm' => trans('admin.confirm'),
'cancel' => trans('admin.cancel'),
];

return <<<EOT
Expand All @@ -25,13 +27,13 @@ public function script()
var id = {$this->grid->getSelectedRowsName()}().join();
swal({
title: "$deleteConfirm",
title: "{$trans['delete_confirm']}",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "$confirm",
confirmButtonText: "{$trans['confirm']}",
showLoaderOnConfirm: true,
cancelButtonText: "$cancel",
cancelButtonText: "{$trans['cancel']}",
preConfirm: function() {
return new Promise(function(resolve) {
$.ajax({
Expand Down
18 changes: 10 additions & 8 deletions src/Grid/Tools/ExportButton.php
Expand Up @@ -59,25 +59,27 @@ public function render()

$this->setUpScripts();

$export = trans('admin.export');
$all = trans('admin.all');
$currentPage = trans('admin.current_page');
$selectedRows = trans('admin.selected_rows');
$trans = [
'export' => trans('admin.export'),
'all' => trans('admin.all'),
'current_page' => trans('admin.current_page'),
'selected_rows' => trans('admin.selected_rows'),
];

$page = request('page', 1);

return <<<EOT
<div class="btn-group pull-right" style="margin-right: 10px">
<a class="btn btn-sm btn-twitter" title="{$export}"><i class="fa fa-download"></i><span class="hidden-xs"> {$export}</span></a>
<a class="btn btn-sm btn-twitter" title="{$trans['export']}"><i class="fa fa-download"></i><span class="hidden-xs"> {$trans['export']}</span></a>
<button type="button" class="btn btn-sm btn-twitter dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="{$this->grid->getExportUrl('all')}" target="_blank">{$all}</a></li>
<li><a href="{$this->grid->getExportUrl('page', $page)}" target="_blank">{$currentPage}</a></li>
<li><a href="{$this->grid->getExportUrl('selected', '__rows__')}" target="_blank" class='{$this->grid->getExportSelectedName()}'>{$selectedRows}</a></li>
<li><a href="{$this->grid->getExportUrl('all')}" target="_blank">{$trans['all']}</a></li>
<li><a href="{$this->grid->getExportUrl('page', $page)}" target="_blank">{$trans['current_page']}</a></li>
<li><a href="{$this->grid->getExportUrl('selected', '__rows__')}" target="_blank" class='{$this->grid->getExportSelectedName()}'>{$trans['selected_rows']}</a></li>
</ul>
</div>
EOT;
Expand Down
10 changes: 6 additions & 4 deletions src/Grid/Tools/PerPageSelector.php
Expand Up @@ -74,18 +74,20 @@ public function render()
return "<option value=\"$url\" $selected>$option</option>";
})->implode("\r\n");

$show = trans('admin.show');
$entries = trans('admin.entries');
$trans = [
'show' => trans('admin.show'),
'entries' => trans('admin.entries'),
];

return <<<EOT
<label class="control-label pull-right" style="margin-right: 10px; font-weight: 100;">
<small>$show</small>&nbsp;
<small>{$trans['show']}</small>&nbsp;
<select class="input-sm {$this->grid->getPerPageName()}" name="per-page">
$options
</select>
&nbsp;<small>$entries</small>
&nbsp;<small>{$trans['entries']}</small>
</label>
EOT;
Expand Down
22 changes: 11 additions & 11 deletions src/Show/Tools.php
Expand Up @@ -222,9 +222,12 @@ protected function renderEdit()
*/
protected function renderDelete()
{
$deleteConfirm = trans('admin.delete_confirm');
$confirm = trans('admin.confirm');
$cancel = trans('admin.cancel');
$trans = [
'delete_confirm' => trans('admin.delete_confirm'),
'confirm' => trans('admin.confirm'),
'cancel' => trans('admin.cancel'),
'delete' => trans('admin.delete'),
];

$class = uniqid();

Expand All @@ -233,13 +236,13 @@ protected function renderDelete()
$('.{$class}-delete').unbind('click').click(function() {
swal({
title: "$deleteConfirm",
title: "{$trans['delete_confirm']}",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "$confirm",
confirmButtonText: "{$trans['confirm']}",
showLoaderOnConfirm: true,
cancelButtonText: "$cancel",
cancelButtonText: "{$trans['cancel']}",
preConfirm: function() {
return new Promise(function(resolve) {
$.ajax({
Expand Down Expand Up @@ -270,15 +273,12 @@ protected function renderDelete()
});
SCRIPT;

$delete = trans('admin.delete');

Admin::script($script);

return <<<HTML
<div class="btn-group pull-right" style="margin-right: 5px">
<a href="javascript:void(0);" class="btn btn-sm btn-danger {$class}-delete" title="{$delete}">
<i class="fa fa-trash"></i><span class="hidden-xs"> {$delete}</span>
<a href="javascript:void(0);" class="btn btn-sm btn-danger {$class}-delete" title="{$trans['delete']}">
<i class="fa fa-trash"></i><span class="hidden-xs"> {$trans['delete']}</span>
</a>
</div>
HTML;
Expand Down
26 changes: 14 additions & 12 deletions src/Tree.php
Expand Up @@ -219,12 +219,14 @@ public function saveOrder($serialize)
*/
protected function script()
{
$deleteConfirm = trans('admin.delete_confirm');
$saveSucceeded = trans('admin.save_succeeded');
$refreshSucceeded = trans('admin.refresh_succeeded');
$deleteSucceeded = trans('admin.delete_succeeded');
$confirm = trans('admin.confirm');
$cancel = trans('admin.cancel');
$trans = [
'delete_confirm' => trans('admin.delete_confirm'),
'save_succeeded' => trans('admin.save_succeeded'),
'refresh_succeeded' => trans('admin.refresh_succeeded'),
'delete_succeeded' => trans('admin.delete_succeeded'),
'confirm' => trans('admin.confirm'),
'cancel' => trans('admin.cancel'),
];

$nestableOptions = json_encode($this->nestableOptions);

Expand All @@ -235,13 +237,13 @@ protected function script()
$('.tree_branch_delete').click(function() {
var id = $(this).data('id');
swal({
title: "$deleteConfirm",
title: "{$trans['delete_confirm']}",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "$confirm",
confirmButtonText: "{$trans['confirm']}",
showLoaderOnConfirm: true,
cancelButtonText: "$cancel",
cancelButtonText: "{$trans['cancel']}",
preConfirm: function() {
return new Promise(function(resolve) {
$.ajax({
Expand All @@ -253,7 +255,7 @@ protected function script()
},
success: function (data) {
$.pjax.reload('#pjax-container');
toastr.success('{$deleteSucceeded}');
toastr.success('{$trans['delete_succeeded']}');
resolve(data);
}
});
Expand All @@ -280,13 +282,13 @@ protected function script()
},
function(data){
$.pjax.reload('#pjax-container');
toastr.success('{$saveSucceeded}');
toastr.success('{$trans['save_succeeded']}');
});
});
$('.{$this->elementId}-refresh').click(function () {
$.pjax.reload('#pjax-container');
toastr.success('{$refreshSucceeded}');
toastr.success('{$trans['refresh_succeeded']}');
});
$('.{$this->elementId}-tree-tools').on('click', function(e){
Expand Down

0 comments on commit 38a1242

Please sign in to comment.