From c6c257380f1ff975db6a54e96f3ab2a34aa166c2 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Wed, 7 Jul 2021 16:19:04 +0200 Subject: [PATCH 1/1] Dynamic login in editor. --- src/redakcja/static/js/wiki/base.js | 24 +++++++++++++++++++ .../templates/registration/head_login.html | 2 +- src/wiki/templates/wiki/back.html | 3 +++ .../templates/wiki/document_details_base.html | 12 ++++++++-- src/wiki/templates/wiki/editor-user-area.html | 6 +++++ src/wiki/urls.py | 3 +++ src/wiki/views.py | 15 ++++++++++++ 7 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 src/wiki/templates/wiki/back.html create mode 100644 src/wiki/templates/wiki/editor-user-area.html diff --git a/src/redakcja/static/js/wiki/base.js b/src/redakcja/static/js/wiki/base.js index 32554b17..5262ab72 100644 --- a/src/redakcja/static/js/wiki/base.js +++ b/src/redakcja/static/js/wiki/base.js @@ -339,4 +339,28 @@ } }; + + window.addEventListener("message", (event) => { + event.source.close() + + $.ajax("/editor/editor-user-area/", { + success: function(d) { + $("#user-area")[0].innerHTML = d; + } + }); + }, false); + + $("#login").click(function (e) { + e.preventDefault(); + let h = 600; + let w = 500; + let x = window.screenX + (window.innerWidth - w) / 2; + let y = window.screenY + (window.innerHeight - h) / 2; + window.open( + "/accounts/login/?next=/editor/back", + "login-window", + "width=" + w + " height=" + h + " top=" + y + " left=" + x + ); + }); + })(jQuery); diff --git a/src/redakcja/templates/registration/head_login.html b/src/redakcja/templates/registration/head_login.html index 26ccfb5e..4af3db92 100644 --- a/src/redakcja/templates/registration/head_login.html +++ b/src/redakcja/templates/registration/head_login.html @@ -17,6 +17,6 @@ {% else %} {% url "cas_ng_login" as login_url %} {% if login_url != request.path %} - {% trans "Log In" %} + {% trans "Log In" %} {% endif %} {% endif %} diff --git a/src/wiki/templates/wiki/back.html b/src/wiki/templates/wiki/back.html new file mode 100644 index 00000000..10677ad5 --- /dev/null +++ b/src/wiki/templates/wiki/back.html @@ -0,0 +1,3 @@ + diff --git a/src/wiki/templates/wiki/document_details_base.html b/src/wiki/templates/wiki/document_details_base.html index 6cf25432..75d2911e 100644 --- a/src/wiki/templates/wiki/document_details_base.html +++ b/src/wiki/templates/wiki/document_details_base.html @@ -48,7 +48,16 @@ - {% block dialogs %} {% endblock %} {% endblock %} diff --git a/src/wiki/templates/wiki/editor-user-area.html b/src/wiki/templates/wiki/editor-user-area.html new file mode 100644 index 00000000..f4e6783f --- /dev/null +++ b/src/wiki/templates/wiki/editor-user-area.html @@ -0,0 +1,6 @@ +{% include "registration/head_login.html" %} +{% include "wiki/save_dialog.html" %} +{% include "wiki/revert_dialog.html" %} +{% if can_pubmark %} + {% include "wiki/pubmark_dialog.html" %} +{% endif %} diff --git a/src/wiki/urls.py b/src/wiki/urls.py index ddc0dfcb..f1a45087 100644 --- a/src/wiki/urls.py +++ b/src/wiki/urls.py @@ -31,4 +31,7 @@ urlpatterns = [ url(r'^pubmark/(?P\d+)/$', views.pubmark, name="wiki_pubmark"), url(r'^themes$', views.themes, name="themes"), + + url(r'^back/$', views.back), + url(r'^editor-user-area/$', views.editor_user_area), ] diff --git a/src/wiki/views.py b/src/wiki/views.py index b664d301..7bcea51f 100644 --- a/src/wiki/views.py +++ b/src/wiki/views.py @@ -77,6 +77,17 @@ def editor(request, slug, chunk=None, template_name='wiki/document_details.html' }) +def editor_user_area(request): + return render(request, 'wiki/editor-user-area.html', { + 'forms': { + "text_save": forms.DocumentTextSaveForm(user=request.user, prefix="textsave"), + "text_revert": forms.DocumentTextRevertForm(prefix="textrevert"), + "pubmark": forms.DocumentPubmarkForm(prefix="pubmark"), + }, + 'can_pubmark': request.user.has_perm('documents.can_pubmark'), + }) + + @require_GET def editor_readonly(request, slug, chunk=None, template_name='wiki/document_details_readonly.html'): try: @@ -314,3 +325,7 @@ def pubmark(request, chunk_id): def themes(request): prefix = request.GET.get('q', '') return http.HttpResponse('\n'.join([str(t) for t in Theme.objects.filter(name__istartswith=prefix)])) + + +def back(request): + return render(request, 'wiki/back.html') -- 2.20.1