diff --git a/data/interfaces/default/notification_config.html b/data/interfaces/default/notification_config.html index e7fc16f2..41fcfa93 100644 --- a/data/interfaces/default/notification_config.html +++ b/data/interfaces/default/notification_config.html @@ -90,9 +90,18 @@ from plexpy import helpers $('#ajaxMsg').addClass('success').fadeIn().delay(3000).fadeOut(); }) - var notificationConfig = $("#set_notification_config"); $('#save-notification-item').click(function() { - doAjaxCall('set_notification_config',$(this),'tabs',true); + doAjaxCall('set_notification_config', $(this), 'tabs', true); + // Reload modal to update certain fields + $.ajax({ + url: 'get_notification_agent_config', + data: { config_id: '${config_id}' }, + cache: false, + async: true, + complete: function (xhr, status) { + $("#notification-config-modal").html(xhr.responseText); + } + }); return false; }); diff --git a/plexpy/notifiers.py b/plexpy/notifiers.py index dd1e42ea..74ee23c9 100644 --- a/plexpy/notifiers.py +++ b/plexpy/notifiers.py @@ -874,9 +874,9 @@ class PUSHOVER(object): 'priority': plexpy.CONFIG.PUSHOVER_PRIORITY} http_handler.request("POST", - "/1/messages.json", - headers={'Content-type': "application/x-www-form-urlencoded"}, - body=urlencode(data)) + "/1/messages.json", + headers={'Content-type': "application/x-www-form-urlencoded"}, + body=urlencode(data)) response = http_handler.getresponse() request_status = response.status # logger.debug(u"Pushover response status: %r" % request_status) @@ -905,11 +905,31 @@ class PUSHOVER(object): self.notify('Main Screen Activate', 'Test Message') + def get_sounds(self): + http_handler = HTTPSConnection("api.pushover.net") + http_handler.request("GET", "/1/sounds.json?token=" + self.application_token) + response = http_handler.getresponse() + request_status = response.status + + if request_status == 200: + data = json.loads(response.read()) + sounds = data.get('sounds', {}) + return sounds + elif request_status >= 400 and request_status < 500: + logger.info(u"Unable to retrieve Pushover notification sounds: %s" % response.reason) + return {} + else: + logger.info(u"Unable to retrieve Pushover notification sounds.") + return {} + def return_config_options(self): - config_option = [{'label': 'Pushover API Key', + sounds = self.get_sounds() + sounds[''] = '' + + config_option = [{'label': 'Pushover User Key', 'value': self.keys, 'name': 'pushover_keys', - 'description': 'Your Pushover API key.', + 'description': 'Your Pushover user key.', 'input_type': 'text' }, {'label': 'Priority', @@ -922,13 +942,14 @@ class PUSHOVER(object): {'label': 'Sound', 'value': self.sound, 'name': 'pushover_sound', - 'description': 'Set the notification sound (choose from this list or leave blank for default)', - 'input_type': 'text' + 'description': 'Set the notification sound. Leave blank for the default sound.', + 'input_type': 'select', + 'select_options': sounds }, {'label': 'Pushover API Token', 'value': plexpy.CONFIG.PUSHOVER_APITOKEN, 'name': 'pushover_apitoken', - 'description': 'Your Pushover API toekn. Leave blank to use PlexPy default.', + 'description': 'Your Pushover API token. Leave blank to use PlexPy default.', 'input_type': 'text' } ] diff --git a/plexpy/webserve.py b/plexpy/webserve.py index 93e0682a..7ba6c176 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -1305,7 +1305,7 @@ class WebInterface(object): checkboxes = {'email_tls': checked(plexpy.CONFIG.EMAIL_TLS)} return serve_template(templatename="notification_config.html", title="Notification Configuration", - data=config, checkboxes=checkboxes) + config_id=config_id, data=config, checkboxes=checkboxes) @cherrypy.expose def get_notification_agent_triggers(self, config_id, **kwargs):