090c57bf4af260d60fd9fa08fdcfa36d5e65d59a
[PlinnDocument.git] / skins / plinn_attachment_form.py
1 ##parameters=
2 form = context.REQUEST.form
3 formId = form.get('formId')
4 epozInsert = form.get('epozInsert', False)
5 file = form.get('file', None)
6 fileOb = None
7
8 if file : fileOb = context.addAttachment(file, formId)
9
10 onload = None
11 if fileOb is not None :
12 if fileOb.meta_type == 'Photo' :
13 fileUrl = 'attachments/%s/getThumbnail' % fileOb.getId()
14 if epozInsert :
15 onload = "dispatchImageAndHideUploadForm('%s', '%s', true);" % (fileUrl, formId)
16 else :
17 ratio = float(fileOb.height)/fileOb.width
18 dispatchValue = "%f_%s" % (ratio, fileUrl)
19 onload = "dispatchImageAndHideUploadForm('%s','%s', false);" % (dispatchValue, formId)
20 else :
21 dispatchValue = '%s[%s]' % (fileOb.getId(), 'attachments/'+fileOb.getId())
22 onload = "dispatchFileAndHideUploadForm('%s', '%s');" % (dispatchValue, formId)
23
24 hideFormCode = "hideUploadForm('%s');" % formId
25
26 return context.plinn_attachment_template(onload=onload,
27 hideFormCode=hideFormCode,
28 formId=formId)