From 90f32ef32f702ed00ac6f4cd1a93a2227f53dcde Mon Sep 17 00:00:00 2001 From: Ivan Schneider Date: Mon, 30 Oct 2023 13:55:39 +0100 Subject: [PATCH] Convert some coffeescript files into JS --- app/assets/javascripts/autolinks.js | 18 ++++++++++++++++++ app/assets/javascripts/autolinks.js.coffee | 12 ------------ app/assets/javascripts/collaborators.js | 12 ++++++++++++ app/assets/javascripts/collaborators.js.coffee | 13 ------------- app/assets/javascripts/docs.js | 5 +++++ app/assets/javascripts/docs.js.coffee | 7 ------- app/assets/javascripts/timezone_select2.js | 4 ++++ .../javascripts/timezone_select2.js.coffee | 3 --- 8 files changed, 39 insertions(+), 35 deletions(-) create mode 100644 app/assets/javascripts/autolinks.js delete mode 100644 app/assets/javascripts/autolinks.js.coffee create mode 100644 app/assets/javascripts/collaborators.js delete mode 100644 app/assets/javascripts/collaborators.js.coffee create mode 100644 app/assets/javascripts/docs.js delete mode 100644 app/assets/javascripts/docs.js.coffee create mode 100644 app/assets/javascripts/timezone_select2.js delete mode 100644 app/assets/javascripts/timezone_select2.js.coffee diff --git a/app/assets/javascripts/autolinks.js b/app/assets/javascripts/autolinks.js new file mode 100644 index 000000000..2b3f5b27f --- /dev/null +++ b/app/assets/javascripts/autolinks.js @@ -0,0 +1,18 @@ +const autolinkQueryResults = () => { + $('.table td, dl dd').each(function(){ + const text = $(this).text() + if (text.match(/^\S+@\S+\.\S+$/)) { + $(this).append(` `) + } else { + if (text.match(/\d+\.\d+/)) { + return // Skip processing for numeric patterns with a dot + } + if (text.match(/^((http|ftp|https):\/\/)?[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?$/)) { + const link = text.match('://') ? text : `http://${text}` + $(this).append(` `) + } + } + }) +} + +$(autolinkQueryResults) diff --git a/app/assets/javascripts/autolinks.js.coffee b/app/assets/javascripts/autolinks.js.coffee deleted file mode 100644 index f8addb068..000000000 --- a/app/assets/javascripts/autolinks.js.coffee +++ /dev/null @@ -1,12 +0,0 @@ -autolinkQueryResults = -> - $('.table td, dl dd').each -> - text = $(this).text() - if text.match(/^\S+@\S+\.\S+$/) - $(this).append(" ") - else - return if text.match /\d+\.\d+/ - if text.match(/^((http|ftp|https):\/\/)?[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?$/) - link = if text.match('://') then text else "http://#{text}" - $(this).append(" ") - -$ autolinkQueryResults diff --git a/app/assets/javascripts/collaborators.js b/app/assets/javascripts/collaborators.js new file mode 100644 index 000000000..a0e5afb77 --- /dev/null +++ b/app/assets/javascripts/collaborators.js @@ -0,0 +1,12 @@ +$("input[name=all_actions]").click(function(){ + const scope = $(this).closest("tr").find("input:not(:first)") + scope.prop('checked', this.checked) +}) +const column_check = (index) => { + return () => { + const checked = $("table").find(`tr:first-child th:nth-child(${index+2}) input[type=checkbox]`).get(0).checked + const scope = $("table").find(`td:nth-child(${index+3}) input[type=checkbox]`) + scope.prop('checked', checked) + } +} +["create", "read", "update", "delete"].forEach((action, index) => $(`input[name=${action}_all]`).click(column_check(index))) diff --git a/app/assets/javascripts/collaborators.js.coffee b/app/assets/javascripts/collaborators.js.coffee deleted file mode 100644 index 0d5827d1b..000000000 --- a/app/assets/javascripts/collaborators.js.coffee +++ /dev/null @@ -1,13 +0,0 @@ -$ -> - $("input[name=all_actions]").click -> - scope = $(this).closest("tr").find("input:not(:first)") - scope.prop('checked', this.checked) - - column_check = (index) -> - -> - checked = $("table").find("tr:first-child th:nth-child(#{index+2}) input[type=checkbox]").get(0).checked - scope = $("table").find("td:nth-child(#{index+3}) input[type=checkbox]") - scope.prop('checked', checked) - - for action, index in ["create", "read", "update", "delete"] - $("input[name=#{action}_all]").click column_check(index) diff --git a/app/assets/javascripts/docs.js b/app/assets/javascripts/docs.js new file mode 100644 index 000000000..4df0ea97e --- /dev/null +++ b/app/assets/javascripts/docs.js @@ -0,0 +1,5 @@ +$('#cancel_tip').on('ajax:complete', (et, e) => { + if (!JSON.parse(e.responseText)) return + $("#welcome-modal .modal-footer").html("

Okay, tips will not appear anymore

") + setTimeout(() => $("#welcome-modal").modal('hide'), 1500) +}) diff --git a/app/assets/javascripts/docs.js.coffee b/app/assets/javascripts/docs.js.coffee deleted file mode 100644 index 120975969..000000000 --- a/app/assets/javascripts/docs.js.coffee +++ /dev/null @@ -1,7 +0,0 @@ -$ -> - $('#cancel_tip').on 'ajax:complete', (et, e) -> - if JSON.parse(e.responseText) - $("#welcome-modal .modal-footer").html("

Okay, tips will not appear anymore

") - setTimeout () -> - $("#welcome-modal").modal('hide') - , 1500 diff --git a/app/assets/javascripts/timezone_select2.js b/app/assets/javascripts/timezone_select2.js new file mode 100644 index 000000000..75ee16ba9 --- /dev/null +++ b/app/assets/javascripts/timezone_select2.js @@ -0,0 +1,4 @@ +$(() => { + const format = (state) => $('').html(state.text.replace(')', ')').replace('(GMT', '(GMT')) + $('.timezone_select2').select2({ templateResult: format, placeholder: '(GMT+00:00) UTC' }) +}) diff --git a/app/assets/javascripts/timezone_select2.js.coffee b/app/assets/javascripts/timezone_select2.js.coffee deleted file mode 100644 index f0688bdf7..000000000 --- a/app/assets/javascripts/timezone_select2.js.coffee +++ /dev/null @@ -1,3 +0,0 @@ -$ -> - format = (state) -> $('').html(state.text.replace(')', ')').replace('(GMT', '(GMT')) - $('.timezone_select2').select2(templateResult: format, placeholder: '(GMT+00:00) UTC')