Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Helpers #754

Open
wants to merge 116 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
fde0b3f
initial checkin of fields being inserted visually into tinymce
djay Jul 11, 2016
35d23b7
Merge remote-tracking branch 'origin/missing-tinymce-buttons' into ti…
djay Jul 11, 2016
28ee077
store layout without example widgets
djay Jul 15, 2016
5037fb1
fix formatting of html on save stripping html widgets
djay Jul 16, 2016
fce2bb0
cache,label and hidewhen should now work as noneditable dragable elem…
djay Aug 19, 2016
3b73857
Merge branch 'master' into tinymcevisualfields
djay Aug 19, 2016
ddd99ff
allow adding a field without typing the id first
djay Aug 23, 2016
b629fef
fix up popups for hidewhen and actions
djay Aug 24, 2016
bc57a05
clean up css for visual elements in tinymce
djay Aug 24, 2016
d912880
dnd subforms now work
djay Aug 25, 2016
5b49943
handle inserting dnd datagrids using very basic progressive table. Ca…
djay Aug 26, 2016
b0661e8
fix bug in creating empty form
djay Aug 29, 2016
af4fc27
fix for display fields with no content
djay Aug 29, 2016
ec2fa66
initial version of helpers
djay Sep 1, 2016
9249554
Merge branch 'dynamic-display-fields' into multipage-p2
Sep 1, 2016
2f636f0
Include pyquery
Sep 2, 2016
203086e
Attempt to merge multipage into Plomino 2
Sep 2, 2016
ede6dc2
Fix Flake version and add a resources directory
Sep 2, 2016
5c3b8bd
Merge tinymcevisualfields
Sep 2, 2016
7f17ca1
helpers is now a behaviour.
djay Sep 2, 2016
dc81085
Fix syntax error
instification Sep 2, 2016
c6ae104
automatically detect and list helpers in the same db
djay Sep 2, 2016
775f530
try to improve import/export so it uses datamanagers and handles beha…
djay Sep 5, 2016
862c3f6
Merge remote-tracking branch 'origin/master' into helpers_ide
djay Sep 5, 2016
6d1a8e2
titles in datagrid for helpers and hack to fix the import
djay Sep 5, 2016
80185bd
Handle multiple colons in a hidewhen, cache or label
Sep 5, 2016
b6bd02f
Use isinstance and set the date format
Sep 5, 2016
8f1b52e
keep track of form used in datagrid and reedit using that
djay Sep 5, 2016
aa5a40a
Add a combo date widget that uses separate day/month/year input fields
Sep 6, 2016
895827d
Add the id of the field to the combo widget
Sep 6, 2016
b2f00a5
Add a getSelectionList method directly to a Field so it can be called…
Sep 6, 2016
8a4ec26
Style labels in TinyMCE
Sep 6, 2016
62f949b
Wrap the combo date widget in a span instead of a div
Sep 6, 2016
159445f
Don't change plominoLabels, and handle hidewhens if they haven't been…
Sep 6, 2016
83a12b1
Don't change plominoLabels, and handle hidewhens if they haven't been…
Sep 6, 2016
dffc6a9
use subscribers again so helpers update code. fix export.
djay Sep 6, 2016
38da306
include formulas in field settings in helpers generation. Fix datagri…
djay Sep 6, 2016
ce66451
Merge latest helpers code
Sep 7, 2016
1abcad9
Handle empty records when processing or validating inputs
Sep 7, 2016
322474b
import macros from another db
djay Sep 7, 2016
10e636f
Replace plomino accordions with <hr>
Sep 7, 2016
7d92faf
Merge branch 'helpers' into multipage-p2
Sep 7, 2016
defdce1
Merge in latest master
Sep 7, 2016
8d13e3e
fix hidewhen inserting in tinymce. insert parent context into helpers…
djay Sep 7, 2016
f989089
Don't convert record fields to unicode
Sep 7, 2016
0defec3
Workaround a tzinfo problem
Sep 7, 2016
236bd46
Merge branch 'helpers' into helpers_ide
djay Sep 7, 2016
fc9b738
Merge remote-tracking branch 'origin/multipage-p2' into helpers_ide
djay Sep 7, 2016
31abd19
include macro context properly. fix macro popup
djay Sep 7, 2016
7bb6ef0
Merge branch 'helpers' into helpers_ide
djay Sep 7, 2016
d0b3bf2
fix behaviour setting on import
djay Sep 7, 2016
a389da9
Merge branch 'helpers' into helpers_ide
djay Sep 7, 2016
c5b350f
change name to formula macros
djay Sep 8, 2016
a107993
Fix typo in registry
Sep 13, 2016
6ed5535
Fix typo in template
Sep 13, 2016
a631269
Merge latest master
Sep 13, 2016
e03de26
Fix splitting bug
Sep 13, 2016
dc125e9
Don't change plominoLabels, and handle hidewhens if they haven't been…
Sep 6, 2016
33d0134
Stop handling labels for the moment
Sep 13, 2016
68035cf
Merge branch 'master' into tinymcevisualfields
Sep 14, 2016
d3923b4
Add a span before a hidden field so it can be dragged
Sep 14, 2016
25222de
Number fields should use the appropriate input type
Sep 14, 2016
020daa0
Add test for the rendering of number fields
Sep 14, 2016
d3c5ddc
Merge in Dylan's label grouping code
Sep 14, 2016
ffada38
Update tests for modified label handling code
Sep 14, 2016
6d70a3a
improve the code for updating multiple macros in the same formula
djay Sep 15, 2016
faf283d
Merge branch 'helpers_ide' into helpers
djay Sep 15, 2016
f19d329
make macro code reverse order properly
djay Sep 15, 2016
2820220
macros retaining ids correctly
djay Sep 15, 2016
c2093e8
only show helpers relevent to this field
djay Sep 16, 2016
4fe1d28
Add label support to tinymce visualfields
Sep 19, 2016
98f894a
Re-parse the HTML before replacing elements with nothing inside
Sep 19, 2016
03dbd63
Add some tests for visual fields
Sep 19, 2016
dbe9753
Merge branch 'master' into tinymcevisualfields
Sep 19, 2016
8325c74
Merge branch 'master' into helpers
djay Sep 19, 2016
2d3df00
fix up processing datagrid input and defaults for mapping_fields
djay Sep 20, 2016
02c1110
Fix the restrictedTraverse params to ascii path
ivanteoh Sep 20, 2016
c18395f
Fix the typo on registeration on IHelpers behaviors in portal_types
ivanteoh Sep 23, 2016
25249e1
Add a class if we're in a macro context
Sep 23, 2016
70f7f5f
In the macro popup context, make sure the close button closes the mod…
Sep 23, 2016
95d4bfd
Clean code and add more comments
ivanteoh Sep 23, 2016
5924afb
Add more comment on macro code must be hidden text field type and hid…
ivanteoh Sep 23, 2016
7efac39
datagrids fixes
djay Sep 23, 2016
b568639
Merge branch 'helpers' of github.com:plomino/Plomino into helpers
djay Sep 24, 2016
8f9e349
Merge tinymcevisualfields
Sep 26, 2016
31e4517
Update tests for visual form layout
Sep 26, 2016
5720846
Handle nonvisual label code
Sep 27, 2016
d2b3a33
Use the right setting for a multiple select2 field
Sep 28, 2016
d9b8a6f
Fix the datetime to check json dict
ivanteoh Sep 28, 2016
b271c13
Update plomin-compiled.js with latest datagrids and macros
Sep 28, 2016
0d76d75
Update compile time of bundle
Sep 28, 2016
b93c553
Merge branch 'helpers' of github.com:plomino/Plomino into helpers
Sep 28, 2016
534bf69
Values may be None
Sep 29, 2016
ffe967a
Datetime format is on the context
Sep 30, 2016
e39fba8
Set a fieldvalue when displaying a datetime example widget
Sep 30, 2016
2252adf
Trim whitespace around elementIds when selecting text
Sep 30, 2016
6eb3010
Replace a confusing list comprehension
Sep 30, 2016
a0f9a9e
Get the ajax datatime value from request and display on the form
ivanteoh Oct 5, 2016
9a9dfa0
Add tooltips for the plomino buttons
Oct 5, 2016
1e4077e
Add a Page break button to TinyMCE and use a page break class to diff…
Oct 5, 2016
42a2b47
Fix the datime default values.
ivanteoh Oct 5, 2016
1de98c1
Change the log to debug instead of info
ivanteoh Oct 5, 2016
ce13c24
When inserting content into TinyMCE, ensure cursor moves to a new line
Oct 7, 2016
beed132
Return outer_html in handleLabels
Oct 12, 2016
eb51ed5
Handle empty forms properly in handleLabels
Oct 12, 2016
379642d
Remove debug line that was causing encoding errors
Oct 12, 2016
20edc58
Add advanced form fields to an advanced fieldset
Oct 12, 2016
c084ea0
Hide advanced fields on database and field
Oct 13, 2016
96cf586
Add a BR after inserting a HR so that cursor moves to the next line
Oct 13, 2016
af59437
Fix #765 datetime does not show right date time format
ivanteoh Oct 13, 2016
4014a6a
Fix flake8 warnings.
ivanteoh Oct 13, 2016
2da6625
Fix some typo
ivanteoh Oct 13, 2016
9c58c28
Add the missing logger statement.
ivanteoh Oct 13, 2016
73adfbf
Fix more flake8 warning in datetime
ivanteoh Oct 13, 2016
4f731d0
Change the rich text editor to 100% width for now
ivanteoh Oct 13, 2016
aba166f
Fix the SCRIPT_ID_DELIMITER import error
ivanteoh Oct 14, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ plone.rest = git ${remotes:plone}/plone.rest.git pushurl=${remotes:plone_push}/p
recipe = plone.recipe.zope2instance
user = admin:admin
http-address = 8080
resources = ${buildout:directory}/resources
eggs =
Plone
Pillow
Expand Down Expand Up @@ -69,7 +70,7 @@ setuptools = 8.3
zc.buildout = 2.2.5
zc.recipe.egg = 2.0.1

