def setup_form(self): self.buttons = button.Buttons() self.handlers = button.Handlers() if self.form_type() == 'addform': preview = button.Button(title=_(u'Continue'), name='save') self.buttons += button.Buttons(preview) preview_handler = button.Handler(preview, self.__class__.handle_preview) self.handlers.addHandler(preview, preview_handler) self.ignoreContext = True self.ignoreReadonly = True else: update = button.Button(title=_(u'Continue'), name='save') self.buttons += button.Buttons(update) update_handler = button.Handler(update, self.__class__.handle_update) self.handlers.addHandler(update, update_handler) self.context = self.event cancel = button.Button(title=_(u'Cancel'), name='cancel') self.buttons += button.Buttons(cancel) cancel_handler = button.Handler(cancel, self.__class__.handle_cancel) self.handlers.addHandler(cancel, cancel_handler)
def setup_form(self): self.buttons = button.Buttons() self.handlers = button.Handlers() save = button.Button(title=_(u'Save Event'), name='save') self.buttons += button.Buttons(save) save_handler = button.Handler(save, self.__class__.handle_save) self.handlers.addHandler(save, save_handler) self.event = self.context cancel = button.Button(title=_(u'Cancel Event Submission'), name='cancel') self.buttons += button.Buttons(cancel) cancel_handler = button.Handler(cancel, self.__class__.handle_cancel) self.handlers.addHandler(cancel, cancel_handler)
def append_action_buttons(form): # Get currently available workflow actions (re-use from menu) actions = {} menu = getUtility(IBrowserMenu, name='plone_contentmenu_workflow') def lower_first(s): if s and isinstance(s, unicode) and len(s) > 1: return s[0].lower() + s[1:] elif s and isinstance(s, unicode): return s.lower() return s for action in menu.getMenuItems(form.context, form.request): item_id = action.get('extra', {}).get('id', u'') or u'' action_id = re.sub('^workflow-transition-(.*)', '\\1', item_id) actions[action_id] = action for action in ['advanced', 'policy']: # blacklisted menuitems if action in actions: del actions[action] form.buttons = form.buttons.copy() for action_id, action in actions.iteritems(): new_button = button.Button( name=re.sub('^workflow-transition-(.*)', '\\1', action_id), title=u' '.join([ translate( _(u'Save and'), context=form.request, ), lower_first( translate( action['title'], domain='plone', context=form.request, ), ), ]), ) form.buttons += button.Buttons(new_button) form.handlers.addHandler( new_button, button.Handler( new_button, functools.partial(form.redirect, action['action']), ), )
HAVE_RESOURCE_EDITOR = True except ImportError: HAVE_RESOURCE_EDITOR = False # We want to add a Plone-specific feature to the SchemaListing # form from plone.schemaeditor. We'll do this by subclassing, then # adding the plone-specific button for the ace model editor. class EnhancedSchemaListing(SchemaListing): def handleModelEdit(self, action): self.request.response.redirect('@@modeleditor') if HAVE_RESOURCE_EDITOR: but = button.Button("modeleditor", title=u'Edit XML Field Model') EnhancedSchemaListing.buttons += button.Buttons(but) handler = button.Handler(but, EnhancedSchemaListing.handleModelEdit) EnhancedSchemaListing.handlers.addHandler(but, handler) class TypeFieldsPage(TypeFormLayout): label = _(u'Fields') @property def form(self): if self.context.fti.hasDynamicSchema: return EnhancedSchemaListing else: return ReadOnlySchemaListing
class FieldsSchemaListing(SchemaListing): template = ViewPageTemplateFile('fields_listing.pt') @property def default_fieldset_label(self): return (self.context.aq_parent.default_fieldset_label or super(FieldsSchemaListing, self).default_fieldset_label) def handleModelEdit(self, action): self.request.response.redirect('@@modeleditor') if HAVE_RESOURCE_EDITOR: but = button.Button("modeleditor", title=_(u'Edit XML Fields Model')) FieldsSchemaListing.buttons += button.Buttons(but) handler = button.Handler(but, FieldsSchemaListing.handleModelEdit) FieldsSchemaListing.handlers.addHandler(but, handler) class EasyFormFieldsListingPage(SchemaListingPage): """ Form wrapper so we can get a form with layout. We define an explicit subclass rather than using the wrap_form method from plone.z3cform.layout so that we can inject the schema name into the form label. """ form = FieldsSchemaListing index = ViewPageTemplateFile('model_listing.pt') class FieldEditForm(FieldEditForm):
form = ActionEditForm def __init__(self, context, request): super(ActionEditView, self).__init__(context, request) self.field = context.field @lazy_property def label(self): return _(u"Edit Action '${fieldname}'", mapping={'fieldname': self.field.__name__}) if HAVE_RESOURCE_EDITOR: but = button.Button("modeleditor", title=_(u'Edit XML Actions Model')) EasyFormActionsListing.buttons += button.Buttons(but) handler = button.Handler(but, EasyFormActionsListing.handleModelEdit) EasyFormActionsListing.handlers.addHandler(but, handler) class ModelEditorView(BrowserView): """ editor view """ title = _(u'Edit XML Actions Model') def modelSource(self): return self.context.aq_parent.actions_model class AjaxSaveHandler(AjaxSaveHandler): """ handle AJAX save posts """ def save(self, source): self.context.aq_parent.actions_model = source