-
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '2.x' into sample-batch-reference-show-title-or-id
- Loading branch information
Showing
23 changed files
with
591 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/senaite/core/browser/static/bundles/senaite.core.widgets.js
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
src/senaite/core/browser/static/bundles/senaite.core.widgets.js.map
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import json | ||
from bika.lims import _ | ||
from Products.Archetypes.Registry import registerWidget | ||
from Products.Archetypes.Widget import StringWidget | ||
from senaite.core.i18n import translate as t | ||
from senaite.core.z3cform.widgets.selectother.widget import OTHER_OPTION_VALUE | ||
|
||
|
||
class SelectOtherWidget(StringWidget): | ||
"""Select Other Widget for AT fields | ||
""" | ||
# CSS class that is picked up by the ReactJS component | ||
klass = u"senaite-selectother-widget-input" | ||
|
||
_properties = StringWidget._properties.copy() | ||
_properties.update({ | ||
"macro": "senaite_widgets/selectotherwidget", | ||
}) | ||
|
||
def process_form(self, instance, field, form, empty_marker=None, | ||
emptyReturnsMarker=False, validating=True): | ||
value = form.get(field.getName(), "") | ||
if isinstance(value, list): | ||
if value[0] == OTHER_OPTION_VALUE: | ||
return value[1], {} | ||
value = value[0] | ||
|
||
return value, {} | ||
|
||
def get_input_widget_attributes(self, context, field, value): | ||
"""Return input widget attributes for the ReactJS component | ||
This method get called from the page template to populate the | ||
attributes that are used by the ReactJS widget component. | ||
:param context: The current context of the field | ||
:param field: The current field of the widget | ||
:param value: The current field value | ||
""" | ||
option = "" | ||
other = "" | ||
|
||
# find out if the value is a predefined option | ||
choices = self.get_choices(context, field) | ||
options = dict(choices).keys() | ||
if value in options: | ||
option = value | ||
elif value: | ||
option = OTHER_OPTION_VALUE | ||
other = value | ||
|
||
attributes = { | ||
"data-id": field.getName(), | ||
"data-name": field.getName(), | ||
"data-choices": choices, | ||
"data-option": option, | ||
"data-option_other": OTHER_OPTION_VALUE, | ||
"data-other": other, | ||
} | ||
|
||
# convert all attributes to JSON | ||
for key, value in attributes.items(): | ||
attributes[key] = json.dumps(value) | ||
|
||
return attributes | ||
|
||
def get_vocabulary(self, context, field): | ||
func = getattr(field, "Vocabulary", None) | ||
if callable(func): | ||
return func(context) | ||
return None | ||
|
||
def get_choices(self, context, field): | ||
"""Returns the predefined options for this field | ||
""" | ||
# generate a list of tuples (value, text) from vocabulary | ||
vocabulary = self.get_vocabulary(context, field) | ||
choices = list(vocabulary.items()) if vocabulary else [] | ||
|
||
# insert the empty option | ||
choices.insert(0, ("", "")) | ||
|
||
# append the "Other..." choice | ||
other = (OTHER_OPTION_VALUE, t(_("Other..."))) | ||
choices.append(other) | ||
|
||
return choices | ||
|
||
|
||
registerWidget(SelectOtherWidget, title="Select Other Widget") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from senaite.core.schema.fields import BaseField | ||
from senaite.core.schema.interfaces import ISelectOtherField | ||
from zope.interface import implementer | ||
from zope.schema import Choice | ||
|
||
|
||
@implementer(ISelectOtherField) | ||
class SelectOtherField(Choice, BaseField): | ||
"""A field that handles a value from a predefined vocabulary or custom | ||
""" | ||
def _validate(self, value): | ||
super(SelectOtherField, self)._validate(value) |
61 changes: 61 additions & 0 deletions
61
src/senaite/core/skins/senaite_templates/senaite_widgets/selectotherwidget.pt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<html xmlns="http://www.w3.org/1999/xhtml" | ||
xmlns:tal="http://xml.zope.org/namespaces/tal" | ||
xmlns:metal="http://xml.zope.org/namespaces/metal" | ||
xmlns:i18n="http://xml.zope.org/namespaces/i18n" | ||
metal:use-macro="here/main_template/macros/master" | ||
i18n:domain="senaite.core"> | ||
<body> | ||
|
||
<!-- VIEW MACRO --> | ||
<metal:view_macro define-macro="view"> | ||
</metal:view_macro> | ||
|
||
<!-- EDIT MACRO --> | ||
<metal:edit_macro define-macro="edit"> | ||
<tal:values define="value python:field.getEditAccessor(here)() or []; | ||
session_value python:here.session_restore_value(fieldName, value); | ||
cached_value python:request.get(fieldName, session_value); | ||
value python:cached_value or value; | ||
required field/required|nothing; | ||
required python: required and 'required' or None; | ||
error_id python:errors.get(fieldName); | ||
i18n_domain field/widget/i18n_domain|context/i18n_domain|string:plone;"> | ||
|
||
<tal:ifLabel tal:condition="not: widget/render_own_label | nothing"> | ||
<label class="formQuestion" | ||
tal:attributes="for python:fieldName"> | ||
<span tal:replace="python:widget.Label(here)" | ||
i18n:translate=""></span> | ||
<span class="required" | ||
tal:condition="field/required" | ||
title="Required" | ||
i18n:attributes="title title_required;"> </span> | ||
<span class="formHelp" | ||
tal:define="description python:widget.Description(here)" | ||
tal:content="structure description" | ||
tal:attributes="id string:${fieldName}_help" | ||
i18n:translate=""> | ||
Help | ||
</span> | ||
</label> | ||
</tal:ifLabel> | ||
|
||
<div tal:define="widget_attrs python:field.widget.get_input_widget_attributes(context, field, value);" | ||
tal:attributes="id python:fieldName; | ||
class python: test(error_id, 'field error ' + 'Archetypes' + widget.getName(), 'field ' + 'Archetypes' + widget.getName()) + ' ' + widget.klass; | ||
data-required python:required and '1' or '0'; | ||
python:widget_attrs;"> | ||
<!-- ReactJS controlled component --> | ||
</div> | ||
|
||
<div class="fieldErrorBox" tal:condition="required"></div> | ||
<div class="fieldErrorBox" tal:content="error_id" i18n:translate=""></div> | ||
</tal:values> | ||
|
||
</metal:edit_macro> | ||
|
||
<metal:search_macro define-macro="search"> | ||
<div metal:use-macro="context/widgets/string/macros/edit"></div> | ||
</metal:search_macro> | ||
|
||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# -*- coding: utf-8 -*- |
Oops, something went wrong.