Commit 3f5376be authored by Arnaud Fontaine's avatar Arnaud Fontaine

ZODB Components: Add CodeMirror editor.

CodeMirror API is much more cleaner (from code and design point of view) than
Ace Editor and include useful plugins, such as MergeView supported in ERP5 to
diff with previous versions.
parent 6560ac6d
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>import json\n
return json.dumps(context.getTextContentHistoryRevisionDictList())\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Component_getTextContentHistoryRevisionDictListAsJSON</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -75,7 +75,8 @@ class EditorWidget(Widget.TextAreaWidget): ...@@ -75,7 +75,8 @@ class EditorWidget(Widget.TextAreaWidget):
('Xinha Editor', 'xinha'), ('Xinha Editor', 'xinha'),
('SVG Editor', 'svg_editor'), ('SVG Editor', 'svg_editor'),
('Spreadsheet Editor', 'spreadsheet_editor'), ('Spreadsheet Editor', 'spreadsheet_editor'),
('Ace Editor', 'ace')]) ('Ace Editor', 'ace'),
('CodeMirror', 'codemirror')])
def render(self, field, key, value, REQUEST, render_prefix=None): def render(self, field, key, value, REQUEST, render_prefix=None):
""" """
...@@ -118,6 +119,14 @@ class EditorWidget(Widget.TextAreaWidget): ...@@ -118,6 +119,14 @@ class EditorWidget(Widget.TextAreaWidget):
return ace_editor_support.pt_render(extra_context={'field': field, return ace_editor_support.pt_render(extra_context={'field': field,
'content': value, 'content': value,
'id': key}) 'id': key})
elif text_editor == 'codemirror':
code_mirror_support = getattr(here, 'code_mirror_support', None)
if code_mirror_support is not None:
site_root = here.getWebSiteValue() or here.getPortalObject()
return code_mirror_support(field=field,
content=value,
field_id=key,
portal_url=site_root.absolute_url())
elif text_editor != 'text_area': elif text_editor != 'text_area':
return here.fckeditor_wysiwyg_support.pt_render( return here.fckeditor_wysiwyg_support.pt_render(
extra_context= { extra_context= {
......
...@@ -355,3 +355,47 @@ class ComponentMixin(PropertyRecordableMixin, Base): ...@@ -355,3 +355,47 @@ class ComponentMixin(PropertyRecordableMixin, Base):
new_component.validate() new_component.validate()
return new_component return new_component
security.declareProtected(Permissions.ModifyPortalContent,
'getTextContentHistoryRevisionDictList')
def getTextContentHistoryRevisionDictList(self, limit=100):
"""
TODO
"""
history_dict_list = self._p_jar.db().history(self._p_oid, size=limit)
if history_dict_list is None:
# Storage doesn't support history
return ()
from struct import unpack
from OFS.History import historicalRevision
previous_text_content = None
result = []
for history_dict in history_dict_list:
text_content = historicalRevision(self, history_dict['tid']).getTextContent()
if text_content and text_content != previous_text_content:
history_dict['time'] = history_dict['time']
history_dict['user_name'] = history_dict['user_name'].strip()
history_dict['key'] = '.'.join(map(str, unpack(">HHHH", history_dict['tid'])))
del history_dict['tid']
del history_dict['size']
result.append(history_dict)
previous_text_content = text_content
return result
security.declareProtected(Permissions.ModifyPortalContent,
'getTextContentHistory')
def getTextContentHistory(self, key):
"""
TODO
"""
from struct import pack
from OFS.History import historicalRevision
serial = apply(pack, ('>HHHH',) + tuple(map(int, key.split('.'))))
rev = historicalRevision(self, serial)
return rev.getTextContent()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment