vfs (contd.)

This commit is contained in:
Xuan Sang LE
2018-01-25 19:15:41 +01:00
parent d70cef3e95
commit 15f1fb45eb
8 changed files with 212 additions and 21 deletions

View File

@ -40,11 +40,12 @@ this.OS.GUI.BaseDialog = BaseDialog
}
###
class BasicDialog extends BaseDialog
constructor: ( name, @conf ) ->
constructor: ( name, @conf, @title) ->
super name
init: () ->
html = "<afx-app-window data-id = 'dia-window' apptitle='#{@name}' width='#{@conf.width}' height='#{@conf.height}'>
@title = @name if not @title
html = "<afx-app-window data-id = 'dia-window' apptitle='#{@title}' width='#{@conf.width}' height='#{@conf.height}'>
<afx-hbox>"
html += "<#{@conf.tag} #{@conf.att} data-id = 'content'></#{@conf.tag}>"
html += "<div data-height = '40' style=' text-align:right;padding-top:3px;'>"
@ -70,6 +71,7 @@ class PromptDialog extends BasicDialog
tag: "input",
width: 200,
height: 90,
att: "type = 'text'"
resizable: false,
buttons: [
{
@ -86,7 +88,8 @@ class PromptDialog extends BasicDialog
}
],
filldata: (d) ->
d.scheme.set "apptitle", d.data if d.data
return unless d.data
(d.find "content").value = d.data
}
this.OS.register "PromptDialog", PromptDialog
@ -156,10 +159,38 @@ class InfoDialog extends BasicDialog
rows = []
rows.push [ { value: k }, { value: v } ] for k, v of d.data
(d.find "content").set "rows", rows
d.scheme.set "apptitle", d.data.filename
}
this.OS.register "InfoDialog", InfoDialog
class YesNoDialog extends BasicDialog
constructor: () ->
super "YesNoDialog", {
tag: "afx-label",
width: 300,
height: 100,
att:"style = 'padding:10px;'"
resizable: true,
buttons: [
{
label: "Yes", onclick: (d) ->
d.handler true if d.handler
d.quit()
},
{
label: "No", onclick: (d) ->
d handler false if dhandler
d.quit()
}
],
filldata: (d) ->
return unless d.data
l = d.find "content"
for k, v of d.data
l.set k, v
}
this.OS.register "YesNoDialog", YesNoDialog
class AboutDialog extends BaseDialog
constructor: () ->
super "AboutDialog"

View File

@ -31,7 +31,7 @@ class BaseModel
subscribe: (e, f) ->
_courrier.on e, f, @
openDialog: (d, f, data) ->
openDialog: (d, f, title, data) ->
if @dialog
@dialog.show()
return
@ -43,6 +43,7 @@ class BaseModel
@dialog.handler = f
@dialog.pid = @pid
@dialog.data = data
@dialog.title = title
@dialog.init()
publish: (t, m) ->

View File

@ -23,6 +23,61 @@ self.OS.API =
.fail (e, s) ->
_API.loaded q, p, "FAIL"
f(e, s)
blob: (p, c, f) ->
q = _courrier.getMID()
r = new XMLHttpRequest()
r.open "GET", p, true
r.responseType = "arraybuffer"
r.onload = (e) ->
if @status is 200 and @readyState is 4
c @response
_API.loaded q, p, "OK"
else
f e, @
_API.loaded q, p, "FAIL"
_API.loading q, p
r.send()
upload: (p, d, c, f) ->
q = _courrier.getMID()
#insert a temporal file selector
o = ($ '<input>').attr('type', 'file').css("display", "none")
o.change () ->
_API.loading q, p
formd = new FormData()
formd.append 'path', d
# TODO: only one file is selected at this time
formd.append 'upload', o[0].files[0]
$.ajax {
url: p,
data: formd,
type: 'POST',
contentType: false,
processData: false,
}
.done (data) ->
_API.loaded q, p, "OK"
c(data)
.fail (e, s) ->
_API.loaded q, p, "FAIL"
f(e, s)
o.click()
saveblob: (name, b) ->
url = window.URL.createObjectURL b
o = ($ '<a>')
.attr("href", url)
.attr("download", name)
.css("display", "none")
.appendTo("body")
o[0].click()
window.URL.revokeObjectURL(url)
o.remove()
systemConfig: ->
_API.request 'config', (result) ->
@ -54,7 +109,7 @@ self.OS.API =
resource: (r, c, f) ->
path = "resources/#{r}"
_API.get path, c, f
throwe: (n) ->
err = undefined
try

View File

@ -156,7 +156,6 @@ self.OS.GUI =
username: ($ "#txtuser").val(),
password: ($ "#txtpass").val()
_API.handler.login data, (d) ->
console.log d
if d.error then ($ "#login_error").html d.error else _GUI.startAntOS d.result
, (e, s) ->
alert "System fall: Cannot init login screen"

View File

@ -16,7 +16,27 @@ self.OS.API.handler =
readfile: (p, c) ->
path = "lua-api/fs/get/"
_API.get path + p, c, (e, s) ->
_courrier.osfail "Fail to read file: #{p}",e , s
_courrier.osfail "Fail to read file: #{p}", e, s
move: (s, d, c) ->
path = "lua-api/fs/move"
_API.post path, { src: s, dest: d }, c, (e, s) ->
_courrier.osfail "Fail to move file: #{s} -> #{d}", e, s
delete: (p , c) ->
path = "lua-api/fs/delete"
_API.post path, { path: p }, c, (e, s) ->
_courrier.osfail "Fail to delete: #{p}", e, s
fileblob: (p, c) ->
path = "lua-api/fs/get/"
_API.blob path + p, c, (e, s) ->
_courrier.osfail "Fail to read file: #{p}", e, s
upload: (d, c) ->
path = "lua-api/fs/upload"
_API.upload path, d, c, (e, s) ->
_courrier.osfail "Fail to upload file to: #{d}", e, s
write: (p, d , c) ->
path = "lua-api/fs/write"

View File

@ -64,9 +64,17 @@ class BasicFileHandler
me = @
@onready (() -> me.action "remove", null, f)
upload: (f) ->
me = @
@onready (() -> me.action "upload", null, f)
download: (f) ->
me = @
@onready (() -> me.action "download", null, f)
move: (d, f) ->
me = @
@onready (() -> me action "move", d, f)
@onready (() -> me.action "move", d, f)
execute: (f) ->
me = @
@ -93,6 +101,7 @@ class RemoteFileHandler extends self.OS.API.VFS.BasicFileHandler
_API.handler.fileinfo @path, f
action: (n, p, f) ->
me = @
switch n
when "read"
return _API.handler.scandir @path, f if @meta.type is "dir"
@ -103,6 +112,18 @@ class RemoteFileHandler extends self.OS.API.VFS.BasicFileHandler
_API.handler.mkdir "#{@path}/#{p}", f
when "write"
_API.handler.write @path, p, f
when "upload"
return if @meta.type is "file"
_API.handler.upload @path, f
when "remove"
_API.handler.delete @path, f
when "download"
return if @meta.type is "dir"
_API.handler.fileblob @path, (d) ->
blob = new Blob [d], { type: "octet/stream" }
_API.saveblob me.basename, blob
when "move"
_API.handler.move @path, p, f
else
return _courrier.osfail "VFS unknown action: #{n}", (_API.throwe "OS.VFS"), n