Beispiel #1
0
    def getMenuItems(self, context, request):
        """Return menu item entries in a TAL-friendly form."""
        results = BaseFactoriesMenu.getMenuItems(self, context, request)
        
        factories_view = getMultiAdapter((context, request), name='folder_factories')

        haveMore = False
        include = None

        addContext = factories_view.default_page_add_context()
        if not addContext:
            return results
        allowedTypes = _allowedTypes(request, addContext)

        constraints = IConstrainTypes(addContext, None)
        if constraints is not None:
            include = constraints.getImmediatelyAddableTypes()
            if len(include) < len(allowedTypes):
                haveMore = True

        results.append({'title'       : _p(u'folder_add_to_default_page', default=u'Add to default page'),
                        'description' : _p(u'Add content to the default page'),
                        'action'      : None,
                        'selected'    : False,
                        'icon'        : None,
                        'extra'       : {'id': 'add-to-default', 'separator': 'actionSeparator', 'class': ''},
                        'submenu'     : None,
                        })

        results += factories_view.default_page_addable_types(include=include)

        if haveMore:
            url = '%s/folder_factories' % (addContext.absolute_url(),)
            results.append({ 'title'       : _p(u'folder_add_more', default=u'More\u2026'),
                             'description' : _p(u'Show all available content types'),
                             'action'      : url,
                             'selected'    : False,
                             'icon'        : None,
                             'extra'       : {'id': 'more', 'separator': None, 'class': ''},
                             'submenu'     : None,
                            })

        constraints = ISelectableConstrainTypes(addContext, None)
        if constraints is not None:
            if constraints.canSetConstrainTypes() and constraints.getDefaultAddableTypes():
                url = '%s/folder_constraintypes_form' % (addContext.absolute_url(),)
                results.append({'title'       : _p(u'folder_add_settings', default=u'Restrictions\u2026'),
                                'description' : _p(u'title_configure_addable_content_types', default=u'Configure which content types can be added here'),
                                'action'      : url,
                                'selected'    : False,
                                'icon'        : None,
                                'extra'       : {'id': 'settings', 'separator': None, 'class': ''},
                                'submenu'     : None,
                                })

        return results
    def getMenuItems(self, context, request):
        """Return menu item entries in a TAL-friendly form."""
        results = PloneFactoriesMenu.getMenuItems(self, context, request)

        # No menu customization if the product is not installed
        if not ICustomMenuFactoryLayer.providedBy(request):
            return results
        
        portal_url = getToolByName(context, 'portal_url')

        # First of all, get the real context of the menu
        if IFolder.providedBy(context):
            folder = context
        elif isFolderOrFolderDefaultPage(context, request):
            folder = aq_parent(aq_inner(context))
        else:
            # don't know how to handle this
            folder = context

        data = {'context': context, 'portal_url': portal_url, 'container': folder}

        # If folder can't be annotable, do nothing
        # uncommon but may happen for old stuff like PloneGazette
        if not queryAdapter(folder, interface=IAnnotations):
            return results

        try:
            m_provider = ICustomFactoryMenuProvider(folder)
        except TypeError:
            # For any adaptation problem
            return results
        
        results = m_provider.getMenuCustomization(data, results)

        # Re-sort
        results.sort(lambda x, y: cmp(x['title'],y['title']))

        mtool = getToolByName(context, 'portal_membership')
        if not mtool.isAnonymousUser() and mtool.getAuthenticatedMember().has_permission('Customize menu: factories', folder):
            context_url = folder.absolute_url()
            results.append({'title'       : _(u'custommenu_manage_title', default=_(u'Customize menu\u2026')),
                            'description' : _(u'custommenu_manage_description', default=_(u'Manage custom elements of this menu')),
                            'action'      : context_url+'/@@customize-factoriesmenu',
                            'selected'    : False,
                            'icon'        : None,
                            'submenu'     : None,
                            'extra'       : {'separator': 'actionSeparator', 'id': 'customize-factoriesmenu', 'class': 'customize-menu'},
                            })
        return results
    def getMenuItems(self, context, request):
        """Return menu item entries in a TAL-friendly form."""
        results = BaseFactoriesMenu.getMenuItems(self, context, request)

        factories_view = getMultiAdapter((context, request),
                                         name='folder_factories')

        haveMore = False
        include = None

        addContext = factories_view.default_page_add_context()
        if not addContext:
            return results
        allowedTypes = _allowedTypes(request, addContext)

        constraints = IConstrainTypes(addContext, None)
        if constraints is not None:
            include = constraints.getImmediatelyAddableTypes()
            if len(include) < len(allowedTypes):
                haveMore = True

        results.append({
            'title':
            _p(u'folder_add_to_default_page', default=u'Add to default page'),
            'description':
            _p(u'Add content to the default page'),
            'action':
            None,
            'selected':
            False,
            'icon':
            None,
            'extra': {
                'id': 'add-to-default',
                'separator': 'actionSeparator',
                'class': ''
            },
            'submenu':
            None,
        })

        results += factories_view.default_page_addable_types(include=include)

        if haveMore:
            url = '%s/folder_factories' % (addContext.absolute_url(), )
            results.append({
                'title':
                _p(u'folder_add_more', default=u'More\u2026'),
                'description':
                _p(u'Show all available content types'),
                'action':
                url,
                'selected':
                False,
                'icon':
                None,
                'extra': {
                    'id': 'more',
                    'separator': None,
                    'class': ''
                },
                'submenu':
                None,
            })

        constraints = ISelectableConstrainTypes(addContext, None)
        if constraints is not None:
            if constraints.canSetConstrainTypes(
            ) and constraints.getDefaultAddableTypes():
                url = '%s/folder_constraintypes_form' % (
                    addContext.absolute_url(), )
                results.append({
                    'title':
                    _p(u'folder_add_settings', default=u'Restrictions\u2026'),
                    'description':
                    _p(u'title_configure_addable_content_types',
                       default=
                       u'Configure which content types can be added here'),
                    'action':
                    url,
                    'selected':
                    False,
                    'icon':
                    None,
                    'extra': {
                        'id': 'settings',
                        'separator': None,
                        'class': ''
                    },
                    'submenu':
                    None,
                })

        return results
