diff --git a/.gitignore b/.gitignore index ecc4f38e7..3edd9e228 100644 --- a/.gitignore +++ b/.gitignore @@ -30,4 +30,4 @@ node_modules/ /public/generated-js/ project/metals.sbt project/project/metals.sbt -project/project/project/metals.sbt \ No newline at end of file +project/project/project/metals.sbt diff --git a/app/views/createApplication.scala.html b/app/views/createApplication.scala.html index a682c59f5..f8d2c2018 100644 --- a/app/views/createApplication.scala.html +++ b/app/views/createApplication.scala.html @@ -345,5 +345,4 @@
} }{ - } diff --git a/app/views/showApplication.scala.html b/app/views/showApplication.scala.html index fb352c50e..fb5335d4b 100644 --- a/app/views/showApplication.scala.html +++ b/app/views/showApplication.scala.html @@ -679,5 +679,4 @@
Votre réponse :
We use twemoji for emoji : https://github.com/twitter/twemoji --> }{ - } diff --git a/public/javascripts/application-attachment.js b/public/javascripts/application-attachment.js deleted file mode 100644 index 0e6e7321e..000000000 --- a/public/javascripts/application-attachment.js +++ /dev/null @@ -1,35 +0,0 @@ -ApplicationAttachment = {}; - -window.document.addEventListener("DOMContentLoaded", function (event) { - "use strict"; - var attachmentList = document.getElementById("attachment-list"); - if (attachmentList != null) { - ApplicationAttachment.list = attachmentList; - ApplicationAttachment.fileInputCount = 1; - ApplicationAttachment.idSequence = 0; // In order to avoid id collisions - ApplicationAttachment.increaseOrDecreaseFileInputList = function (event) { - if (event.target.files.length > 0) { - // If a new file is added, add a new file input. - var li = document.createElement("li"); - var input = document.createElement("input"); - input.setAttribute("type", "file"); - input.setAttribute("name", "file["+(ApplicationAttachment.idSequence++)+"]"); - ApplicationAttachment.fileInputCount++; - input.addEventListener("change", ApplicationAttachment.increaseOrDecreaseFileInputList); - ApplicationAttachment.list.appendChild(li); - li.appendChild(input); - } else { - // If a previous file is unset for upload, remove the corresponding input file. - if (ApplicationAttachment.fileInputCount > 1) { - event.target.parentElement.parentElement.removeChild(event.target.parentElement); - ApplicationAttachment.fileInputCount--; - } - } - }; - // For all file inputs, add a listener that adds a new file input to allow - // for more attachments to be made. - ApplicationAttachment.list.querySelectorAll("input").forEach(function (input) { - input.addEventListener("change", ApplicationAttachment.increaseOrDecreaseFileInputList); - }); - } -}, false); diff --git a/typescript/src/application-attachment.ts b/typescript/src/application-attachment.ts new file mode 100644 index 000000000..837e47a78 --- /dev/null +++ b/typescript/src/application-attachment.ts @@ -0,0 +1,55 @@ +interface ApplicationAttachment { + list: HTMLElement + fileInputCount: number + idSequence: number + increaseOrDecreaseFileInputList: (EventListener) => any +} + +let attachment: any = {} + + +const createAttachment = (list: HTMLElement, count: number, sequence: number): ApplicationAttachment => { + return { + list, + fileInputCount: count, + idSequence: sequence, // In order to avoid id collisions + increaseOrDecreaseFileInputList: event => { + if (event.target.files.length > 0) { + // If a new file is added, add a new file input. + const li: HTMLLIElement = document.createElement("li"); + const input: HTMLInputElement = document.createElement("input"); + input.setAttribute("type", "file"); + input.setAttribute("name", "file[" + (attachment.idSequence++) + "]"); + attachment.fileInputCount++; + input.addEventListener("change", attachment.increaseOrDecreaseFileInputList); + attachment.list.appendChild(li); + li.appendChild(input); + } else { + // If a previous file is unset for upload, remove the corresponding input file. + if (attachment.fileInputCount > 1) { + event.target.parentElement.parentElement.removeChild(event.target.parentElement); + attachment.fileInputCount--; + } + } + } + } +} + +const main = (list: HTMLElement | null) => { + if (list != null) { + const attachment = createAttachment(list, 1, 0) + // For all file inputs, add a listener that adds a new file input to allow + // for more attachments to be made. + attachment.list.querySelectorAll("input").forEach(input => { + input.addEventListener("change", attachment.increaseOrDecreaseFileInputList); + }); + + return attachment; + } +} + +window.document.addEventListener("DOMContentLoaded", _ => { + "use strict"; + const attachmentList: HTMLElement | null = document.getElementById("attachment-list"); + attachment = main(attachmentList) +}, false); diff --git a/typescript/src/index.ts b/typescript/src/index.ts index 01da126f1..0cf9094e9 100644 --- a/typescript/src/index.ts +++ b/typescript/src/index.ts @@ -1,8 +1,11 @@ // Polyfills // See https://github.com/ryanelian/ts-polyfill/tree/master/lib import 'ts-polyfill/lib/es2015-core'; +// This adds NodeList.forEach, etc. +import 'core-js/web/dom-collections'; // Our scripts import "./admin.ts" import "./mdl-extensions.ts" -import "./validateAccount" \ No newline at end of file +import "./application-attachment" +import "./validateAccount"