From 101e698a86a5cf4349e9c5e1931330654139ff14 Mon Sep 17 00:00:00 2001 From: JackDandy Date: Sun, 17 Jan 2016 18:50:26 +0000 Subject: [PATCH] Change refactor email notifier. --- CHANGES.md | 1 + gui/slick/css/dark.css | 6 +- gui/slick/css/light.css | 2 + .../default/config_notifications.tmpl | 110 ++--- gui/slick/js/configNotifications.js | 405 ++++++++++-------- sickbeard/__init__.py | 6 +- sickbeard/notifiers/emailnotify.py | 239 +++++------ sickbeard/webserve.py | 106 +++-- 8 files changed, 460 insertions(+), 415 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 2953b7d1..52e8fafc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -19,6 +19,7 @@ * Update Requests library 2.7.0 (5d6d1bc) to 2.9.1 (a1c9b84) * Update SimpleJSON library 3.8.0 (a37a9bd) to 3.8.1 (6022794) * Update Six compatibility library 1.9.0 (r400) to 1.10.0 (r405) +* Change refactor email notifier ### 0.11.3 (2016-01-16 20:00:00 UTC) diff --git a/gui/slick/css/dark.css b/gui/slick/css/dark.css index 49977547..5b898c67 100644 --- a/gui/slick/css/dark.css +++ b/gui/slick/css/dark.css @@ -1177,14 +1177,16 @@ pre{ /* ======================================================================= input sizing (for config pages) ========================================================================== */ - + +.showlist-select optgroup, #pickShow optgroup, #showfilter optgroup, #editAProvider optgroup{ color:#eee; background-color:rgb(51, 51, 51) } - + +.showlist-select optgroup option, #pickShow optgroup option, #showfilter optgroup option, #editAProvider optgroup option{ diff --git a/gui/slick/css/light.css b/gui/slick/css/light.css index eb79039e..f5f2cd23 100644 --- a/gui/slick/css/light.css +++ b/gui/slick/css/light.css @@ -1142,6 +1142,7 @@ pre{ input sizing (for config pages) ========================================================================== */ +.showlist-select optgroup, #pickShow optgroup, #showfilter optgroup, #editAProvider optgroup{ @@ -1149,6 +1150,7 @@ input sizing (for config pages) background-color:#888 } +.showlist-select optgroup option, #pickShow optgroup option, #showfilter optgroup option, #editAProvider optgroup option{ diff --git a/gui/slick/interfaces/default/config_notifications.tmpl b/gui/slick/interfaces/default/config_notifications.tmpl index 242fd89e..1de8e626 100644 --- a/gui/slick/interfaces/default/config_notifications.tmpl +++ b/gui/slick/interfaces/default/config_notifications.tmpl @@ -1637,7 +1637,7 @@

Email

-

Allows configuration of email notifications on a per show basis.

+

Email notification settings.

