# HG changeset patch # User Thierry Florac # Date 1484922960 -3600 # Node ID 2986440f9797d986400304f607936bcccc28866a # Parent 2e8d9336f0ac476298e8077e5c46d25b7d95b192 Ajout d'un composant pour permettre la sélection d'un lien unique diff -r 2e8d9336f0ac -r 2986440f9797 src/pyams_content/component/links/zmi/templates/widget-display.pt --- a/src/pyams_content/component/links/zmi/templates/widget-display.pt Tue Dec 20 18:56:24 2016 +0100 +++ b/src/pyams_content/component/links/zmi/templates/widget-display.pt Fri Jan 20 15:36:00 2017 +0100 @@ -1,5 +1,4 @@
+ tal:attributes="data-ams-select2-target view/name">
- + value python:','.join(view.value); + data-ams-select2-data view/values_data;" />
diff -r 2e8d9336f0ac -r 2986440f9797 src/pyams_content/component/links/zmi/templates/widget-list-display.pt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_content/component/links/zmi/templates/widget-list-display.pt Fri Jan 20 15:36:00 2017 +0100 @@ -0,0 +1,22 @@ + diff -r 2e8d9336f0ac -r 2986440f9797 src/pyams_content/component/links/zmi/templates/widget-list-input.pt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_content/component/links/zmi/templates/widget-list-input.pt Fri Jan 20 15:36:00 2017 +0100 @@ -0,0 +1,67 @@ +
+ + +
+
+ +
+ diff -r 2e8d9336f0ac -r 2986440f9797 src/pyams_content/component/links/zmi/widget.py --- a/src/pyams_content/component/links/zmi/widget.py Tue Dec 20 18:56:24 2016 +0100 +++ b/src/pyams_content/component/links/zmi/widget.py Fri Jan 20 15:36:00 2017 +0100 @@ -27,8 +27,14 @@ @widgettemplate_config(mode='input', template='templates/widget-input.pt', layer=IPyAMSLayer) @widgettemplate_config(mode='display', template='templates/widget-display.pt', layer=IPyAMSLayer) -class LinkLinksSelectWidget(OrderedSelectWidget): - """Links links select widget""" +class SingleLinkLinkSelectWidget(OrderedSelectWidget): + """Single Link link select widget""" + + @property + def values_data(self): + result = sorted([{'id': entry['value'], 'text': entry['content']} for entry in self.items], + key=lambda x: x['text']) + return json.dumps(result) @property def values_map(self): @@ -37,6 +43,23 @@ return json.dumps(result) -def LinkLinkSelectFieldWidget(field, request): +def SingleLinkLinkSelectFieldWidget(field, request): + """Single link link select widget factory""" + return FieldWidget(field, SingleLinkLinkSelectWidget(request)) + + +@widgettemplate_config(mode='input', template='templates/widget-list-input.pt', layer=IPyAMSLayer) +@widgettemplate_config(mode='display', template='templates/widget-list-display.pt', layer=IPyAMSLayer) +class LinkLinksSelectWidget(OrderedSelectWidget): + """Multiple inks links select widget""" + + @property + def values_map(self): + result = {} + [result.update({entry['value']: entry['content']}) for entry in self.selectedItems] + return json.dumps(result) + + +def LinkLinksSelectFieldWidget(field, request): """Links links select widget factory""" return FieldWidget(field, LinkLinksSelectWidget(request))