src/pyams_content_es/zmi/__init__.py
changeset 150 16da0050b814
parent 59 a80821967d4f
equal deleted inserted replaced
149:81086f654208 150:16da0050b814
    13 __docformat__ = 'restructuredtext'
    13 __docformat__ = 'restructuredtext'
    14 
    14 
    15 
    15 
    16 # import standard library
    16 # import standard library
    17 
    17 
    18 # import interfaces
       
    19 from pyams_content_es.interfaces import IContentIndexerUtility
       
    20 from pyams_form.interfaces.form import IWidgetsSuffixViewletsManager
       
    21 from pyams_skin.interfaces.viewlet import ITableItemColumnActionsMenu
       
    22 from pyams_skin.layer import IPyAMSLayer
       
    23 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION, MANAGE_SYSTEM_PERMISSION
       
    24 
       
    25 # import packages
       
    26 from pyams_form.form import AJAXEditForm, AJAXAddForm
       
    27 from pyams_form.schema import CloseButton
       
    28 from pyams_pagelet.pagelet import pagelet_config
       
    29 from pyams_skin.viewlet.toolbar import ToolbarMenuItem
       
    30 from pyams_template.template import template_config
       
    31 from pyams_viewlet.viewlet import viewlet_config, Viewlet
       
    32 from pyams_zmi.form import AdminDialogEditForm, AdminDialogAddForm
       
    33 from pyams_zmi.layer import IAdminLayer
       
    34 from pyams_zmi.zmi.control_panel import UtilitiesTable
       
    35 from pyramid.view import view_config
    18 from pyramid.view import view_config
    36 from z3c.form import field, button
    19 from z3c.form import button, field
    37 from zope.interface import Interface
    20 from zope.interface import Interface
    38 
    21 
    39 from pyams_content_es import _
    22 from pyams_content_es import _
       
    23 # import interfaces
       
    24 from pyams_content_es.interfaces import IContentIndexerUtility
       
    25 # import packages
       
    26 from pyams_form.form import AJAXAddForm, AJAXEditForm, ajax_config
       
    27 from pyams_form.interfaces.form import IWidgetsSuffixViewletsManager
       
    28 from pyams_form.schema import CloseButton
       
    29 from pyams_pagelet.pagelet import pagelet_config
       
    30 from pyams_skin.interfaces.viewlet import ITableItemColumnActionsMenu
       
    31 from pyams_skin.layer import IPyAMSLayer
       
    32 from pyams_skin.viewlet.toolbar import ToolbarMenuItem
       
    33 from pyams_template.template import template_config
       
    34 from pyams_utils.interfaces import MANAGE_SYSTEM_PERMISSION, VIEW_SYSTEM_PERMISSION
       
    35 from pyams_viewlet.viewlet import Viewlet, viewlet_config
       
    36 from pyams_zmi.form import AdminDialogAddForm, AdminDialogEditForm
       
    37 from pyams_zmi.layer import IAdminLayer
       
    38 from pyams_zmi.zmi.control_panel import UtilitiesTable
    40 
    39 
    41 
    40 
    42 @pagelet_config(name='properties.html', context=IContentIndexerUtility, layer=IPyAMSLayer,
    41 @pagelet_config(name='properties.html', context=IContentIndexerUtility, layer=IPyAMSLayer,
    43                 permission=VIEW_SYSTEM_PERMISSION)
    42                 permission=VIEW_SYSTEM_PERMISSION)
    44 class ContentIndexerUtilityPropertiesEditForm(AdminDialogEditForm):
    43 class ContentIndexerUtilityPropertiesEditForm(AdminDialogEditForm):
    83     test = button.Button(name='test', title=_("Test connection"))
    82     test = button.Button(name='test', title=_("Test connection"))
    84 
    83 
    85 
    84 
    86 @pagelet_config(name='test-indexer-process.html', context=IContentIndexerUtility, layer=IPyAMSLayer,
    85 @pagelet_config(name='test-indexer-process.html', context=IContentIndexerUtility, layer=IPyAMSLayer,
    87                 permission=MANAGE_SYSTEM_PERMISSION)
    86                 permission=MANAGE_SYSTEM_PERMISSION)
       
    87 @ajax_config(name='text-indexer-process.json', context=IContentIndexerUtility, layer=IPyAMSLayer,
       
    88              base=AJAXAddForm)
    88 class ContentIndexerProcessTestForm(AdminDialogAddForm):
    89 class ContentIndexerProcessTestForm(AdminDialogAddForm):
    89     """Content indexer process test form"""
    90     """Content indexer process test form"""
    90 
    91 
    91     @property
    92     @property
    92     def title(self):
    93     def title(self):
    96     icon_css_class = 'fa fa-fw fa-server'
    97     icon_css_class = 'fa fa-fw fa-server'
    97 
    98 
    98     prefix = 'test_form.'
    99     prefix = 'test_form.'
    99     fields = field.Fields(Interface)
   100     fields = field.Fields(Interface)
   100     buttons = button.Buttons(IContentIndexerProcessTestButtons)
   101     buttons = button.Buttons(IContentIndexerProcessTestButtons)
   101     ajax_handler = 'test-indexer-process.json'
   102 
   102     edit_permission = MANAGE_SYSTEM_PERMISSION
   103     edit_permission = MANAGE_SYSTEM_PERMISSION
   103 
   104 
   104     @property
   105     @property
   105     def form_target(self):
   106     def form_target(self):
   106         return '#{0}_test_result'.format(self.id)
   107         return '#{0}_test_result'.format(self.id)
   110         if 'test' in self.actions:
   111         if 'test' in self.actions:
   111             self.actions['test'].addClass('btn-primary')
   112             self.actions['test'].addClass('btn-primary')
   112 
   113 
   113     def createAndAdd(self, data):
   114     def createAndAdd(self, data):
   114         return self.context.test_process()
   115         return self.context.test_process()
   115 
       
   116 
       
   117 @viewlet_config(name='test-indexer-process.suffix', layer=IAdminLayer, manager=IWidgetsSuffixViewletsManager,
       
   118                 view=ContentIndexerProcessTestForm, weight=50)
       
   119 @template_config(template='templates/process-test.pt')
       
   120 class ContentIndexerProcessTestSuffix(Viewlet):
       
   121     """Content indexer process test form suffix"""
       
   122 
       
   123 
       
   124 @view_config(name='test-indexer-process.json', context=IContentIndexerUtility, request_type=IPyAMSLayer,
       
   125              permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
       
   126 class ContentIndexerProcessAJAXTestForm(AJAXAddForm, ContentIndexerProcessTestForm):
       
   127     """Content indexer process test form, JSON renderer"""
       
   128 
   116 
   129     def get_ajax_output(self, changes):
   117     def get_ajax_output(self, changes):
   130         status, message = changes
   118         status, message = changes
   131         if status == 200:
   119         if status == 200:
   132             return {
   120             return {
   138             return {
   126             return {
   139                 'status': 'info',
   127                 'status': 'info',
   140                 'content': {'html': message},
   128                 'content': {'html': message},
   141                 'close_form': False
   129                 'close_form': False
   142             }
   130             }
       
   131 
       
   132 
       
   133 @viewlet_config(name='test-indexer-process.suffix', layer=IAdminLayer, manager=IWidgetsSuffixViewletsManager,
       
   134                 view=ContentIndexerProcessTestForm, weight=50)
       
   135 @template_config(template='templates/process-test.pt')
       
   136 class ContentIndexerProcessTestSuffix(Viewlet):
       
   137     """Content indexer process test form suffix"""