antos-frontend/src/core/api.coffee

58 lines
1.7 KiB
CoffeeScript
Raw Normal View History

2017-08-26 16:50:13 +02:00
self.OS.API =
2017-08-07 00:49:24 +02:00
# the handler object could be a any remote or local handle to
# fetch user data, used by the API to make requests
# handlers are defined in /src/handlers
2017-08-26 16:50:13 +02:00
handler: {}
VFS:
scandir: (p, c, f) ->
_API.handler.request "scandir", { path: p }, c, f
2017-08-07 00:49:24 +02:00
#request a user data
2017-08-26 16:50:13 +02:00
post: (p, d, c, f) ->
q = _courrier.getMID()
_API.loading q, p
$.ajax {
type: "POST",
url: p,
data: d,
success: null,
dataType: 'json'
}
.done (data) ->
_API.loaded q, p, "OK"
c(data)
.fail (e, s) ->
_API.loaded q, p, "FAIL"
f(e, s)
2017-08-07 00:49:24 +02:00
systemConfig: ->
_API.request 'config', (result) ->
console.log result
2017-08-26 16:50:13 +02:00
loading: (q, p) ->
_courrier.trigger "loading", { id: q, data: { m: "#{p}", s: true }, name: "OS" }
loaded: (q, p, m ) ->
_courrier.trigger "loaded", { id: q, data: { m: "#{m}: #{p}", s: false }, name: "OS" }
get: (p, c, f) ->
2017-08-26 16:50:13 +02:00
q = _courrier.getMID()
_API.loading q, p
$.get p
2017-08-26 16:50:13 +02:00
.done (data) ->
_API.loaded q, p, "OK"
c(data)
.fail (e, s) ->
_API.loaded q, p, "FAIL"
f(e, s)
script: (p, c, f) ->
q = _courrier.getMID()
_API.loading q, p
$.getScript p
.done (data) ->
_API.loaded q, p, "OK"
c(data)
.fail (e, s) ->
_API.loaded q, p, "FAIL"
f(e, s)
resource: (resource, callback) ->
2017-08-11 01:58:46 +02:00
path = "resources/#{resource}"
_API.get path, callback
2017-08-11 01:58:46 +02:00