Changed way to connect to api
This commit is contained in:
4
ui/resources/routes/98_api.php
Normal file
4
ui/resources/routes/98_api.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
use ProVM\Common\Controller\Api;
|
||||
|
||||
$app->post('/api', Api::class);
|
@ -1,4 +1,4 @@
|
||||
<?php
|
||||
use ProVM\Common\Controller\Home;
|
||||
|
||||
$app->get('[/]', Home::class);
|
||||
$app->get('[/]', Home::class);
|
||||
|
@ -33,8 +33,8 @@
|
||||
).append(
|
||||
$('<button></button>').addClass('ui mini circular red icon button').append(
|
||||
$('<i></i>').addClass('remove icon')
|
||||
).click(() => {
|
||||
this.unregister()
|
||||
).click(e => {
|
||||
this.unregister($(e.currentTarget))
|
||||
})
|
||||
)
|
||||
} else {
|
||||
@ -42,7 +42,7 @@
|
||||
register.append(
|
||||
$('<button></button>').addClass('ui mini circular icon button').append(
|
||||
$('<i></i>').addClass('save icon')
|
||||
).click((e) => {
|
||||
).click(e => {
|
||||
this.register($(e.currentTarget))
|
||||
})
|
||||
)
|
||||
@ -72,20 +72,25 @@
|
||||
})
|
||||
})
|
||||
}
|
||||
unregister() {
|
||||
unregister(button) {
|
||||
const uri = '/mailboxes/unregister'
|
||||
const data = {
|
||||
mailboxes: [this.id]
|
||||
}
|
||||
button.html('').append(
|
||||
$('<i></i>').addClass('redo loading icon')
|
||||
)
|
||||
return Send.delete({
|
||||
uri,
|
||||
data
|
||||
}).then(response => {
|
||||
response.mailboxes.forEach(mb => {
|
||||
if (mb.id === this.id && mb.removed) {
|
||||
response.unregistered.mailboxes.forEach(mb => {
|
||||
if (mb.id === this.id && mb.unregistered) {
|
||||
this.id = null
|
||||
this.registered = false
|
||||
mailboxes.draw().table()
|
||||
const tr = button.parent().parent()
|
||||
tr.html('')
|
||||
this.draw(tr)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
@ -1,38 +1,33 @@
|
||||
<script type="text/javascript">
|
||||
const Send = {
|
||||
base_url: '{{$urls->api}}',
|
||||
base: function({method, uri, data = null, dataType = 'json', contentType = 'application/json'}) {
|
||||
const url = this.base_url + '/' + uri.replace(/^\//g, '')
|
||||
base: function({method, uri, data = null}) {
|
||||
const request = {
|
||||
uri: uri.replace(/^\//g, ''),
|
||||
method
|
||||
}
|
||||
const options = {
|
||||
method,
|
||||
url,
|
||||
crossDomain: true,
|
||||
headers: {
|
||||
'Authorization': [
|
||||
'Bearer {{$api_key}}'
|
||||
]
|
||||
},
|
||||
dataType
|
||||
url: this.base_url,
|
||||
method: 'post',
|
||||
contentType: 'application/json'
|
||||
}
|
||||
if (method.toLowerCase() !== 'get' && data !== null) {
|
||||
if (!(typeof data === 'string' || data instanceof String)) {
|
||||
options['data'] = JSON.stringify(data)
|
||||
}
|
||||
options['contentType'] = contentType
|
||||
request['data'] = data
|
||||
}
|
||||
options['data'] = JSON.stringify(request)
|
||||
return $.ajax(options)
|
||||
},
|
||||
get: function(uri, dataType = 'json') {
|
||||
return this.base({method: 'get', uri, dataType})
|
||||
get: function(uri) {
|
||||
return this.base({method: 'get', uri})
|
||||
},
|
||||
post: function({uri, data, dataType = 'json', contentType = 'application/json'}) {
|
||||
return this.base({method: 'post', uri, data, dataType, contentType})
|
||||
post: function({uri, data}) {
|
||||
return this.base({method: 'post', uri, data})
|
||||
},
|
||||
put: function({uri, data, dataType = 'json', contentType = 'application/json'}) {
|
||||
return this.base({method: 'put', uri, data, dataType, contentType})
|
||||
put: function({uri, data}) {
|
||||
return this.base({method: 'put', uri, data})
|
||||
},
|
||||
delete: function({uri, data, dataType = 'json', contentType = 'application/json'}) {
|
||||
return this.base({method: 'delete', uri, data, dataType, contentType})
|
||||
delete: function({uri, data}) {
|
||||
return this.base({method: 'delete', uri, data})
|
||||
}
|
||||
}
|
||||
const _urls = JSON.parse('{!! Safe\json_encode($urls) !!}')
|
||||
|
Reference in New Issue
Block a user