Skip to content

Commit

Permalink
Fix Plone 4.3 with p.a.widgets 1.x edit modals
Browse files Browse the repository at this point in the history
see issue #719
  • Loading branch information
petschki committed May 30, 2017
1 parent bac226c commit fced329
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ There's a frood who really knows where his towel is.
You should explicitly add plone.app.drafts to the `eggs` part of your buildout configuration to avoid issues.
You can safely unistall plone.app.drafts after that, if you are not using it.

- Fix Plone 4.3 with plone.app.widgets 1.x installed. The tile-edit forms are now opened
with .pat-plone-modal (fixes `#719`_)
[petschki]

- Update recommended versions of Blocks dependencies to keep in sync with curren Mosaic development.
[hvelarde]

Expand Down Expand Up @@ -191,3 +195,4 @@ Previous entries can be found in the HISTORY.rst file.
.. _`#651`: https://github.com/collective/collective.cover/issues/651
.. _`#686`: https://github.com/collective/collective.cover/issues/686
.. _`#710`: https://github.com/collective/collective.cover/issues/710
.. _`#719`: https://github.com/collective/collective.cover/issues/719
2 changes: 1 addition & 1 deletion src/collective/cover/browser/templates/tile.pt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</div>
</div>
<a href="#" class="edit-tile-link pat-plone-modal"
data-pat-plone-modal="content: .tile-content"
data-pat-plone-modal='{"actionOptions": {"displayInModal": false}, "content": ".tile-content", "position": "center top"}'
tal:condition="python:view.tile_is_editable(tile_type)"
tal:attributes="href string:${context/absolute_url}/@@edit-tile/${tile_type}/${tile_id}"
i18n:translate="">Edit</a>
Expand Down
5 changes: 5 additions & 0 deletions src/collective/cover/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
xmlns:i18n="http://namespaces.zope.org/i18n"
xmlns:plone="http://namespaces.plone.org/plone"
xmlns:zcml="http://namespaces.zope.org/zcml"
i18n_domain="collective.cover">

<i18n:registerTranslations directory="locales" />
Expand Down Expand Up @@ -43,6 +44,10 @@
/>
</class>

<configure zcml:condition="installed plone.app.widgets">
<adapter factory=".widgets.richtext.TileRichTextFieldWidget" />
</configure>

<adapter name="SearchableText" factory=".content.searchableText" />

</configure>
25 changes: 4 additions & 21 deletions src/collective/cover/static/js/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ $(document).ready(function() {

TitleMarkupSetup();

if ($.fn.prepOverlay !== undefined) {
// if mockup is installed let pat-plone-modal do its job
// XXX: the check for require === 'undefined' should probably be more explicit
if ($.fn.prepOverlay !== undefined && typeof require === 'undefined') {
$('a.edit-tile-link').prepOverlay({
subtype: 'ajax',
filter: '.tile-content',
Expand Down Expand Up @@ -140,26 +142,7 @@ $(document).ready(function() {
},
config: {
onLoad: function() {
// With plone.app.widgets and Plone 4.3
if (typeof require !== 'undefined' && require.defined('pat-registry')) {
// Remove old editors references to work with ajax
if (typeof tinyMCE !== 'undefined' && tinyMCE !== null) {
if (tinyMCE.EditorManager != null) {
tinyMCE.EditorManager.editors = [];
}
}
// Add tinymce
$('.overlay textarea.mce_editable').addClass('pat-tinymce');
require('pat-registry').scan($('.overlay'), ['tinymce']);
// Wire save buttom to save tinymce
$( '.overlay input#buttons-save').on('click', function() {
tinyMCE.triggerSave();
});
// Hack to make overlay work over overlay
$('.overlay').on('mouseover', function() {
$('div.plone-modal-wrapper').css('z-index', '10050');
});
} else if (typeof initTinyMCE !== 'undefined') { // Plone 4.3
if (typeof initTinyMCE !== 'undefined') { // Plone 4.3
// Remove old editors references to work with ajax
if (typeof tinyMCE !== 'undefined' && tinyMCE !== null) {
if (tinyMCE.EditorManager != null) {
Expand Down
50 changes: 50 additions & 0 deletions src/collective/cover/widgets/richtext.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import pkg_resources

try:
pkg_resources.get_distribution('plone.app.widgets')
except pkg_resources.DistributionNotFound:
pass
else:
from Acquisition import aq_parent
from Products.CMFCore.utils import getToolByName
from collective.cover.tiles.richtext import IRichTextTile
from plone.app.widgets.base import dict_merge
from plone.app.widgets.dx import RichTextWidget
from plone.app.widgets.utils import get_tinymce_options
from z3c.form.interfaces import IFieldWidget, IFormLayer
from z3c.form.util import getSpecification
from z3c.form.widget import FieldWidget
from zope.component import adapter
from zope.interface import implementer


class TileRichTextWidget(RichTextWidget):
""" """

def _base_args(self):
args = {
'pattern': self.pattern,
'pattern_options': self.pattern_options.copy(),
}
context = aq_parent(self.wrapped_context())
args['name'] = self.name
properties = getToolByName(context, 'portal_properties')
charset = properties.site_properties.getProperty(
'default_charset', 'utf-8')
value = self.value and self.value.raw_encoded or ''
args['value'] = (self.request.get(
self.field.getName(), value)).decode(charset)

args.setdefault('pattern_options', {})
merged = dict_merge(
get_tinymce_options(context, self.field, self.request),
args['pattern_options'])
args['pattern_options'] = merged

return args


@adapter(getSpecification(IRichTextTile['text']), IFormLayer)
@implementer(IFieldWidget)
def TileRichTextFieldWidget(field, request):
return FieldWidget(field, TileRichTextWidget(request))

0 comments on commit fced329

Please sign in to comment.