17 |
17 |
18 # import interfaces |
18 # import interfaces |
19 from hypatia.interfaces import ICatalog, IIndexStatistics, IIndexEnumeration |
19 from hypatia.interfaces import ICatalog, IIndexStatistics, IIndexEnumeration |
20 from pyams_form.interfaces.form import IWidgetsSuffixViewletsManager |
20 from pyams_form.interfaces.form import IWidgetsSuffixViewletsManager |
21 from pyams_skin.layer import IPyAMSLayer |
21 from pyams_skin.layer import IPyAMSLayer |
22 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION, MANAGE_SYSTEM_PERMISSION |
22 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION, MANAGE_SYSTEM_PERMISSION, ICacheKeyValue |
23 from pyams_zmi.layer import IAdminLayer |
23 from pyams_zmi.layer import IAdminLayer |
24 from z3c.table.interfaces import IColumn, IValues |
24 from z3c.table.interfaces import IColumn, IValues |
25 |
25 |
26 # import packages |
26 # import packages |
27 from pyams_catalog.index import InterfaceSupportIndexMixin |
27 from pyams_catalog.index import InterfaceSupportIndexMixin |
28 from pyams_pagelet.pagelet import pagelet_config |
28 from pyams_pagelet.pagelet import pagelet_config |
|
29 from pyams_skin.container import delete_container_element |
29 from pyams_skin.table import BaseTable, I18nColumn, TrashColumn, TableViewlet |
30 from pyams_skin.table import BaseTable, I18nColumn, TrashColumn, TableViewlet |
30 from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter |
31 from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter |
31 from pyams_utils.text import text_to_html |
32 from pyams_utils.text import text_to_html |
32 from pyams_utils.url import absolute_url |
33 from pyams_utils.url import absolute_url |
33 from pyams_viewlet.viewlet import viewlet_config |
34 from pyams_viewlet.viewlet import viewlet_config |
55 |
56 |
56 |
57 |
57 class CatalogIndexesTable(BaseTable): |
58 class CatalogIndexesTable(BaseTable): |
58 """Catalog indexes table""" |
59 """Catalog indexes table""" |
59 |
60 |
60 id = 'CatalogIndexes' |
61 prefix = 'CatalogIndexes' |
|
62 |
61 title = _("Catalog indexes") |
63 title = _("Catalog indexes") |
62 cssClasses = {'table': 'table table-bordered table-striped table-hover table-tight datatable'} |
64 cssClasses = {'table': 'table table-bordered table-striped table-hover table-tight datatable'} |
63 sortOn = None |
65 sortOn = None |
64 |
66 |
65 @property |
67 @property |
66 def data_attributes(self): |
68 def data_attributes(self): |
67 attributes = super(CatalogIndexesTable, self).data_attributes |
69 attributes = super(CatalogIndexesTable, self).data_attributes |
68 table_attrs = {'data-ams-location': absolute_url(self.context, self.request), |
70 attributes.setdefault('table', {}).update({ |
69 'data-ams-delete-target': 'delete-index.json', |
71 'data-ams-location': absolute_url(self.context, self.request), |
70 'data-ams-datatable-global-filter': 'false', |
72 'data-ams-datatable-global-filter': 'false', |
71 'data-ams-datatable-info': 'false', |
73 'data-ams-datatable-info': 'false', |
72 'data-ams-datatable-sdom': "t<'dt-row dt-bottom-row'<'text-right'p>>", |
74 'data-ams-datatable-sdom': "t<'dt-row dt-bottom-row'<'text-right'p>>", |
73 'data-ams-datatable-display-length': '20', |
75 'data-ams-datatable-display-length': '20', |
74 'data-ams-datatable-pagination-type': 'bootstrap_prevnext'} |
76 'data-ams-datatable-pagination-type': 'bootstrap_prevnext' |
75 if 'table' in attributes: |
77 }) |
76 attributes['table'].update(table_attrs) |
78 attributes.setdefault('tr', {}).update({ |
77 else: |
79 'id': lambda x, col: '{0}::{1}'.format(self.prefix, ICacheKeyValue(x)) |
78 attributes['table'] = table_attrs |
80 }) |
79 return attributes |
81 return attributes |
80 |
82 |
81 |
83 |
82 @adapter_config(name='name', context=(Interface, IAdminLayer, CatalogIndexesTable), provides=IColumn) |
84 @adapter_config(name='name', context=(Interface, IAdminLayer, CatalogIndexesTable), provides=IColumn) |
83 class CatalogIndexNameColumn(I18nColumn, GetAttrColumn): |
85 class CatalogIndexNameColumn(I18nColumn, GetAttrColumn): |
215 """Catalog indexes viewlet""" |
217 """Catalog indexes viewlet""" |
216 |
218 |
217 table_class = CatalogIndexesTable |
219 table_class = CatalogIndexesTable |
218 |
220 |
219 |
221 |
220 @view_config(name='delete-index.json', context=ICatalog, request_type=IPyAMSLayer, |
222 @view_config(name='delete-element.json', context=ICatalog, request_type=IPyAMSLayer, |
221 permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True) |
223 permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True) |
222 def delete_catalog_index(request): |
224 def delete_catalog_index(request): |
223 """Delete index from catalog""" |
225 """Delete index from catalog""" |
224 translate = request.localizer.translate |
226 return delete_container_element(request) |
225 name = request.params.get('object_name') |
|
226 if not name: |
|
227 return {'status': 'message', |
|
228 'messagebox': {'status': 'error', |
|
229 'content': translate(_("No provided object_name argument!"))}} |
|
230 if name not in request.context: |
|
231 return {'status': 'message', |
|
232 'messagebox': {'status': 'error', |
|
233 'content': translate(_("Given index doesn't exist!"))}} |
|
234 del request.context[name] |
|
235 return {'status': 'success'} |
|