Commit Graph

128 Commits

Author SHA1 Message Date
Chris Hill-Scott
a9baa36005 Hide ‘nothing selected’ if nothing to select
It’s doesn’t make sense to show the state if the state can’t change.
This is especially true when you’re in a brand new, empty service.
2019-01-03 11:16:56 +00:00
Chris Hill-Scott
6487273ced Fix sticky with find as you type
It was losing its position because filtering the list of templates with
find as you type was causing the height of the page to change.
2018-12-21 14:37:01 +00:00
Leo Hemsted
1bcee4c1b0 render if currentState is defined
(this fixes bug where on error, it would show all states)
2018-12-19 15:25:43 +00:00
Tom Byers
f6a6de41aa Merge pull request #2590 from alphagov/fix-sticky-init
Fix issues with JS for sticky elements
2018-12-17 13:29:19 +00:00
Chris Hill-Scott
c30af92050 Merge pull request #2574 from alphagov/selected-template-counter
Add counter of selected templates and folders
2018-12-17 10:34:45 +00:00
Tom Byers
573d2d1d65 Fix code for sticky JS when window resizes
Includes:
- change .stopped method to .isStopped() for
  consistency
- replace code in checkResize that adjusts
  dimensions for setElementDimensions
- add code that deals with the window size being
  too small to run whenever positions are calculated
- add reset method for when screen is too small
  for sticking behaviour
- move guard out of methods for stopping and
  sticking (it hid info that was useful at the
  point they were called)
2018-12-14 16:33:00 +00:00
Tom Byers
b55acc4981 Add comments 2018-12-14 16:33:00 +00:00
Tom Byers
108cec7938 Remove fixedTop property from sticky elements
It's no longer used by this code.
2018-12-14 16:33:00 +00:00
Tom Byers
030701ab1b Make folder controls update sticky JS on change
Also removes a call the `render` method which
duplicates one already made by the
`selectActionButtons` method on load.
2018-12-14 16:33:00 +00:00
Tom Byers
9823ff831f Add publich recalculate method
Allows other JS to tell sticky elements to
recalculate their dimensions and then position
(and then check to see if their state needs
changing).

We need this because we change the content of our
element so its dimensions change.

The recalculation code also updates the shim for
elements that are 'stuck' so the horizontal space
the element would occupy in the flow of the page
is correct.
2018-12-14 16:30:07 +00:00
Tom Byers
6fb2d14cc3 Move shim handling to StickyElement
Includes other code that splits the height
StickyElement stores into two properties:
1. `verticalSpace`
2. `height`

`verticalSpace` is the vertical space the element
occupies in the document flow when not stuck.

`height` is the visual space of the element,
including padding and border.
2018-12-14 16:16:40 +00:00
Pea (Malgorzata Tyczynska)
1e3be7d640 Merge pull request #2577 from alphagov/disable_ajax_if_inactive
Page stops auto-refreshing when it's not active
2018-12-12 12:32:52 +00:00
Pea Tyczynska
b65f5abf92 Page stops auto-refreshing when it's not active 2018-12-12 11:42:54 +00:00
Chris Hill-Scott
ce86604a49 Only trigger clear/cancel buttons on certain keys
It’s annoying having these buttons triggered by the tab or command keys.
2018-12-10 17:32:36 +00:00
Chris Hill-Scott
0c71ca0f0e Move cancel buttons alongside submit buttons
This is better because it saves vertical space for the contents of the
pop-up menu.

This commit also adds some padding to the cancel and clear buttons, to
make them easier targets to hit.
2018-12-10 17:11:01 +00:00
Chris Hill-Scott
4b305376f7 Add counter of selected templates and folders
Being able to see how many things you have selected gives you positive
feedback that reinforces that what you’ve done has been recognised. It
helps you understand the implications of your actions (ie you see ‘3
selected’ before you press the ‘Move’ button). And it gives you an
escape hatch the get out of the state you’re in by providing the ‘Clear’
button.

We also found in prototyping that having a ‘Nothing selected’ message
helps draws people’s attention to the checkboxes when they first
encounter the folders feature.

This commit implements the counter and the cancel button. It tries to
follow the existing patterns for this module.
2018-12-10 16:53:12 +00:00
Chris Hill-Scott
cac2ce661b Fix sticky shim having zero height
We ‘shim’ the sticky element so that its space in the page is reserved
while it is sticky.

This means the shim have have the same height as the sticky element.
It’s height was not getting set because of a missing semicolon in the
shim element’s `style` attribute.
2018-12-10 16:03:37 +00:00
Chris Hill-Scott
b0f89f7fe9 Style cancel link and make it keyboard navigable
So that it looks and behaves like a normal link.
2018-12-05 16:47:45 +00:00
Chris Hill-Scott
224630a790 Merge pull request #2561 from alphagov/always-show-checked-search
Always show checked items in live search
2018-12-05 16:36:22 +00:00
Leo Hemsted
827b58e7ac remove the unknown button in js
When you hit enter while an input in a form is in focus, your browser
finds the first button in the form, and carries out that action. So,
for non-js users, we added a hidden submit button with a value of
"unknown" to reflect that we don't know the intention of the user.

