def __call__(self): request = self.request context = self.context plone_utils = getToolByName(context, 'plone_utils') message = None if request.form.get("add-command",''): # request.response.setHeader('Content-Type','application/json') message = self._addMenuEntry(request.form) request.response.redirect(context.absolute_url()+'/@@customize-factoriesmenu') elif request.form.get("update-command",''): message = self._updateMenuEntries(request.form) request.response.redirect(context.absolute_url()+'/@@customize-factoriesmenu') elif request.form.get("delete-command",''): message = self._deleteMenuEntries(request.form) request.response.redirect(context.absolute_url()+'/@@customize-factoriesmenu') elif request.form.get("enable-command",''): self.enable() message = _(u"Enabled local customizations") request.response.redirect(context.absolute_url()+'/@@customize-factoriesmenu') elif request.form.get("disable-command",''): self.disable() message = _(u"Local customizations disabled") request.response.redirect(context.absolute_url()) if message: if type(message)==tuple: message, tp = message else: tp = 'info' plone_utils.addPortalMessage(message, type=tp) return if self.enabled: return self.index() return self.enable_template()
def _deleteMenuEntries(self, form): context = self.context extras, saved_customizations = self.getSavedCustomizations() to_delete = form.get('delete',[]) if not to_delete: return _(u'Please, select at least one entry to be deleted'), 'error' saved_customizations = [x for x in saved_customizations if x['index'] not in to_delete] self._reindex(saved_customizations) annotations = IAnnotations(context) annotations[ANN_CUSTOMMENU_KEY] = (extras, saved_customizations) annotations._p_changed=1 return _(u'Customizations removed')
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 _updateMenuEntries(self, form): context = self.context saved_customizations = [] for x in range(0, len(form.get('index',[]))): # check not-mandatory data if not form.get('element-name')[x] or not form.get('element-tales')[x]: return _(u'Please, provide all required data'), 'error' saved_customizations.append( self._generateNewMenuElement(x, form.get('element-id')[x], form.get('element-name')[x], form.get('element-descr')[x], form.get('icon-tales')[x], form.get('condition-tales')[x], form.get('element-tales')[x])) annotations = IAnnotations(context) annotations[ANN_CUSTOMMENU_KEY] = ({'inherit': form.get('inherit',False)}, saved_customizations) annotations._p_changed=1 return _(u'Customizations updated')
def _addMenuEntry(self, form): context = self.context # check not-mandatory data if not form.get('element-name') or not form.get('element-tales'): return _(u'Please, provide all required data'), 'error' extras, saved_customizations = self.getSavedCustomizations() saved_customizations.append(self._generateNewMenuElement( len(saved_customizations), form.get('element-id'), form.get('element-name'), form.get('element-descr'), form.get('icon-tales'), form.get('condition-tales'), form.get('element-tales')) ) annotations = IAnnotations(context) annotations[ANN_CUSTOMMENU_KEY] = (extras, saved_customizations) annotations._p_changed=1 return _(u'New entry added')