Skip to content

Commit

Permalink
feat(templates,css): select2;
Browse files Browse the repository at this point in the history
- Select2 for organization selects when more than 12 user permissions.
  • Loading branch information
JVickery-TBS committed Oct 25, 2024
1 parent ef0450d commit 14e173f
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 6 deletions.
43 changes: 40 additions & 3 deletions ckanext/canada/assets/internal/canada_internal.css
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,33 @@ body ul.xloader-log li.item.failure > i{
body ul.xloader-log li.item.failure > i::after{
background-color: #B95252 !important;
}
#s2id_field-department,
#s2id_field-organizations{
min-height: 37px !important;
}
#s2id_field-department.select2-container,
#s2id_field-organizations.select2-container{
vertical-align: initial !important;
width: 100% !important;
}
#s2id_field-department.select2-container,
#s2id_field-department.select2-container .select2-choice,
#s2id_field-department.select2-container .select2-chosen,
#s2id_field-organizations.select2-container,
#s2id_field-organizations.select2-container .select2-choice,
#s2id_field-organizations.select2-container .select2-chosen{
height: 100% !important;
}
#s2id_field-department.select2-container .select2-choice,
#s2id_field-organizations.select2-container .select2-choice{
font-size: 16px !important;
line-height: 1.4375 !important;
padding: 6px 12px !important;
}
#s2id_field-department.select2-container .select2-arrow b,
#s2id_field-organizations.select2-container .select2-arrow b{
background-position-y: -100%;
}
/*###########################
## END ##
## CKAN Base CSS Overrides##
Expand Down Expand Up @@ -674,18 +701,21 @@ body ul.xloader-log li.item.failure > i::after{
pointer-events: none;
animation: fade-opacity-in 0.5s ease-in 1s 1 normal forwards;
}
.canada-pd-org-select-wrapper .recombinant-org-select-wrapper .select2-container{
.canada-pd-org-select-wrapper .recombinant-org-select-wrapper .select2-container,
.canada-pd-org-select-wrapper .recombinant-org-select-wrapper .recombinant-org-select1-wrapper select{
vertical-align: initial !important;
flex: 1;
width: auto !important;
}
.canada-pd-org-select-wrapper .recombinant-org-select-wrapper .select2-container,
.canada-pd-org-select-wrapper .recombinant-org-select-wrapper .select2-container .select2-choice,
.canada-pd-org-select-wrapper .recombinant-org-select-wrapper .select2-container .select2-chosen{
.canada-pd-org-select-wrapper .recombinant-org-select-wrapper .select2-container .select2-chosen,
.canada-pd-org-select-wrapper .recombinant-org-select-wrapper .recombinant-org-select1-wrapper select{
height: 100% !important;
border-radius: 0 !important;
}
.canada-pd-org-select-wrapper .recombinant-org-select-wrapper .select2-container .select2-choice{
.canada-pd-org-select-wrapper .recombinant-org-select-wrapper .select2-container .select2-choice,
.canada-pd-org-select-wrapper .recombinant-org-select-wrapper .recombinant-org-select1-wrapper select{
background: #335075 !important;
border-color: #335075 !important;
box-shadow: none !important;
Expand All @@ -706,6 +736,13 @@ body ul.xloader-log li.item.failure > i::after{
transition-duration: 0.325s !important;
color: white !important;
}
.canada-pd-org-select-wrapper .recombinant-org-select-wrapper .recombinant-org-select1-wrapper{
width: 100% !important;
}
.canada-pd-org-select-wrapper .recombinant-org-select-wrapper .recombinant-org-select1-wrapper select{
color: white !important;
width: 100% !important;
}
.canada-pd-org-select-wrapper .recombinant-org-select-wrapper .select2-container .select2-arrow{
border-radius: 0 !important;
background: #335075 !important;
Expand Down
2 changes: 1 addition & 1 deletion ckanext/canada/schemas/presets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ presets:
class: form-control form-select
# copied from dataset_organization preset
validators: scheming_required string_safe owner_org_validator
form_snippet: organization.html
form_snippet: organization_autocomplete.html

# Field = Publisher - Organization Name at Publication (English).
# {The organization Title at publication Time}
Expand Down
5 changes: 5 additions & 0 deletions ckanext/canada/templates/recombinant/snippets/org_select.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
{% block select_classes %}recombinant-org-select-wrapper{% endblock %}

{% block select_field %}
{% set organizations_available = h.organizations_available('create_dataset') %}
{% if organizations_available|length > 12 %}
<input id="org-select"
type="text"
name="org_select"
Expand All @@ -25,4 +27,7 @@
data-module-createtags="false"
class="control-medium"
/>
{% else %}
<div class="recombinant-org-select1-wrapper">{{ super() }}</div>
{% endif %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{% set organizations_available = h.organizations_available('create_dataset') %}

{% if organizations_available|length > 12 %}

{% import 'macros/form.html' as form %}

{% set org_required = not h.check_config_permission('create_unowned_dataset') %}

{% call form.input_block('field-organizations',
label=h.scheming_language_text(field.label),
error=errors[field.field_name],
is_required=org_required,
classes=field.classes if 'classes' in field else ['form-group', 'control-medium'],
extra_html=caller() if caller,
) %}
<div {{
form.attributes(field.form_attrs) if 'form_attrs' in field else '' }}>
<input id="field-organizations"
type="text"
name="owner_org"
value="{{ h.split_piped_bilingual_field(field.title, h.lang()) }}"
placeholder="{{ _('Search organizations...') }}"
data-module="autocomplete"
data-module-source="/organization/autocomplete?q=?"
data-module-key="id"
data-module-label="title"
data-module-dropdownClass="org-select2-dropdown"
data-module-containerClass="org-select2-container"
data-module-tags="false"
data-module-createtags="false"
class="control-medium"
/>
{%- snippet 'scheming/form_snippets/help_text.html', field=field %}
</div>
{% endcall %}

{% else %}

{% extends "scheming/form_snippets/organization.html" %}

{% endif %}
4 changes: 2 additions & 2 deletions ckanext/canada/templates/user/new_user_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
{% call form.input("email", id="field-email", label=_("Email"), type="email", value=data.email, error=errors.email, attrs=valid_dict2, is_required=true, classes=["control-medium"]) %}
{{ form.info(_('Example: [email protected]')) }}
{% endcall %}
{% set format_attrs={ 'oninvalid': "setCustomValidity('"+_("Please fill out this field.")+"')", 'onchange':"setCustomValidity('')", 'data-module': 'autocomplete', 'data-module-source': '/organization/autocomplete?q=?', 'data-module-key': 'title', 'class':'control-medium'} %}
{{ form.input('department', id='field-department', label=_('Organization'), value=data.department, error=errors.department, attrs=format_attrs, is_required=true) }}
{% set format_attrs={ 'oninvalid': "setCustomValidity('"+_("Please fill out this field.")+"')", 'onchange':"setCustomValidity('')", 'data-module': 'autocomplete', 'data-module-source': '/organization/autocomplete?q=?', 'data-module-key': 'title', 'data-module-label': 'title', 'data-module-dropdownClass': 'org-select2-dropdown', 'data-module-containerClass': 'org-select2-container', 'data-module-tags': 'false', 'data-module-createtags': 'false', 'class':'control-medium'} %}
{{ form.input('department', id='field-department', label=_('Organization'), value=data.department, error=errors.department, attrs=format_attrs, is_required=true, placeholder=_('Search organizations...')) }}
{% call form.input("phoneno", id="field-phoneno", label=_("Phone Number"), value=data.phoneno, error=errors.phoneno, classes=["control-medium"]) %}
{{ form.info(_('Example: 000 000 0000')) }}
{% endcall %}
Expand Down

0 comments on commit 14e173f

Please sign in to comment.