// Copyright 2017-2018 Xuan Sang LE // 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/. namespace OS { export namespace application { export namespace blogger { declare var EasyMDE; export class BloggerCategoryDialog extends OS.GUI.BasicDialog { private tree: OS.GUI.tag.TreeViewTag; private txtinput: HTMLInputElement; constructor() { super("BloggerCategoryDialog", BloggerCategoryDialog.scheme); } main() { super.main(); this.tree = this.find("tree") as OS.GUI.tag.TreeViewTag; this.txtinput = this.find("txtinput") as HTMLInputElement; (this.find("bt-ok") as OS.GUI.tag.ButtonTag).onbtclick = (e: any) => { const sel = this.tree.selectedItem; if (!sel) { return this.notify(__("Please select a parent category")); } const seldata = sel.data; const val = this.txtinput.value; if ((val === "") && !this.data.selonly) { return this.notify(__("Please enter category name")); } if (this.data.cat && (this.data.cat.id === seldata.id)) { return this.notify(__("Parent can not be the category itself")); } if (this.handle) { this.handle({ p: seldata, value: val }); } return this.quit(); }; (this.find("bt-cancel") as OS.GUI.tag.ButtonTag).onbtclick = (e: any) => { return this.quit(); }; if (this.data && this.data.tree) { if (this.data && this.data.cat) { let seldata: GenericObject; this.txtinput.value = this.data.cat.name; if (this.data.cat.pid === "0") { seldata = this.data.tree; } else { seldata = this.findDataByID(this.data.cat.pid, this.data.tree.nodes); } if (seldata) { seldata.selected = true; } } this.tree.data = this.data.tree; return this.tree.expandAll(); } } // TODO set selected category name findDataByID(id: number, list: GenericObject[]) { for (let data of list) { if (data.id === id) { return data; } if (data.nodes) { this.findDataByID(id, data.nodes); } } return undefined; } } BloggerCategoryDialog.scheme = `\
\ `; // This dialog is use for cv section editing export class BloggerCVSectionDiaglog extends OS.GUI.BasicDialog { private editor: GenericObject; constructor() { super("BloggerCVSectionDiaglog"); } main() { super.main(); this.editor = new EasyMDE({ autoDownloadFontAwesome: false, element: this.find("contentarea"), status: false, toolbar: false }); ($((this.select('[class = "CodeMirror-scroll"]'))[0])).css("min-height", "50px"); ($((this.select('[class="CodeMirror cm-s-paper CodeMirror-wrap"]'))[0])).css("min-height", "50px"); const inputs = this.select("[input-class='user-input']"); if (this.data && this.data.section) { for (let v of inputs) { ($(v)).val(this.data.section[(v as HTMLInputElement).name]); } } if (this.data && this.data.section) { this.editor.value(this.data.section.content); } (this.find("section-publish") as OS.GUI.tag.SwitchTag).swon = (this.data && this.data.section && Number(this.data.section.publish) ? true : false); (this.find("bt-cv-sec-save") as OS.GUI.tag.ButtonTag).onbtclick = (e: any) => { const data: GenericObject = {}; for (let v of inputs) { data[(v as HTMLInputElement).name] = ($(v)).val(); } data.content = this.editor.value(); if ((data.title === "") && (data.content === "")) { return this.notify(__("Title or content must not be blank")); } //return @notify "Content must not be blank" if data.content is "" if (this.data && this.data.section) { data.id = this.data.section.id; } const val = (this.find("section-publish") as OS.GUI.tag.SwitchTag).swon; if (val === true) { data.publish = 1; } else { data.publish = 0; } if (this.handle) { this.handle(data); } return this.quit(); }; this.on("resize", () => this.resizeContent()); return this.resizeContent(); } resizeContent() { const container = this.find("editor-container"); const children = ($(".EasyMDEContainer", container)).children(); const cheight = ($(container)).height() - 30; return ($(children[0])).css("height", cheight + "px"); } } BloggerCVSectionDiaglog.scheme = `\
`; // this dialog is for send mail export class BloggerSendmailDiaglog extends OS.GUI.BasicDialog { static template: string; private maillinglist: OS.GUI.tag.StackMenuTag; // TODO: convert to SQLite handle private subdb: API.VFS.BaseFileHandle; constructor() { super("BloggerSendmailDiaglog"); } main() { super.main(); this.maillinglist = this.find("email-list") as OS.GUI.tag.StackMenuTag; const title = (new RegExp("^#+(.*)\n", "g")).exec(this.data.content); (this.find("mail-title") as HTMLInputElement).value = title[1]; const content = (this.data.content.substring(0, 500)) + "..."; (this.find("contentarea") as HTMLTextAreaElement).value = BloggerSendmailDiaglog.template.format(this.data.id, content); const mlist = this.data.mails.map((el)=> { return { text: el.name, email: el.email, switch: true, checked: true } }); console.log(mlist); this.maillinglist.items = mlist; return (this.find("bt-sendmail") as OS.GUI.tag.ButtonTag).onbtclick = (e: any) => { const items = this.maillinglist.items; const emails = []; for (let v of items) { if (v.checked === true) { emails.push(v); } } if (emails.length === 0) { return this.notify(__("No email selected")); } // send the email const data = { path: `${this.meta().path}/sendmail.lua`, parameters: { to: emails, title: (this.find("mail-title") as HTMLInputElement).value, content: (this.find("contentarea") as HTMLTextAreaElement).value, user: (this.find("mail-user") as HTMLInputElement).value, password: (this.find("mail-password") as HTMLInputElement).value, } }; return this._api.apigateway(data, false) .then((d: { error: any; result: { join: (arg0: string) => any; }; }) => { if (d.error) { const str = d.result.join(','); return this.notify(__("Unable to send mail to: {0}", str)); } return this.quit(); }).catch((e) => { return this.error(__("Error sending mail: {0}", e.toString()), e); }); }; } } BloggerSendmailDiaglog.scheme = `\
`; BloggerSendmailDiaglog.template = `\ Hello, Dany LE has just published a new post on his blog: https://blog.iohub.dev/post/id/{0} ========== {1} ========== Read the full article via: https://blog.iohub.dev/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\ `; } } }