--- a/src/pyams_thesaurus/widget/__init__.py Mon Jul 09 13:43:31 2018 +0200
+++ b/src/pyams_thesaurus/widget/__init__.py Tue Jul 10 15:46:24 2018 +0200
@@ -172,6 +172,32 @@
return FieldWidget(field, ThesaurusTermsListWidget(request))
+@widgettemplate_config(mode='input', template='templates/terms-tree-input.pt', layer=IFormLayer)
+class ThesaurusTermsTreeWidget(ThesaurusTermsListWidget):
+ """Thesaurus terms tree widget"""
+
+ @property
+ def top_terms(self):
+ thesaurus = query_utility(IThesaurus, name=self.thesaurus_name)
+ if thesaurus is not None:
+ return sorted(thesaurus.get_top_terms(extract=self.extract_name),
+ key=lambda x: x.label)
+ else:
+ return ()
+
+ def get_subterms(self, term):
+ for subterm in term.specifics:
+ if (not self.extract_name) or (self.extract_name in subterm.extracts):
+ yield subterm
+ for another in self.get_subterms(subterm):
+ yield another
+
+
+def ThesaurusTermsTreeFieldWidget(field, request):
+ """Thesaurus terms tree field widget factory"""
+ return FieldWidget(field, ThesaurusTermsTreeWidget(request))
+
+
#
# Terms list widget with selector
#
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_thesaurus/widget/templates/terms-tree-input.pt Tue Jul 10 15:46:24 2018 +0200
@@ -0,0 +1,32 @@
+<tal:loop repeat="term view/top_terms">
+ <div class="col col-xs-6 col-sm-4 col-md-4 col-lg-3">
+ <div class="ams-widget" data-ams-widget-toggle-button="false"
+ tal:define="index python:repeat['term'].index()"
+ tal:attributes="id string:them_${index}">
+ <header class="no-margin">
+ <h2 tal:content="term/label"></h2>
+ </header>
+ <div class="widget-body no-padding viewport-y viewport-200 viewport-x-none"
+ style="height: 200px; width: calc(100% - 2px);">
+ <tal:loop repeat="subterm python:view.get_subterms(term)">
+ <div tal:define="padding python:(subterm.level - 1) * 20"
+ tal:attributes="style string:padding-left: ${padding}px;; line-height: 1em;;">
+ <label class="checkbox"
+ tal:define="published python:subterm.status == 'published'"
+ tal:omit-tag="not:published">
+ <input type="checkbox" name="form.widgets.themes:list"
+ tal:condition="published"
+ tal:attributes="id string:term_${subterm/label};
+ name string:${view/name}:list;
+ value subterm/label;
+ checked python:subterm.label in view.value" />
+ <i></i>
+ <div tal:attributes="class python:'' if published else 'bold margin-top-5'"
+ tal:content="subterm/label"></div>
+ </label>
+ </div>
+ </tal:loop>
+ </div>
+ </div>
+ </div>
+</tal:loop>