@@ -1678,95 +1678,71 @@
-
- - -
-
- - -
- -
-
+
+ SMTP server hostname + + + and port + +
+ +
-
- - -
-
- - -
-
-
Click below to test.
- - + +
diff --git a/gui/slick/js/configNotifications.js b/gui/slick/js/configNotifications.js index 9bfde006..d616e3c3 100644 --- a/gui/slick/js/configNotifications.js +++ b/gui/slick/js/configNotifications.js @@ -75,6 +75,16 @@ }); }); + // show instructions for plex when enabled + $('#use_plex').click(function() { + if ( $(this).is(':checked') ) { + $('.plexinfo').removeClass('hide'); + } else { + $('.plexinfo').addClass('hide'); + } + }); + if ($('input[id="use_plex"]').is(':checked')) {$('.plexinfo').removeClass('hide')} + $('#testPMC').click(function () { var plex_host = $.trim($('#plex_host').val()); var plex_username = $.trim($('#plex_username').val()); @@ -224,30 +234,6 @@ $.get(sbRoot + '/home/testLibnotify', function (data) { $('#testLibnotify-result').html(data); }); }); - - $('#twitterStep1').click(function() { - $('#testTwitter-result').html(loading); - $.get(sbRoot + '/home/twitterStep1', function (data) {window.open(data); }) - .done(function () { $('#testTwitter-result').html('Step1: Confirm Authorization'); }); - }); - - $('#twitterStep2').click(function () { - var twitter_key = $.trim($('#twitter_key').val()); - if (!twitter_key) { - $('#testTwitter-result').html('Please fill out the necessary fields above.'); - $('#twitter_key').addClass('warning'); - return; - } - $('#twitter_key').removeClass('warning'); - $('#testTwitter-result').html(loading); - $.get(sbRoot + '/home/twitterStep2', {'key': twitter_key}, - function (data) { $('#testTwitter-result').html(data); }); - }); - - $('#testTwitter').click(function() { - $.get(sbRoot + '/home/testTwitter', - function (data) { $('#testTwitter-result').html(data); }); - }); $('#settingsNMJ').click(function() { if (!$('#nmj_host').val()) { @@ -352,6 +338,139 @@ }); }); + $('#testNMA').click(function () { + var nma_api = $.trim($('#nma_api').val()); + var nma_priority = $('#nma_priority').val(); + if (!nma_api) { + $('#testNMA-result').html('Please fill out the necessary fields above.'); + $('#nma_api').addClass('warning'); + return; + } + $('#nma_api').removeClass('warning'); + $(this).prop('disabled', true); + $('#testNMA-result').html(loading); + $.get(sbRoot + '/home/testNMA', {'nma_api': nma_api, 'nma_priority': nma_priority}) + .done(function (data) { + $('#testNMA-result').html(data); + $('#testNMA').prop('disabled', false); + }); + }); + + $('#testPushalot').click(function () { + var pushalot_authorizationtoken = $.trim($('#pushalot_authorizationtoken').val()); + if (!pushalot_authorizationtoken) { + $('#testPushalot-result').html('Please fill out the necessary fields above.'); + $('#pushalot_authorizationtoken').addClass('warning'); + return; + } + $('#pushalot_authorizationtoken').removeClass('warning'); + $(this).prop('disabled', true); + $('#testPushalot-result').html(loading); + $.get(sbRoot + '/home/testPushalot', {'authorizationToken': pushalot_authorizationtoken}) + .done(function (data) { + $('#testPushalot-result').html(data); + $('#testPushalot').prop('disabled', false); + }); + }); + + $('#testPushbullet').click(function () { + var pushbullet_access_token = $.trim($('#pushbullet_access_token').val()); + var pushbullet_device_iden = $('#pushbullet_device_iden').val(); + if (!pushbullet_access_token) { + $('#testPushbullet-result').html('Please fill out the necessary fields above.'); + $('#pushbullet_access_token').addClass('warning'); + return; + } + $('#pushbullet_access_token').removeClass('warning'); + $(this).prop('disabled', true); + $('#testPushbullet-result').html(loading); + $.get(sbRoot + '/home/testPushbullet', {'accessToken': pushbullet_access_token, 'device_iden': pushbullet_device_iden}) + .done(function (data) { + $('#testPushbullet-result').html(data); + $('#testPushbullet').prop('disabled', false); + }); + }); + + function get_pushbullet_devices (msg) { + var pushbullet_access_token = $.trim($('#pushbullet_access_token').val()); + if (!pushbullet_access_token) { + $('#testPushbullet-result').html('Please fill out the necessary fields above.'); + $('#pushbullet_access_token').addClass('warning'); + return; + } + $(this).prop("disabled", true); + if (msg) { + $('#testPushbullet-result').html(loading); + } + var current_pushbullet_device = $('#pushbullet_device_iden').val(); + $.get(sbRoot + '/home/getPushbulletDevices', {'accessToken': pushbullet_access_token}) + .done(function (data) { + var devices = jQuery.parseJSON(data || '{}').devices; + var error = jQuery.parseJSON(data || '{}').error; + $('#pushbullet_device_list').html(''); + if (devices) { + // add default option to send to all devices + $('#pushbullet_device_list').append(''); + for (var i = 0; i < devices.length; i++) { + // only list active device targets + if (devices[i].active == true) { + // if a device in the list matches our current iden, select it + if (current_pushbullet_device == devices[i].iden) { + $('#pushbullet_device_list').append(''); + } else { + $('#pushbullet_device_list').append(''); + } + } + } + } + $('#getPushbulletDevices').prop('disabled', false); + if (msg) { + if (error.message) { + $('#testPushbullet-result').html(error.message); + } else { + $('#testPushbullet-result').html(msg); + } + } + }); + + $('#pushbullet_device_list').change(function () { + $('#pushbullet_device_iden').val($('#pushbullet_device_list').val()); + $('#testPushbullet-result').html('Don\'t forget to save your new Pushbullet settings.'); + }); + } + + $('#getPushbulletDevices').click(function () { + get_pushbullet_devices('Device list updated. Select specific device to use.'); + }); + + if ($('#use_pushbullet').prop('checked')) { + get_pushbullet_devices(); + } + + $('#twitterStep1').click(function() { + $('#testTwitter-result').html(loading); + $.get(sbRoot + '/home/twitterStep1', function (data) {window.open(data); }) + .done(function () { $('#testTwitter-result').html('Step1: Confirm Authorization'); }); + }); + + $('#twitterStep2').click(function () { + var twitter_key = $.trim($('#twitter_key').val()); + if (!twitter_key) { + $('#testTwitter-result').html('Please fill out the necessary fields above.'); + $('#twitter_key').addClass('warning'); + return; + } + $('#twitter_key').removeClass('warning'); + $('#testTwitter-result').html(loading); + $.get(sbRoot + '/home/twitterStep2', {'key': twitter_key}, + function (data) { $('#testTwitter-result').html(data); }); + }); + + $('#testTwitter').click(function() { + $.get(sbRoot + '/home/testTwitter', + function (data) { $('#testTwitter-result').html(data); }); + }); + var elTraktAuth = $('#trakt-authenticate'), elTraktAuthResult = $('#trakt-authentication-result'); function trakt_send_auth(){ @@ -510,6 +629,67 @@ }); }); + function load_show_notify_lists() { + $.get(sbRoot + '/home/loadShowNotifyLists', function (data) { + var list, html, item, len= 0, el; + list = $.parseJSON(data); + html = []; + for (item in list) { + for (var k in list[item]) { + if ($.isArray(list[item][k])) { + len += list[item][k].length; + html.push('\t'); + for (var show in list[item][k]) { + html.push('\t\t'); + } + html.push('\t'); + } + } + } + + if (len) { + el = $('#email_show'); + el.html('' + + html.join('\n')); + + $('#show_email_list').val(''); + + el.change(function () { + $('#show_email_list').val( + $(this).find('option[value="' + $(this).val() + '"]').attr('data')) + }); + } + }); + } + // Load the per show notify lists everytime this page is loaded + load_show_notify_lists(); + + // Update the internal data struct anytime settings are saved to the server + $('#email_show').bind('notify', function () { load_show_notify_lists(); }); + + $('#save_show_email').click( + function(){ + var show = $('#email_show').val(); + if ('-1' == show) { + $('#testEmail-result').html('No show selected for save.'); + return + } + $.post(sbRoot + '/home/save_show_email', { + show: show, + emails: $('#show_email_list').val()}, + function (data){ + // Reload the per show notify lists to reflect changes + load_show_notify_lists(); + var result = $.parseJSON(data), + show = $('#email_show').find('option[value="' + result.id + '"]').text(); + $('#testEmail-result').html(result.success + ? 'Success. Notify list updated for show "' + show + '". Click below to test.' + : 'Error saving notify list for show %s' % show); + }); + }); + $('#testEmail').click(function () { var status, host, port, tls, from, user, pwd, err, to; status = $('#testEmail-result'); @@ -523,174 +703,27 @@ from = from.length > 0 ? from : 'root@localhost'; user = $('#email_user').val().trim(); pwd = $('#email_password').val(); - err = ''; - if (host === null) { - err += '
  • You must specify an SMTP hostname!
  • '; + err = []; + if (null == host) { + err.push('SMTP server hostname'); } - if (port === null) { - err += '
  • You must specify an SMTP port!
  • '; - } else if (port.match(/^\d+$/) === null || parseInt(port, 10) > 65535) { - err += '
  • SMTP port must be between 0 and 65535!
  • '; + if (null == port) { + err.push('SMTP server host port'); + } else if (null == port.match(/^\d+$/) || parseInt(port, 10) > 65535) { + err.push('SMTP server host port must be between 0 and 65535'); } - if (err.length > 0) { - err = '
      ' + err + '
    '; - status.html(err); + if (0 < err.length) { + status.html('Required: ' + err.join(', ')); } else { - to = prompt('Enter an email address to send the test to:', null); - if (to === null || to.length === 0 || to.match(/.*@.*/) === null) { - status.html('

    You must provide a recipient email address!

    '); + to = prompt('Enter an email address to send the test to:', ''); + if (null == to || 0 == to.length || null == to.match(/.*@.*/)) { + status.html('Required: A valid address for email test'); } else { - $.get(sbRoot + '/home/testEmail', {host: host, port: port, smtp_from: from, use_tls: tls, user: user, pwd: pwd, to: to}, - function (msg) { $('#testEmail-result').html(msg); }); + $.get(sbRoot + '/home/testEmail', + {host:host, port:port, smtp_from:from, use_tls:tls, user:user, pwd:pwd, to:to}, + function(msg) {$('#testEmail-result').html(msg);}); } } }); - $('#testNMA').click(function () { - var nma_api = $.trim($('#nma_api').val()); - var nma_priority = $('#nma_priority').val(); - if (!nma_api) { - $('#testNMA-result').html('Please fill out the necessary fields above.'); - $('#nma_api').addClass('warning'); - return; - } - $('#nma_api').removeClass('warning'); - $(this).prop('disabled', true); - $('#testNMA-result').html(loading); - $.get(sbRoot + '/home/testNMA', {'nma_api': nma_api, 'nma_priority': nma_priority}) - .done(function (data) { - $('#testNMA-result').html(data); - $('#testNMA').prop('disabled', false); - }); - }); - - $('#testPushalot').click(function () { - var pushalot_authorizationtoken = $.trim($('#pushalot_authorizationtoken').val()); - if (!pushalot_authorizationtoken) { - $('#testPushalot-result').html('Please fill out the necessary fields above.'); - $('#pushalot_authorizationtoken').addClass('warning'); - return; - } - $('#pushalot_authorizationtoken').removeClass('warning'); - $(this).prop('disabled', true); - $('#testPushalot-result').html(loading); - $.get(sbRoot + '/home/testPushalot', {'authorizationToken': pushalot_authorizationtoken}) - .done(function (data) { - $('#testPushalot-result').html(data); - $('#testPushalot').prop('disabled', false); - }); - }); - - $('#testPushbullet').click(function () { - var pushbullet_access_token = $.trim($('#pushbullet_access_token').val()); - var pushbullet_device_iden = $('#pushbullet_device_iden').val(); - if (!pushbullet_access_token) { - $('#testPushbullet-result').html('Please fill out the necessary fields above.'); - $('#pushbullet_access_token').addClass('warning'); - return; - } - $('#pushbullet_access_token').removeClass('warning'); - $(this).prop('disabled', true); - $('#testPushbullet-result').html(loading); - $.get(sbRoot + '/home/testPushbullet', {'accessToken': pushbullet_access_token, 'device_iden': pushbullet_device_iden}) - .done(function (data) { - $('#testPushbullet-result').html(data); - $('#testPushbullet').prop('disabled', false); - }); - }); - - function get_pushbullet_devices (msg) { - var pushbullet_access_token = $.trim($('#pushbullet_access_token').val()); - if (!pushbullet_access_token) { - $('#testPushbullet-result').html('Please fill out the necessary fields above.'); - $('#pushbullet_access_token').addClass('warning'); - return; - } - $(this).prop("disabled", true); - if (msg) { - $('#testPushbullet-result').html(loading); - } - var current_pushbullet_device = $('#pushbullet_device_iden').val(); - $.get(sbRoot + '/home/getPushbulletDevices', {'accessToken': pushbullet_access_token}) - .done(function (data) { - var devices = jQuery.parseJSON(data || '{}').devices; - var error = jQuery.parseJSON(data || '{}').error; - $('#pushbullet_device_list').html(''); - if (devices) { - // add default option to send to all devices - $('#pushbullet_device_list').append(''); - for (var i = 0; i < devices.length; i++) { - // only list active device targets - if (devices[i].active == true) { - // if a device in the list matches our current iden, select it - if (current_pushbullet_device == devices[i].iden) { - $('#pushbullet_device_list').append(''); - } else { - $('#pushbullet_device_list').append(''); - } - } - } - } - $('#getPushbulletDevices').prop('disabled', false); - if (msg) { - if (error.message) { - $('#testPushbullet-result').html(error.message); - } else { - $('#testPushbullet-result').html(msg); - } - } - }); - - $('#pushbullet_device_list').change(function () { - $('#pushbullet_device_iden').val($('#pushbullet_device_list').val()); - $('#testPushbullet-result').html('Don\'t forget to save your new Pushbullet settings.'); - }); - } - - $('#getPushbulletDevices').click(function () { - get_pushbullet_devices('Device list updated. Select specific device to use.'); - }); - - if ($('#use_pushbullet').prop('checked')) { - get_pushbullet_devices(); - } - - $('#email_show').change(function () { - var key = parseInt($('#email_show').val(), 10); - $('#email_show_list').val(key >= 0 ? notify_data[key.toString()].list : ''); - }); - - // Update the internal data struct anytime settings are saved to the server - $('#email_show').bind('notify', function () { load_show_notify_lists(); }); - - function load_show_notify_lists() { - $.get(sbRoot + "/home/loadShowNotifyLists", function (data) { - var list, html, s; - list = $.parseJSON(data); - notify_data = list; - if (list._size === 0) { - return; - } - html = ''; - for (s in list) { - if (s.charAt(0) !== '_') { - html += '