Skip to content

Commit

Permalink
fix: Several fixes for the versioning forms: django-cms#382, django-c…
Browse files Browse the repository at this point in the history
…ms#383, django-cms#384 (django-cms#386)

* fix django-cms#384: Unlock button in toolbar points onto DRAFT version

* Fix django-cms#382, django-cms#383

---------

Co-authored-by: Jacob Rief <[email protected]>
  • Loading branch information
fsbraun and jrief authored Mar 5, 2024
1 parent 93a3e52 commit 2d22c0d
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 21 deletions.
1 change: 0 additions & 1 deletion djangocms_versioning/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,6 @@ def publish_view(self, request, object_id):

# Redirect to published?
if conf.ON_PUBLISH_REDIRECT == "published":
redirect_url = None
if hasattr(version.content, "get_absolute_url"):
redirect_url = version.content.get_absolute_url() or redirect_url

Expand Down
4 changes: 2 additions & 2 deletions djangocms_versioning/cms_toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def _add_unlock_button(self):
if LOCK_VERSIONS and self._is_versioned():
item = ButtonList(side=self.toolbar.RIGHT)
proxy_model = self._get_proxy_model()
version = Version.objects.get_for_content(self.toolbar.obj)
if version.check_unlock.as_bool(self.request.user):
version = Version.objects.filter_by_content_grouping_values(self.toolbar.obj).filter(state=DRAFT).first()
if version and version.check_unlock.as_bool(self.request.user):
unlock_url = reverse(
f"admin:{proxy_model._meta.app_label}_{proxy_model.__name__.lower()}_unlock",
args=(version.pk,),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,3 @@ ins.cms-diff img {
.cms-select::-ms-expand {
opacity: 0;
}
input.button.revert-button {
margin: 5px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(function () {
"use strict";

function closeSideFrame() {
try {
window.top.CMS.API.Sideframe.close();
} catch (err) {}
}

document.addEventListener('DOMContentLoaded', function () {
document.querySelectorAll('form.js-close-sideframe').forEach(el => {
el.addEventListener("submit", (ev) => {
ev.preventDefault();
closeSideFrame();
const form = window.top.document.body.appendChild(ev.target);
form.style.display = 'none';
form.submit();
});
});
});
})();
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
{{ block.super }}
{{ media }}
<script type="text/javascript" src="{% static 'admin/js/cancel.js' %}"></script>
<script type="text/javascript" src="{% static 'djangocms_versioning/js/admin/versioning-actions.js' %}"></script>
{% endblock %}

{% block breadcrumbs %}{% endblock %}
Expand All @@ -15,15 +16,17 @@
<p>{% translate "Are you sure you want to archive the following version?" %}</p>
<h3>{{ object_name }}</h3>
<h4>{% blocktrans %} Version number: {{ version_number }}{% endblocktrans %}</h4>
<form action="" method="POST">
<form action="" method="POST" class="js-close-sideframe">
{% csrf_token %}
<input class="button confirm-link js-versioning-keep-sideframe"
type="submit"
value="{% translate "Yes, I'm sure" %}">
<a href="{{ back_url }}">
<input type="button"
class="button js-versioning-keep-sideframe"
value="{% translate 'No, take me back' %}">
</a>
<div class="submit-row">
<input class="button confirm-link"
type="submit"
value="{% translate "Yes, I'm sure" %}">
<a href="{{ back_url }}">
<input type="button"
class="button js-versioning-keep-sideframe"
value="{% translate 'No, take me back' %}">
</a>
</div>
</form>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
{{ media }}
<link rel="stylesheet" href="{% static 'djangocms_versioning/css/versioning.css' %}">
<script type="text/javascript" src="{% static 'admin/js/cancel.js' %}"></script>
<script type="text/javascript" src="{% static 'djangocms_versioning/js/admin/versioning-actions.js' %}"></script>
{% endblock %}

{% block breadcrumbs %}{% endblock %}
Expand All @@ -22,20 +23,20 @@ <h1>{% block title %}{% translate "Revert Confirmation" %}{% endblock %}</h1>
</p>
<h3>{{ object_name }}</h3>
<h4>{% blocktrans %}Version number: {{ version_number }}{% endblocktrans %}</h4>
<form action="" method="POST">
<form action="" method="POST" class="js-close-sideframe">
{% csrf_token %}
<div class="submit-row">
{% if draft_version %}
<input class="button revert-button confirm-link js-versioning-keep-sideframe"
<input class="button revert-button confirm-link"
type="submit"
name="discard"
value="{% translate 'Discard existing draft and Revert' %}">
<input class="button revert-button confirm-link js-versioning-keep-sideframe"
<input class="button revert-button confirm-link"
name="archive"
type="submit"
value="{% translate 'Archive existing draft and Revert' %}">
{% else %}
<input class="button revert-button confirm-link js-versioning-keep-sideframe"
<input class="button revert-button confirm-link"
type="submit"
name="revert"
value="{% translate "Yes, I'm sure" %}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{{ block.super }}
{{ media }}
<script type="text/javascript" src="{% static 'admin/js/cancel.js' %}"></script>
<script type="text/javascript" src="{% static 'djangocms_versioning/js/admin/versioning-actions.js' %}"></script>
{% endblock %}

{% block breadcrumbs %}{% endblock %}
Expand All @@ -20,10 +21,10 @@ <h4>{% blocktrans %} Version number: {{ version_number }}{% endblocktrans %}</h4
<p>{{thing}}</p>
{% endfor %}
</div>
<form action="" method="POST">
<form action="" method="POST" class="js-close-sideframe">
{% csrf_token %}
<div class="submit-row">
<input class="button confirm-link js-versioning-keep-sideframe"
<input class="button confirm-link"
type="submit"
value="{% translate "Yes, I'm sure" %}">
<a href="{{ back_url }}">
Expand Down

0 comments on commit 2d22c0d

Please sign in to comment.