Dynamic login in editor.
authorRadek Czajka <rczajka@rczajka.pl>
Wed, 7 Jul 2021 14:19:04 +0000 (16:19 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Wed, 7 Jul 2021 14:19:04 +0000 (16:19 +0200)
src/redakcja/static/js/wiki/base.js
src/redakcja/templates/registration/head_login.html
src/wiki/templates/wiki/back.html [new file with mode: 0644]
src/wiki/templates/wiki/document_details_base.html
src/wiki/templates/wiki/editor-user-area.html [new file with mode: 0644]
src/wiki/urls.py
src/wiki/views.py

index 32554b1..5262ab7 100644 (file)
                }
        };
 
+
+    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);
index 26ccfb5..4af3db9 100644 (file)
@@ -17,6 +17,6 @@
 {% else %}
   {% url "cas_ng_login" as login_url %}
   {% if login_url != request.path %}
-    <a class="nav-item nav-link" href='{{ login_url }}'>{% trans "Log In" %}</a>
+    <a id="login" class="nav-item nav-link" href='{{ login_url }}'>{% trans "Log In" %}</a>
   {% endif %}
 {% endif %}
diff --git a/src/wiki/templates/wiki/back.html b/src/wiki/templates/wiki/back.html
new file mode 100644 (file)
index 0000000..10677ad
--- /dev/null
@@ -0,0 +1,3 @@
+<script>
+ window.opener.postMessage('login');
+</script>
index 6cf2543..75d2911 100644 (file)
     <div class='navbar-nav'>
       <a class='nav-item nav-link' href="{{ REDMINE_URL }}projects/wl-publikacje/wiki/Pomoc" target="_blank">
         {% trans "Help" %}</a>
-      {% include "registration/head_login.html" %}
+
+
+      <div id="user-area">
+        {% include "registration/head_login.html" %}
+        {% block dialogs %} {% endblock %}
+      </div>
+
+
+
+
       <span class="navbar-text">{% trans "Version" %}: <span id="document-revision">{% trans "Unknown" %}</span></span>
       {% if not readonly %}
         <button class='ml-2 nav-item btn btn-primary' id="save-button">{% trans "Save" %}</button>
@@ -64,6 +73,5 @@
     {% block splitter-extra %} {% endblock %}
   </div>
 
-  {% 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 (file)
index 0000000..f4e6783
--- /dev/null
@@ -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 %}
index ddc0dfc..f1a4508 100644 (file)
@@ -31,4 +31,7 @@ urlpatterns = [
     url(r'^pubmark/(?P<chunk_id>\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),
 ]
index b664d30..7bcea51 100644 (file)
@@ -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')