|
12 | 12 | from cms.api import get_page_draft, can_change_page
|
13 | 13 | from cms.constants import TEMPLATE_INHERITANCE_MAGIC, PUBLISHER_STATE_PENDING
|
14 | 14 | from cms.models import CMSPlugin, Title, Page
|
15 |
| -from cms.toolbar.items import TemplateItem, REFRESH_PAGE |
| 15 | +from cms.toolbar.items import ButtonList, TemplateItem, REFRESH_PAGE |
16 | 16 | from cms.toolbar_base import CMSToolbar
|
17 | 17 | from cms.toolbar_pool import toolbar_pool
|
18 | 18 | from cms.utils.i18n import get_language_tuple, force_language, get_language_dict, get_default_language
|
@@ -364,25 +364,30 @@ def has_dirty_objects(self):
|
364 | 364 | def add_publish_button(self, classes=('cms-btn-action', 'cms-btn-publish',)):
|
365 | 365 | # only do dirty lookups if publish permission is granted else button isn't added anyway
|
366 | 366 | if self.toolbar.edit_mode and self.has_publish_permission():
|
367 |
| - classes = list(classes or []) |
368 |
| - dirty = self.has_dirty_objects() |
| 367 | + button = self.get_publish_button(classes=classes) |
| 368 | + self.toolbar.add_item(button) |
369 | 369 |
|
370 |
| - if dirty: |
371 |
| - classes.append('cms-btn-publish-active') |
| 370 | + def get_publish_button(self, classes=None): |
| 371 | + dirty = self.has_dirty_objects() |
| 372 | + classes = list(classes or []) |
372 | 373 |
|
373 |
| - if self.dirty_statics or (self.page and self.page.is_published(self.current_lang)): |
374 |
| - title = _('Publish page changes') |
375 |
| - else: |
376 |
| - title = _('Publish page now') |
377 |
| - classes.append('cms-publish-page') |
378 |
| - |
379 |
| - self.toolbar.add_button( |
380 |
| - name=title, |
381 |
| - url=self.get_publish_url(), |
382 |
| - extra_classes=classes, |
383 |
| - side=self.toolbar.RIGHT, |
384 |
| - disabled=not dirty, |
385 |
| - ) |
| 374 | + if dirty and 'cms-btn-publish-active' not in classes: |
| 375 | + classes.append('cms-btn-publish-active') |
| 376 | + |
| 377 | + if self.dirty_statics or (self.page and self.page.is_published(self.current_lang)): |
| 378 | + title = _('Publish page changes') |
| 379 | + else: |
| 380 | + title = _('Publish page now') |
| 381 | + classes.append('cms-publish-page') |
| 382 | + |
| 383 | + item = ButtonList(side=self.toolbar.RIGHT) |
| 384 | + item.add_button( |
| 385 | + title, |
| 386 | + url=self.get_publish_url(), |
| 387 | + disabled=not dirty, |
| 388 | + extra_classes=classes, |
| 389 | + ) |
| 390 | + return item |
386 | 391 |
|
387 | 392 | def get_publish_url(self):
|
388 | 393 | pk = self.page.pk if self.page else 0
|
|
0 commit comments