phpvms/resources/views/admin/aircraft/script.blade.php
Nabeel S 0d1f38cf85
Refactor all JS API calls #360 (#375)
* Refactor all JS API calls #360

* Remove unused imports

* Lint JS

* Fix doubled api key

* Formatting

* Added extra logging to distance lookup

* Remove the .editorconfig file in distrib

* shell check fixes

* Remove the .editorconfig file in distrib
2019-08-30 08:08:00 -04:00

71 lines
1.8 KiB
PHP

@section('scripts')
<script>
function setEditable() {
const token = $('meta[name="csrf-token"]').attr('content');
const api_key = $('meta[name="api-key"]').attr('content');
@if(isset($aircraft))
$('#expenses a.text').editable({
emptytext: '0',
url: '{{ url('/admin/aircraft/'.$aircraft->id.'/expenses') }}',
title: 'Enter override value',
ajaxOptions: {
type: 'post',
headers: {
'x-api-key': api_key,
'X-CSRF-TOKEN': token,
}
},
params: function (params) {
return {
_method: 'put',
expense_id: params.pk,
name: params.name,
value: params.value
}
}
});
$('#expenses a.dropdown').editable({
type: 'select',
emptytext: '0',
source: {!! json_encode(list_to_editable(\App\Models\Enums\ExpenseType::select())) !!},
url: '{{ url('/admin/aircraft/'.$aircraft->id.'/expenses') }}',
title: 'Enter override value',
ajaxOptions: {
type: 'post',
headers: {
'x-api-key': api_key,
'X-CSRF-TOKEN': token,
}
},
params: function (params) {
return {
_method: 'put',
expense_id: params.pk,
name: params.name,
value: params.value
}
}
});
@endif
}
$(document).ready(function() {
setEditable();
$(document).on('submit', 'form.modify_expense', function (event) {
event.preventDefault();
console.log(event);
$.pjax.submit(event, '#expenses-wrapper', {push: false});
});
$(document).on('pjax:complete', function () {
initPlugins();
setEditable();
});
});
</script>
@endsection