Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes
plone.app.form.kss.edit.FormlibInlineEdit Class Reference
Inheritance diagram for plone.app.form.kss.edit.FormlibInlineEdit:
Inheritance graph
[legend]
Collaboration diagram for plone.app.form.kss.edit.FormlibInlineEdit:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def begin
def cancel
def save
def macroContent
def issueAllPortalMessages

Static Public Attributes

tuple form_template = ViewPageTemplateFile('inline_edit_wrapper.pt')
tuple header_macros = ZopeTwoPageTemplateFile('browser/macro_wrapper.pt')

Detailed Description

KSS actions for formlib form inline editing

Definition at line 20 of file edit.py.


Member Function Documentation

def plone.app.form.kss.edit.FormlibInlineEdit.begin (   self,
  formname,
  fieldname,
  structure = 'false' 
)
Begin inline editing - find the widget for the given field name
in the given form (looked up as a view on the context), then hide the
block with the id '${fieldname}-display' and display an edit form in
its place. If 'structure' is 'true' (a string), then the inline 
editable field will eventually permit HTML input to be rendered
unescaped.

Definition at line 27 of file edit.py.

00027 
00028     def begin(self, formname, fieldname, structure='false'):
00029         """Begin inline editing - find the widget for the given field name
00030         in the given form (looked up as a view on the context), then hide the
00031         block with the id '${fieldname}-display' and display an edit form in
00032         its place. If 'structure' is 'true' (a string), then the inline 
00033         editable field will eventually permit HTML input to be rendered
00034         unescaped.
00035         """
00036         context = aq_inner(self.context)
00037         request = aq_inner(self.request)
00038         
00039         form = getMultiAdapter((context, request), name=formname)
00040         form = form.__of__(context)
00041         
00042         if fieldname.startswith(form.prefix):
00043             fieldname = fieldname[len(form.prefix)+1:]
00044             
00045         formlib_field = form.form_fields[fieldname]
00046         widgets = formlib.setUpEditWidgets((formlib_field,), form.prefix, 
00047             context, request, ignore_request=True)
00048             
00049         widget = widgets[fieldname]
00050         
00051         display_id = '%s-display' % fieldname
00052         form_id = '%s-form' % fieldname
00053         
00054         ksscore = self.getCommandSet('core')
00055         zopecommands = self.getCommandSet('zope')
00056         plonecommands = self.getCommandSet('plone')
00057         
00058         # lock the context (or issue warning)
00059         locking = ILockable(context, None)
00060         if locking:
00061             if not locking.can_safely_unlock():
00062                 selector = ksscore.getHtmlIdSelector('plone-lock-status')
00063                 zopecommands.refreshViewlet(selector, 'plone.abovecontent', 'plone.lockinfo')
00064                 plonecommands.refreshContentMenu()
00065                 return
00066             else: # we are locking the content
00067                 locking.lock()
00068         
00069         plonecommands.issuePortalMessage('')
00070         
00071         # hide the existing display field
00072         display_selector = ksscore.getHtmlIdSelector(display_id)
00073         ksscore.addClass(display_selector, 'hiddenStructure')
00074         
00075         # show the form
00076         form_html = self.form_template(widget=widget,
00077                                        form_id=form_id,
00078                                        fieldname=fieldname,
00079                                        structure=structure)
00080 
00081         ksscore.insertHTMLAfter(display_selector, form_html)
00082         
00083         # XXX: Focus on the input field?
        

Here is the call graph for this function:

def plone.app.form.kss.edit.FormlibInlineEdit.cancel (   self,
  fieldname 
)
Cancel the inline editing taking place for the given field, by
removing the inline editing form and unhiding the block with id
'${fieldname}-display'.

Definition at line 85 of file edit.py.

00085 
00086     def cancel(self, fieldname):
00087         """Cancel the inline editing taking place for the given field, by
00088         removing the inline editing form and unhiding the block with id
00089         '${fieldname}-display'.
00090         """
00091         context = aq_inner(self.context)
00092         
00093         display_id = '%s-display' % fieldname
00094         form_id = '%s-form' % fieldname
00095         
00096         ksscore = self.getCommandSet('core')
00097         
00098         # unlock the context if it was locked before
00099         locking = ILockable(context, None)
00100         if locking and locking.can_safely_unlock():
00101             locking.unlock()
00102 
00103         # show the existing display field
00104         ksscore.removeClass(ksscore.getHtmlIdSelector(display_id), 'hiddenStructure')
00105         
00106         # hide the form
00107         ksscore.deleteNode(ksscore.getHtmlIdSelector(form_id))
        

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 45 of file plonekssview.py.

00045 
00046     def issueAllPortalMessages(self):
00047         if hasattr(self.request.RESPONSE, 'cookies'):
00048             cookie = self.request.RESPONSE.cookies.get(STATUSMESSAGEKEY)
00049             if cookie:
00050                 encodedstatusmessages = cookie['value']
00051                 statusmessages = _decodeCookieValue(encodedstatusmessages)
00052             else:
00053                 statusmessages = []
00054             for msg in statusmessages:
00055                 self.getCommandSet('plone').issuePortalMessage(msg)
00056             self.request.RESPONSE.expireCookie(STATUSMESSAGEKEY, path='/')