Beispiel #4
0
    def getMenuItems(self, context, request):
        """Return menu item entries in a TAL-friendly form."""
        results = PloneFactoriesMenu.getMenuItems(self, context, request)

        # No menu customization if the product is not installed
        if not ICollectiveFactorymenuLayer.providedBy(request):
            return results

        portal_url = getToolByName(context, 'portal_url')

        # First of all, get the real context of the menu
        if IFolder.providedBy(context):
            folder = context
        elif isFolderOrFolderDefaultPage(context, request):
            folder = aq_parent(aq_inner(context))
        else:
            # don't know how to handle this
            folder = context

        data = {
            'context': context,
            'portal_url': portal_url,
            'container': folder
        }

        # If folder can't be annotable, do nothing
        # uncommon but may happen for old stuff like PloneGazette
        if not queryAdapter(folder, interface=IAnnotations):
            return results

        try:
            m_provider = ICustomFactoryMenuProvider(folder)
        except TypeError:
            # For any adaptation problem
            return results

        results = m_provider.getMenuCustomization(data, results)

        # Re-sort
        results.sort(lambda x, y: cmp(x['title'], y['title']))

        mtool = getToolByName(context, 'portal_membership')
        if not mtool.isAnonymousUser() and\
            mtool.getAuthenticatedMember().has_permission(
                'Customize menu: factories', folder
        ):
            context_url = folder.absolute_url()
            results.append({
                'title':
                _(u'custommenu_manage_title', default=u'Customize menu\u2026'),
                'description':
                _(u'custommenu_manage_description',
                  default=u'Manage custom elements '
                  u'of this menu'),
                'action':
                context_url + '/@@customize-factoriesmenu',
                'selected':
                False,
                'icon':
                None,
                'submenu':
                None,
                'extra': {
                    'separator': 'actionSeparator',
                    'id': 'customize-factoriesmenu',
                    'class': 'customize-menu'
                },
            })
        return results