Skip to content

Commit

Permalink
Merge 23087c6 into 452f7b3
Browse files Browse the repository at this point in the history
  • Loading branch information
jean committed Sep 3, 2013
2 parents 452f7b3 + 23087c6 commit 9b27904
Show file tree
Hide file tree
Showing 10 changed files with 390 additions and 171 deletions.
5 changes: 2 additions & 3 deletions Products/CMFPlomino/PlominoDocument.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,7 @@ def tojson(
data = self.items.data

if datatables_format:
data = {
'iTotalRecords': len(data),
data = {'iTotalRecords': len(data),
'iTotalDisplayRecords': len(data),
'aaData': data }
if lastmodified:
Expand Down Expand Up @@ -587,7 +586,7 @@ def send(self, recipients, title, form=None):
message = self.openWithForm(form)
sendMail(db, recipients, title, message)

security.declarePublic('getTitle')
security.declarePublic('Title')
def Title(self):
""" Return the stored title or compute the title (if dynamic).
"""
Expand Down
28 changes: 28 additions & 0 deletions Products/CMFPlomino/PlominoForm.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,19 @@
),
default_output_type="text/html",
),
TextField(
name='FormMethod',
accessor='getFormMethod',
default='Auto',
widget=SelectionWidget(
label="Form method",
description="The form method: GET, POST or Auto (default).",
label_msgid=_('CMFPlomino_label_FormMethod', default="Form method"),
description_msgid=_('CMFPlomino_help_FormMethod', default="The form method: GET or POST or Auto (default)."),
i18n_domain='CMFPlomino',
),
vocabulary=('GET', 'POST', 'Auto')
),
TextField(
name='DocumentTitle',
widget=TextAreaWidget(
Expand Down Expand Up @@ -311,6 +324,21 @@ def getForm(self, formname=None):
form = obj.aq_parent
return form

def getFormMethod(self):
""" Return form submit HTTP method
"""
# if self.isEditMode():
# Log('POST because isEditMode', 'PlominoForm/getFormMethod') #DBG
# return 'POST'

value = self.Schema()['FormMethod'].get(self)
if value == 'Auto':
if self.isPage or self.isSearchForm:
return 'GET'
else:
return 'POST'
return value

security.declareProtected(READ_PERMISSION, 'createDocument')
def createDocument(self, REQUEST):
""" Create a document using the form's submitted content.
Expand Down
12 changes: 7 additions & 5 deletions Products/CMFPlomino/fields/datagrid_edit.pt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
request field/REQUEST;
v options/fieldvalue;
data python:field.getSettings().tojson(v);
formname python:field.getParentNode().id;
associated_form python:field.getSettings().associated_form;
form field/getParentNode;
form_name form/id;
form_method form/getFormMethod;
datagrid_associated_form python:field.getSettings().associated_form;
">
<input type='hidden'
tal:attributes="
Expand All @@ -23,7 +25,7 @@
$$(document).ready(function() {
${fieldname}_datatable = $$('#${fieldname}_datagrid').dataTable( {
'sAjaxSource': 'tojson?item=${fieldname}&rendered=true&datatables=true',
'sServerMethod': 'POST',
'sServerMethod': '${form_method}',
'fnServerParams': function ( aoData ) {
${request_items}
},
Expand Down Expand Up @@ -59,13 +61,13 @@
<div tal:attributes="id string:${fieldname}_editform"></div>
<p><a class="context add-row"
tal:attributes="id string:${fieldname}_addrow;
href string:../${associated_form}/OpenBareForm?Plomino_Parent_Field=${fieldname}&Plomino_Parent_Form=${formname};
href string:../${datagrid_associated_form}/OpenBareForm?Plomino_Parent_Field=${fieldname}&Plomino_Parent_Form=${form_name};
onclick string:event.preventDefault ? event.preventDefault() : event.returnValue = false;; return false"
tal:content="python:options['field'].getSettings().getActionLabel('add')"
>Add row</a>
<a class="context edit-row"
tal:attributes="id string:${fieldname}_editrow;
href string:../${associated_form}/OpenBareForm?Plomino_Parent_Field=${fieldname}&Plomino_Parent_Form=${formname};
href string:../${datagrid_associated_form}/OpenBareForm?Plomino_Parent_Field=${fieldname}&Plomino_Parent_Form=${form_name};
onclick string:event.preventDefault ? event.preventDefault() : event.returnValue = false;; return false;
style python:{0: 'display:none'}.get(len(v), '')"
tal:content="python:options['field'].getSettings().getActionLabel('edit')"
Expand Down
10 changes: 6 additions & 4 deletions Products/CMFPlomino/fields/datagrid_read.pt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<tal:block
define="fieldname python:options['fieldname'];
field python:options['field'];
v options/fieldvalue;
define="field python:options['field'];
fieldname python:options['fieldname'];
request field/REQUEST;
v options/fieldvalue;
form field/getParentNode;
form_method form/getFormMethod;
widget python:field.getSettings('widget');">

<tal:read_dynamic condition="python:widget!='READ_STATIC'">
Expand All @@ -13,7 +15,7 @@
$$(document).ready(function() {
$$('#${fieldname}_datagrid').dataTable( {
'sAjaxSource': 'tojson?item=${fieldname}&rendered=true&datatables=true',
'sServerMethod': 'GET',
'sServerMethod': '${form_method}',
'fnServerParams': function ( aoData ) {
${request_items}
},
Expand Down
3 changes: 1 addition & 2 deletions Products/CMFPlomino/fields/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,8 @@ def processInput(self, values):
return values

def tojson(self, selection):
"""Return a JSON table storing documents to be displayed
""" Return a JSON table storing documents to be displayed
"""

return json.dumps([v.split('|')[::-1] for v in selection])


Expand Down
65 changes: 43 additions & 22 deletions Products/CMFPlomino/skins/cmfplomino_templates/EditBareDocument.pt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
xmlns:metal="http://xml.zope.org/namespaces/metal"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
lang="en"
i18n:domain="plone">
i18n:domain="plone"
tal:define="form python:here;
form_method python:form.getFormMethod();
"
>
<head tal:define="view context/@@plone;
ajax_load request/ajax_load | nothing;
ajax_include_head request/ajax_include_head | nothing;"
ajax_include_head request/ajax_include_head | nothing;
"
tal:condition="python: not ajax_load or ajax_include_head">
<div tal:replace="structure provider:plone.resourceregistries.styles" />
<div tal:replace="structure provider:plone.resourceregistries.scripts" />
Expand All @@ -25,27 +30,43 @@
<tal:has_googleviz condition="python:here.getForm().hasGoogleVisualizationField()">
<script type='text/javascript' src='http://www.google.com/jsapi'></script>
</tal:has_googleviz>
<script type="text/javascript" tal:condition="python:here.getForm().hasDynamicHidewhen()">
function refreshHidewhen() {
var onsuccess = function(data, textStatus, xhr) {
for (var hw in data)
jq('.hidewhen-' + hw).css('display', data[hw]?'none':'block');
}
jq.post('computehidewhens', jq('#plomino_form').serialize(), onsuccess, 'json');
}
jq(document).ready( function() {
jq('form :input').change(refreshHidewhen);
});
<script
type="text/javascript"
tal:condition="python:here.getForm().hasDynamicHidewhen()"
tal:content="string:
function refreshHidewhen() {
var onsuccess = function(data, textStatus, xhr) {
for (var hw in data)
jq('.hidewhen-' + hw).css('display', data[hw]?'none':'block');
}
jq.ajax({
type: '${form_method}',
url: 'computehidewhens',
data: jq('#plomino_form').serialize(),
success: onsuccess,
dataType: 'json'
});
}
jq(document).ready( function() {
jq('form :input').change(refreshHidewhen);
});">
</script>
</head>
<body>
<div id="content">
<tal:block tal:define="this_form python:here.getForm();
b myF/ActionBarPosition|nothing">
<tal:block tal:define="b myF/ActionBarPosition|nothing">

<form tal:attributes="name python:here.getForm().id;
action python:here.doc_url()+'/saveDocument'"
id="plomino_form" method="POST" enctype="multipart/form-data">
<form
tal:define="
enctype python:(form_method == 'POST') and 'multipart/form-data'
"
tal:attributes="
name myF/id;
action python:here.doc_url()+'/saveDocument';
method form_method;
enctype enctype|nothing
"
id="plomino_form">

<span style="display: none" id="plomino_path" tal:content="python:'/'.join(here.getPhysicalPath())">path</span>
<span style="display: none" id="plomino_childof"
Expand All @@ -59,17 +80,17 @@
tal:content="python:here.getItem('Plomino_Parent_Field')">Plomino_Parent_Field</span>

<tal:form_actions_top
define="owner python:this_form"
condition= "python:test((b and this_form.ActionBarPosition=='BOTTOM'), False, True)">
define="owner python:myF"
condition= "python:test((b and myF.ActionBarPosition=='BOTTOM'), False, True)">
<span metal:use-macro="here/ActionBar/macros/EditDocumentActionBar" >
display form actions above form fields
</span><br/>
</tal:form_actions_top>

<span tal:content="structure python:here.editWithForm(this_form)" />
<span tal:content="structure python:here.editWithForm(myF)" />

<tal:form_actions_bottom
define="owner python:this_form">
define="owner python:myF">
<span metal:use-macro="here/ActionBar/macros/EditDocumentActionBar" >
display form actions below form fields
</span>
Expand Down
77 changes: 47 additions & 30 deletions Products/CMFPlomino/skins/cmfplomino_templates/EditDocument.pt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
<metal:javascript_head_slot fill-slot="javascript_head_slot"
tal:define="
has_form python:here.hasItem('Form');
this_form python:here.getForm();
hasDateTimeField python:this_form.hasDateTimeField();
hasDynamicHidewhen python:this_form.hasDynamicHidewhen();
hasGoogleVisualizationField python:this_form.hasGoogleVisualizationField()
form python:here.getForm();
form_method python:form.getFormMethod();
hasDateTimeField python:form.hasDateTimeField();
hasDynamicHidewhen python:form.hasDynamicHidewhen();
hasGoogleVisualizationField python:form.hasGoogleVisualizationField()
">
<tal:has_form condition="has_form">
<tal:has_date condition="hasDateTimeField">
Expand All @@ -33,17 +34,24 @@
<tal:has_googleviz condition="hasGoogleVisualizationField">
<tal:script metal:use-macro="here/googlevisualization_macro/macros/js_library">//load google js</tal:script>
</tal:has_googleviz>
<script type="text/javascript" tal:condition="hasDynamicHidewhen">
function refreshHidewhen() {
var onsuccess = function(data, textStatus, xhr) {
for (var hw in data)
$('.hidewhen-' + hw).css('display', data[hw]?'none':'block');
}
$.post('computehidewhens', $('#plomino_form').serialize(), onsuccess, 'json');
}
$(document).ready( function() {
$('#plomino_form :input').change(refreshHidewhen);
});
<script type="text/javascript" tal:condition="hasDynamicHidewhen" tal:content="string:
function refreshHidewhen() {
var onsuccess = function(data, textStatus, xhr) {
for (var hw in data)
jq('.hidewhen-' + hw).css('display', data[hw]?'none':'block');
}
jq.ajax({
type: '${form_method}',
url: 'computehidewhens',
data: jq('#plomino_form').serialize(),
success: onsuccess,
dataType: 'json'
});
}
jq(document).ready( function() {
jq('#plomino_form :input').change(refreshHidewhen);
});
">
</script>
</tal:has_form>
</metal:javascript_head_slot>
Expand All @@ -53,10 +61,10 @@
<metal:css_style_slot fill-slot="style_slot"
tal:define="
has_form python:here.hasItem('Form');
this_form python:here.getForm();
hasDateTimeField python:this_form.hasDateTimeField();
hasDynamicHidewhen python:this_form.hasDynamicHidewhen();
hasGoogleVisualizationField python:this_form.hasGoogleVisualizationField()
form python:here.getForm();
hasDateTimeField python:form.hasDateTimeField();
hasDynamicHidewhen python:form.hasDynamicHidewhen();
hasGoogleVisualizationField python:form.hasGoogleVisualizationField()
">
<tal:has_form condition="has_form">
<tal:has_date condition="hasDateTimeField">
Expand All @@ -75,25 +83,34 @@
</metal:top_slot>

<metal:main fill-slot="main">
<tal:TODO condition="nothing"> Do we need to redefine 'this_form' here? </tal:TODO>
<tal:TODO condition="nothing"> Do we need to redefine 'form' here? </tal:TODO>
<tal:main-macro
metal:define-macro="main"
define="kssClassesView context/@@kss_field_decorator_view;
getKssClasses nocall:kssClassesView/getKssClassesInlineEditable;
templateId template/getId;
has_form python:here.hasItem('Form');
this_form python:here.getForm()
form python:here.getForm()
">
<tal:has_form condition="has_form">
<form tal:attributes="name python:here.getForm().id;
action python:here.doc_url()+'/saveDocument'"
id="plomino_form" method="POST" enctype="multipart/form-data">
<form
tal:define="
form_method python:form.getFormMethod();
enctype python:(form_method == 'POST') and 'multipart/form-data'
"
tal:attributes="
name form/id;
action python:here.doc_url()+'/saveDocument';
method form_method;
enctype enctype|nothing
"
id="plomino_form">
<tal:validation metal:use-macro="here/validation_messages/macros/messages">display form actions</tal:validation>
<tal:form define="b this_form/ActionBarPosition|nothing">
<tal:form define="b form/ActionBarPosition|nothing">
<div tal:replace="structure provider:plone.abovecontenttitle" />
<tal:form_actions_top
define="owner python:this_form"
condition= "python:b and this_form.ActionBarPosition in ['TOP', 'BOTH']">
define="owner python:form"
condition= "python:b and form.ActionBarPosition in ['TOP', 'BOTH']">
<span metal:use-macro="here/ActionBar/macros/EditDocumentActionBar" >
display form actions above form fields
</span><br/>
Expand All @@ -102,11 +119,11 @@
<h1 class="documentFirstHeading" tal:content="here/Title">Title</h1>
<div tal:replace="structure provider:plone.belowcontenttitle" />
<div tal:replace="structure provider:plone.abovecontentbody" />
<span tal:content="structure python:here.editWithForm(this_form)" />
<span tal:content="structure python:here.editWithForm(form)" />

<tal:form_actions_bottom
define="owner python:this_form"
condition="python:b and this_form.ActionBarPosition in ['BOTTOM', 'BOTH']">
define="owner python:form"
condition="python:b and form.ActionBarPosition in ['BOTTOM', 'BOTH']">
<span metal:use-macro="here/ActionBar/macros/EditDocumentActionBar" >
display form actions below form fields
</span>
Expand Down
Loading

0 comments on commit 9b27904

Please sign in to comment.