Skip to content

Commit 053593f

Browse files
committed
Merge branch 'master' of https://github.com/z-song/laravel-admin
2 parents d2d1022 + 59e60cb commit 053593f

File tree

5 files changed

+60
-8
lines changed

5 files changed

+60
-8
lines changed

resources/views/form.blade.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</div>
99
<!-- /.box-header -->
1010
<!-- form start -->
11-
{!! $form->open(['class' => "form-horizontal"]) !!}
11+
{!! $form->open() !!}
1212

1313
<div class="box-body">
1414

resources/views/form/keyvalue.blade.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<td>
2323
<div class="form-group {{ $errors->has($keysErrorKey) ? 'has-error' : '' }}">
2424
<div class="col-sm-12">
25-
<input name="{{ $column }}[keys][]" value="{{ old("{$column}.keys.{$k}", $k) }}" class="form-control" required/>
25+
<input name="{{ $name }}[keys][]" value="{{ old("{$column}.keys.{$k}", $k) }}" class="form-control" required/>
2626

2727
@if($errors->has($keysErrorKey))
2828
@foreach($errors->get($keysErrorKey) as $message)
@@ -35,7 +35,7 @@
3535
<td>
3636
<div class="form-group {{ $errors->has($valsErrorKey) ? 'has-error' : '' }}">
3737
<div class="col-sm-12">
38-
<input name="{{ $column }}[values][]" value="{{ old("{$column}.values.{$k}", $v) }}" class="form-control" />
38+
<input name="{{ $name }}[values][]" value="{{ old("{$column}.values.{$k}", $v) }}" class="form-control" />
3939
@if($errors->has($valsErrorKey))
4040
@foreach($errors->get($valsErrorKey) as $message)
4141
<label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i> {{$message}}</label><br/>
@@ -75,14 +75,14 @@
7575
<td>
7676
<div class="form-group ">
7777
<div class="col-sm-12">
78-
<input name="{{ $column }}[keys][]" class="form-control" required/>
78+
<input name="{{ $name }}[keys][]" class="form-control" required/>
7979
</div>
8080
</div>
8181
</td>
8282
<td>
8383
<div class="form-group ">
8484
<div class="col-sm-12">
85-
<input name="{{ $column }}[values][]" class="form-control" />
85+
<input name="{{ $name }}[values][]" class="form-control" />
8686
</div>
8787
</div>
8888
</td>
@@ -95,4 +95,4 @@
9595
</div>
9696
</td>
9797
</tr>
98-
</template>
98+
</template>

src/Console/stubs/routes.stub

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Route::group([
88
'prefix' => config('admin.route.prefix'),
99
'namespace' => config('admin.route.namespace'),
1010
'middleware' => config('admin.route.middleware'),
11+
'as' => config('admin.route.prefix') . '.',
1112
], function (Router $router) {
1213

1314
$router->get('/', 'HomeController@index')->name('admin.home');

src/Form.php

+13
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,19 @@ public function setTitle($title = ''): self
12181218
return $this;
12191219
}
12201220

1221+
/**
1222+
* Set a submit confirm.
1223+
*
1224+
* @param string $message
1225+
* @return $this
1226+
*/
1227+
public function confirm(string $message)
1228+
{
1229+
$this->builder()->confirm($message);
1230+
1231+
return $this;
1232+
}
1233+
12211234
/**
12221235
* Add a row in form.
12231236
*

src/Form/Builder.php

+40-2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ class Builder
9797
*/
9898
protected $title;
9999

100+
/**
101+
* @var string
102+
*/
103+
protected $formClass;
104+
100105
/**
101106
* Builder constructor.
102107
*
@@ -118,6 +123,8 @@ public function init()
118123
{
119124
$this->tools = new Tools($this);
120125
$this->footer = new Footer($this);
126+
127+
$this->formClass = 'model-form-' . uniqid();
121128
}
122129

123130
/**
@@ -487,10 +494,9 @@ public function open($options = []): string
487494

488495
$attributes['action'] = $this->getAction();
489496
$attributes['method'] = Arr::get($options, 'method', 'post');
497+
$attributes['class'] = implode(' ', ['form-horizontal', $this->formClass]);
490498
$attributes['accept-charset'] = 'UTF-8';
491499

492-
$attributes['class'] = Arr::get($options, 'class');
493-
494500
if ($this->hasFile()) {
495501
$attributes['enctype'] = 'multipart/form-data';
496502
}
@@ -516,6 +522,38 @@ public function close(): string
516522
return '</form>';
517523
}
518524

525+
/**
526+
* @param string $message
527+
*/
528+
public function confirm(string $message)
529+
{
530+
$trans = [
531+
'confirm' => trans('admin.confirm'),
532+
'cancel' => trans('admin.cancel'),
533+
];
534+
535+
$script = <<<SCRIPT
536+
$('form.{$this->formClass} button[type=submit]').click(function (e) {
537+
e.preventDefault();
538+
var form = $(this).parents('form');
539+
swal({
540+
title: "$message",
541+
type: "warning",
542+
showCancelButton: true,
543+
confirmButtonColor: "#DD6B55",
544+
confirmButtonText: "{$trans['confirm']}",
545+
cancelButtonText: "{$trans['cancel']}",
546+
}).then(function (result) {
547+
if (result.value) {
548+
form.submit();
549+
}
550+
});
551+
});
552+
SCRIPT;
553+
554+
Admin::script($script);
555+
}
556+
519557
/**
520558
* Remove reserved fields like `id` `created_at` `updated_at` in form fields.
521559
*

0 commit comments

Comments
 (0)