From e76d1fb995e25d78f0131ac56660846b0e9ecb9a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 3 Dec 2018 14:21:50 +0300 Subject: [PATCH] plugins: mail, mailto: remove code from global context --- classes/feeds.php | 4 +- js/tt-rss.js | 8 ++-- plugins/mail/init.php | 2 +- plugins/mail/mail.js | 86 +++++++++++++++++++++-------------------- plugins/mailto/init.js | 49 +++++++++++++---------- plugins/mailto/init.php | 2 +- 6 files changed, 80 insertions(+), 71 deletions(-) diff --git a/classes/feeds.php b/classes/feeds.php index 58d4f68d9..9fe528723 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -124,12 +124,12 @@ class Feeds extends Handler_Protected { } if (PluginHost::getInstance()->get_plugin("mail")) { - $reply .= ""; } if (PluginHost::getInstance()->get_plugin("mailto")) { - $reply .= ""; } diff --git a/js/tt-rss.js b/js/tt-rss.js index 8931e9860..fc87ae24d 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -302,12 +302,10 @@ require(["dojo/_base/kernel", } }; this.hotkey_actions["email_article"] = function () { - if (typeof emailArticle != "undefined") { - emailArticle(); - } else if (typeof mailtoArticle != "undefined") { - mailtoArticle(); + if (typeof Plugins.Mail != "undefined") { + Plugins.Mail.onHotkey(Headlines.getSelected()); } else { - alert(__("Please enable mail plugin first.")); + alert(__("Please enable mail or mailto plugin first.")); } }; this.hotkey_actions["select_all"] = function () { diff --git a/plugins/mail/init.php b/plugins/mail/init.php index d8f92853e..1609a05c3 100644 --- a/plugins/mail/init.php +++ b/plugins/mail/init.php @@ -72,7 +72,7 @@ class Mail extends Plugin { function hook_article_button($line) { return "Zoom"; } diff --git a/plugins/mail/mail.js b/plugins/mail/mail.js index 87e354b42..eb7b7e6b6 100644 --- a/plugins/mail/mail.js +++ b/plugins/mail/mail.js @@ -1,52 +1,56 @@ -function emailArticle(id) { - if (!id) { - let ids = Headlines.getSelected(); +Plugins.Mail = { + send: function(id) { + if (!id) { + let ids = Headlines.getSelected(); - if (ids.length == 0) { - alert(__("No articles selected.")); - return; + if (ids.length == 0) { + alert(__("No articles selected.")); + return; + } + + id = ids.toString(); } - id = ids.toString(); - } + if (dijit.byId("emailArticleDlg")) + dijit.byId("emailArticleDlg").destroyRecursive(); - if (dijit.byId("emailArticleDlg")) - dijit.byId("emailArticleDlg").destroyRecursive(); + const query = "backend.php?op=pluginhandler&plugin=mail&method=emailArticle¶m=" + encodeURIComponent(id); - const query = "backend.php?op=pluginhandler&plugin=mail&method=emailArticle¶m=" + encodeURIComponent(id); + const dialog = new dijit.Dialog({ + id: "emailArticleDlg", + title: __("Forward article by email"), + style: "width: 600px", + execute: function () { + if (this.validate()) { + xhrJson("backend.php", this.attr('value'), (reply) => { + if (reply) { + const error = reply['error']; - const dialog = new dijit.Dialog({ - id: "emailArticleDlg", - title: __("Forward article by email"), - style: "width: 600px", - execute: function() { - if (this.validate()) { - xhrJson("backend.php", this.attr('value'), (reply) => { - if (reply) { - const error = reply['error']; + if (error) { + alert(__('Error sending email:') + ' ' + error); + } else { + Notify.info('Your message has been sent.'); + dialog.hide(); + } - if (error) { - alert(__('Error sending email:') + ' ' + error); - } else { - Notify.info('Your message has been sent.'); - dialog.hide(); } + }); + } + }, + href: query + }); - } - }); - } - }, - href: query}); - - /* var tmph = dojo.connect(dialog, 'onLoad', function() { - dojo.disconnect(tmph); - - new Ajax.Autocompleter('emailArticleDlg_destination', 'emailArticleDlg_dst_choices', - "backend.php?op=pluginhandler&plugin=mail&method=completeEmails", - { tokens: '', paramName: "search" }); - }); */ - - dialog.show(); -} + /* var tmph = dojo.connect(dialog, 'onLoad', function() { + dojo.disconnect(tmph); + new Ajax.Autocompleter('emailArticleDlg_destination', 'emailArticleDlg_dst_choices', + "backend.php?op=pluginhandler&plugin=mail&method=completeEmails", + { tokens: '', paramName: "search" }); + }); */ + dialog.show(); + }, + onHotkey: function(id) { + Plugins.Mail.send(id); + } +}; diff --git a/plugins/mailto/init.js b/plugins/mailto/init.js index 92a90f8e9..f81f70fc7 100644 --- a/plugins/mailto/init.js +++ b/plugins/mailto/init.js @@ -1,27 +1,34 @@ -function mailtoArticle(id) { - if (!id) { - const ids = Headlines.getSelected(); +Plugins.Mailto = { + send: function (id) { + if (!id) { + const ids = Headlines.getSelected(); - if (ids.length == 0) { - alert(__("No articles selected.")); - return; + if (ids.length == 0) { + alert(__("No articles selected.")); + return; + } + + id = ids.toString(); } - id = ids.toString(); + if (dijit.byId("emailArticleDlg")) + dijit.byId("emailArticleDlg").destroyRecursive(); + + const query = "backend.php?op=pluginhandler&plugin=mailto&method=emailArticle¶m=" + encodeURIComponent(id); + + const dialog = new dijit.Dialog({ + id: "emailArticleDlg", + title: __("Forward article by email"), + style: "width: 600px", + href: query}); + + dialog.show(); } +}; - if (dijit.byId("emailArticleDlg")) - dijit.byId("emailArticleDlg").destroyRecursive(); - - const query = "backend.php?op=pluginhandler&plugin=mailto&method=emailArticle¶m=" + encodeURIComponent(id); - - const dialog = new dijit.Dialog({ - id: "emailArticleDlg", - title: __("Forward article by email"), - style: "width: 600px", - href: query}); - - dialog.show(); -} - +// override default hotkey action if enabled +Plugins.Mail = Plugins.Mail || {}; +Plugins.Mail.onHotkey = function(id) { + Plugins.Mailto.send(id); +}; \ No newline at end of file diff --git a/plugins/mailto/init.php b/plugins/mailto/init.php index 60c58b707..3dbc8d643 100644 --- a/plugins/mailto/init.php +++ b/plugins/mailto/init.php @@ -21,7 +21,7 @@ class MailTo extends Plugin { function hook_article_button($line) { return "Zoom"; }