Back to index

plone3  3.1.7
skins.py
Go to the documentation of this file.
00001 from zope.interface import Interface
00002 from zope.component import adapts
00003 from zope.formlib.form import FormFields
00004 from zope.interface import implements
00005 from zope.schema import Bool
00006 from zope.schema import Choice
00007 
00008 from Products.CMFCore.utils import getToolByName
00009 from Products.CMFDefault.formlib.schema import SchemaAdapterBase
00010 from Products.CMFPlone import PloneMessageFactory as _
00011 from Products.CMFPlone.interfaces import IPloneSiteRoot
00012 
00013 from form import ControlPanelForm
00014 from widgets import DropdownChoiceWidget
00015 
00016 from zope.schema.vocabulary import SimpleTerm
00017 from zope.schema.vocabulary import SimpleVocabulary
00018 
00019 ICON_VISIBILITY_CHOICES = {
00020     _(u"Only for users who are logged in"): 'authenticated',
00021     _(u"Never show icons"): 'disabled',
00022     _(u"Always show icons"): 'enabled',
00023 }
00024 
00025 ICON_VISIBILITY_VOCABULARY = SimpleVocabulary(
00026     [SimpleTerm(v, v, k) for k, v in ICON_VISIBILITY_CHOICES.items()]
00027     )
00028 
00029 
00030 class ISkinsSchema(Interface):
00031 
00032     theme = Choice(title=_(u'Default theme'),
00033                   description=_(u'''Select the default theme for the site.'''),
00034                   required=True,
00035                   missing_value=tuple(),
00036                   vocabulary="plone.app.vocabularies.Skins")
00037 
00038     mark_special_links = Bool(title=_(u'Mark external links'),
00039                               description=_(u"If enabled all external links "
00040                                              "will be marked with link type "
00041                                              "specific icons. If disabled "
00042                                              "the 'external links open in new "
00043                                              "window' setting has no effect."),
00044                               default=True)
00045 
00046     ext_links_open_new_window = Bool(title=_(u"External links open in new "
00047                                               "window"),
00048                                      description=_(u"If enabled all external "
00049                                                     "links in the content "
00050                                                     "region open in a new "
00051                                                     "window."),
00052                                      default=False)
00053 
00054     icon_visibility = Choice(title=_(u'Show content type icons'),
00055                              description=_(u"If disabled the content icons "
00056                                             "in folder listings and portlets "
00057                                             "won't be visible."),
00058                              vocabulary=ICON_VISIBILITY_VOCABULARY)
00059 
00060 
00061 class SkinsControlPanelAdapter(SchemaAdapterBase):
00062 
00063     adapts(IPloneSiteRoot)
00064     implements(ISkinsSchema)
00065 
00066     def __init__(self, context):
00067         super(SkinsControlPanelAdapter, self).__init__(context)
00068         self.context = getToolByName(context, 'portal_skins')
00069         self.jstool = getToolByName(context, 'portal_javascripts')
00070         ptool = getToolByName(context, 'portal_properties')
00071         self.props = ptool.site_properties
00072 
00073     def get_theme(self):
00074         return self.context.getDefaultSkin()
00075 
00076     def set_theme(self, value):
00077         self.context.default_skin = value
00078 
00079     theme = property(get_theme, set_theme)
00080 
00081     def get_mark_special_links(self):
00082         return self.jstool.getResource('mark_special_links.js').getEnabled()
00083 
00084     def set_mark_special_links(self, value):
00085         if value:
00086             self.jstool.getResource('mark_special_links.js').setEnabled(True)
00087         else:
00088             self.jstool.getResource('mark_special_links.js').setEnabled(False)
00089         self.jstool.cookResources()
00090 
00091     mark_special_links = property(get_mark_special_links,
00092                                   set_mark_special_links)
00093 
00094     def get_ext_links_open_new_window(self):
00095         elonw = self.props.external_links_open_new_window
00096         if elonw == 'true':
00097             return True
00098         return False
00099 
00100     def set_ext_links_open_new_window(self, value):
00101         if value:
00102             self.props.manage_changeProperties(external_links_open_new_window='true')
00103         else:
00104             self.props.manage_changeProperties(external_links_open_new_window='false')
00105         self.jstool.cookResources()
00106 
00107     ext_links_open_new_window = property(get_ext_links_open_new_window,
00108                                          set_ext_links_open_new_window)
00109 
00110     def get_icon_visibility(self):
00111         return self.props.icon_visibility
00112 
00113     def set_icon_visibility(self, value):
00114         self.props.manage_changeProperties(icon_visibility=value)
00115 
00116     icon_visibility = property(get_icon_visibility,set_icon_visibility)
00117 
00118 
00119 class SkinsControlPanel(ControlPanelForm):
00120 
00121     form_fields = FormFields(ISkinsSchema)
00122     form_fields['theme'].custom_widget = DropdownChoiceWidget
00123 
00124     label = _("Theme settings")
00125     description = _("Settings that affect the site's look and feel.")
00126     form_name = _("Theme settings")