# -*- coding: utf-8
# Copyright 2006 by Meelis Mets
from Products.Archetypes.public import BaseSchema, Schema
from Products.Archetypes.public import BooleanField, ImageField, StringField
from Products.Archetypes.public import BooleanWidget, ImageWidget, StringWidget, SelectionWidget
from Products.Archetypes.public import BaseContent, registerType
from Globals import InitializeClass
from Products.CMFCore.utils import getToolByName
from AccessControl import ClassSecurityInfo, Unauthorized
from config import PROJECT_NAME
from BaseFunctions import BaseFunctions
schema = BaseSchema + Schema((
ImageField('elementImage',
accessor = 'getElementImage',
#max_size = (150,150),
widget = ImageWidget(
label = 'Element\'s image',
description = 'If you want use your own image, upload it here',
label_msgid="label_elements_image",
description_msgid="desc_elements_image",
i18n_domain="psyhvel",
visible = {'view': 'invisible', 'edit':'visible'},
),
),
StringField('elementShape',
accessor = 'getElementShape',
default = 'circle',
widget = StringWidget(
label = 'Element\'s shape',
label_msgid='label_elements_shape',
description = 'if image not used',
description_msgid = 'desc_elements_shape',
i18n_domain="psyhvel",
visible = {'view': 'invisible', 'edit':'invisible'},
),
),
StringField('elementWidth',
accessor = 'getElementWidth',
default = '20',
widget = StringWidget(
label = 'Element\'s width',
label_msgid='label_elements_width',
description = 'if set, image will be scaled for this size',
description_msgid = 'desc_elements_width',
i18n_domain="psyhvel",
visible = {'view': 'invisible', 'edit':'invisible'},
),
),
StringField('elementHeight',
accessor = 'getElementHeight',
default = '20',
widget = StringWidget(
label = 'Element\'s height',
label_msgid='label_elements_height',
description = 'if set, image will be scaled for this size',
description_msgid = 'desc_elements_height',
i18n_domain="psyhvel",
visible = {'view': 'invisible', 'edit':'invisible'},
),
),
StringField('elementColor',
accessor = 'getElementColor',
default = 'black',
widget = StringWidget(
label = 'Element\'s color',
label_msgid='label_elements_color',
description = 'if image not used',
description_msgid = 'desc_elements_color',
i18n_domain="psyhvel",
visible = {'view': 'invisible', 'edit':'invisible'},
),
),
StringField('elementPlace',
accessor = 'getElementPlace',
default = '30',
widget = StringWidget(
label = 'Element place\'s size',
label_msgid='label_elements_place',
description = 'if',
description_msgid = 'desc_elements_palce',
i18n_domain="psyhvel",
visible = {'view': 'invisible', 'edit':'invisible'},
),
),
StringField('elementX',
accessor = 'getElementX',
default = 0,
widget = StringWidget(
label = 'Element X',
visible = {'view': 'invisible', 'edit':'invisible'},
),
),
StringField('elementY',
accessor = 'getElementY',
default = 0,
widget = StringWidget(
label = 'Element place\'s size',
visible = {'view': 'invisible', 'edit':'invisible'},
),
),
#BooleanField('useTitle',
# accessor = 'getUseTitle',
# widget = BooleanWidget(
# label = 'Use title',
# label_msgid='label_usetitle',
# description = 'Check if you want use title as text (description) in answer',
# description_msgid = 'desc_usetitle',
# i18n_domain="psyhvel",
# visible = {'view': 'invisible', 'edit':'visible'},
# ),
#),
))
class ElementObject(BaseContent, BaseFunctions):
""" Psyhvel element object"""
meta_type = "ElementObject"
archetype_name = "Element Object"
global_allow = 0
exclude_from_nav = True
filter_content_types = True
allowed_content_types = ()
security = ClassSecurityInfo()
schema = schema
actions = (
{
'id':'view',
'name':'View',
'action':'string:${object_url}/element_edit',
'permissions': ('View',),
},
{
'id':'edit',
'name':'Configuration',
'action':'string:${object_url}/base_edit',
'permissions': ('Modify portal content',),
},
{
'id':'metadata',
'visible':False,
'permissions': ('Modify portal content',),
},
)
def saveElement(self):
""" saving element data """
shape = self.REQUEST.get('eShape')
width = self.REQUEST.get('elementWidth')
height = self.REQUEST.get('elementHeight')
place = self.REQUEST.get('elementPlace')
color = self.REQUEST.get('elementColor')
self.elementShape = shape
self.elementWidth = width
self.elementHeight = height
self.elementPlace = place
self.elementColor = color
return self.REQUEST.RESPONSE.redirect(self.absolute_url())
def setElementPosition(self, dex, dey):
"""set new positions"""
self.elementX = dex
self.elementY = dey
def getElementData(self):
"""return all data"""
image = ""
if self.getElementImage():
image = self.absolute_url()+"/elementImage"
return [self.getElementX(),self.getElementY(),self.getElementShape(),self.getElementWidth(),self.getElementHeight(),self.getElementColor(),image,self.getElementPlace()]
def getObjectsXML(self, files):
"""special xml"""
xml = self.getBaseXML()
img = self.getField('elementImage')
fname = img.getFilename(self)
imagefile = img.getBaseUnit(self)
xml += '\n'
xml += '\n'
xml += '\n'
xml += '\n'
xml += '\n'
xml += '\n'
xml += '\n'
xml += '\n'
xml += ''
files.append({'filename':fname, 'file':str(imagefile)})
return [xml, files]
registerType(ElementObject, PROJECT_NAME)