Skip to content

Commit

Permalink
Cleanup the api_key and csrf_token setters
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeelio committed Mar 13, 2018
1 parent 684ee54 commit 57cddee
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
5 changes: 3 additions & 2 deletions resources/views/admin/aircraft/script.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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({
Expand All @@ -12,7 +13,7 @@ function setEditable() {
ajaxOptions: {
type: 'post',
headers: {
'x-api-key': '{{ Auth::user()->api_key }}',
'x-api-key': api_key,
'X-CSRF-TOKEN': token,
}
},
Expand All @@ -35,7 +36,7 @@ function setEditable() {
ajaxOptions: {
type: 'post',
headers: {
'x-api-key': '{{ Auth::user()->api_key }}',
'x-api-key': api_key,
'X-CSRF-TOKEN': token,
}
},
Expand Down
20 changes: 14 additions & 6 deletions resources/views/admin/airports/script.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
function setEditable() {
const csrf_token = $('meta[name="csrf-token"]').attr('content');
const api_key = $('meta[name="api-key"]').attr('content');
@if(isset($airport))
$('#airport-expenses a.text').editable({
Expand All @@ -12,7 +13,7 @@ function setEditable() {
ajaxOptions: {
type: 'post',
headers: {
'x-api-key': '{{ Auth::user()->api_key }}',
'x-api-key': api_key,
'X-CSRF-TOKEN': csrf_token
}
},
Expand All @@ -35,7 +36,7 @@ function setEditable() {
ajaxOptions: {
type: 'post',
headers: {
'x-api-key': '{{ Auth::user()->api_key }}',
'x-api-key': api_key,
'X-CSRF-TOKEN': csrf_token
}
},
Expand All @@ -52,12 +53,16 @@ function setEditable() {
}
function phpvms_vacentral_airport_lookup(icao, callback) {
const csrf_token = $('meta[name="csrf-token"]').attr('content');
const api_key = $('meta[name="api-key"]').attr('content');
$.ajax({
url: BASE_URL + '/api/airports/'+ icao + '/lookup',
method: 'GET',
headers: {
'x-api-key': '{{ Auth::user()->api_key }}',
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
'x-api-key': api_key,
'X-CSRF-TOKEN': csrf_token
}
}).done(function (data, status) {
callback(data.data);
Expand All @@ -66,6 +71,9 @@ function phpvms_vacentral_airport_lookup(icao, callback) {
$(document).ready(function() {
const csrf_token = $('meta[name="csrf-token"]').attr('content');
const api_key = $('meta[name="api-key"]').attr('content');
setEditable();
$('#airports-table a.inline').editable({
Expand All @@ -77,8 +85,8 @@ function phpvms_vacentral_airport_lookup(icao, callback) {
ajaxOptions: {
type: 'post',
headers: {
'x-api-key': '{{ Auth::user()->api_key }}',
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
'x-api-key': api_key,
'X-CSRF-TOKEN': csrf_token
}
},
params: function(params) {
Expand Down
15 changes: 11 additions & 4 deletions resources/views/admin/flights/scripts.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<script>
function setEditable() {
const csrf_token = $('meta[name="csrf-token"]').attr('content');
const api_key = $('meta[name="api-key"]').attr('content');
$('#flight_fares a').editable({
type: 'text',
mode: 'inline',
Expand All @@ -11,8 +15,8 @@ function setEditable() {
ajaxOptions: {
type: 'post',
headers: {
'x-api-key': '{{ Auth::user()->api_key }}',
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
'x-api-key': api_key,
'X-CSRF-TOKEN': csrf_token
}
},
params: function (params) {
Expand All @@ -28,6 +32,9 @@ function setEditable() {
$(document).ready(function () {
const csrf_token = $('meta[name="csrf-token"]').attr('content');
const api_key = $('meta[name="api-key"]').attr('content');
setEditable();
$('#flight_fields_wrapper a.inline').editable({
Expand All @@ -38,8 +45,8 @@ function setEditable() {
ajaxOptions: {
type: 'post',
headers: {
'x-api-key': '{{ Auth::user()->api_key }}',
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
'x-api-key': api_key,
'X-CSRF-TOKEN': csrf_token
}
},
params: function (params) {
Expand Down
9 changes: 5 additions & 4 deletions resources/views/admin/subfleets/script.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
function setEditable() {
const token = $('meta[name="csrf-token"]').attr('content');
const api_key = $('meta[name="api-key"]').attr('content');
$('#aircraft_fares a').editable({
type: 'text',
Expand All @@ -13,7 +14,7 @@ function setEditable() {
ajaxOptions: {
type: 'post',
headers: {
'x-api-key': '{{ Auth::user()->api_key }}',
'x-api-key': api_key,
'X-CSRF-TOKEN': token,
}
},
Expand All @@ -36,7 +37,7 @@ function setEditable() {
ajaxOptions: {
type: 'post',
headers: {
'x-api-key': '{{ Auth::user()->api_key }}',
'x-api-key': api_key,
'X-CSRF-TOKEN': token,
}
},
Expand All @@ -57,7 +58,7 @@ function setEditable() {
ajaxOptions: {
type: 'post',
headers: {
'x-api-key': '{{ Auth::user()->api_key }}',
'x-api-key': api_key,
'X-CSRF-TOKEN': token,
}
},
Expand All @@ -80,7 +81,7 @@ function setEditable() {
ajaxOptions: {
type: 'post',
headers: {
'x-api-key': '{{ Auth::user()->api_key }}',
'x-api-key': api_key,
'X-CSRF-TOKEN': token,
}
},
Expand Down

0 comments on commit 57cddee

Please sign in to comment.