Skip to content

Commit abc8ea7

Browse files
authored
fix: burger menu to also work with new core icons (#323)
* Fix burger menu to work with core icons and/or img icons * Fix: added missing preventDefault to dropdown js * Fix bug that in rare cases showed an unpublished indicator for an archived version * Fix test * Update changelog * Django CMS 4.1.0rc2 compatibility * Update admin.py
1 parent 1e8a48c commit abc8ea7

File tree

7 files changed

+48
-56
lines changed

7 files changed

+48
-56
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Changelog
44

55
Unreleased
66
==========
7+
* fix: burger menu adjusts to the design of django cms core dropdown
8+
* fix: bug that showed an archived version as unpublished in some cases in the state indicator
79
* add: Dutch and French translations thanks to Stefan van den Eertwegh and François Palmierso
810
* add: transifex support, German translations
911
* add: Revert button as replacement for dysfunctional Edit button for unpublished

djangocms_versioning/admin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class Media:
215215
js = ("admin/js/jquery.init.js", "djangocms_versioning/js/actions.js")
216216
css = {
217217
"all": (
218-
static_with_version("cms/css/cms.icons.css"),
218+
static_with_version("cms/css/cms.admin.css"),
219219
"djangocms_versioning/css/actions.css",
220220
)
221221
}
@@ -493,7 +493,7 @@ class VersionAdmin(admin.ModelAdmin):
493493
class Media:
494494
js = ("admin/js/jquery.init.js", "djangocms_versioning/js/actions.js", "djangocms_versioning/js/compare.js",)
495495
css = {"all": (
496-
static_with_version("cms/css/cms.icons.css"),
496+
static_with_version("cms/css/cms.admin.css"),
497497
"djangocms_versioning/css/actions.css",
498498
)}
499499

djangocms_versioning/indicators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ def content_indicator(content_obj):
108108
elif signature[PUBLISHED]:
109109
content_obj._indicator_status = "published"
110110
content_obj._version = signature[PUBLISHED]
111-
elif signature[UNPUBLISHED]:
111+
elif versions[0].state == UNPUBLISHED:
112112
content_obj._indicator_status = "unpublished"
113113
content_obj._version = signature[UNPUBLISHED]
114-
elif signature[ARCHIVED]:
114+
elif versions[0].state == ARCHIVED:
115115
content_obj._indicator_status = "archived"
116116
content_obj._version = signature[ARCHIVED]
117117
else: # pragma: no cover

djangocms_versioning/static/djangocms_versioning/css/actions.css

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ extending the pagetree classes provided by CMS
8888
width: 10px;
8989
height: 10px;
9090
margin-left: -5px;
91-
background-color: #fff;
91+
background-color: var(--dca-white, var(--body-bg, #fff));
9292
box-shadow: 0 0 10px rgba(0,0,0,.25);
9393
-webkit-transform: rotate(45deg) translateZ(0);
9494
transform: rotate(45deg) translateZ(0);
9595
}
9696

9797
.cms-actions-dropdown-menu.open {
9898
display: block;
99-
width: 200px;
99+
width: fit-content;
100100
}
101101

102102
.cms-actions-dropdown-menu.closed {
@@ -117,18 +117,18 @@ ul.cms-actions-dropdown-menu-inner {
117117
margin: 0;
118118
padding: 0 !important;
119119
border-radius: 5px;
120-
background-color: #fff;
120+
background-color: var(--dca-white, var(--body-bg, #fff));
121+
overflow: hidden;
121122
}
122123

123124
ul.cms-actions-dropdown-menu-inner li {
124-
border: 1px solid transparent;
125-
border-radius: 5px;
126-
padding: 2px 6px;
125+
border: 0px solid transparent;
126+
padding: 0;
127127
list-style-type: none;
128128
}
129129
ul.cms-actions-dropdown-menu-inner li:hover {
130-
border: 1px solid #ccc;
131-
background-color: #0bf;
130+
border: 0px solid var(--dca-gray-lighter, var(--border-color, #ccc));
131+
background-color: var(--dca-primary, var(--primary, #79aec8));
132132
}
133133

134134
a.cms-actions-dropdown-menu-item-anchor {
@@ -147,27 +147,23 @@ a.cms-actions-dropdown-menu-item-anchor:visited,
147147
a.cms-actions-dropdown-menu-item-anchor:link,
148148
a.cms-actions-dropdown-menu-item-anchor:link:visited
149149
{
150-
color: #666 !important;
150+
color: unset !important;
151151
}
152152
a.cms-actions-dropdown-menu-item-anchor:hover,
153153
a.cms-actions-dropdown-menu-item-anchor:active,
154154
a.cms-actions-dropdown-menu-item-anchor:link:hover,
155155
a.cms-actions-dropdown-menu-item-anchor:link:active
156156
{
157-
color: #fff !important;
158-
background: #0bf;
157+
color: var(--dca-white, var(--body-bg, #fff)) !important;
158+
background: var(--dca-primary, var(--primary, #79aec8));
159159
}
160160

161161
/* set the size of the option icon */
162-
a.cms-actions-dropdown-menu-item-anchor img {
162+
a.cms-actions-dropdown-menu-item-anchor span.cms-icon {
163163
width: 20px;
164164
height: 20px;
165-
}
166-
/* align the option text with it's icon */
167-
a.cms-actions-dropdown-menu-item-anchor span {
168-
line-height: 1rem;
169-
vertical-align: 20%;
170-
margin-left: 10px;
165+
margin-right: 10px;
166+
vertical-align: middle;
171167
}
172168
/* disable any inactive option */
173169
a.cms-actions-dropdown-menu-item-anchor.inactive {

djangocms_versioning/static/djangocms_versioning/js/actions.js

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,7 @@
6868
// Create burger menu:
6969
$(function() {
7070

71-
let burger_menu_icon;
72-
if(typeof(versioning_static_url_prefix) != 'undefined'){
73-
burger_menu_icon = `${versioning_static_url_prefix}svg/menu.svg`;
74-
} else {
75-
burger_menu_icon = '/static/djangocms_versioning/svg/menu.svg';
76-
console.warn('"versioning_static_url_prefix" not defined! No value has been provided for static_url, '
77-
+ 'defaulting to "/static/djangocms_versioning/svg/" for icon location.');
78-
}
79-
80-
let createBurgerMenu = function createBurgerMenu(row) {
71+
let createBurgerMenu = function createBurgerMenu(row) {
8172

8273
let actions = $(row).children('.field-list_actions');
8374
if (!actions.length) {
@@ -87,9 +78,9 @@
8778

8879
/* create burger menu anchor icon */
8980
let anchor = document.createElement('a');
90-
let icon = document.createElement('img');
81+
let icon = document.createElement('span');
9182

92-
icon.setAttribute('src', burger_menu_icon);
83+
icon.setAttribute('class', 'cms-icon cms-icon-menu');
9384
anchor.setAttribute('class', 'btn cms-versioning-action-btn closed');
9485
anchor.setAttribute('title', 'Actions');
9586
anchor.appendChild(icon);
@@ -107,7 +98,6 @@
10798

10899
/* get the existing actions and move them into the options container */
109100
$(actions[0]).children('.cms-versioning-action-btn').each(function (index, item) {
110-
111101
/* exclude preview and edit buttons */
112102
if (item.classList.contains('cms-versioning-action-preview') ||
113103
item.classList.contains('cms-versioning-action-edit')) {
@@ -123,11 +113,12 @@
123113
if ($(item).hasClass('cms-form-get-method')) {
124114
li_anchor.classList.add('cms-form-get-method'); // Ensure the fake-form selector is propagated to the new anchor
125115
}
126-
/* move the icon image */
127-
li_anchor.appendChild($(item).children('img')[0]);
116+
/* move the icon */
117+
li_anchor.appendChild($(item).children()[0]);
128118

129119
/* create the button text and construct the button */
130120
let span = document.createElement('span');
121+
span.setAttribute('class', 'label');
131122
span.appendChild(
132123
document.createTextNode(item.title)
133124
);
@@ -140,21 +131,23 @@
140131
actions[0].removeChild(item);
141132
});
142133

143-
/* add the options to the drop-down */
144-
optionsContainer.appendChild(ul);
145-
actions[0].appendChild(anchor);
146-
document.body.appendChild(optionsContainer);
147-
148-
/* listen for burger menu clicks */
149-
anchor.addEventListener('click', function (ev) {
150-
ev.stopPropagation();
151-
toggleBurgerMenu(anchor, optionsContainer);
152-
});
153-
154-
/* close burger menu if clicking outside */
155-
$(window).click(function () {
156-
closeBurgerMenu();
157-
});
134+
if ($(ul).children().length > 0) {
135+
/* add the options to the drop-down */
136+
optionsContainer.appendChild(ul);
137+
actions[0].appendChild(anchor);
138+
document.body.appendChild(optionsContainer);
139+
140+
/* listen for burger menu clicks */
141+
anchor.addEventListener('click', function (ev) {
142+
ev.stopPropagation();
143+
toggleBurgerMenu(anchor, optionsContainer);
144+
});
145+
146+
/* close burger menu if clicking outside */
147+
$(window).click(function () {
148+
closeBurgerMenu();
149+
});
150+
}
158151
};
159152

160153
let toggleBurgerMenu = function toggleBurgerMenu(burgerMenuAnchor, optionsContainer) {
@@ -172,8 +165,8 @@
172165
}
173166

174167
let pos = bm.offset();
175-
op.css('left', pos.left - 200);
176-
op.css('top', pos.top);
168+
op.css('left', pos.left - op.width() - 5);
169+
op.css('top', pos.top - 2);
177170
};
178171

179172
let closeBurgerMenu = function closeBurgerMenu() {

djangocms_versioning/static/djangocms_versioning/js/indicators.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
$(function() {
108108
$('.js-cms-pagetree-dropdown-trigger').click(function(event) {
109109
event.stopPropagation();
110+
event.preventDefault();
110111
var menu = JSON.parse(this.dataset.menu);
111112
menu = open_menu(menu);
112113
var offset = $(this).offset();

tests/test_indicators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ def test_page_indicators(self):
159159
args=(pk,)))
160160
self.assertEqual(response.status_code, 302) # Sends a redirect
161161

162-
# Is unpublished indicator? No draft indicator
162+
# Is archived indicator? No draft indicator
163163
response = self.client.get(page_tree, {"language": "en"})
164-
self.assertContains(response, "cms-pagetree-node-state-unpublished")
164+
self.assertContains(response, "cms-pagetree-node-state-archived")
165165
self.assertNotContains(response, "cms-pagetree-node-state-draft")
166166

167167
# Now revert

0 commit comments

Comments
 (0)