diff --git a/app/assets/javascripts/fileUpload.js b/app/assets/javascripts/fileUpload.js new file mode 100644 index 000000000..5380ac87f --- /dev/null +++ b/app/assets/javascripts/fileUpload.js @@ -0,0 +1,27 @@ +(function(Modules) { + "use strict"; + + Modules.FileUpload = function() { + + let $field, $button, $filename; + + this.update = function() { + + $filename.text($field.val().split('\\').pop()); + + }; + + this.start = function(component) { + + $field = $('.file-upload-field', component); + $button = $('.file-upload-button', component); + $filename = $('.file-upload-filename', component); + + // Need to put the event on the container, not the input for it to work properly + $(component).on('change', '.file-upload-field', this.update); + + }; + + }; + +})(window.GOVUK.Modules); diff --git a/app/assets/stylesheets/components/file-upload.scss b/app/assets/stylesheets/components/file-upload.scss new file mode 100644 index 000000000..8f75a8e4c --- /dev/null +++ b/app/assets/stylesheets/components/file-upload.scss @@ -0,0 +1,36 @@ +.js-enabled { + + .file-upload { + + &-label { + @include bold-19; + display: block; + margin: 0 0 10px 0; + } + + &-field { + width: 0.1px; + height: 0.1px; + opacity: 0; + overflow: hidden; + position: absolute; + z-index: -1; + } + + &-field:focus + .file-upload-button { + outline: 3px solid $yellow; + } + + &-button { + @include button($panel-colour); + display: inline-block; + } + + &-filename { + display: inline-block; + padding-left: $gutter-half; + } + + } + +} diff --git a/app/assets/stylesheets/main.scss b/app/assets/stylesheets/main.scss index 8a624473c..614b7c9c8 100644 --- a/app/assets/stylesheets/main.scss +++ b/app/assets/stylesheets/main.scss @@ -40,6 +40,7 @@ @import 'components/big-number'; @import 'components/banner'; @import 'components/textbox'; +@import 'components/file-upload'; @import 'components/browse-list'; @import 'components/email-message'; @import 'components/api-key'; diff --git a/app/main/views/styleguide.py b/app/main/views/styleguide.py index f778f9dcf..68947ffbd 100644 --- a/app/main/views/styleguide.py +++ b/app/main/views/styleguide.py @@ -1,6 +1,6 @@ from flask import render_template from flask_wtf import Form -from wtforms import StringField, PasswordField, TextAreaField, validators +from wtforms import StringField, PasswordField, TextAreaField, FileField, validators from app.main import main @@ -11,6 +11,7 @@ def styleguide(): username = StringField(u'Username') password = PasswordField(u'Password', [validators.required()]) message = TextAreaField(u'Message') + file_upload = FileField('Upload a CSV file to add your recipients’ details') form = FormExamples() diff --git a/app/templates/components/file-upload.html b/app/templates/components/file-upload.html new file mode 100644 index 000000000..0c92c0f76 --- /dev/null +++ b/app/templates/components/file-upload.html @@ -0,0 +1,24 @@ +{% macro file_upload(field) %} +
+ + {{ field(**{ + 'class': 'file-upload-field' + }) }} + + +
+{% endmacro %} diff --git a/app/templates/views/choose-sms-template.html b/app/templates/views/choose-sms-template.html index 5599cb1e2..8205df27f 100644 --- a/app/templates/views/choose-sms-template.html +++ b/app/templates/views/choose-sms-template.html @@ -20,7 +20,8 @@ ) }} {% endfor %} - {{ page_footer("Continue") }} + + {{ page_footer("Continue") }} {% else %} {{ banner( 'Add a text message template to start sending messages'.format( diff --git a/app/templates/views/send-sms.html b/app/templates/views/send-sms.html index 039edc7b4..9c81e4631 100644 --- a/app/templates/views/send-sms.html +++ b/app/templates/views/send-sms.html @@ -12,6 +12,12 @@

Send text messages

+ {{ banner( + 'You can only send notifications to yourself', + subhead='Trial mode', + type='info' + ) }} + {{ sms_message( template.content, name='Preview' ) }} diff --git a/app/templates/views/styleguide.html b/app/templates/views/styleguide.html index b62449140..a27dbe7f9 100644 --- a/app/templates/views/styleguide.html +++ b/app/templates/views/styleguide.html @@ -7,6 +7,7 @@ {% from "components/sms-message.html" import sms_message %} {% from "components/table.html" import mapping_table, list_table, row, field %} {% from "components/textbox.html" import textbox %} +{% from "components/file-upload.html" import file_upload %} {% from "components/api-key.html" import api_key %} {% block page_title %} @@ -205,6 +206,9 @@ {{ textbox(form.password) }} {{ textbox(form.message, highlight_tags=True) }} +

File upload

+ {{ file_upload(form.file_upload) }} +

API key

{{ api_key('d30512af92e1386d63b90e5973b49a10') }} diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 24c431155..3a58ef99c 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -37,6 +37,7 @@ gulp.task('javascripts', () => gulp paths.src + 'javascripts/apiKey.js', paths.src + 'javascripts/autofocus.js', paths.src + 'javascripts/highlightTags.js', + paths.src + 'javascripts/fileUpload.js', paths.src + 'javascripts/main.js' ]) .pipe(plugins.babel({