From 7d3b87e1673dbed7cf76dbb418d37c3b57ab28c1 Mon Sep 17 00:00:00 2001 From: mdulac Date: Fri, 23 Oct 2020 19:29:10 +0200 Subject: [PATCH 1/2] Update application-attachment to typescript --- .gitignore | 3 ++ app/views/createApplication.scala.html | 1 - app/views/showApplication.scala.html | 1 - public/javascripts/application-attachment.js | 35 ------------- typescript/src/application-attachment.ts | 55 ++++++++++++++++++++ typescript/src/index.ts | 1 + 6 files changed, 59 insertions(+), 37 deletions(-) delete mode 100644 public/javascripts/application-attachment.js create mode 100644 typescript/src/application-attachment.ts diff --git a/.gitignore b/.gitignore index 0e1191411..fff1f1e6f 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,6 @@ files package-lock.json node_modules/ /public/generated-js/ +./project/metals.sbt +./project/project/metals.sbt +./project/project/project/metals.sbt \ No newline at end of file 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..bbe562b0a --- /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 e16e01a77..c8791ab16 100644 --- a/typescript/src/index.ts +++ b/typescript/src/index.ts @@ -5,3 +5,4 @@ import 'ts-polyfill/lib/es2015-core'; // Our scripts import "./admin.ts" import "./mdl-extensions.ts" +import "./application-attachment" \ No newline at end of file From 4630f2c1f7286863e1d5e9cffc13ffcf57ebd11a Mon Sep 17 00:00:00 2001 From: niladic Date: Wed, 28 Oct 2020 15:28:25 +0100 Subject: [PATCH 2/2] Fix missing polyfill for NodeList --- .gitignore | 6 +- typescript/src/application-attachment.ts | 76 ++++++++++++------------ typescript/src/index.ts | 2 + 3 files changed, 43 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index c99853942..3edd9e228 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,6 @@ files package-lock.json node_modules/ /public/generated-js/ -./project/metals.sbt -./project/project/metals.sbt -./project/project/project/metals.sbt +project/metals.sbt +project/project/metals.sbt +project/project/project/metals.sbt diff --git a/typescript/src/application-attachment.ts b/typescript/src/application-attachment.ts index bbe562b0a..837e47a78 100644 --- a/typescript/src/application-attachment.ts +++ b/typescript/src/application-attachment.ts @@ -1,55 +1,55 @@ interface ApplicationAttachment { - list: HTMLElement - fileInputCount: number - idSequence: number - increaseOrDecreaseFileInputList: (EventListener) => any + 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--; - } - } + 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); - }); + 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; - } + return attachment; + } } window.document.addEventListener("DOMContentLoaded", _ => { - "use strict"; - const attachmentList: HTMLElement | null = document.getElementById("attachment-list"); - attachment = main(attachmentList) + "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 dd024b5b3..0cf9094e9 100644 --- a/typescript/src/index.ts +++ b/typescript/src/index.ts @@ -1,6 +1,8 @@ // 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"