|
3 | 3 | text = image_kind.permitted_uses.include?("govspeak_embed") ? "Upload an image" : "Upload an #{image_kind.display_name} image" |
4 | 4 | %> |
5 | 5 |
|
6 | | -<%= form_tag( |
7 | | - admin_edition_images_path(@edition), |
8 | | - multipart: true, |
9 | | -) do %> |
10 | | - <%= render "govuk_publishing_components/components/file_upload", { |
11 | | - label: { |
12 | | - text:, |
13 | | - }, |
14 | | - heading_level: 2, |
15 | | - heading_size: "l", |
16 | | - javascript: true, |
17 | | - multiple: true, |
18 | | - name: "images[][image_data][file]", |
19 | | - id: "edition_images_image_data_file", |
20 | | - hint: raw('Images can be JPEG, PNG, SVG or GIF files. If you are uploading more than one image, <a class="govuk-link" href="https://www.gov.uk/guidance/how-to-publish-on-gov-uk/images-and-videos">read the image guidance</a> on using unique file names.'), |
21 | | - error_items: @new_image.present? ? errors_for(@new_image.errors, :"image_data.file") : nil, |
22 | | - accept: "image/png, image/jpeg, image/gif, image/svg+xml", |
23 | | - } %> |
24 | | - |
25 | | - <% if image_kind.present? %> |
26 | | - <%= hidden_field_tag("image[image_data][image_kind]", @edition.permitted_image_kinds.first.name) %> |
27 | | - <% else %> |
28 | | - <%= render "govuk_publishing_components/components/radio", { |
29 | | - heading: "What kind of image is this?", |
30 | | - name: "image[image_data][image_kind]", |
31 | | - items: @edition.permitted_image_kinds.map do |image_kind| |
32 | | - { |
33 | | - value: image_kind.name, |
34 | | - text: image_kind.display_name, |
35 | | - } |
36 | | - end, |
| 6 | +<% unless !@edition.allows_multiple_of_image_kind?(image_kind.permitted_uses.first) && @edition.images.select { |image| Whitehall.image_kinds.fetch(image.image_data.image_kind) == image_kind }.count == 1 %> |
| 7 | + <%= form_tag( |
| 8 | + admin_edition_images_path(@edition), |
| 9 | + multipart: true, |
| 10 | + ) do %> |
| 11 | + <%= render "govuk_publishing_components/components/file_upload", { |
| 12 | + label: { |
| 13 | + text:, |
| 14 | + }, |
| 15 | + heading_level: 2, |
| 16 | + heading_size: "l", |
| 17 | + javascript: true, |
| 18 | + multiple: @edition.allows_multiple_of_image_kind?(image_kind.permitted_uses.first), |
| 19 | + name: "images[][image_data][file]", |
| 20 | + id: "edition_images_image_data_file", |
| 21 | + hint: raw('Images can be JPEG, PNG, SVG or GIF files. If you are uploading more than one image, <a class="govuk-link" href="https://www.gov.uk/guidance/how-to-publish-on-gov-uk/images-and-videos">read the image guidance</a> on using unique file names.'), |
| 22 | + error_items: @new_image.present? ? errors_for(@new_image.errors, :"image_data.file") : nil, |
| 23 | + accept: "image/png, image/jpeg, image/gif, image/svg+xml", |
37 | 24 | } %> |
38 | | - <% end %> |
39 | 25 |
|
40 | | - <%= render "govuk_publishing_components/components/details", { |
41 | | - title: "You must use an SVG for charts and diagrams", |
42 | | - } do %> |
43 | | - SVGs allow users to magnify images without losing quality. |
44 | | - Find out <%= link_to "how to create an SVG file (opens in new tab)", |
45 | | - "https://www.gov.uk/guidance/how-to-publish-on-gov-uk/images-and-videos#creating-an-svg-file", |
46 | | - class: "govuk-link", |
47 | | - target: "_blank", |
48 | | - rel: "noopener" %>. |
| 26 | + <% if image_kind.present? %> |
| 27 | + <%= hidden_field_tag("images[][image_data][image_kind]", @edition.permitted_image_kinds.first.name) %> |
| 28 | + <% else %> |
| 29 | + <%= render "govuk_publishing_components/components/radio", { |
| 30 | + heading: "What kind of image is this?", |
| 31 | + name: "images[][image_data][image_kind]", |
| 32 | + items: @edition.permitted_image_kinds.map do |image_kind| |
| 33 | + { |
| 34 | + value: image_kind.name, |
| 35 | + text: image_kind.display_name, |
| 36 | + } |
| 37 | + end, |
| 38 | + } %> |
49 | 39 | <% end %> |
50 | 40 |
|
51 | | - <%= render "govuk_publishing_components/components/button", { |
52 | | - text: "Upload", |
53 | | - margin_bottom: 10, |
54 | | - } %> |
| 41 | + <%= render "govuk_publishing_components/components/details", { |
| 42 | + title: "You must use an SVG for charts and diagrams", |
| 43 | + } do %> |
| 44 | + SVGs allow users to magnify images without losing quality. |
| 45 | + Find out <%= link_to "how to create an SVG file (opens in new tab)", |
| 46 | + "https://www.gov.uk/guidance/how-to-publish-on-gov-uk/images-and-videos#creating-an-svg-file", |
| 47 | + class: "govuk-link", |
| 48 | + target: "_blank", |
| 49 | + rel: "noopener" %>. |
| 50 | + <% end %> |
| 51 | + |
| 52 | + <%= render "govuk_publishing_components/components/button", { |
| 53 | + text: "Upload", |
| 54 | + margin_bottom: 10, |
| 55 | + } %> |
| 56 | + <% end %> |
55 | 57 | <% end %> |
| 58 | + |
| 59 | +<%= render Admin::EditionImages::UploadedImagesComponent.new(edition: @edition, image_kind:) %> |
0 commit comments