From 48eb307bd7b5e4bf0b16bcd9a67df322bf97e282 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Tue, 28 Dec 2021 11:45:41 +0100 Subject: [PATCH] update items fields in live_process_fields --- wcs/fields.py | 19 +++++++------- wcs/formdef.py | 2 +- wcs/forms/common.py | 2 +- wcs/qommon/static/js/qommon.forms.js | 37 +++++++++++++++++++++++++++- 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/wcs/fields.py b/wcs/fields.py index abe9064c0..5c46873b7 100644 --- a/wcs/fields.py +++ b/wcs/fields.py @@ -1867,6 +1867,15 @@ class ItemFieldMixin: data_source_type.set_value(None) data_source_type.transfer_form_value(get_request()) + def get_extended_options(self): + if self.data_source: + return data_sources.get_structured_items( + self.data_source, mode='lazy', include_disabled=self.display_disabled_items + ) + if self.items: + return [{'id': x, 'text': x} for x in self.items] + return [] + class ItemField(WidgetField, MapOptionsMixin, ItemFieldMixin): key = 'item' @@ -1921,15 +1930,6 @@ class ItemField(WidgetField, MapOptionsMixin, ItemFieldMixin): return [(x, x) for x in self.items] return [] - def get_extended_options(self): - if self.data_source: - return data_sources.get_structured_items( - self.data_source, mode='lazy', include_disabled=self.display_disabled_items - ) - if self.items: - return [{'id': x, 'text': x} for x in self.items] - return [] - def get_display_mode(self, data_source=None): if not data_source: data_source = data_sources.get_object(self.data_source) @@ -2260,6 +2260,7 @@ class ItemsField(WidgetField, ItemFieldMixin): data_source = {} in_filters = False display_disabled_items = False + display_mode = None widget_class = CheckboxesWidget diff --git a/wcs/formdef.py b/wcs/formdef.py index 81d776e90..7efd5d6ef 100644 --- a/wcs/formdef.py +++ b/wcs/formdef.py @@ -825,7 +825,7 @@ class FormDef(StorableObject): if varname not in live_condition_fields: live_condition_fields[varname] = [] live_condition_fields[varname].append(field) - if field.key == 'item' and field.data_source: + if field.key in ('item', 'items') and field.data_source: data_source = data_sources.get_object(field.data_source) if data_source.type not in ('json', 'geojson') and not data_source.type.startswith( 'carddef:' diff --git a/wcs/forms/common.py b/wcs/forms/common.py index 29ddba503..1522bdbc1 100644 --- a/wcs/forms/common.py +++ b/wcs/forms/common.py @@ -758,7 +758,7 @@ class FormStatusPage(Directory, FormTemplateMixin): break for field in displayed_fields: - if field.key == 'item' and field.data_source: + if field.key in ('item', 'items') and field.data_source: data_source = data_sources.get_object(field.data_source) if data_source.type not in ('json', 'geojson') and not data_source.type.startswith( 'carddef:' diff --git a/wcs/qommon/static/js/qommon.forms.js b/wcs/qommon/static/js/qommon.forms.js index f6f8d4bba..6dfdf1b96 100644 --- a/wcs/qommon/static/js/qommon.forms.js +++ b/wcs/qommon/static/js/qommon.forms.js @@ -473,7 +473,42 @@ $(function() { } else { $widget.hide(); } - if (value.items && $widget.is('.RadiobuttonsWidget')) { + if (value.items && $widget.is('.CheckboxesWidget')) { + var input_name = $widget.data('widget-name'); + /* get current list */ + var current_value = {}; + var items = []; + $widget.find('li').each(function (i, elt) { + var label = $(elt).find('label span').text(); + items.push(label); + if ($(elt).find('input:checked')) { + current_value[label] = true; + } + }); + var $ul = $widget.find('.content ul'); + var new_items = value.items.map(function (item) { return item.text }); + $ul.empty() + for (var i=0; i'); + var $label = $('