Skip to content

Commit c1b3895

Browse files
authored
Merge pull request #1615 from z-song/1.5
1.5
2 parents eca2b7b + 1b28ebe commit c1b3895

File tree

14 files changed

+199
-23
lines changed

14 files changed

+199
-23
lines changed

resources/assets/laravel-admin/laravel-admin.js

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ $.fn.editable.defaults.params = function (params) {
55
return params;
66
};
77

8+
$.fn.editable.defaults.error = function (data) {
9+
var msg = '';
10+
if (data.responseJSON.errors) {
11+
$.each(data.responseJSON.errors, function (k, v) {
12+
msg += v + '\\n';
13+
});
14+
}
15+
return msg
16+
};
17+
818
toastr.options = {
919
closeButton: true,
1020
progressBar: true,
@@ -18,45 +28,47 @@ $(document).pjax('a:not(a[target="_blank"])', {
1828
container: '#pjax-container'
1929
});
2030

21-
NProgress.configure({ parent: '#pjax-container' });
31+
NProgress.configure({parent: '#pjax-container'});
2232

23-
$(document).on('pjax:timeout', function(event) { event.preventDefault(); })
33+
$(document).on('pjax:timeout', function (event) {
34+
event.preventDefault();
35+
})
2436

25-
$(document).on('submit', 'form[pjax-container]', function(event) {
37+
$(document).on('submit', 'form[pjax-container]', function (event) {
2638
$.pjax.submit(event, '#pjax-container')
2739
});
2840

29-
$(document).on("pjax:popstate", function() {
41+
$(document).on("pjax:popstate", function () {
3042

31-
$(document).one("pjax:end", function(event) {
32-
$(event.target).find("script[data-exec-on-popstate]").each(function() {
43+
$(document).one("pjax:end", function (event) {
44+
$(event.target).find("script[data-exec-on-popstate]").each(function () {
3345
$.globalEval(this.text || this.textContent || this.innerHTML || '');
3446
});
3547
});
3648
});
3749

38-
$(document).on('pjax:send', function(xhr) {
39-
if(xhr.relatedTarget && xhr.relatedTarget.tagName && xhr.relatedTarget.tagName.toLowerCase() === 'form') {
50+
$(document).on('pjax:send', function (xhr) {
51+
if (xhr.relatedTarget && xhr.relatedTarget.tagName && xhr.relatedTarget.tagName.toLowerCase() === 'form') {
4052
$submit_btn = $('form[pjax-container] :submit');
41-
if($submit_btn) {
53+
if ($submit_btn) {
4254
$submit_btn.button('loading')
4355
}
4456
}
4557
NProgress.start();
4658
});
4759

48-
$(document).on('pjax:complete', function(xhr) {
49-
if(xhr.relatedTarget && xhr.relatedTarget.tagName && xhr.relatedTarget.tagName.toLowerCase() === 'form') {
60+
$(document).on('pjax:complete', function (xhr) {
61+
if (xhr.relatedTarget && xhr.relatedTarget.tagName && xhr.relatedTarget.tagName.toLowerCase() === 'form') {
5062
$submit_btn = $('form[pjax-container] :submit');
51-
if($submit_btn) {
63+
if ($submit_btn) {
5264
$submit_btn.button('reset')
5365
}
5466
}
5567
NProgress.done();
5668
});
5769

58-
$(function(){
59-
$('.sidebar-menu li:not(.treeview) > a').on('click', function(){
70+
$(function () {
71+
$('.sidebar-menu li:not(.treeview) > a').on('click', function () {
6072
var $parent = $(this).parent().addClass('active');
6173
$parent.siblings('.treeview.active').find('> a').trigger('click');
6274
$parent.siblings().removeClass('active').find('li').removeClass('active');
@@ -65,7 +77,7 @@ $(function(){
6577
$('[data-toggle="popover"]').popover();
6678
});
6779

68-
(function($){
80+
(function ($) {
6981
$.fn.admin = LA;
7082
$.admin = LA;
7183

resources/lang/ru/admin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
'description' => 'Описание',
4141
'back' => 'Назад',
4242
'back_to_list' => 'Вернуться к списку',
43-
'submit' => 'Сохранить',
43+
'submit' => 'Создать',
4444
'menu' => 'Меню',
4545
'input' => 'Ввод',
4646
'succeeded' => 'Завершена',

resources/views/widgets/form.blade.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
<!-- /.box-body -->
1111
<div class="box-footer">
12+
@if( ! $method == 'GET')
1213
<input type="hidden" name="_token" value="{{ csrf_token() }}">
14+
@endif
1315
<div class="col-md-2"></div>
1416

1517
<div class="col-md-8">
@@ -23,4 +25,4 @@
2325
</div>
2426

2527
</div>
26-
</form>
28+
</form>

src/Auth/Database/HasPermissions.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,20 @@ public function visible(array $roles = []) : bool
145145

146146
return $this->inRoles($roles) || $this->isAdministrator();
147147
}
148+
149+
/**
150+
* Detach models from the relationship.
151+
*
152+
* @return void
153+
*/
154+
protected static function boot()
155+
{
156+
parent::boot();
157+
158+
static::deleting(function ($model) {
159+
$model->roles()->detach();
160+
161+
$model->permissions()->detach();
162+
});
163+
}
148164
}

src/Auth/Database/Menu.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,18 @@ public function allNodes() : array
6666

6767
return static::with('roles')->orderByRaw($byOrder)->get()->toArray();
6868
}
69+
70+
/**
71+
* Detach models from the relationship.
72+
*
73+
* @return void
74+
*/
75+
protected static function boot()
76+
{
77+
parent::boot();
78+
79+
static::deleting(function ($model) {
80+
$model->roles()->detach();
81+
});
82+
}
6983
}

src/Auth/Database/Permission.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,18 @@ public function getHttpMethodAttribute($method)
130130

131131
return $method;
132132
}
133+
134+
/**
135+
* Detach models from the relationship.
136+
*
137+
* @return void
138+
*/
139+
protected static function boot()
140+
{
141+
parent::boot();
142+
143+
static::deleting(function ($model) {
144+
$model->roles()->detach();
145+
});
146+
}
133147
}

src/Auth/Database/Role.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,20 @@ public function cannot(string $permission) : bool
7676
{
7777
return !$this->can($permission);
7878
}
79+
80+
/**
81+
* Detach models from the relationship.
82+
*
83+
* @return void
84+
*/
85+
protected static function boot()
86+
{
87+
parent::boot();
88+
89+
static::deleting(function ($model) {
90+
$model->administrators()->detach();
91+
92+
$model->permissions()->detach();
93+
});
94+
}
7995
}

src/Auth/Permission.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ public static function allow($roles)
5252
}
5353
}
5454

55+
/**
56+
* Don't check permission.
57+
*
58+
* @return bool
59+
*/
60+
public static function free()
61+
{
62+
return true;
63+
}
64+
5565
/**
5666
* Roles denied to access.
5767
*

src/Form.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,8 @@ public function update($id)
502502
{
503503
$data = Input::all();
504504

505+
$isEditable = $this->isEditable($data);
506+
505507
$data = $this->handleEditable($data);
506508

507509
$data = $this->handleFileDelete($data);
@@ -520,7 +522,11 @@ public function update($id)
520522

521523
// Handle validation errors.
522524
if ($validationMessages = $this->validationMessages($data)) {
523-
return back()->withInput()->withErrors($validationMessages);
525+
if (!$isEditable) {
526+
return back()->withInput()->withErrors($validationMessages);
527+
} else {
528+
return response()->json(['errors' => array_dot($validationMessages->getMessages())], 422);
529+
}
524530
}
525531

526532
if (($response = $this->prepare($data)) instanceof Response) {
@@ -565,6 +571,18 @@ protected function redirectAfterUpdate()
565571
return redirect($url);
566572
}
567573

574+
/**
575+
* Check if request is from editable.
576+
*
577+
* @param array $input
578+
*
579+
* @return bool
580+
*/
581+
protected function isEditable(array $input = [])
582+
{
583+
return array_key_exists('_editable', $input);
584+
}
585+
568586
/**
569587
* Handle editable update.
570588
*

src/Form/Field/Checkbox.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,26 @@ public function options($options = [])
3636

3737
/**
3838
* Draw inline checkboxes.
39+
*
40+
* @return $this
3941
*/
4042
public function inline()
4143
{
4244
$this->inline = true;
45+
46+
return $this;
4347
}
4448

4549
/**
4650
* Draw stacked checkboxes.
51+
*
52+
* @return $this
4753
*/
4854
public function stacked()
4955
{
5056
$this->inline = false;
57+
58+
return $this;
5159
}
5260

5361
/**

0 commit comments

Comments
 (0)