|
29 | 29 | <td>{{ $location->long }}</td> |
30 | 30 | <td class="text-center">{{ $location->a_nodeCount }}</td> |
31 | 31 | <td class="text-center">{{ $location->a_serverCount }}</td> |
32 | | - <td class="text-center"><a href="#edit"><i class="fa fa-wrench" data-action="edit" data-id="{{ $location->id }}" data-short="{{ $location->short }}" data-long="{{ $location->long }}"></i></a></td> |
| 32 | + <td class="text-center"><a href="#edit"><i class="fa fa-wrench" data-toggle="modal" data-target="#editModal" data-action="edit" data-id="{{ $location->id }}" data-short="{{ $location->short }}" data-long="{{ $location->long }}"></i></a></td> |
33 | 33 | <td class="text-center"><a href="#delete" class="text-danger" data-action="delete" data-id="{{ $location->id }}"><i class="fa fa-trash-o"></i></a></td> |
34 | 34 | </tr> |
35 | 35 | @endforeach |
|
46 | 46 | </div> |
47 | 47 | </div> |
48 | 48 | </div> |
| 49 | +<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"> |
| 50 | + <div class="modal-dialog" role="document"> |
| 51 | + <div class="modal-content"> |
| 52 | + <div class="modal-header"> |
| 53 | + <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
| 54 | + <h4 class="modal-title" id="exampleModalLabel">Editing Location</h4> |
| 55 | + </div> |
| 56 | + <form action="{{ route('admin.locations') }}" method="POST" id="editLocationForm"> |
| 57 | + <div class="modal-body"> |
| 58 | + <div class="form-group"> |
| 59 | + <label for="location-short" class="control-label">Location Code:</label> |
| 60 | + <input type="text" class="form-control" id="location-short"> |
| 61 | + </div> |
| 62 | + <div class="form-group"> |
| 63 | + <label for="location-long" class="control-label">Description:</label> |
| 64 | + <input type="text" class="form-control" id="location-long"> |
| 65 | + </div> |
| 66 | + </div> |
| 67 | + <div class="modal-footer"> |
| 68 | + <input type="hidden" id="location-id"> |
| 69 | + <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">Close</button> |
| 70 | + <button type="submit" class="btn btn-sm btn-primary">Edit Location</button> |
| 71 | + </div> |
| 72 | + </form> |
| 73 | + </div> |
| 74 | + </div> |
| 75 | +</div> |
49 | 76 | <script> |
50 | 77 | $(document).ready(function () { |
51 | 78 | $('#sidebar_links').find("a[href='/admin/locations']").addClass('active'); |
| 79 | + $('#editModal').on('show.bs.modal', function (event) { |
| 80 | + var button = $(event.relatedTarget); |
| 81 | + var short = button.data('short'); |
| 82 | + var long = button.data('long'); |
| 83 | + var id = button.data('id'); |
| 84 | + var modal = $(this); |
| 85 | +
|
| 86 | + modal.find('#location-id').val(id); |
| 87 | + modal.find('#location-short').val(short); |
| 88 | + modal.find('#location-long').val(long); |
| 89 | + }); |
| 90 | + $('#editLocationForm').submit(function (event) { |
| 91 | + event.preventDefault(); |
| 92 | + $.ajax({ |
| 93 | + method: 'PATCH', |
| 94 | + url: '{{ route('admin.locations') }}/' + $('#location-id').val(), |
| 95 | + headers: { |
| 96 | + 'X-CSRF-TOKEN': '{{ csrf_token() }}' |
| 97 | + }, |
| 98 | + data: { |
| 99 | + short: $('#location-short').val(), |
| 100 | + long: $('#location-long').val() |
| 101 | + } |
| 102 | + }).done(function (data) { |
| 103 | + swal({ |
| 104 | + type: 'success', |
| 105 | + title: '', |
| 106 | + text: 'Successfully updated location information.', |
| 107 | + closeOnConfirm: false, |
| 108 | + showLoaderOnConfirm: true |
| 109 | + }, function () { |
| 110 | + window.location = '{{ route('admin.locations') }}'; |
| 111 | + }); |
| 112 | + }).fail(function (jqXHR) { |
| 113 | + console.error(jqXHR); |
| 114 | + swal({ |
| 115 | + type: 'error', |
| 116 | + title: 'Whoops!', |
| 117 | + text: (typeof jqXHR.responseJSON.error !== 'undefined') ? jqXHR.responseJSON.error : 'An error occured while processing this request.' |
| 118 | + }); |
| 119 | + }); |
| 120 | + }); |
52 | 121 | $('[data-action="delete"]').click(function (event) { |
53 | 122 | event.preventDefault(); |
54 | 123 | var self = $(this); |
|
78 | 147 | swal({ |
79 | 148 | type: 'error', |
80 | 149 | title: 'Whoops!', |
81 | | - text: (typeof jqXHR.responseJSON !== 'undefined') ? jqXHR.responseJSON.error : 'An error occured while processing this request.' |
| 150 | + text: (typeof jqXHR.responseJSON.error !== 'undefined') ? jqXHR.responseJSON.error : 'An error occured while processing this request.' |
82 | 151 | }); |
83 | 152 | }); |
84 | 153 | }); |
|
0 commit comments