Here is the call graph for this function:

Here is the caller graph for this function:

def plone.app.kss.plonekssview.PloneKSSView.macroContent (   self,
  macropath,
  kw 
) [inherited]

Definition at line 24 of file plonekssview.py.

00024 
00025     def macroContent(self, macropath, **kw):
00026         'Renders a macro and returns its text'
00027         path = macropath.split('/')
00028         if len(path) < 2 or path[-2] != 'macros':
00029             raise RuntimeError, 'Path must end with macros/name_of_macro (%s)' % (repr(macropath), )
00030         # needs string, do not tolerate unicode (causes but at traverse)
00031         jointpath = '/'.join(path[:-2]).encode('ascii')
00032         macroobj = self.context.restrictedTraverse(jointpath)
00033         try:
00034             the_macro = macroobj.macros[path[-1]]
00035         except AttributeError, IndexError:
00036             raise RuntimeError, 'Macro not found'
00037         #  
00038         # put parameters on the request, by saving the original context
00039         self.request.form, orig_form = kw, self.request.form
00040         content = self.header_macros.__of__(macroobj.aq_parent)(the_macro=the_macro)
00041         self.request.form = orig_form
00042         # Always encoded as utf-8
00043         content = force_unicode(content, 'utf')
00044         return content

Here is the call graph for this function:

Here is the caller graph for this function:

def plone.app.form.kss.edit.FormlibInlineEdit.save (   self,
  formname,
  fieldname,
  structure = 'false' 
)
Attempt to save the given field in the given form which is being
inline-edited. If there is a validation error, the error will be
highlighted. If not, the value will be saved, and the inline editing
form removed. Before the form is re-displayed, the contents of the
element with id '${fieldname}-display' will be updated with the new
field value.

Definition at line 109 of file edit.py.

00109 
00110     def save(self, formname, fieldname, structure='false'):
00111         """Attempt to save the given field in the given form which is being
00112         inline-edited. If there is a validation error, the error will be
00113         highlighted. If not, the value will be saved, and the inline editing
00114         form removed. Before the form is re-displayed, the contents of the
00115         element with id '${fieldname}-display' will be updated with the new
00116         field value.
00117         """
00118         
00119         context = aq_inner(self.context)
00120         request = aq_inner(self.request)
00121         
00122         structure = (structure == 'true')
00123         
00124         form = getMultiAdapter((context, request), name=formname)
00125         form = form.__of__(context)
00126         
00127         raw_fieldname = fieldname
00128         if fieldname.startswith(form.prefix):
00129             raw_fieldname = fieldname[len(form.prefix)+1:]
00130             full_fieldname = fieldname
00131         else:
00132             full_fieldname = "%s.%s" % (form.prefix, raw_fieldname)
00133             
00134         formlib_field = form.form_fields[raw_fieldname]
00135         widgets = formlib.setUpEditWidgets((formlib_field,), form.prefix, 
00136             context, request, ignore_request=False)
00137             
00138         widget = widgets[raw_fieldname]
00139         
00140         # validate and issue a message if there's an error
00141         
00142         ksscore = self.getCommandSet('core')
00143         error = validate_and_issue_message(ksscore, widget, full_fieldname)
00144 
00145         if not error:
00146         
00147             field_value = request.form.get('%s.%s' % (form.prefix, raw_fieldname))
00148             data = { raw_fieldname : field_value }
00149         
00150             # update value
00151             changed = formlib.applyChanges(context, (formlib_field,), data)
00152             if changed:
00153                 
00154                 # send modified events if something actually changed
00155                 field = widget.context
00156                 adapter = field.interface(context)
00157                 
00158                 descriptor = lifecycleevent.Attributes(field.interface, raw_fieldname)
00159                 notify(lifecycleevent.ObjectModifiedEvent(context, descriptor))
00160                 
00161                 # update the rendered value
00162                 display_widget = getMultiAdapter((formlib_field.field, request), IDisplayWidget)
00163                 display_widget.setRenderedValue(field.get(adapter))
00164                 output = display_widget()
00165                 
00166                 if structure:
00167                     output = unescape(output)
00168                 
00169                 display_id = '%s-display' % fieldname
00170                 ksscore.replaceInnerHTML(ksscore.getHtmlIdSelector(display_id), output)
00171         
00172             # unlock and remove the field
            self.cancel(fieldname)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

tuple plone.app.form.kss.edit.FormlibInlineEdit.form_template = ViewPageTemplateFile('inline_edit_wrapper.pt') [static]

Definition at line 24 of file edit.py.

tuple plone.app.kss.plonekssview.PloneKSSView.header_macros = ZopeTwoPageTemplateFile('browser/macro_wrapper.pt') [static, inherited]

Definition at line 22 of file plonekssview.py.


The documentation for this class was generated from the following file: