mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-24 00:07:02 -04:00
Show letter branding preview when selecting a brand
This adds a preview pane which is visible when updating a letter brand. If JavaScript is enabled, the preview pane shows on the set-letter-branding page, and submitting the form saves updates the letter brand for a service immediately. If Javascript is not enabled, there is a separate 'Preview email branding' page which shows a preview of the brand and has a 'Save' button on it.
This commit is contained in:
@@ -10,9 +10,9 @@ from flask_login import current_user, login_required
|
||||
from notifications_utils.international_billing_rates import (
|
||||
INTERNATIONAL_BILLING_RATES,
|
||||
)
|
||||
from notifications_utils.template import HTMLEmailTemplate
|
||||
from notifications_utils.template import HTMLEmailTemplate, LetterImageTemplate
|
||||
|
||||
from app import email_branding_client
|
||||
from app import email_branding_client, letter_branding_client
|
||||
from app.main import main
|
||||
from app.main.forms import FieldWithNoneOption, SearchByNameForm
|
||||
from app.main.views.sub_navigation_dictionaries import features_nav
|
||||
@@ -174,6 +174,35 @@ def email_template():
|
||||
return resp
|
||||
|
||||
|
||||
@main.route('/_letter')
|
||||
def letter_template():
|
||||
branding_style = request.args.get('branding_style')
|
||||
|
||||
if branding_style == FieldWithNoneOption.NONE_OPTION_VALUE:
|
||||
branding_style = None
|
||||
|
||||
if branding_style:
|
||||
filename = letter_branding_client.get_letter_branding(branding_style)['filename']
|
||||
else:
|
||||
filename = 'no-branding'
|
||||
|
||||
template = {'subject': '', 'content': ''}
|
||||
image_url = url_for('main.letter_branding_preview_image', filename=filename)
|
||||
|
||||
template_image = str(LetterImageTemplate(
|
||||
template,
|
||||
image_url=image_url,
|
||||
page_count=1,
|
||||
))
|
||||
|
||||
resp = make_response(
|
||||
render_template('views/service-settings/letter-preview.html', template=template_image)
|
||||
)
|
||||
|
||||
resp.headers['X-Frame-Options'] = 'SAMEORIGIN'
|
||||
return resp
|
||||
|
||||
|
||||
@main.route('/documentation')
|
||||
def documentation():
|
||||
return render_template('views/documentation.html')
|
||||
|
||||
@@ -810,6 +810,28 @@ def service_set_letter_branding(service_id):
|
||||
current_branding=current_service.letter_branding_id,
|
||||
)
|
||||
|
||||
if form.validate_on_submit():
|
||||
return redirect(url_for(
|
||||
'.service_preview_letter_branding',
|
||||
service_id=service_id,
|
||||
branding_style=form.branding_style.data,
|
||||
))
|
||||
|
||||
return render_template(
|
||||
'views/service-settings/set-letter-branding.html',
|
||||
form=form,
|
||||
search_form=SearchByNameForm()
|
||||
)
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/service-settings/preview-letter-branding", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@user_is_platform_admin
|
||||
def service_preview_letter_branding(service_id):
|
||||
branding_style = request.args.get('branding_style')
|
||||
|
||||
form = ServicePreviewBranding(branding_style=branding_style)
|
||||
|
||||
if form.validate_on_submit():
|
||||
current_service.update(
|
||||
letter_branding=form.branding_style.data
|
||||
@@ -817,9 +839,10 @@ def service_set_letter_branding(service_id):
|
||||
return redirect(url_for('.service_settings', service_id=service_id))
|
||||
|
||||
return render_template(
|
||||
'views/service-settings/set-letter-branding.html',
|
||||
'views/service-settings/preview-letter-branding.html',
|
||||
form=form,
|
||||
search_form=SearchByNameForm()
|
||||
service_id=service_id,
|
||||
action=url_for('main.service_preview_letter_branding', service_id=service_id),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ from app.utils import (
|
||||
get_template,
|
||||
should_skip_template_page,
|
||||
user_has_permissions,
|
||||
user_is_platform_admin,
|
||||
)
|
||||
|
||||
form_objects = {
|
||||
@@ -222,6 +223,34 @@ def view_letter_template_preview(service_id, template_id, filetype):
|
||||
return TemplatePreview.from_database_object(db_template, filetype, page=request.args.get('page'))
|
||||
|
||||
|
||||
@main.route("/templates/letter-preview-image/<filename>")
|
||||
@login_required
|
||||
@user_is_platform_admin
|
||||
def letter_branding_preview_image(filename):
|
||||
template = {
|
||||
'subject': 'An example letter',
|
||||
'content': (
|
||||
'Lorem Ipsum is simply dummy text of the printing and typesetting '
|
||||
'industry.\n\nLorem Ipsum has been the industry’s standard dummy '
|
||||
'text ever since the 1500s, when an unknown printer took a galley '
|
||||
'of type and scrambled it to make a type specimen book.\n\n'
|
||||
'# History\n\nIt has survived not only\n\n'
|
||||
'* five centuries\n'
|
||||
'* but also the leap into electronic typesetting\n\n'
|
||||
'It was popularised in the 1960s with the release of Letraset '
|
||||
'sheets containing Lorem Ipsum passages, and more recently with '
|
||||
'desktop publishing software like Aldus PageMaker including '
|
||||
'versions of Lorem Ipsum.\n\n'
|
||||
'The point of using Lorem Ipsum is that it has a more-or-less '
|
||||
'normal distribution of letters, as opposed to using ‘Content '
|
||||
'here, content here’, making it look like readable English.'
|
||||
)
|
||||
}
|
||||
filename = None if filename == 'no-branding' else filename
|
||||
|
||||
return TemplatePreview.from_example_template(template, filename)
|
||||
|
||||
|
||||
def _view_template_version(service_id, template_id, version, letters_as_pdf=False):
|
||||
return dict(template=get_template(
|
||||
service_api_client.get_service_template(service_id, template_id, version=version)['data'],
|
||||
|
||||
Reference in New Issue
Block a user