src/pyams_content/shared/common/zmi/types.py
changeset 833 987838f48783
parent 826 eb16b1127e06
child 848 a7cfc19b1b1b
equal deleted inserted replaced
832:54e1fc14724b 833:987838f48783
     7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
     7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
     8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
    10 # FOR A PARTICULAR PURPOSE.
    10 # FOR A PARTICULAR PURPOSE.
    11 #
    11 #
       
    12 from pyams_content.reference.pictograms.zmi.widget import PictogramSelectFieldWidget
       
    13 from pyams_content.shared.common.zmi import SharedContentAddForm
       
    14 from pyams_content.shared.common.zmi.properties import SharedContentPropertiesEditForm
       
    15 from pyams_i18n.widget import I18nSEOTextLineFieldWidget
    12 
    16 
    13 __docformat__ = 'restructuredtext'
    17 __docformat__ = 'restructuredtext'
    14 
    18 
    15 
    19 
    16 # import standard library
    20 # import standard library
    17 import json
    21 import json
    18 
    22 
    19 # import interfaces
    23 # import interfaces
    20 from pyams_content.interfaces import MANAGE_TOOL_PERMISSION
    24 from pyams_content.interfaces import MANAGE_TOOL_PERMISSION, MANAGE_CONTENT_PERMISSION
    21 from pyams_content.shared.common.interfaces.types import ITypedSharedTool, ITypedDataManager, \
    25 from pyams_content.shared.common.interfaces.types import ITypedSharedTool, ITypedDataManager, \
    22     IBaseDataType, IDataType, ISubType
    26     IBaseDataType, IDataType, ISubType, IWfTypedSharedContent
    23 from pyams_content.skin import pyams_content
    27 from pyams_content.skin import pyams_content
    24 from pyams_i18n.interfaces import II18n
    28 from pyams_i18n.interfaces import II18n
    25 from pyams_skin.interfaces.container import ITableElementName
    29 from pyams_skin.interfaces.container import ITableElementName
    26 from pyams_skin.interfaces.viewlet import IWidgetTitleViewletManager
    30 from pyams_skin.interfaces.viewlet import IWidgetTitleViewletManager
    27 from pyams_skin.layer import IPyAMSLayer
    31 from pyams_skin.layer import IPyAMSLayer
   264     legend = _("Add new data type")
   268     legend = _("Add new data type")
   265     icon_css_class = 'fa fa-fw fa-folder-o'
   269     icon_css_class = 'fa fa-fw fa-folder-o'
   266     label_css_class = 'control-label col-md-4'
   270     label_css_class = 'control-label col-md-4'
   267     input_css_class = 'col-md-8'
   271     input_css_class = 'col-md-8'
   268 
   272 
   269     fields = field.Fields(IDataType).omit('__parent__', '__name__')
   273     @property
       
   274     def fields(self):
       
   275         fields = field.Fields(IDataType).omit('__parent__', '__name__')
       
   276         fields['pictogram'].widgetFactory = PictogramSelectFieldWidget
       
   277         if not self.context.shared_content_types_fields:
       
   278             fields = fields.omit('field_names')
       
   279         return fields
   270 
   280 
   271     edit_permission = MANAGE_TOOL_PERMISSION
   281     edit_permission = MANAGE_TOOL_PERMISSION
   272 
   282 
   273     def create(self, data):
   283     def create(self, data):
   274         return DataType()
   284         return DataType()
   301     legend = _("Data type properties")
   311     legend = _("Data type properties")
   302     icon_css_class = 'fa fa-fw fa-folder-o'
   312     icon_css_class = 'fa fa-fw fa-folder-o'
   303     label_css_class = 'control-label col-md-4'
   313     label_css_class = 'control-label col-md-4'
   304     input_css_class = 'col-md-8'
   314     input_css_class = 'col-md-8'
   305 
   315 
   306     fields = field.Fields(IDataType).omit('__parent__', '__name__')
   316     @property
       
   317     def fields(self):
       
   318         fields = field.Fields(IDataType).omit('__parent__', '__name__')
       
   319         fields['pictogram'].widgetFactory = PictogramSelectFieldWidget
       
   320         tool = get_parent(self.context, ITypedSharedTool)
       
   321         if not tool.shared_content_types_fields:
       
   322             fields = fields.omit('field_names')
       
   323         return fields
   307 
   324 
   308     edit_permission = MANAGE_TOOL_PERMISSION
   325     edit_permission = MANAGE_TOOL_PERMISSION
   309 
   326 
   310     def updateWidgets(self, prefix=None):
   327     def updateWidgets(self, prefix=None):
   311         super(DataTypeEditForm, self).updateWidgets(prefix)
   328         super(DataTypeEditForm, self).updateWidgets(prefix)
   469     icon_css_class = 'fa fa-fw fa-folder-o'
   486     icon_css_class = 'fa fa-fw fa-folder-o'
   470     label_css_class = 'control-label col-md-4'
   487     label_css_class = 'control-label col-md-4'
   471     input_css_class = 'col-md-8'
   488     input_css_class = 'col-md-8'
   472 
   489 
   473     fields = field.Fields(ISubType).omit('__parent__', '__name__')
   490     fields = field.Fields(ISubType).omit('__parent__', '__name__')
       
   491     fields['pictogram'].widgetFactory = PictogramSelectFieldWidget
   474 
   492 
   475     edit_permission = MANAGE_TOOL_PERMISSION
   493     edit_permission = MANAGE_TOOL_PERMISSION
   476 
   494 
   477     def create(self, data):
   495     def create(self, data):
   478         return SubType()
   496         return SubType()
   515     icon_css_class = 'fa fa-fw fa-folder-o'
   533     icon_css_class = 'fa fa-fw fa-folder-o'
   516     label_css_class = 'control-label col-md-4'
   534     label_css_class = 'control-label col-md-4'
   517     input_css_class = 'col-md-8'
   535     input_css_class = 'col-md-8'
   518 
   536 
   519     fields = field.Fields(ISubType).omit('__parent__', '__name__')
   537     fields = field.Fields(ISubType).omit('__parent__', '__name__')
       
   538     fields['pictogram'].widgetFactory = PictogramSelectFieldWidget
   520 
   539 
   521     edit_permission = MANAGE_TOOL_PERMISSION
   540     edit_permission = MANAGE_TOOL_PERMISSION
   522 
   541 
   523     def updateWidgets(self, prefix=None):
   542     def updateWidgets(self, prefix=None):
   524         super(DataSubtypeEditForm, self).updateWidgets(prefix)
   543         super(DataSubtypeEditForm, self).updateWidgets(prefix)
   535                     get_json_table_refresh_event(target, self.request, DatatypeSubtypesTable)
   554                     get_json_table_refresh_event(target, self.request, DatatypeSubtypesTable)
   536                 ]
   555                 ]
   537             }
   556             }
   538         else:
   557         else:
   539             return super(self.__class__, self).get_ajax_output(changes)
   558             return super(self.__class__, self).get_ajax_output(changes)
       
   559 
       
   560 
       
   561 #
       
   562 # Typed shared content views
       
   563 #
       
   564 
       
   565 class TypedSharedContentAddForm(SharedContentAddForm):
       
   566     """Typed shared content add form"""
       
   567 
       
   568     fields = field.Fields(IWfTypedSharedContent).select('title', 'data_type', 'notepad')
       
   569 
       
   570 
       
   571 @pagelet_config(name='properties.html', context=IWfTypedSharedContent, layer=IPyAMSLayer,
       
   572                 permission=MANAGE_CONTENT_PERMISSION)
       
   573 @ajax_config(name='properties.json', context=IWfTypedSharedContent, layer=IPyAMSLayer,
       
   574              permission=MANAGE_CONTENT_PERMISSION)
       
   575 class TypedSharedContentProperteisEditForm(SharedContentPropertiesEditForm):
       
   576     """Typed shared content properties edit form"""
       
   577 
       
   578     fields = field.Fields(IWfTypedSharedContent).select('title', 'short_name', 'content_url',
       
   579                                                         'data_type', 'description', 'notepad')
       
   580     fields['title'].widgetFactory = I18nSEOTextLineFieldWidget