Adds a [Add email] button to notification settings with a prefix set from NOTIFICATION_MAIL_BUTTON_PREFIX env var when defined.

pull/528/head
dgtlmoon 3 years ago
parent f6e518497a
commit 30b0130837

@ -417,9 +417,10 @@ def changedetection_app(config=None, datastore_o=None):
return make_response({'error': 'No Notification URLs set'}, 400) return make_response({'error': 'No Notification URLs set'}, 400)
for server_url in request.form['notification_urls'].splitlines(): for server_url in request.form['notification_urls'].splitlines():
if not apobj.add(server_url): if len(server_url.strip()):
message = '{} is not a valid AppRise URL.'.format(server_url) if not apobj.add(server_url):
return make_response({'error': message}, 400) message = '{} is not a valid AppRise URL.'.format(server_url)
return make_response({'error': message}, 400)
try: try:
n_object = {'watch_url': request.form['window_url'], n_object = {'watch_url': request.form['window_url'],
@ -620,7 +621,8 @@ def changedetection_app(config=None, datastore_o=None):
watch=datastore.data['watching'][uuid], watch=datastore.data['watching'][uuid],
form=form, form=form,
using_default_minutes=using_default_minutes, using_default_minutes=using_default_minutes,
current_base_url = datastore.data['settings']['application']['base_url'] current_base_url=datastore.data['settings']['application']['base_url'],
emailprefix=os.getenv('NOTIFICATION_MAIL_BUTTON_PREFIX', False)
) )
return output return output
@ -685,7 +687,8 @@ def changedetection_app(config=None, datastore_o=None):
output = render_template("settings.html", output = render_template("settings.html",
form=form, form=form,
current_base_url = datastore.data['settings']['application']['base_url'], current_base_url = datastore.data['settings']['application']['base_url'],
hide_remove_pass=os.getenv("SALTED_PASS", False)) hide_remove_pass=os.getenv("SALTED_PASS", False),
emailprefix=os.getenv('NOTIFICATION_MAIL_BUTTON_PREFIX', False))
return output return output

@ -1,4 +1,15 @@
$(document).ready(function() { $(document).ready(function() {
$('#add-email-helper').click(function (e) {
e.preventDefault();
email = prompt("Destination email");
if(email) {
var n = $("#notification_urls");
var p=email_notification_prefix;
$(n).val( $.trim( $(n).val() )+"\n"+email_notification_prefix+email );
}
});
$('#send-test-notification').click(function (e) { $('#send-test-notification').click(function (e) {
e.preventDefault(); e.preventDefault();

@ -1,7 +1,7 @@
{% from '_helpers.jinja' import render_field %} {% from '_helpers.jinja' import render_field %}
{% macro render_common_settings_form(form, current_base_url) %} {% macro render_common_settings_form(form, current_base_url, emailprefix) %}
<div class="pure-control-group"> <div class="pure-control-group">
{{ render_field(form.notification_urls, rows=5, placeholder="Examples: {{ render_field(form.notification_urls, rows=5, placeholder="Examples:
@ -20,6 +20,10 @@
</div> </div>
<br/> <br/>
<a id="send-test-notification" class="pure-button button-secondary button-xsmall" style="font-size: 70%">Send test notification</a> <a id="send-test-notification" class="pure-button button-secondary button-xsmall" style="font-size: 70%">Send test notification</a>
{% if emailprefix %}
<a id="add-email-helper" class="pure-button button-secondary button-xsmall" style="font-size: 70%">Add email</a>
{% endif %}
</div> </div>
<div id="notification-customisation"> <div id="notification-customisation">
<div class="pure-control-group"> <div class="pure-control-group">

@ -4,10 +4,13 @@
{% from '_helpers.jinja' import render_button %} {% from '_helpers.jinja' import render_button %}
{% from '_common_fields.jinja' import render_common_settings_form %} {% from '_common_fields.jinja' import render_common_settings_form %}
<script type="text/javascript" src="{{url_for('static_content', group='js', filename='tabs.js')}}" defer></script> <script type="text/javascript" src="{{url_for('static_content', group='js', filename='tabs.js')}}" defer></script>
<script type="text/javascript" src="{{url_for('static_content', group='js', filename='notifications.js')}}" defer></script>
<script> <script>
var notification_base_url="{{url_for('ajax_callback_send_notification_test')}}"; const notification_base_url="{{url_for('ajax_callback_send_notification_test')}}";
{% if emailprefix %}
const email_notification_prefix=JSON.parse('{{ emailprefix|tojson }}');
{% endif %}
</script> </script>
<script type="text/javascript" src="{{url_for('static_content', group='js', filename='notifications.js')}}" defer></script>
<div class="edit-form monospaced-textarea"> <div class="edit-form monospaced-textarea">
@ -96,7 +99,7 @@ User-Agent: wonderbra 1.0") }}
<strong>Note: <i>These settings override the global settings for this watch.</i></strong> <strong>Note: <i>These settings override the global settings for this watch.</i></strong>
<fieldset> <fieldset>
<div class="field-group"> <div class="field-group">
{{ render_common_settings_form(form, current_base_url) }} {{ render_common_settings_form(form, current_base_url, emailprefix) }}
</div> </div>
</fieldset> </fieldset>
</div> </div>

@ -3,13 +3,16 @@
{% block content %} {% block content %}
{% from '_helpers.jinja' import render_field, render_button %} {% from '_helpers.jinja' import render_field, render_button %}
{% from '_common_fields.jinja' import render_common_settings_form %} {% from '_common_fields.jinja' import render_common_settings_form %}
<script>
const notification_base_url="{{url_for('ajax_callback_send_notification_test')}}";
{% if emailprefix %}
const email_notification_prefix=JSON.parse('{{emailprefix|tojson}}');
{% endif %}
</script>
<script type="text/javascript" src="{{url_for('static_content', group='js', filename='settings.js')}}" defer></script> <script type="text/javascript" src="{{url_for('static_content', group='js', filename='settings.js')}}" defer></script>
<script type="text/javascript" src="{{url_for('static_content', group='js', filename='tabs.js')}}" defer></script> <script type="text/javascript" src="{{url_for('static_content', group='js', filename='tabs.js')}}" defer></script>
<script type="text/javascript" src="{{url_for('static_content', group='js', filename='notifications.js')}}" defer></script> <script type="text/javascript" src="{{url_for('static_content', group='js', filename='notifications.js')}}" defer></script>
<script>
var notification_base_url="{{url_for('ajax_callback_send_notification_test')}}";
</script>
<div class="edit-form"> <div class="edit-form">
<div class="tabs collapsable"> <div class="tabs collapsable">
<ul> <ul>
@ -65,7 +68,7 @@
<div class="tab-pane-inner" id="notifications"> <div class="tab-pane-inner" id="notifications">
<fieldset> <fieldset>
<div class="field-group"> <div class="field-group">
{{ render_common_settings_form(form, current_base_url) }} {{ render_common_settings_form(form, current_base_url, emailprefix) }}
</div> </div>
</fieldset> </fieldset>
<a href="{{url_for('notification_logs')}}">Notification debug logs</a> <a href="{{url_for('notification_logs')}}">Notification debug logs</a>

Loading…
Cancel
Save