Improved Pod field with triggerable actions.
This commit is contained in:
parent
9974769075
commit
a326f00c2f
|
@ -470,13 +470,17 @@ class Pod(Type):
|
||||||
searchable=False, specificReadPermission=False,
|
searchable=False, specificReadPermission=False,
|
||||||
specificWritePermission=False, width=None, height=None,
|
specificWritePermission=False, width=None, height=None,
|
||||||
master=None, masterValue=None, focus=False, historized=False,
|
master=None, masterValue=None, focus=False, historized=False,
|
||||||
template=None, context=None):
|
template=None, context=None, action=None, askAction=False):
|
||||||
Type.__init__(self, None, (0,1), index, default, optional,
|
Type.__init__(self, None, (0,1), index, default, optional,
|
||||||
False, show, page, group, move, indexed, searchable,
|
False, show, page, group, move, indexed, searchable,
|
||||||
specificReadPermission, specificWritePermission, width,
|
specificReadPermission, specificWritePermission, width,
|
||||||
height, master, masterValue, focus, historized)
|
height, master, masterValue, focus, historized)
|
||||||
self.template = template # The path to a POD template
|
self.template = template # The path to a POD template
|
||||||
self.context = context # A dict containing a specific pod context
|
self.context = context # A dict containing a specific pod context
|
||||||
|
self.action = action # A method that will be triggered after the
|
||||||
|
# document has been generated.
|
||||||
|
self.askAction = askAction # If True, the action will be triggered only
|
||||||
|
# if the user checks a checkbox, which, by default, will be unchecked.
|
||||||
|
|
||||||
# Workflow-specific types ------------------------------------------------------
|
# Workflow-specific types ------------------------------------------------------
|
||||||
class State:
|
class State:
|
||||||
|
|
|
@ -198,6 +198,12 @@ class ArchetypeFieldDescriptor:
|
||||||
self.fieldType = 'FileField'
|
self.fieldType = 'FileField'
|
||||||
self.widgetType = 'FileWidget'
|
self.widgetType = 'FileWidget'
|
||||||
self.fieldParams['storage'] = 'python:AttributeStorage()'
|
self.fieldParams['storage'] = 'python:AttributeStorage()'
|
||||||
|
# Add i18n-specific messages
|
||||||
|
if self.appyType.askAction:
|
||||||
|
label = '%s_%s_askaction' % (self.classDescr.name, self.fieldName)
|
||||||
|
msg = PoMessage(label, '', PoMessage.POD_ASKACTION)
|
||||||
|
self.generator.labels.append(msg)
|
||||||
|
self.classDescr.labelsToPropagate.append(msg)
|
||||||
# Add the POD-related fields on the Flavour
|
# Add the POD-related fields on the Flavour
|
||||||
Flavour._appy_addPodRelatedFields(self)
|
Flavour._appy_addPodRelatedFields(self)
|
||||||
|
|
||||||
|
|
|
@ -131,6 +131,7 @@ class FlavourMixin(AbstractMixin):
|
||||||
appyType = ploneObj.getAppyType(fieldName)
|
appyType = ploneObj.getAppyType(fieldName)
|
||||||
res['title'] = self.translate(appyType['label'])
|
res['title'] = self.translate(appyType['label'])
|
||||||
res['context'] = appyType['context']
|
res['context'] = appyType['context']
|
||||||
|
res['action'] = appyType['action']
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def generateDocument(self):
|
def generateDocument(self):
|
||||||
|
@ -156,10 +157,11 @@ class FlavourMixin(AbstractMixin):
|
||||||
format = podTemplate.getPodFormat()
|
format = podTemplate.getPodFormat()
|
||||||
template = appyPt.podTemplate.content
|
template = appyPt.podTemplate.content
|
||||||
podTitle = podTemplate.Title()
|
podTitle = podTemplate.Title()
|
||||||
|
doAction = False
|
||||||
else:
|
else:
|
||||||
fieldName = rq.get('fieldName')
|
fieldName = rq.get('fieldName')
|
||||||
|
format = rq.get('podFormat')
|
||||||
podInfo = self.getPodInfo(obj, fieldName)
|
podInfo = self.getPodInfo(obj, fieldName)
|
||||||
format = podInfo['formats'][0]
|
|
||||||
template = podInfo['template'].content
|
template = podInfo['template'].content
|
||||||
podTitle = podInfo['title']
|
podTitle = podInfo['title']
|
||||||
if podInfo['context']:
|
if podInfo['context']:
|
||||||
|
@ -167,6 +169,7 @@ class FlavourMixin(AbstractMixin):
|
||||||
specificPodContext = podInfo['context'](appyObj)
|
specificPodContext = podInfo['context'](appyObj)
|
||||||
else:
|
else:
|
||||||
specificPodContext = podInfo['context']
|
specificPodContext = podInfo['context']
|
||||||
|
doAction = rq.get('askAction') == 'True'
|
||||||
# Temporary file where to generate the result
|
# Temporary file where to generate the result
|
||||||
tempFileName = '%s/%s_%f.%s' % (
|
tempFileName = '%s/%s_%f.%s' % (
|
||||||
getOsTempFolder(), obj.UID(), time.time(), format)
|
getOsTempFolder(), obj.UID(), time.time(), format)
|
||||||
|
@ -203,14 +206,16 @@ class FlavourMixin(AbstractMixin):
|
||||||
f = file(tempFileName, 'rb')
|
f = file(tempFileName, 'rb')
|
||||||
res = f.read()
|
res = f.read()
|
||||||
# Identify the filename to return
|
# Identify the filename to return
|
||||||
fileName = u'%s-%s' % (obj.Title().decode('utf-8'),
|
fileName = u'%s-%s' % (obj.Title().decode('utf-8'), podTitle)
|
||||||
podTitle.decode('utf-8'))
|
|
||||||
fileName = appyTool.normalize(fileName)
|
fileName = appyTool.normalize(fileName)
|
||||||
response = obj.REQUEST.RESPONSE
|
response = obj.REQUEST.RESPONSE
|
||||||
response.setHeader('Content-Type', mimeTypes[format])
|
response.setHeader('Content-Type', mimeTypes[format])
|
||||||
response.setHeader('Content-Disposition', 'inline;filename="%s.%s"'\
|
response.setHeader('Content-Disposition', 'inline;filename="%s.%s"'\
|
||||||
% (fileName, format))
|
% (fileName, format))
|
||||||
f.close()
|
f.close()
|
||||||
|
# Execute the related action if relevant
|
||||||
|
if doAction and podInfo['action']:
|
||||||
|
podInfo['action'](appyObj, podContext)
|
||||||
# Returns the doc and removes the temp file
|
# Returns the doc and removes the temp file
|
||||||
try:
|
try:
|
||||||
os.remove(tempFileName)
|
os.remove(tempFileName)
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
tal:repeat="podTemplate podTemplates">
|
tal:repeat="podTemplate podTemplates">
|
||||||
<a style="cursor: pointer"
|
<a style="cursor: pointer"
|
||||||
tal:define="podFormat podTemplate/getPodFormat"
|
tal:define="podFormat podTemplate/getPodFormat"
|
||||||
tal:attributes="onclick python: 'javascript:generatePodDocument(\'%s\',\'%s\', \'\')' % (contextObj.UID(), podTemplate.UID())" >
|
tal:attributes="onclick python: 'javascript:generatePodDocument(\'%s\',\'%s\', \'\', \'\')' % (contextObj.UID(), podTemplate.UID())" >
|
||||||
<img tal:attributes="src string: $portal_url/skyn/$podFormat.png"/>
|
<img tal:attributes="src string: $portal_url/skyn/$podFormat.png"/>
|
||||||
<span tal:replace="podTemplate/Title"/>
|
<span tal:replace="podTemplate/Title"/>
|
||||||
</a>
|
</a>
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
<select tal:condition="python: len(podTemplates)>maxShownTemplates">
|
<select tal:condition="python: len(podTemplates)>maxShownTemplates">
|
||||||
<option value="" tal:content="python: tool.translate('choose_a_doc')"></option>
|
<option value="" tal:content="python: tool.translate('choose_a_doc')"></option>
|
||||||
<option tal:repeat="podTemplate podTemplates" tal:content="podTemplate/Title"
|
<option tal:repeat="podTemplate podTemplates" tal:content="podTemplate/Title"
|
||||||
tal:attributes="onclick python: 'javascript:generatePodDocument(\'%s\',\'%s\', \'\')' % (contextObj.UID(), podTemplate.UID())" />
|
tal:attributes="onclick python: 'javascript:generatePodDocument(\'%s\',\'%s\', \'\', \'\')' % (contextObj.UID(), podTemplate.UID())" />
|
||||||
</select>
|
</select>
|
||||||
</tal:podTemplates>
|
</tal:podTemplates>
|
||||||
</div>
|
</div>
|
||||||
|
@ -138,12 +138,19 @@
|
||||||
</metal:showString>
|
</metal:showString>
|
||||||
|
|
||||||
<metal:showPod define-macro="showPodField"
|
<metal:showPod define-macro="showPodField"
|
||||||
tal:define="fieldName field/getName;
|
tal:define="fieldName field/getName">
|
||||||
format python:flavour.getPodInfo(contextObj, fieldName)['formats'][0]">
|
<img tal:repeat="podFormat python:flavour.getPodInfo(contextObj, fieldName)['formats']"
|
||||||
<img tal:attributes="src string: $portal_url/skyn/${format}.png;
|
tal:attributes="src string: $portal_url/skyn/${podFormat}.png;
|
||||||
title label;
|
title label;
|
||||||
onClick python: 'javascript:generatePodDocument(\'%s\',\'\',\'%s\')' % (contextObj.UID(), fieldName)"
|
onClick python: 'javascript:generatePodDocument(\'%s\',\'\',\'%s\',\'%s\')' % (contextObj.UID(), fieldName, podFormat)"
|
||||||
style="cursor:pointer"/>
|
style="cursor:pointer"/>
|
||||||
|
<tal:askAction condition="appyType/askAction"
|
||||||
|
define="doLabel python:'%s_askaction' % appyType['label'];
|
||||||
|
chekboxId python: '%s_%s' % (contextObj.UID(), fieldName)">
|
||||||
|
<input type="checkbox" tal:attributes="name doLabel; id chekboxId"/>
|
||||||
|
<label tal:attributes="for chekboxId" class="discreet"
|
||||||
|
tal:content="python: tool.translate(doLabel)"></label>
|
||||||
|
</tal:askAction>
|
||||||
</metal:showPod>
|
</metal:showPod>
|
||||||
|
|
||||||
<div metal:define-macro="showArchetypesField"
|
<div metal:define-macro="showArchetypesField"
|
||||||
|
@ -486,11 +493,17 @@
|
||||||
createCookie(cookieId, newState);
|
createCookie(cookieId, newState);
|
||||||
}
|
}
|
||||||
// Function that allows to generate a document from a pod template.
|
// Function that allows to generate a document from a pod template.
|
||||||
function generatePodDocument(contextUid, templateUid, fieldName) {
|
function generatePodDocument(contextUid, templateUid, fieldName, podFormat) {
|
||||||
var theForm = document.forms["podTemplateForm"];
|
var theForm = document.forms["podTemplateForm"];
|
||||||
theForm.objectUid.value = contextUid;
|
theForm.objectUid.value = contextUid;
|
||||||
theForm.templateUid.value = templateUid;
|
theForm.templateUid.value = templateUid;
|
||||||
theForm.fieldName.value = fieldName;
|
theForm.fieldName.value = fieldName;
|
||||||
|
theForm.podFormat.value = podFormat;
|
||||||
|
theForm.askAction.value = "False";
|
||||||
|
var askActionWidget = document.getElementById(contextUid + '_' + fieldName);
|
||||||
|
if (askActionWidget && askActionWidget.checked) {
|
||||||
|
theForm.askAction.value = "True";
|
||||||
|
}
|
||||||
theForm.submit();
|
theForm.submit();
|
||||||
}
|
}
|
||||||
-->
|
-->
|
||||||
|
@ -504,9 +517,11 @@
|
||||||
<form name="podTemplateForm" method="post"
|
<form name="podTemplateForm" method="post"
|
||||||
tal:attributes="action python: flavour.absolute_url() + '/generateDocument'">
|
tal:attributes="action python: flavour.absolute_url() + '/generateDocument'">
|
||||||
<input type="hidden" name="objectUid"/>
|
<input type="hidden" name="objectUid"/>
|
||||||
<tal:comment replace="nothing">templateUid is given if class-wide pod, fieldName is given if podField.</tal:comment>
|
<tal:comment replace="nothing">templateUid is given if class-wide pod, fieldName and podFormat are given if podField.</tal:comment>
|
||||||
<input type="hidden" name="templateUid"/>
|
<input type="hidden" name="templateUid"/>
|
||||||
<input type="hidden" name="fieldName"/>
|
<input type="hidden" name="fieldName"/>
|
||||||
|
<input type="hidden" name="podFormat"/>
|
||||||
|
<input type="hidden" name="askAction"/>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ class PoMessage:
|
||||||
'comment every time a transition is triggered'
|
'comment every time a transition is triggered'
|
||||||
MSG_showAllStatesInPhaseFor = 'Show all states in phase'
|
MSG_showAllStatesInPhaseFor = 'Show all states in phase'
|
||||||
POD_TEMPLATE = 'POD template'
|
POD_TEMPLATE = 'POD template'
|
||||||
|
POD_ASKACTION = 'Trigger related action'
|
||||||
DEFAULT_VALID_ERROR = 'Please fill or correct this.'
|
DEFAULT_VALID_ERROR = 'Please fill or correct this.'
|
||||||
REF_NO = 'No object.'
|
REF_NO = 'No object.'
|
||||||
REF_ADD = 'Add a new one'
|
REF_ADD = 'Add a new one'
|
||||||
|
|
Loading…
Reference in a new issue