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,
|
||||
specificWritePermission=False, width=None, height=None,
|
||||
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,
|
||||
False, show, page, group, move, indexed, searchable,
|
||||
specificReadPermission, specificWritePermission, width,
|
||||
height, master, masterValue, focus, historized)
|
||||
self.template = template # The path to a POD template
|
||||
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 ------------------------------------------------------
|
||||
class State:
|
||||
|
|
|
@ -198,6 +198,12 @@ class ArchetypeFieldDescriptor:
|
|||
self.fieldType = 'FileField'
|
||||
self.widgetType = 'FileWidget'
|
||||
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
|
||||
Flavour._appy_addPodRelatedFields(self)
|
||||
|
||||
|
|
|
@ -131,6 +131,7 @@ class FlavourMixin(AbstractMixin):
|
|||
appyType = ploneObj.getAppyType(fieldName)
|
||||
res['title'] = self.translate(appyType['label'])
|
||||
res['context'] = appyType['context']
|
||||
res['action'] = appyType['action']
|
||||
return res
|
||||
|
||||
def generateDocument(self):
|
||||
|
@ -156,10 +157,11 @@ class FlavourMixin(AbstractMixin):
|
|||
format = podTemplate.getPodFormat()
|
||||
template = appyPt.podTemplate.content
|
||||
podTitle = podTemplate.Title()
|
||||
doAction = False
|
||||
else:
|
||||
fieldName = rq.get('fieldName')
|
||||
format = rq.get('podFormat')
|
||||
podInfo = self.getPodInfo(obj, fieldName)
|
||||
format = podInfo['formats'][0]
|
||||
template = podInfo['template'].content
|
||||
podTitle = podInfo['title']
|
||||
if podInfo['context']:
|
||||
|
@ -167,6 +169,7 @@ class FlavourMixin(AbstractMixin):
|
|||
specificPodContext = podInfo['context'](appyObj)
|
||||
else:
|
||||
specificPodContext = podInfo['context']
|
||||
doAction = rq.get('askAction') == 'True'
|
||||
# Temporary file where to generate the result
|
||||
tempFileName = '%s/%s_%f.%s' % (
|
||||
getOsTempFolder(), obj.UID(), time.time(), format)
|
||||
|
@ -203,14 +206,16 @@ class FlavourMixin(AbstractMixin):
|
|||
f = file(tempFileName, 'rb')
|
||||
res = f.read()
|
||||
# Identify the filename to return
|
||||
fileName = u'%s-%s' % (obj.Title().decode('utf-8'),
|
||||
podTitle.decode('utf-8'))
|
||||
fileName = u'%s-%s' % (obj.Title().decode('utf-8'), podTitle)
|
||||
fileName = appyTool.normalize(fileName)
|
||||
response = obj.REQUEST.RESPONSE
|
||||
response.setHeader('Content-Type', mimeTypes[format])
|
||||
response.setHeader('Content-Disposition', 'inline;filename="%s.%s"'\
|
||||
% (fileName, format))
|
||||
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
|
||||
try:
|
||||
os.remove(tempFileName)
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
tal:repeat="podTemplate podTemplates">
|
||||
<a style="cursor: pointer"
|
||||
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"/>
|
||||
<span tal:replace="podTemplate/Title"/>
|
||||
</a>
|
||||
|
@ -15,7 +15,7 @@
|
|||
<select tal:condition="python: len(podTemplates)>maxShownTemplates">
|
||||
<option value="" tal:content="python: tool.translate('choose_a_doc')"></option>
|
||||
<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>
|
||||
</tal:podTemplates>
|
||||
</div>
|
||||
|
@ -138,12 +138,19 @@
|
|||
</metal:showString>
|
||||
|
||||
<metal:showPod define-macro="showPodField"
|
||||
tal:define="fieldName field/getName;
|
||||
format python:flavour.getPodInfo(contextObj, fieldName)['formats'][0]">
|
||||
<img tal:attributes="src string: $portal_url/skyn/${format}.png;
|
||||
tal:define="fieldName field/getName">
|
||||
<img tal:repeat="podFormat python:flavour.getPodInfo(contextObj, fieldName)['formats']"
|
||||
tal:attributes="src string: $portal_url/skyn/${podFormat}.png;
|
||||
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"/>
|
||||
<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>
|
||||
|
||||
<div metal:define-macro="showArchetypesField"
|
||||
|
@ -486,11 +493,17 @@
|
|||
createCookie(cookieId, newState);
|
||||
}
|
||||
// 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"];
|
||||
theForm.objectUid.value = contextUid;
|
||||
theForm.templateUid.value = templateUid;
|
||||
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();
|
||||
}
|
||||
-->
|
||||
|
@ -504,9 +517,11 @@
|
|||
<form name="podTemplateForm" method="post"
|
||||
tal:attributes="action python: flavour.absolute_url() + '/generateDocument'">
|
||||
<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="fieldName"/>
|
||||
<input type="hidden" name="podFormat"/>
|
||||
<input type="hidden" name="askAction"/>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ class PoMessage:
|
|||
'comment every time a transition is triggered'
|
||||
MSG_showAllStatesInPhaseFor = 'Show all states in phase'
|
||||
POD_TEMPLATE = 'POD template'
|
||||
POD_ASKACTION = 'Trigger related action'
|
||||
DEFAULT_VALID_ERROR = 'Please fill or correct this.'
|
||||
REF_NO = 'No object.'
|
||||
REF_ADD = 'Add a new one'
|
||||
|
|
Loading…
Reference in a new issue