flake8 = 2.3.0
flake8 = 2.4.0

robotframework = 2.8.4
robotframework-ride = 1.3
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
'plone.app.dexterity',
'jsonutil',
'collective.instancebehavior',
'pyquery',
'plone.restapi',
],
extras_require={
Expand Down
106 changes: 95 additions & 11 deletions src/Products/CMFPlomino/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:plone="http://namespaces.plone.org/plone"
xmlns:z3c="http://namespaces.zope.org/z3c"
i18n_domain="Products.CMFPlomino">

<!-- permissions -->
Expand Down Expand Up @@ -95,6 +96,13 @@
permission="zope.Public"
/>

<browser:page
for="Products.CMFPlomino.contents.form.IPlominoForm"
name="page"
class=".form.PageView"
permission="zope.Public"
/>

<browser:page
for="Products.CMFPlomino.contents.form.IPlominoForm"
name="add-field"
Expand Down Expand Up @@ -162,43 +170,36 @@
<browser:page
name="tinyform"
for="Products.CMFPlomino.contents.form.IPlominoForm"
class=".tinymce.PlominoForm"
class=".tinymce.PlominoFormSettings"
permission="zope.Public"
allowed_attributes="getField addField addLabel addAction addHidewhen addCache addSubForm action_template"
/>

<browser:page
name="tinyfield"
for="Products.CMFPlomino.contents.field.IPlominoField"
class=".tinymce.PlominoField"
class=".tinymce.PlominoFieldSettings"
permission="zope.Public"
allowed_attributes="setFieldProperties"
/>

<browser:page
name="tinyhidewhen"
for="Products.CMFPlomino.contents.hidewhen.IPlominoHidewhen"
class=".tinymce.PlominoHidewhen"
class=".tinymce.PlominoHidewhenSettings"
permission="zope.Public"
allowed_attributes="setHidewhenProperties"
/>

<browser:page
name="tinyaction"
for="Products.CMFPlomino.contents.action.IPlominoAction"
class=".tinymce.PlominoAction"
class=".tinymce.PlominoActionSettings"
permission="zope.Public"
allowed_attributes="setActionProperties"
/>

<!--
<browser:page
name="tinyhidewhen"
for="Products.CMFPlomino.contents..IPlominoHidewhen"
class=".hidewhen.PlominoHidewhen"
permission="zope.Public"
allowed_attributes="setHidewhenProperties"
/>

<browser:page
name="tinycache"
Expand All @@ -209,6 +210,89 @@
/>
-->

<!--<browser:page-->
<!--for="Products.CMFPlomino.contents.form.IPlominoForm"-->
<!--name="HelperForm"-->
<!--class=".helpers.HelperView"-->
<!--attribute="openform"-->
<!--permission="zope.Public"-->
<!--/>-->

<adapter
factory="Products.CMFPlomino.browser.helpers.SubformWidget"
provides="z3c.form.interfaces.IFieldWidget"
for="zope.schema.interfaces.IAbstractSet
zope.schema.interfaces.IObject
plone.app.z3cform.interfaces.IPloneFormLayer"
/>
<adapter factory=".helpers.SubformWidgetConverter" />
<subscriber
for="Products.CMFPlomino.contents.form.IPlominoForm
zope.lifecycleevent.interfaces.IObjectModifiedEvent"
handler=".helpers.update_helpers"
/>
<subscriber
for="Products.CMFPlomino.contents.field.IPlominoField
zope.lifecycleevent.interfaces.IObjectModifiedEvent"
handler=".helpers.update_helpers"
/>
<subscriber
for="Products.CMFPlomino.contents.action.IPlominoAction
zope.lifecycleevent.interfaces.IObjectModifiedEvent"
handler=".helpers.update_helpers"
/>
<subscriber
for="Products.CMFPlomino.contents.hidewhen.IPlominoHidewhen
zope.lifecycleevent.interfaces.IObjectModifiedEvent"
handler=".helpers.update_helpers"
/>
<subscriber
for="Products.CMFPlomino.contents.view.IPlominoView
zope.lifecycleevent.interfaces.IObjectModifiedEvent"
handler=".helpers.update_helpers"
/>

<plone:behavior
title="Helpers"
description="Lets an object use external forms to generate its formulas"
provides=".helpers.IHelpers"
factory=".helpers.Helpers"
/>
<!--for="Products.CMFPlomino.contents.form.IPlominoForm"-->
<!--<plone:behavior-->
<!--title="Helpers"-->
<!--description="Lets an object use external forms to generate its formulas"-->
<!--provides=".helpers.IHelpers"-->
<!--for="Products.CMFPlomino.contents.field.IPlominoField"-->
<!--/>-->
<!--<plone:behavior-->
<!--title="Helpers"-->
<!--description="Lets an object use external forms to generate its formulas"-->
<!--provides=".helpers.IHelpers"-->
<!--for="Products.CMFPlomino.contents.action.IPlominoAction"-->
<!--/>-->
<!--<plone:behavior-->
<!--title="Helpers"-->
<!--description="Lets an object use external forms to generate its formulas"-->
<!--provides=".helpers.IHelpers"-->
<!--for="Products.CMFPlomino.contents.hidewhen.IPlominoHidewhen"-->
<!--/>-->
<!--<plone:behavior-->
<!--title="Helpers"-->
<!--description="Lets an object use external forms to generate its formulas"-->
<!--provides=".helpers.IHelpers"-->
<!--for="Products.CMFPlomino.contents.view.IPlominoView"-->
<!--/>-->

<z3c:widgetTemplate
mode="input"
widget=".helpers.ISubformWidget"
layer="plone.app.z3cform.interfaces.IPloneFormLayer"
template="templates/multi_helpers.pt"
/>



<plone:portlet
name="plomino.designportlet"
interface=".portlet.IPortlet"
Expand Down
159 changes: 159 additions & 0 deletions src/Products/CMFPlomino/browser/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from Products.Five.browser import BrowserView

from ..config import DESIGN_PERMISSION
from ..config import SCRIPT_ID_DELIMITER
from ..exceptions import PlominoScriptException


class DocumentView(BrowserView):
Expand All @@ -26,6 +28,20 @@ def __init__(self, context, request):
self.form = None

def publishTraverse(self, request, name):
if name == "page" or name == "pageview":
# Stop traversing
request['TraversalRequestNameStack'] = []
self.action = name
# Default page is page 1
self.page = 1
# Ignore everything past the first page
if request.path:
try:
self.page = int(request.path[0])
except ValueError:
pass
self.request['plomino_current_page'] = self.page
return self
if name == "OpenDocument" or name == "view":
self.action = "view"
return self
Expand Down Expand Up @@ -71,7 +87,14 @@ def publishTraverse(self, request, name):
return self

def render(self):
if self.action == "page":
return self._page_edit()
if self.action == "pageview":
return self._page_view()
if self.action == "edit":
# If a user tries to edit a multipage form
if self.target.getIsMulti():
return self.redirect('page', '1')
return self.edit_template()
if self.action == "bareedit":
return self.bare_edit_template()
Expand All @@ -94,7 +117,143 @@ def render(self):
else:
raise Unauthorized("You cannot read this content")
else:
# If a user tries to view a multipage form
if self.target.getIsMulti():
return self.redirect('pageview', '1')
return self.view_template()

def __call__(self):
return self.render()

def _page_edit(self):
# Multipage edit mode
form = self.target.getForm()

# Get multi page information
current_page = form._get_current_page()
num_pages = form._get_num_pages()

# If they have gone past the end of the form, send them back
if current_page > num_pages:
return self.redirect('page', num_pages)

# Handle POST requests differently.
if self.request['REQUEST_METHOD'] == 'POST':
# Look up the form. This might be the context, or the parent form
# or a value from the request

if 'back' in self.request.form or 'previous' in self.request.form:
next_page = form._get_next_page(self.request, doc=self.target, action='back')
return self.redirect('page', next_page)

# Handle linking
linkto = False
for key in self.request.form.keys():
if key.startswith('plominolinkto-'):
linkto = key.replace('plominolinkto-', '')
next_page = form._get_next_page(self.request, doc=self.target, action='linkto', target=linkto)
return self.redirect('page', next_page)

# Pass in the current doc as well. This ensures that fields on other
# pages are included (possibly needed for calculations)
errors = form.validateInputs(self.request, doc=self.target)

if errors:
self.page_errors = errors
return self.edit_template()

# Any buttons progress the user through the form
# XXX: We need to handle other types of buttons here
if current_page < (num_pages):
next_page = form._get_next_page(self.request, doc=self.target, action='continue')
else:
# Don't go past the end of the form
next_page = num_pages

# execute the beforeSave code of the form
error = None
try:
error = self.target.runFormulaScript(
SCRIPT_ID_DELIMITER.join(['form', form.id, 'beforesave']),
self.target,
form.beforeSaveDocument)
except PlominoScriptException, e:
e.reportError('Form submitted, but beforeSave formula failed')

if error:
errors.append({'field': 'beforeSave', 'error': error})
self.page_errors = errors
# Stay on this page
return self.edit_template()

# Now save and move forwards
self.target.setItem('Form', form.id)

# process editable fields (we read the submitted value in the request)
form.readInputs(self.target, self.request, process_attachments=True)

# refresh computed values, run onSave, reindex. Should never be creation.
self.target.save(form, False)

# If there is a redirect, redirect to it:
redirect = self.request.get('plominoredirecturl')
if not redirect:
redirect = self.target.getItem("plominoredirecturl")

if redirect:
return self.request.RESPONSE.redirect(redirect)

# Otherwise continue to the next page of the document
return self.redirect('page', next_page)

return self.edit_template()

def _page_view(self):
# Multipage view mode. No need to check validation in this mode.
form = self.target.getForm()

# Get multi page information
current_page = form._get_current_page()
num_pages = form._get_num_pages()

# If there is something in the form (i.e. a paging request)
if self.request.form:
# If they have gone past the end of the form, send them back
if current_page > num_pages:
return self.redirect('pageview', num_pages)

if 'back' in self.request.form or 'previous' in self.request.form:
next_page = form._get_next_page(
self.request,
doc=self.target,
action='back'
)
return self.redirect('pageview', next_page)

# Handle linking
linkto = False
for key in self.request.form.keys():
if key.startswith('plominolinkto-'):
linkto = key.replace('plominolinkto-', '')
next_page = form._get_next_page(self.request, doc=self.target, action='linkto', target=linkto)
return self.redirect('pageview', next_page)

# Any buttons progress the user through the form
# XXX: We need to handle other types of buttons here
if current_page < (num_pages):
next_page = form._get_next_page(
self.request,
doc=self.target,
action='continue'
)
else:
# Don't go past the end of the form
next_page = num_pages

return self.redirect('pageview', next_page)

return self.view_template()

def redirect(self, view, page):
url = '%s/%s/%s' % (self.target.absolute_url(), view, page)
return self.request.RESPONSE.redirect(url)
Loading