From 29e50f610819d572b98f6c7c2aab0e52a1178de7 Mon Sep 17 00:00:00 2001 From: Eugene Alvin Villar Date: Thu, 11 Aug 2016 04:40:25 +0800 Subject: [PATCH] Resolve #441: Improve relationship party selection widget --- cadasta/core/static/css/main.css | 32 +++++++++++++-- cadasta/core/static/css/main.scss | 40 +++++++++++++++++-- cadasta/spatial/tests/test_widgets.py | 24 ++++++----- cadasta/spatial/widgets.py | 34 +++++++--------- .../templates/spatial/relationship_add.html | 32 +++++++++++++-- 5 files changed, 121 insertions(+), 41 deletions(-) diff --git a/cadasta/core/static/css/main.css b/cadasta/core/static/css/main.css index 4d162e92a..968cea6ad 100644 --- a/cadasta/core/static/css/main.css +++ b/cadasta/core/static/css/main.css @@ -5820,8 +5820,7 @@ img.org-logo, img#org-logo { .top-btn .btn-rt { min-width: 20px; } -button#add-contact, -button#add-party { +button#add-contact { padding: 0; } .btn-full { @@ -5945,7 +5944,7 @@ div.add-btn-btm { .modal .modal-footer .btn { min-width: 100px; } -.modal button#add-contact, .modal button#add-party { +.modal button#add-contact { background: transparent; color: #2e51a3 !important; border: 0; @@ -5990,4 +5989,31 @@ tr.contacts-error { padding-top: 0; background: #fcf8e3; } +/* =Party selection widget +-------------------------------------------------------------- */ +#select-party label { + display: block; } + +#select-party #party-select { + width: 100%; } + +#select-party .select2 { + display: block; + margin: 0.5em 0; + width: 100%; } + +#select-party #add-party { + padding: 6px 18px; } + #select-party #add-party .glyphicon { + opacity: 0.5; + padding-right: 8px; } + +.select2-container .party-name { + display: block; } + +.select2-container .party-type { + display: block; + font-size: 0.85em; + opacity: 0.75; } + /*# sourceMappingURL=../../../../../static/css/main.css.map */ \ No newline at end of file diff --git a/cadasta/core/static/css/main.scss b/cadasta/core/static/css/main.scss index c71ec15e7..346088653 100644 --- a/cadasta/core/static/css/main.scss +++ b/cadasta/core/static/css/main.scss @@ -1177,8 +1177,7 @@ img.org-logo, img#org-logo { } } -button#add-contact, -button#add-party { // below contacts table and party table +button#add-contact { // below contacts table padding: 0; } @@ -1324,7 +1323,7 @@ div.add-btn-btm { // add party link at bottom of table min-width: 100px; } } - button#add-contact, button#add-party { + button#add-contact { background: transparent; color: $link-color !important; border: 0; @@ -1380,3 +1379,38 @@ tr.contacts-error { background: $alert-warning-bg; } } + +/* =Party selection widget +-------------------------------------------------------------- */ + +#select-party { + label { + display: block; + } + #party-select { + width: 100%; + } + .select2 { + display: block; + margin: 0.5em 0; + width: 100%; + } + #add-party { + padding: 6px 18px; + .glyphicon { + opacity: 0.5; + padding-right: 8px; + } + } +} + +.select2-container { + .party-name { + display: block; + } + .party-type { + display: block; + font-size: 0.85em; + opacity: 0.75; + } +} diff --git a/cadasta/spatial/tests/test_widgets.py b/cadasta/spatial/tests/test_widgets.py index c62b9686e..18d28c6a8 100644 --- a/cadasta/spatial/tests/test_widgets.py +++ b/cadasta/spatial/tests/test_widgets.py @@ -12,21 +12,22 @@ def test_render(self): widget = SelectPartyWidget(project=project) rendered = widget.render(name='name', value='value') - assert '' in rendered - assert ('' + party_1.name + '' - '' + party_1.get_type_display() + '' - in rendered) - assert ('' + party_2.name + '' - '' + party_2.get_type_display() + '' - in rendered) + assert ('' ) @@ -36,8 +37,9 @@ def test_render_value(self): def test_render_no_value(self): widget = NewEntityWidget() expected = ( - '' + '' '' ) diff --git a/cadasta/spatial/widgets.py b/cadasta/spatial/widgets.py index 190bbb2f7..376fa3a6b 100644 --- a/cadasta/spatial/widgets.py +++ b/cadasta/spatial/widgets.py @@ -1,4 +1,5 @@ from django.forms.widgets import HiddenInput +from django.utils.translation import ugettext as _ from party.models import Party @@ -9,26 +10,15 @@ def __init__(self, project, *args, **kwargs): def render(self, name, value, attrs={}): prj_parties = Party.objects.filter(project_id=self.project) - parties = ['' + p.name + '' - '' + p.get_type_display() + '' + parties = ['' for p in prj_parties] return ( - '' - ' ' - ' ' - ' ' - ' ' - ' ' - ' ' - ' ' - ' {parties}' - ' ' - '
PartyType
' - '' - ).format(parties=''.join(parties), - name=name, - value=value or '') + '' + ).format(parties=''.join(parties), name=name) class NewEntityWidget(HiddenInput): @@ -37,10 +27,14 @@ class Media: def render(self, name, value, attrs={}): html = ( - '' + '' '' ) + button_text = _("Add party") - return html.format(name=name, value=(value if value else '')) + return html.format(name=name, + value=(value if value else ''), + button_text=button_text) diff --git a/cadasta/templates/spatial/relationship_add.html b/cadasta/templates/spatial/relationship_add.html index 5de478b44..1f1cb1629 100644 --- a/cadasta/templates/spatial/relationship_add.html +++ b/cadasta/templates/spatial/relationship_add.html @@ -4,8 +4,33 @@ {% block page_title %}Add new relationship | {% endblock %} +{% block extra_head %} +{{ block.super }} + +{% endblock %} + {% block location_extra_script %} {{ form.media }} + + {% endblock %} {% block form_modal %} @@ -26,11 +51,10 @@

{% trans "1. Connected party" %}

- + {% render_field form.id class+="form-control" %} -
- {% render_field form.new_entity class+="form-control" %} -
+ + {% render_field form.new_entity class+="form-control" %}