However, with JS enabled, this ambiguity doesn't exist - there's only
submit button and forms to fill in at a time, and non-visible fields
aren't even submitted at all. We can remove the unknown button,
supporting enter as submit properly. If the user is on one of the grey
button states, with no submit, it'll press the first button, and go to
the new template / move to existing folder dialog. That's fine enough.
2018-12-05 13:48:07 +00:00
Leo Hemsted
f1dffd1cb8 if state is unknown on load, then work out which action buttons to show
previously, it'd always show nothing-selected-buttons - however, if
some items were checked (due to being selected previously, and loading
with a form error message), it would be showing the wrong buttons.

Now, if the state is unknown, work out which state to show by counting
checkboxes, the same as when someone presses the cancel button.
2018-12-05 12:01:02 +00:00
Chris Hill-Scott
b7e9c1a3e4 Always show checked items in live search
If you’ve searched to select an item and then you want to perform an
action on it it’s confusing when it goes away if you change your search.

It should always be clear which items you’re performing an action on.
This means that checked items should always be visible, no matter what
your search term is.
2018-12-05 11:24:16 +00:00
Leo Hemsted
17cc262ea3 preserve previous state on form error
the html now contains a `data-prev-state` attribute which contains the
previous state, taken from the `operation` value in the form data (from
the submit button). This is used to seed the `currentState` of the
templateFolderForm. If not specified (or 'unknown', because the user
hit enter last time round), then set it to nothingSelectedButtons.
2018-12-04 16:41:47 +00:00
Leo Hemsted
97f663f99e change operations to kebab-case
so that they better align with the front-end, where they'll be used in
data attributes. Also, making the kebab case is nice because it doesn't
give favouritism to either JS or python naming conventions
2018-12-04 16:41:47 +00:00
Leo Hemsted
bb50326811 remove extra add template button and cleanup of html
only remove the add template button if they have the folder service
permission (thus can see the add button at the bottom).

Also make some unnecessary functions into strings in the js, and
remove some commented out code
2018-12-04 16:41:47 +00:00
Leo Hemsted
af8de93c30 add cancel buttons to template folder flow
when cancelled, clears any data inputted into the sub-form action, and
then uses an icky hack to go back to the buttons, by changing the
state to "nothingSelectedButtons", and then pretending a checkbox was
clicked so it works out which actions to show and re-renders.
2018-12-04 16:41:47 +00:00
Leo Hemsted
9942725d35 go to forms on click of action buttons, and detatch and reattach els
the action buttons have a value that matches up with the key for the
target form in the `this.states` object - we can just set the
currentState to that and call re-render and it all Just Works™.

detatch and reattach feel better than hide/unhide, mainly because it
means when the form is posted, any data that might linger in them
definitely won't be sent in the POST.
2018-12-04 16:41:47 +00:00
Leo Hemsted
db9d4aa2cb change actions based on which checkboxes are selected
if action buttons are shown (either the nothing selected actions or the
stuff selected actions), when a checkbox is selected or deselected,
count how many checkboxes are selected. If it's zero, then show the
new template/folder buttons, if it's non-zero, then show the move
options.

Under the hood, we set the `currentState` variable, then the render fn
shows that element and hides all others.
2018-12-04 16:41:47 +00:00
Leo Hemsted
370f2527ff start js for template folder form
have a bunch of separate elements within the sticky_template_forms div
that we hide or show based on button presses and such. This commit just
sets up the class - it doesn't actually deal with button presses or
checkboxes etc yet.
2018-12-04 16:41:47 +00:00
Chris Hill-Scott
cdb03d1eeb Only live search on template or folder name
If you have a folder structure like this:

> FA / FB / FC

and you search for ‘FA’, it’s very noisy to see:

> FA / FB
> FA / FB / T1
> FA / FB / T2
> FA / FB / FC
> FA / FB / FC / T3
> …

It’s clearer to just show:

> FA / FB

This also has the benefit of, if you type ‘template’ (for example) you
don’t get every item any more, because it’s only looking at the name of
the thing. It used to look at the entire description, ie:

> A / B / C / Example
> Text message template

Now it only searches on the name:

> A / B / C / *Example*
> Text message template
2018-11-23 14:39:45 +00:00
Chris Hill-Scott
d7e6e6ae90 Make live search restore items to default state
At the moment live search works by either setting something to hidden
or displayed. When the search term is empty, it sets everything to
visible.

This doesn’t work with folders because some of them should be hidden by
default (the ones not at the current level).

