Skip to content

Commit 2bce817

Browse files
authored
Merge pull request #1 from webfactor/1.0
1.0.1
2 parents 70d7cc7 + 19de012 commit 2bce817

File tree

4 files changed

+84
-6
lines changed

4 files changed

+84
-6
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
@extends('webfactor::modal.modal_layout')
2+
3+
@section('header')
4+
<h3 class="box-title">{{ trans('backpack::crud.add_a_new') }} {{ $crud->entity_name }}</h3>
5+
@endsection
6+
7+
@section('content')
8+
<div class="row">
9+
<div class="col-md-10 col-md-offset-1">
10+
@include('crud::inc.grouped_errors')
11+
12+
<!-- load the view from the application if it exists, otherwise load the one in the package -->
13+
@if(view()->exists('vendor.backpack.crud.form_content'))
14+
@include('vendor.backpack.crud.form_content', ['fields' => $crud->getFields('create')])
15+
@else
16+
@include('crud::form_content', ['fields' => $crud->getFields('create')])
17+
@endif
18+
</div>
19+
</div>
20+
@endsection
21+
22+
@section('footer')
23+
@include('webfactor::modal.inc.form_save_buttons')
24+
@endsection
25+
26+
@push('crud_fields_scripts')
27+
<script>
28+
$("#create_{{ $entity }}").submit(function (e) {
29+
30+
$.ajax({
31+
type: "POST",
32+
url: "/{{ $crud->route . '/ajax' }}",
33+
data: $("#create_{{ $entity }}").serialize(), // serializes the form's elements.
34+
success: function (data) {
35+
new PNotify({
36+
type: "success",
37+
title: "Erfolg",
38+
text: "gespeichert"
39+
});
40+
41+
$("#{{ $entity }}_modal").modal('toggle');
42+
},
43+
error: function (data) {
44+
new PNotify({
45+
type: "error",
46+
title: "Fehler",
47+
text: "Nicht gespeichert: " + data.responseText
48+
});
49+
}
50+
});
51+
52+
e.preventDefault(); // avoid to execute the actual submit of the form.
53+
});
54+
</script>
55+
56+
@endpush
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@stack('crud_fields_styles')
2+
{!! Form::open(['id' => 'create_'.$entity, 'files'=>$crud->hasUploadFields('create')]) !!}
3+
<div class="modal-header">
4+
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
5+
<span aria-hidden="true">&times;</span>
6+
</button>
7+
@yield('header')
8+
</div>
9+
<div class="modal-body" id="modal-body">
10+
@yield('content')
11+
</div>
12+
13+
<div class="modal-footer">
14+
@yield('footer')
15+
</div>
16+
{!! Form::close() !!}
17+
@stack('crud_fields_scripts')

src/InstantFieldsServiceProvider.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ class InstantFieldsServiceProvider extends ServiceProvider
1717
*/
1818
public function boot()
1919
{
20-
// publish views
21-
$this->publishes([__DIR__ . '/../resources/views' => resource_path('views/vendor/backpack/crud')], 'views');
20+
$this->loadViewsFrom(realpath(__DIR__ . '/../resources/views'), 'webfactor');
21+
22+
// publish fields
23+
$this->publishes([__DIR__ . '/../resources/views/fields' => resource_path('views/vendor/backpack/crud/fields')], 'fields');
2224
}
2325

2426
/**

src/Traits/CanBeCreatedOnTheFly.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Webfactor\Laravel\Backpack\InstantFields;
44

5+
use Illuminate\Http\Request;
6+
57
trait CanBeCreatedOnTheFly
68
{
79
/**
@@ -35,7 +37,7 @@ public function ajaxCreate()
3537
{
3638
$this->crud->hasAccessOrFail('create');
3739

38-
return \View::make('backpack_ajax.create')
40+
return \View::make('webfactor::modal.create')
3941
->with('action', 'create')
4042
->with('entity', $this->getAjaxEntity())
4143
->with('crud', $this->crud)
@@ -46,12 +48,13 @@ public function ajaxCreate()
4648
}
4749

4850
/**
49-
* Checks permission and tries to store on-the-fly entity
51+
* Checks permission and tries to store on-the-fly entity. If you want to enable request validation,
52+
* please copy this method in your EntityCrudController and replace Request by your StoreRequest.
5053
*
5154
* @param StoreRequest $request
5255
* @return \Illuminate\Http\JsonResponse
5356
*/
54-
public function ajaxStore(StoreRequest $request)
57+
public function ajaxStore(Request $request)
5558
{
5659
if (!$this->crud->hasAccess('create')) {
5760
return $this->ajaxRespondNoPermission();
@@ -93,4 +96,4 @@ private function ajaxRespondError()
9396
{
9497
return response()->json(['errors' => 'Could not save'], 422);
9598
}
96-
}
99+
}

0 commit comments

Comments
 (0)