antosdk-apps/Blogger/dialogs.coffee

190 lines
7.2 KiB
CoffeeScript
Raw Normal View History

# 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/.
class BloggerCategoryDialog extends this.OS.GUI.BasicDialog
constructor: () ->
2020-06-05 17:45:07 +02:00
super "BloggerCategoryDialog", BloggerCategoryDialog.scheme
2020-05-23 20:09:01 +02:00
main: () ->
super.main()
@tree = @find "tree"
@txtinput = @find "txtinput"
2020-06-05 17:45:07 +02:00
(@find "bt-ok").onbtclick = (e) =>
sel = @tree.selectedItem
2020-05-23 20:09:01 +02:00
return @notify __("Please select a parent category") unless sel
2020-06-05 17:45:07 +02:00
seldata = sel.data
2020-05-23 20:09:01 +02:00
val = @txtinput.value
return @notify __("Please enter category name") if val is "" and not @data.selonly
return @notify __("Parent can not be the category itself") if @data.cat and @data.cat.id is seldata.id
@handle { p: seldata, value: val } if @handle
@quit()
2020-06-05 17:45:07 +02:00
(@find "bt-cancel").onbtclick = (e) =>
2020-05-23 20:09:01 +02:00
@quit()
if @data and @data.tree
if @data and @data.cat
@txtinput.value = @data.cat.name
if @data.cat.pid is "0"
seldata = @data.tree
else
seldata = @findDataByID @data.cat.pid, @data.tree.nodes
seldata.selected = true if seldata
2020-06-05 17:45:07 +02:00
@tree.data = @data.tree
2020-05-23 20:09:01 +02:00
@tree.expandAll()
# TODO set selected category name
findDataByID: (id, list) ->
for data in list
return data if data.id is id
if data.nodes
@findDataByID id, data.nodes
return undefined
BloggerCategoryDialog.scheme = """
<afx-app-window width='300' height='400'>
<afx-vbox>
<afx-label text="__(Pick a parent)" data-height="25" class="lbl-header" ></afx-label>
<afx-tree-view data-id="tree" ></afx-tree-view>
<afx-label text="__(Category name)" data-height="25" class="lbl-header" ></afx-label>
<input type="text" data-height="25" data-id = "txtinput"/ >
2020-06-05 17:45:07 +02:00
<afx-hbox data-height = '30'>
<div style=' text-align:right;'>
<afx-button data-id = "bt-ok" text = "__(Ok)"></afx-button>
<afx-button data-id = "bt-cancel" text = "__(Cancel)"></afx-button>
</div>
<div data-width="5"></div>
</afx-hbox>
2020-05-23 20:09:01 +02:00
</afx-vbox>
</afx-app-window>
"""
# This dialog is use for cv section editing
2020-05-23 20:09:01 +02:00
class BloggerCVSectionDiaglog extends this.OS.GUI.BasicDialog
constructor: (parent) ->
file = "#{parent.meta().path}/cvsection.html".asFileHandle()
super "BloggerCVSectionDiaglog", file
main: () ->
2020-05-23 20:09:01 +02:00
super.main()
@editor = new SimpleMDE
2020-05-23 20:19:50 +02:00
autoDownloadFontAwesome: false
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"
2020-05-23 20:09:01 +02:00
inputs = @select "[input-class='user-input']"
(($ v).val @data.section[v.name] for v in inputs ) if @data and @data.section
@editor.value @data.section.content if @data and @data.section
2020-06-05 17:45:07 +02:00
(@find "section-publish").swon = (if @data and @data.section and Number(@data.section.publish) then true else false)
(@find "bt-cv-sec-save").onbtclick = (e) =>
data = {}
data[v.name] = ($ v).val() for v in inputs
2020-05-23 20:09:01 +02:00
data.content = @editor.value()
return @notify __("Title or content must not be blank") if data.title is "" and data.content is ""
#return @notify "Content must not be blank" if data.content is ""
data.id = @data.section.id if @data and @data.section
2020-06-05 17:45:07 +02:00
val = (@find "section-publish").swon
2020-05-23 20:09:01 +02:00
if val is true
data.publish = 1
else
data.publish = 0
2020-05-23 20:09:01 +02:00
@handle data if @handle
@quit()
2020-05-23 20:09:01 +02:00
@on "vboxchange", () => @resizeContent()
@resizeContent()
resizeContent: () ->
container = @find "editor-container"
children = ($ container).children()
cheight = ($ container).height() - 30
($ children[1]).css("height", cheight + "px")
2020-05-23 20:09:01 +02:00
# this dialog is for send mail
2020-05-23 20:09:01 +02:00
class BloggerSendmailDiaglog extends this.OS.GUI.BasicDialog
constructor: (parent) ->
file = "#{parent.meta().path}/sendmail.html".asFileHandle()
super "BloggerSendmailDiaglog", file
main: () ->
2020-05-23 20:09:01 +02:00
super.main()
@subdb = new @.parent._api.DB("subscribers")
@maillinglist = @find "email-list"
title = (new RegExp "^#+(.*)\n", "g").exec @data.content
(@find "mail-title").value = title[1]
content = (@data.content.substring 0, 500) + "..."
2020-05-23 20:09:01 +02:00
(@find "contentarea").value = BloggerSendmailDiaglog.template.format @data.id, content
@subdb.find {}
.then (d) =>
for v in d
v.text = v.name
v.switch = true
v.checked = true
2020-06-05 17:45:07 +02:00
@maillinglist. items = d
2020-05-23 20:09:01 +02:00
.catch (e) =>
@error __("Cannot fetch subscribers data: {0}", e.toString()), e
2020-06-05 17:45:07 +02:00
(@find "bt-sendmail").onbtclick = (e) =>
items = @maillinglist.items
emails = []
2020-05-23 20:09:01 +02:00
for v in items
if v.checked is true
console.log v.email
emails.push v.email
return @notify __("No email selected") if emails.length is 0
# send the email
data =
2020-05-23 20:09:01 +02:00
path: "#{@parent.path()}/sendmail.lua",
parameters:
to: emails,
2020-05-23 20:09:01 +02:00
title: (@find "mail-title").value,
content: (@find "contentarea").value
@_api.apigateway data, false
.then (d) =>
return @notify __("Unable to send mail to: {0}", d.result.join(", ")) if d.error
@quit()
.catch (e) =>
console.log e
@error __("Error sending mail: {0}", e.toString()), e
BloggerSendmailDiaglog.template = """
Hello,
Xuan Sang LE has just published a new post on his blog: https://blog.lxsang.me/post/id/{0}
==========
{1}
==========
Read the full article via:
2020-05-23 20:09:01 +02:00
https://blog.lxsang.me/post/id/{0}
You receive this email because you have been subscribed to his blog.
Have a nice day,
Sent from Blogger, an AntOS application
"""