eggification
[photoprint.git] / Products / photoprint / skins / photoprint_templates_edit_form.py
diff --git a/Products/photoprint/skins/photoprint_templates_edit_form.py b/Products/photoprint/skins/photoprint_templates_edit_form.py
new file mode 100755 (executable)
index 0000000..b70ce31
--- /dev/null
@@ -0,0 +1,72 @@
+##parameters=addTemplate='', edit='', deleteOptionContainer='', createOptionsContainer=''
+from Products.CMFCore.utils import getToolByName
+from Products.photoprint.utils import translate as _
+
+utool = getToolByName(context, 'portal_url')
+pptool = getToolByName(context, 'portal_photo_print')
+form = context.REQUEST.form.copy()
+
+if addTemplate:
+       context.REQUEST.RESPONSE.setHeader('Content-Type', 'text/xml;;charset=utf-8');
+       fg = form.get
+
+       try :
+               orderTemplate = pptool.addPrintOrderTemplate( context
+                                                                                                       , title=fg('title')
+                                                                                                       , description=fg('description')
+                                                                                                       , productReference=fg('productReference')
+                                                                                                       , maxCopies=fg('maxCopies')
+                                                                                                       , price=fg('price')
+                                                                                                       , VATRate=fg('VATRate')
+                                                                                                       )
+               templateOptions = {}
+               templateOptions['o'] = orderTemplate
+               classRowName = 'odd'
+               if context.printingOptions.getObjectPosition(orderTemplate.getId()) % 2 == 0 :
+                       classRowName = 'even'
+               templateOptions['classRowName'] = classRowName
+               templateOptions['portal_url'] = utool()
+               widget = context.get_photo_print_order_template(**templateOptions).encode('utf-8').strip()
+               return '<computedField type="added">%s</computedField>' % widget
+               
+       except ValueError, e:
+               return '<error>%s</error>' % _(e)
+
+elif edit:
+       context.REQUEST.RESPONSE.setHeader('Content-Type', 'text/xml;;charset=utf-8');
+       id = form.pop('id')
+       try :
+               orderTemplate = pptool.editPrintOrderTemplate(context, id, **form)
+
+               templateOptions = {}
+               templateOptions['o'] = orderTemplate
+               classRowName = 'odd'
+               if context.printingOptions.getObjectPosition(orderTemplate.getId()) % 2 == 0 :
+                       classRowName = 'even'
+               templateOptions['classRowName'] = classRowName
+               templateOptions['portal_url'] = utool()
+               widget = context.get_photo_print_order_template(**templateOptions).encode('utf-8').strip()
+               return '<computedField type="edited">%s</computedField>' % widget
+       except ValueError, e :
+               return '<error>%s</error>' % _(e)
+
+elif createOptionsContainer :
+       pptool.createPrintingOptionsContainer(context)
+       context.setStatus(True, _('Printing options added.'))
+
+elif deleteOptionContainer :   
+       pptool.deletePrintingOptionsContainer(context)
+       context.setStatus(True, _('Printing options deleted.'))
+
+
+options = {}
+options['pptool'] = pptool
+options['hasPO'] = pptool.hasPrintingOptions(context)
+pOptionsSrc = pptool.getPrintingOptionsSrc(context)
+if pOptionsSrc :
+       pourl = pOptionsSrc.getActionInfo('object/printing_settings')['url']
+else :
+       pourl = None
+options['pourl'] = pourl
+
+return context.photoprint_templates_edit_template(**options)