From 4b7f3130abc295a9dbb8ac2ab9b0bb37b30193cb Mon Sep 17 00:00:00 2001 From: sfisher Date: Thu, 7 Nov 2024 16:02:25 -0800 Subject: [PATCH 1/3] This gets the homepage "try" creation for identifiers working, but something has messed up the layout in "create id" now. --- impl/ui_home.py | 18 +++++++++ settings/urls.py | 1 + static_src/javascripts/simple_create_ajax.js | 29 ++++++++++++++ templates/create/_home_demo_form.html | 40 +++++++++++++++++++ templates/index.html | 42 +++----------------- 5 files changed, 93 insertions(+), 37 deletions(-) create mode 100644 static_src/javascripts/simple_create_ajax.js create mode 100644 templates/create/_home_demo_form.html diff --git a/impl/ui_home.py b/impl/ui_home.py index aa31a6672..12d08f505 100644 --- a/impl/ui_home.py +++ b/impl/ui_home.py @@ -35,6 +35,24 @@ def index(request): "/id/" + urllib.parse.quote(result.split()[1], ":/") ) # ID Details page +def ajax_index_form(request): + if request.method not in ["GET"]: + return impl.ui_common.methodNotAllowed(request) + d = {'menu_item': 'ui_home.index'} + d['prefixes'] = sorted( + django.conf.settings.TEST_SHOULDER_DICT, key=lambda p: p['namespace'].lower() + ) + d['form_placeholder'] = True # is this necessary? + d = impl.ui_create.simple_form(request, d) + result = d['id_gen_result'] + if result == 'edit_page': + # noinspection PyUnresolvedReferences + # return impl.ui_common.render(request, 'index', d) # ID Creation page + return impl.ui_common.render(request, 'create/_home_demo_form', d) + # return render(request, 'create/home_demo_form.html', d) + elif result == 'bad_request': + return impl.ui_common.badRequest(request) + def learn(request): if request.method != "GET": diff --git a/settings/urls.py b/settings/urls.py index 5d7c2917d..f3763377e 100644 --- a/settings/urls.py +++ b/settings/urls.py @@ -33,6 +33,7 @@ urlpatterns = [ # UI - RENDERED FROM TEMPLATES IN INFO REPOSITORY django.urls.re_path("^$", impl.ui_home.index, name="ui_home.index"), + django.urls.re_path("^home/ajax_index_form$", impl.ui_home.ajax_index_form, name="ui_home.ajax_index_form"), django.urls.re_path("^learn/$", impl.ui_home.learn, name="ui_home.learn"), django.urls.re_path("^learn/ark_open_faq$", impl.ui_home.ark_open_faq, name="ui_home.ark_open_faq"), django.urls.re_path("^learn/crossref_faq$", impl.ui_home.crossref_faq, name="ui_home.crossref_faq"), diff --git a/static_src/javascripts/simple_create_ajax.js b/static_src/javascripts/simple_create_ajax.js new file mode 100644 index 000000000..f371dc0b9 --- /dev/null +++ b/static_src/javascripts/simple_create_ajax.js @@ -0,0 +1,29 @@ +document.getElementById('form-shoulder').value = document.querySelectorAll('input[name=selshoulder]')[0].value; + +document.querySelectorAll('input[name="selshoulder"]').forEach(radio => { + radio.addEventListener('change', function () { + var profile; + if(this.value.startsWith('ark')) { + profile = 'erc'; + } else { + profile = 'datacite'; + } + + const form = document.querySelector('#create_form'); + const formData = new FormData(form); + formData.set('current_profile', profile); + + // Convert FormData to a query string + const queryString = new URLSearchParams(formData).toString(); + fetch(`/home/ajax_index_form?${queryString}`, { + headers: { + 'X-CSRFToken': document.querySelector('input[name="csrfmiddlewaretoken"]').value, + }, + }) + .then(response => response.text()) + .then(data => { + document.getElementById('form-container').innerHTML = data; // Replace form container HTML + document.getElementById('form-shoulder').value = this.value; // needs to happen after the form is replaced + }); + }); +}); \ No newline at end of file diff --git a/templates/create/_home_demo_form.html b/templates/create/_home_demo_form.html new file mode 100644 index 000000000..575c87cb6 --- /dev/null +++ b/templates/create/_home_demo_form.html @@ -0,0 +1,40 @@ +{% load i18n %} +{% load layout_extras %} +
+ + +{% csrf_token %} + +
+ +
+ {% trans "Describe the identified object" %} +
+ +
+ {{ form.non_field_errors }} + {% for field in form %} +
+
+ {% if field|fieldtype == "TextInput" %} + + {{ field|add_attributes:"fcontrol__text-field-stacked" }} + {% else %} + + {{ field|add_attributes:"fcontrol__select" }} + {% endif %} + {% if field.errors %} + {% for error in field.errors %}{{ error|escape }}{% endfor %} + {% endif %} +
+
+ {% endfor %} + +
+ +
+ +
+
+
\ No newline at end of file diff --git a/templates/index.html b/templates/index.html index df3f11e6e..227aedf7c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -19,6 +19,7 @@ } {% endblock %} {% block content %} +{% csrf_token %}

EZID: {% trans "Identifiers made easy" %}

@@ -52,53 +53,20 @@

EZID: {% trans "Identifiers made easy" %}

-
-
{% trans "Choose an identifier type" %} {% for p in prefixes %} {% endfor %} {% help_icon "choose_id_demo" _("on choosing the type of identifier") %}
- -
- -
- {% trans "Describe the identified object" %} -
- -
- {{ form.non_field_errors }} - {% for field in form %} -
-
- {% if field|fieldtype == "TextInput" %} - - {{ field|add_attributes:"fcontrol__text-field-stacked" }} - {% else %} - - {{ field|add_attributes:"fcontrol__select" }} - {% endif %} - {% if field.errors %} - {% for error in field.errors %}{{ error|escape }}{% endfor %} - {% endif %} -
-
- {% endfor %} - -
- -
- -
+
+ {% include "create/_home_demo_form.html" %}
-
- + {% include "info/popup_help.html" %} From 7cb0ca165537f33b08ee7d529e321464f93c51ce Mon Sep 17 00:00:00 2001 From: sfisher Date: Fri, 8 Nov 2024 16:34:38 -0800 Subject: [PATCH 2/3] Need to change this fieldset back to a div since otherwise it destroys the whole layout of the form. --- templates/includes/simple_id_type.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/includes/simple_id_type.html b/templates/includes/simple_id_type.html index c49da366b..d7cc2876d 100644 --- a/templates/includes/simple_id_type.html +++ b/templates/includes/simple_id_type.html @@ -1,14 +1,14 @@ {% load layout_extras %} {% load i18n %} -
+

{% trans "Choose an identifier type" %}

{% if calling_page == 'demo' %} {% help_icon "choose_id_demo" _("on choosing the type of identifier") %} {% else %} {% help_icon "choose_id" _("on choosing the type of identifier") %} {% endif %} -
+ {% if prefixes|duplicate_id_types %} {% comment %} class 'ays-ignore' is used by 'are-you-sure.js' which prevents users from accidentally leaving From fac439fa005666b0f457ebbb8304921f0bedaedb Mon Sep 17 00:00:00 2001 From: sfisher Date: Tue, 12 Nov 2024 17:34:25 -0800 Subject: [PATCH 3/3] Change this to a heading, I guess I missed this particular place. --- templates/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/index.html b/templates/index.html index 227aedf7c..d2127354a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -34,7 +34,7 @@

EZID: {% trans "Identifiers made easy" %}

-

{% trans "See how easy it is" %}:

+

{% trans "See how easy it is" %}:

{% comment %}Translators: Copy HTML tags over and only translate words outside of these tags i.e.:

TRANSLATE TEXT WRAPPED BY HTML TAGS