This is an automated email from the ASF dual-hosted git repository. beto pushed a commit to branch remove_jquery in repository https://gitbox.apache.org/repos/asf/superset.git
commit 375a0f479e4846af0cd64b184a3b80a5d14be201 Author: Beto Dealmeida <[email protected]> AuthorDate: Fri Mar 19 12:14:41 2021 -0700 chore: remove jquery --- superset-frontend/src/setup/setupApp.ts | 60 ---------------------- .../form_view/csv_to_database_view/edit.html | 51 +++++++++--------- 2 files changed, 28 insertions(+), 83 deletions(-) diff --git a/superset-frontend/src/setup/setupApp.ts b/superset-frontend/src/setup/setupApp.ts index ba3b9ac..69dda10 100644 --- a/superset-frontend/src/setup/setupApp.ts +++ b/superset-frontend/src/setup/setupApp.ts @@ -18,11 +18,6 @@ */ /* eslint global-require: 0 */ import $ from 'jquery'; -import { SupersetClient } from '@superset-ui/core'; -import { - getClientErrorObject, - ClientErrorObject, -} from 'src/utils/getClientErrorObject'; import setupErrorMessages from 'src/setup/setupErrorMessages'; // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -33,62 +28,7 @@ declare global { } } -function showApiMessage(resp: ClientErrorObject) { - const template = - '<div class="alert"> ' + - '<button type="button" class="close" ' + - 'data-dismiss="alert">\xD7</button> </div>'; - const severity = resp.severity || 'info'; - $(template) - .addClass(`alert-${severity}`) - .append(resp.message || '') - .appendTo($('#alert-container')); -} - -function toggleCheckbox(apiUrlPrefix: string, selector: string) { - SupersetClient.get({ - endpoint: apiUrlPrefix + ($(selector)[0] as HTMLInputElement).checked, - }) - .then(() => undefined) - .catch(response => - getClientErrorObject(response).then(parsedResp => { - if (parsedResp && parsedResp.message) { - showApiMessage(parsedResp); - } - }), - ); -} - export default function setupApp() { - $(document).ready(function () { - $(':checkbox[data-checkbox-api-prefix]').change(function ( - this: HTMLElement, - ) { - const $this = $(this); - const prefix = $this.data('checkbox-api-prefix'); - const id = $this.attr('id'); - toggleCheckbox(prefix, `#${id}`); - }); - - // for language picker dropdown - $('#language-picker a').click(function ( - ev: JQuery.ClickEvent< - HTMLLinkElement, - null, - HTMLLinkElement, - HTMLLinkElement - >, - ) { - ev.preventDefault(); - SupersetClient.get({ - url: ev.currentTarget.href, - parseMethod: null, - }).then(() => { - window.location.reload(); - }); - }); - }); - // A set of hacks to allow apps to run within a FAB template // this allows for the server side generated menus to function window.$ = $; diff --git a/superset/templates/superset/form_view/csv_to_database_view/edit.html b/superset/templates/superset/form_view/csv_to_database_view/edit.html index ab647d4..3509b70 100644 --- a/superset/templates/superset/form_view/csv_to_database_view/edit.html +++ b/superset/templates/superset/form_view/csv_to_database_view/edit.html @@ -21,43 +21,48 @@ {% block tail_js %} {{ super() }} <script> - var db = $("#con"); - var schema = $("#schema"); + var db = document.getElementById("con"); + var schema = document.getElementById("schema"); // this element is a text input // copy it here so it can be reused later - var any_schema_is_allowed = schema.clone(); + var any_schema_is_allowed = schema.cloneNode(); - update_schemas_allowed_for_csv_upload(db.val()); - db.change(function(){ - update_schemas_allowed_for_csv_upload(db.val()); + update_schemas_allowed_for_csv_upload(db.value); + db.addEventListener("change", function(){ + update_schemas_allowed_for_csv_upload(db.value); }); function update_schemas_allowed_for_csv_upload(db_id) { - $.ajax({ - method: "GET", - url: "/superset/schemas_access_for_csv_upload", - data: {db_id: db_id}, - dataType: 'json', - contentType: "application/json; charset=utf-8" - }).done(function(data) { - change_schema_field_in_formview(data) - }).fail(function(error) { - var errorMsg = error.responseJSON.error; - alert("ERROR: " + errorMsg); - }); + const request = new XMLHttpRequest(); + request.open("GET", "/superset/schemas_access_for_csv_upload?db_id=" + db_id, true); + request.onload = function () { + if (this.status == 200) { + change_schema_field_in_formview(JSON.parse(request.responseText)); + } + }; + request.onerror = function () { + var errorMsg = request.responseText; + alert("ERROR: " + errorMsg); + }; + request.send(); } function change_schema_field_in_formview(schemas_allowed){ if (schemas_allowed && schemas_allowed.length > 0) { - var dropdown_schema_lists = '<select id="schema" name="schema" required>'; + var dropdown_schema_lists = document.createElement("select"); + dropdown_schema_lists.setAttribute("id", "schema"); + dropdown_schema_lists.setAttribute("name", "schema"); + dropdown_schema_lists.setAttribute("required", "required"); schemas_allowed.forEach(function(schema_allowed) { - dropdown_schema_lists += ('<option value="' + schema_allowed + '">' + schema_allowed + '</option>'); + var option = document.createElement("option"); + option.setAttribute("value", schema_allowed); + option.appendChild(document.createTextNode(schema_allowed)); + dropdown_schema_lists.appendChild(option); }); - dropdown_schema_lists += '</select>'; - $("#schema").replaceWith(dropdown_schema_lists); + schema.replaceWith(dropdown_schema_lists); } else { - $("#schema").replaceWith(any_schema_is_allowed) + schema.replaceWith(any_schema_is_allowed) } } </script>
