src/pyams_thesaurus/zmi/term.py
changeset 125 53d8795a704d
parent 87 dfe19304d980
equal deleted inserted replaced
124:db6aae9e0b8c 125:53d8795a704d
    41 
    41 
    42 from pyams_thesaurus import _
    42 from pyams_thesaurus import _
    43 
    43 
    44 
    44 
    45 @viewlet_config(name='thesaurus.term.adding', context=IThesaurus, view=ThesaurusTermsView,
    45 @viewlet_config(name='thesaurus.term.adding', context=IThesaurus, view=ThesaurusTermsView,
    46                 layer=IAdminLayer, manager=IWidgetTitleViewletManager, permission=MANAGE_THESAURUS_CONTENT_PERMISSION)
    46                 layer=IAdminLayer, manager=IWidgetTitleViewletManager,
       
    47                 permission=MANAGE_THESAURUS_CONTENT_PERMISSION)
    47 class ThesaurusTermAddAction(ToolbarAction):
    48 class ThesaurusTermAddAction(ToolbarAction):
    48     """Thesaurus term add action"""
    49     """Thesaurus term add action"""
    49 
    50 
    50     label = _("Add term")
    51     label = _("Add term")
    51     url = 'add-term.html'
    52     url = 'add-term.html'
    64         return self.context.title
    65         return self.context.title
    65 
    66 
    66     legend = _("Add new term")
    67     legend = _("Add new term")
    67     icon_css_class = 'fa fa-fw fa-tag'
    68     icon_css_class = 'fa fa-fw fa-tag'
    68 
    69 
    69     fields = field.Fields(IThesaurusTerm).select('label', 'alt', 'definition', 'note', 'generic', 'order',
    70     fields = field.Fields(IThesaurusTerm).select('label', 'alt', 'definition', 'note', 'generic',
    70                                                  'associations', 'usage', 'extensions', 'status', 'created')
    71                                                  'order', 'associations', 'usage', 'extensions',
       
    72                                                  'status', 'created')
    71 
    73 
    72     ajax_handler = 'add-term.json'
    74     ajax_handler = 'add-term.json'
    73     edit_permission = None
    75     edit_permission = None
    74 
    76 
    75     def updateWidgets(self, prefix=None):
    77     def updateWidgets(self, prefix=None):
   122     data = event.data
   124     data = event.data
   123     if data.get('label') in event.form.context.terms:
   125     if data.get('label') in event.form.context.terms:
   124         event.form.widgets.errors += (Invalid(_("Specified label is already used!")), )
   126         event.form.widgets.errors += (Invalid(_("Specified label is already used!")), )
   125 
   127 
   126 
   128 
   127 @pagelet_config(name='properties.html', context=IThesaurusTerm, layer=IPyAMSLayer, permission=VIEW_PERMISSION)
   129 @pagelet_config(name='properties.html', context=IThesaurusTerm, layer=IPyAMSLayer,
       
   130                 permission=VIEW_PERMISSION)
   128 @ajax_config(name='properties.json', context=IThesaurusTerm, layer=IPyAMSLayer)
   131 @ajax_config(name='properties.json', context=IThesaurusTerm, layer=IPyAMSLayer)
   129 class ThesaurusTermEditForm(AdminDialogEditForm):
   132 class ThesaurusTermEditForm(AdminDialogEditForm):
   130     """Thesaurus term edit form"""
   133     """Thesaurus term edit form"""
   131 
   134 
   132     prefix = 'term_properties.'
   135     prefix = 'term_properties.'
   136         return self.context.label
   139         return self.context.label
   137 
   140 
   138     legend = _("Edit term properties")
   141     legend = _("Edit term properties")
   139     icon_css_class = 'fa fa-fw fa-tag'
   142     icon_css_class = 'fa fa-fw fa-tag'
   140 
   143 
   141     fields = field.Fields(IThesaurusTerm).select('label', 'alt', 'definition', 'note', 'generic', 'order', 'specifics',
   144     fields = field.Fields(IThesaurusTerm).select('label', 'alt', 'definition', 'note', 'generic',
   142                                                  'associations', 'usage', 'used_for', 'extracts', 'extensions',
   145                                                  'order', 'specifics', 'associations', 'usage',
   143                                                  'status', 'level', 'created', 'modified')
   146                                                  'used_for', 'extracts', 'extensions', 'status',
       
   147                                                  'level', 'created', 'modified')
   144 
   148 
   145     edit_permission = MANAGE_THESAURUS_CONTENT_PERMISSION
   149     edit_permission = MANAGE_THESAURUS_CONTENT_PERMISSION
   146 
   150 
   147     generic_changed = False
   151     generic_changed = False
   148     usage_changed = False
   152     usage_changed = False
   239                 'post_reload_options': {
   243                 'post_reload_options': {
   240                     'term': label
   244                     'term': label
   241                 }
   245                 }
   242             }
   246             }
   243         else:
   247         else:
   244             if ('status' in term_changes) or ('label' in term_changes) or ('extensions' in term_changes):
   248             if ('status' in term_changes) or ('label' in term_changes) or \
       
   249                     ('extensions' in term_changes):
   245                 label = (self.context.generic or self.context).label.replace("'", "'")
   250                 label = (self.context.generic or self.context).label.replace("'", "'")
   246                 return {
   251                 return {
   247                     'status': 'callback',
   252                     'status': 'callback',
   248                     'callback': 'PyAMS_thesaurus.tree.updateTerm',
   253                     'callback': 'PyAMS_thesaurus.tree.updateTerm',
   249                     'options': {
   254                     'options': {
   260     context = event.form.context
   265     context = event.form.context
   261     thesaurus = get_parent(context, IThesaurus)
   266     thesaurus = get_parent(context, IThesaurus)
   262     label = event.data.get('label')
   267     label = event.data.get('label')
   263     if (label != context.label) and (label in thesaurus.terms):
   268     if (label != context.label) and (label in thesaurus.terms):
   264         event.form.widgets.errors += (Invalid(_("Specified new label is already used!")), )
   269         event.form.widgets.errors += (Invalid(_("Specified new label is already used!")), )
       
   270     generic = event.data.get('generic')
       
   271     if generic is context:
       
   272         event.form.widgets.errors += (Invalid(_("A term can't be selected as it's own generic "
       
   273                                                 "term!")), )