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

106 lines
4.5 KiB
CoffeeScript
Raw Normal View History

2018-03-15 11:00:24 +01:00
# Copyright 2017-2018 Xuan Sang LE <xsang.le AT gmail DOT com>
# AnTOS Web desktop is is licensed under the GNU General Public
# License v3.0, see the LICENCE file for more information
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
# You should have received a copy of the GNU General Public License
#along with this program. If not, see https://www.gnu.org/licenses/.
2018-02-13 04:59:08 +01:00
class BloggerCategoryDialog extends this.OS.GUI.BasicDialog
constructor: () ->
super "BloggerCategoryDialog", {
tags: [
{ tag: "afx-label", att: "data-height = '20', text = 'Pick a parent'" },
2018-02-13 04:59:08 +01:00
{ tag: "afx-tree-view" },
{ tag: "afx-label", att: "data-height = '20', text = 'Category name'" },
2018-02-13 04:59:08 +01:00
{ tag: "input", att: "type = 'text' data-height = '20'" }
],
width: 200,
height: 300,
resizable: true,
buttons: [
{
label: "0k",
onclick: (d) ->
sel = (d.find "content1").get "selectedItem"
return d.notify __("Please select a parent category") unless sel
2018-02-13 04:59:08 +01:00
val = (d.find "content3").value
return d.notify __("Please enter category name") if val is "" and not d.data.selonly
return d.notify __("Parent can not be the category itself") if d.data.cat and d.data.cat.id is sel.id
2018-02-13 04:59:08 +01:00
d.handler { p: sel, value: val } if d.handler
d.quit()
},
{
label: "Cancel",
onclick: (d) -> d.quit()
}
],
filldata: (d) ->
return unless d.data
#console.log d.data
tree = d.find "content1"
tree.set "data", d.data.tree if d.data.tree
if d.data.cat
it = (tree.find "id", d.data.cat.pid)[0]
tree.set "selectedItem", it
(d.find "content3").value = d.data.cat.name
#(d.find "content0").set "text", d.data.label
#(d.find "content1").value = d.data.value if d.data.value
xtra: (d) ->
$( d.find "content3" ).keyup (e) ->
(d.find "bt0").trigger() if e.which is 13
}
2018-02-16 18:38:14 +01:00
this.OS.register "BloggerCategoryDialog", BloggerCategoryDialog
# This dialog is use for cv section editing
class BloggerCVSectionDiaglog extends this.OS.GUI.BaseDialog
constructor: () ->
super "BloggerCVSectionDiaglog"
init: () ->
@render "#{@path()}/cvsection.html"
main: () ->
me = @
@scheme.set "apptitle", @title
2018-02-21 00:20:54 +01:00
@editor = new SimpleMDE
element: @find "contentarea"
status: false
toolbar: false
($ (@select '[class = "CodeMirror-scroll"]')[0]).css "min-height", "50px"
($ (@select '[class="CodeMirror cm-s-paper CodeMirror-wrap"]')[0]).css "min-height", "50px"
@on "vboxchange", () ->
me.resizeContent()
2018-02-16 18:38:14 +01:00
inputs = me.select "[input-class='user-input']"
(($ v).val me.data[v.name] for v in inputs ) if me.data
2018-02-21 00:20:54 +01:00
@editor.value me.data.content if me.data and me.data.content
2018-02-16 18:38:14 +01:00
(@find "bt-cv-sec-save").set "onbtclick", (e) ->
data = {}
console.log inputs
data[v.name] = ($ v).val() for v in inputs
2018-02-21 00:20:54 +01:00
data.content = me.editor.value()
return me.notify __("Title or content must not be blank") if data.title is "" and data.content is ""
2018-02-21 11:55:15 +01:00
#return me.notify "Content must not be blank" if data.content is ""
2018-02-16 18:38:14 +01:00
data.id = me.data.id if me.data and me.data.id
me.handler data if me.handler
me.quit()
2018-02-21 00:20:54 +01:00
me.resizeContent()
resizeContent: () ->
container = @find "editor-container"
children = ($ container).children()
cheight = ($ container).height() - 30
($ children[1]).css("height", cheight + "px")
2018-02-16 18:38:14 +01:00
this.OS.register "BloggerCVSectionDiaglog", BloggerCVSectionDiaglog