We can account for this special case (empty search term) by removing
the `display` CSS attribute when the search term is empty. This means
that each item’s visibility will be controlled by whatever is set in the
CSS file. Using jQuery Setting a property to `''` removes it.
2018-11-23 14:35:58 +00:00
Tom Byers
eeb096aa62 Add missed .stopped method to Sticky Element 2018-11-14 16:42:52 +00:00
Tom Byers
8411598390 Remove transition if element is stuck onload
Fade-in and out for sticky elements should only be
when they move from being in-page to stuck from a
user interaction.
2018-11-14 10:25:08 +00:00
Tom Byers
c04c57b043 Fix linting errors 2018-11-08 22:47:52 +00:00
Tom Byers
412b1f1117 Add extra checks for resize and onload
Position of elements are normally checked when you
scroll but we also need it to check when the page
loads.

Re-calculate element positions if window resizes.

Adds a flag to mark if all elements have a height
which will not change as their contents have
loaded.
2018-11-08 22:45:24 +00:00
Tom Byers
fa1d669f4f Rename script to reflect what it now does 2018-11-08 22:39:39 +00:00
Tom Byers
deaa253e65 Add stop-at-bottom functionality
Detach all methods from sticky reference so they
can be attached to different objects.

Split sticky into stickAtTop and stickAtBottom and
make new versions of all methods and properties
specific to stickAtBottom.

Add CSS for stickAtBottom and call on load
2018-11-08 22:39:38 +00:00
Tom Byers
ef76d4eeb3 Record height of each sticky element
Function borrowed from stop-at-bottom JS.
2018-11-08 15:11:01 +00:00
Tom Byers
53d43073ef Refactor stick-at-top to remove top-specific code 2018-11-08 15:11:01 +00:00
Tom Byers
9e1ceb13ea Make local copy of stick-at-top JS 2018-11-08 15:11:01 +00:00
Chris Hill-Scott
666d55e82b Merge pull request #2428 from alphagov/api-key-page-neatness
Make API key page handle multiple lines of text better
2018-11-07 11:17:53 +00:00
Chris Hill-Scott
54bd321504 Make the example spreadsheet scroll horizontally
This replicates how we let large spreadsheets scroll horizontally.

Pro: this looks nicer and is more usable

Con: the code for this feels a bit fragile, especially the calling of
`.maintainWidth` twice, ie as many times as a it takes to get stuff to
render properly.
2018-11-01 15:31:14 +00:00
Chris Hill-Scott
b727a50c13 Don’t have copy API key button jump around
It’s annoying that this button moves after you click on it. It’s
happening because the API key is wrapping onto multiple lines.

This commit fixes the height of the container so that it doesn’t reflow
when it has less content in it.

Uses a bit of flexbox to vertically centre the text.
2018-10-30 13:10:19 +00:00
Tom Byers
151488fa78 Update email preview page
No longer requires the branding_type GET param.

Retains the 'govuk' default brand.
2018-08-29 16:16:15 +01:00
Tom Byers
0df88ea182 Remove branding_type from set_email_branding page
Includes updates to the controller so
branding_type is got from the email_branding model
instead of from user input.

Follows on from:

https://github.com/alphagov/notifications-admin/pull/2249
2018-08-29 11:43:35 +01:00
Chris Hill-Scott
3483490f03 Fix colour preview not loading on page load
The event was changed from `change` to `input`. The trigger was not updated accordingly.
2018-08-22 16:51:16 +01:00
Chris Hill-Scott
b10f0747ae Use input event not keyup
The `oninput` event is a more performant way to detect changes to a
textbox’s contents (compared to `onkeydown`, `onpaste`, etc).

It’s not supported in older browsers, but since this is a likely to be
used by platform admin users only that’s OK.
2018-08-22 16:31:05 +01:00
Chris Hill-Scott
6501105768 Refactor to not repeat lots of Jinja code 2018-08-22 16:31:05 +01:00
Chris Hill-Scott
b73e42650d Refactor hex colour preview Javascript
This commit improves the code that previews a hex colour when setting up
or changing an email branding.

Specifically it:
- refactors the Javascript to conform to our patterns (module pattern,
  preprocessed with Gulp)
- makes the code work when there are multiple colour previews on one
  page

It also does some visual prettifying, because I couldn’t help myself…
2018-08-22 16:31:05 +01:00
Katie Smith
979fd9bbe4 Allow service contact details to be phone number, email or url
Service contact details are needed if the upload document permission is
enabled - this used to be a link but services can now choose to use a
link, email address or phone number. The form to add or change service
contact details now gives these options and validates the data according
to the type of contact details provided.

When validating phone numbers we can't use the existing validation
because we want to allow landlines too, so there is a basic check that
the phone number is the right length and doesn't include certain
characters.
2018-08-13 10:33:39 +01:00