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

121 lines
4.2 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"
2018-02-13 04:59:08 +01:00
@cvlist.set "ontreeselect", (d) ->
#console.log d
2018-02-05 19:05:41 +01:00
@bloglist = @find "blog-list"
2018-02-13 04:59:08 +01:00
@userdb = new @_api.DB("user")
@cvcatdb = new @_api.DB("cv_cat")
2018-02-05 19:05:41 +01:00
@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()
2018-02-13 04:59:08 +01:00
me.trigger "calibrate"
2018-02-05 19:05:41 +01:00
@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
2018-02-13 04:59:08 +01:00
(@find "cv-cat-add").set "onbtclick", (e) ->
me.openDialog "BloggerCategoryDialog",
(d) ->
c =
name: d.value,
pid: d.p.id,
publish: 1
me.cvcatdb.save c, (r) ->
me.error "Cannot add new category" if r.error
me.refreshCVCat()
#update the list
, "Add category", { tree: me.cvlist.get "data" }
(@find "cv-cat-edit").set "onbtclick", (e) ->
cat = me.cvlist.get "selectedItem"
return unless cat
me.openDialog "BloggerCategoryDialog", (d) ->
c =
id: cat.id,
publish: cat.publish,
pid: d.p.id,
name: d.value
me.cvcatdb.save c, (r) ->
me.error "Cannot Edit category" if r.error
me.refreshCVCat()
, "Edit category", { tree: (me.cvlist.get "data"), cat: cat }
(@find "cv-cat-del").set "onbtclick", (e) ->
cat = me.cvlist.get "selectedItem"
return unless cat
me.openDialog "YesNoDialog",
(d) ->
return unless d
console.log "delete all child + theirs content"
, "Delete cagegory" ,
{ iconclass: "fa fa-question-circle", text: "Do you really want to delete: #{cat.name} ?" }
2018-02-11 00:39:08 +01:00
fetchData: (idx) ->
me = @
switch idx
when 0 #user info
2018-02-13 04:59:08 +01:00
@userdb.get null, (d) ->
2018-02-11 00:39:08 +01:00
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
2018-02-13 04:59:08 +01:00
when 1 # category
@refreshCVCat()
2018-02-11 00:39:08 +01:00
else
console.log "Not implemented yet"
2018-02-13 04:59:08 +01:00
refreshCVCat: () ->
me = @
data =
name: "Porfolio",
id:0,
nodes: []
@cvcatdb.get null, (d) ->
return me.notify "Cannot fetch CV categories" if d.error
me.fetchCVCat d.result, data, "0"
me.cvlist.set "data", data
it = (me.cvlist.find "pid", "2")[0]
me.cvlist.set "selectedItem", it
fetchCVCat: (table, data, id) ->
result = (v for v in table when v.pid is id)
return data.nodes = null if result.length is 0
for v in result
v.nodes = []
@fetchCVCat table, v, v.id
#v.nodes = null if v.nodes.length is 0
data.nodes.push v
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-13 04:59:08 +01:00
#console.log @user
@userdb.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