antos-frontend/src/packages/Blogger/main.coffee

55 lines
1.8 KiB
CoffeeScript
Raw Normal View History

2018-02-05 19:05:41 +01:00
class Blogger extends this.OS.GUI.BaseApplication
constructor: (args) ->
super "Blogger", args
main: () ->
me = @
@tabbar = @find "tabbar"
@containers = [
@find("user-container"),
@find("cv-container"),
@find("blog-container")
]
2018-02-11 00:39:08 +01:00
@user = {}
2018-02-05 19:05:41 +01:00
@cvlist = @find "cv-list"
@bloglist = @find "blog-list"
@tabbar.set "onlistselect", (e) ->
($ el).hide() for el in me.containers
2018-02-11 00:39:08 +01:00
me.fetchData e.idx
2018-02-05 19:05:41 +01:00
($ me.containers[e.idx]).show()
@tabbar.set "items", [
{ iconclass: "fa fa-user-circle", selected: true },
{ iconclass: "fa fa-info-circle" },
{ iconclass: "fa fa-book" }
]
(@find "bt-user-save").set "onbtclick", (e) ->
me.saveUser()
2018-02-11 00:39:08 +01:00
fetchData: (idx) ->
me = @
switch idx
when 0 #user info
db = new @_api.DB("user")
db.get null, (d) ->
return me.error "Cannot fetch user data" if d.error
me.user = d.result[0]
inputs = me.select "[imput-class='user-input']"
($ v).val me.user[v.name] for v in inputs
else
console.log "Not implemented yet"
2018-02-05 19:05:41 +01:00
saveUser:() ->
me = @
inputs = @select "[imput-class='user-input']"
2018-02-11 00:39:08 +01:00
@user[v.name] = ($ v).val() for v in inputs
return @notify "Full name must be entered" if not @user.fullname or @user.fullname is ""
2018-02-05 19:05:41 +01:00
db = new @_api.DB("user")
2018-02-11 00:39:08 +01:00
console.log @user
db.save @user, (r) ->
2018-02-05 19:05:41 +01:00
return me.error "Cannot save user data" if r.error
return me.notify "User data updated"
Blogger.singleton = true
this.OS.register "Blogger", Blogger