--- a/src/pyams_content/component/links/zmi/container.py Fri Jan 20 15:36:00 2017 +0100
+++ b/src/pyams_content/component/links/zmi/container.py Fri Jan 20 15:36:31 2017 +0100
@@ -31,7 +31,7 @@
from z3c.table.interfaces import IColumn, IValues
# import packages
-from pyams_content.component.links.zmi.widget import LinkLinkSelectFieldWidget
+from pyams_content.component.links.zmi.widget import LinkLinksSelectFieldWidget
from pyams_content.shared.common.zmi import WfModifiedContentColumnMixin
from pyams_form.form import AJAXEditForm
from pyams_form.security import ProtectedFormObjectMixin
@@ -70,6 +70,22 @@
# Links container views
#
+@view_config(name='get-links.json', context=Interface, request_type=IPyAMSLayer,
+ renderer='json', xhr=True)
+def get_links(request):
+ """Get links list in JSON format for TinyMCE editor"""
+ result = []
+ key_field_name = request.params.get('keyFieldName', 'title')
+ value_field_name = request.params.get('valueFieldName', 'value')
+ target = get_parent(request.context, ILinkContainerTarget)
+ if target is not None:
+ container = ILinkContainer(target)
+ result.extend([{key_field_name: link.__name__,
+ value_field_name: II18n(link).query_attribute('title', request=request)}
+ for link in container.values()])
+ return sorted(result, key=lambda x: x[value_field_name])
+
+
@view_config(name='get-links-list.json', context=Interface, request_type=IPyAMSLayer,
renderer='json', xhr=True)
def get_links_list(request):
@@ -200,7 +216,7 @@
legend = _("Edit useful links links")
fields = field.Fields(ILinkLinksContainer)
- fields['links'].widgetFactory = LinkLinkSelectFieldWidget
+ fields['links'].widgetFactory = LinkLinksSelectFieldWidget
ajax_handler = 'link-links.json'
edit_permission = MANAGE_CONTENT_PERMISSION