[views] Tweak complex keyword form UI
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 16 Mar 2017 12:17:23 +0100
changeset 2498 1b26f8fc74f0
parent 2497 d1278ff559b9
child 2499 4346a9cd582e
[views] Tweak complex keyword form UI * Display type before term, because its value will modify possible term's vocabularies, so it makes sense to display it before * Force display of type as well as term, it make things (js) simpler and user still have the cardinality if he doesn't want to force a type to be set * Hide the 'add new' link in any cases, else it ends up appearing unwillingly while we don't need it at all. Related to extranet #12351787
cubicweb_seda/views/archiveunit.py
--- a/cubicweb_seda/views/archiveunit.py	Thu Mar 16 11:24:40 2017 +0100
+++ b/cubicweb_seda/views/archiveunit.py	Thu Mar 16 12:17:23 2017 +0100
@@ -22,7 +22,7 @@
 from logilab.common.decorators import monkeypatch
 
 from cubicweb import tags, _
-from cubicweb.predicates import is_instance, match_form_params
+from cubicweb.predicates import is_instance, match_form_params, specified_etype_implements
 from cubicweb.view import EntityView
 from cubicweb.web.views import autoform, baseviews, tabs, uicfg
 
@@ -96,7 +96,7 @@
         unit_type = req.form['keyword_type']
         return int(unit_type == 'simple_keyword')
     except KeyError:
-        if not entity.reverse_seda_keyword_reference_from:
+        if entity is not None and not entity.reverse_seda_keyword_reference_from:
             return 1
         return 0
 
@@ -610,7 +610,9 @@
     ('*', 'seda_keyword_reference_from', 'SEDAKeyword'),
     'main', 'hidden')
 # but one ordering is enough to rule them all
-affk.set_fields_order('SEDAKeyword', ['keyword_content', ('seda_keyword_reference_from', 'object')])
+affk.set_fields_order('SEDAKeyword', [('seda_keyword_type_from', 'object'),
+                                      'keyword_content',
+                                      ('seda_keyword_reference_from', 'object')])
 
 affk.set_field_kwargs('SEDAKeywordType', 'seda_keyword_type_to',
                       widget=widgets.KeywordTypeMasterWidget(
@@ -621,9 +623,27 @@
     __select__ = (is_instance('SEDAKeyword') & ~is_simple_keyword())
 
     def should_display_inline_creation_form(self, rschema, existing, card):
-        # 1. force creation of one appraisal/access rule
-        if rschema == 'seda_keyword_reference_from':
+        # force display of type and keyword
+        if not existing and rschema in ('seda_keyword_type_from', 'seda_keyword_reference_from'):
             return True
+        return False
+
+    def should_display_add_new_relation_link(self, rschema, existing, card):
+        return False
+
+
+class ComplexKeywordEditionFormView(autoform.InlineEntityEditionFormView):
+    __select__ = (autoform.InlineEntityEditionFormView.__select__
+                  & is_instance('SEDAKeywordType', 'SEDAKeywordReference')
+                  & ~is_simple_keyword())
+    removejs = None
+
+
+class ComplexKeywordCreationFormView(autoform.InlineEntityCreationFormView):
+    __select__ = (autoform.InlineEntityCreationFormView.__select__
+                  & specified_etype_implements('SEDAKeywordType', 'SEDAKeywordReference')
+                  & ~is_simple_keyword())
+    removejs = None
 
 
 # relations tab ################################################################