X-Git-Url: https://scm.cri.minesparis.psl.eu/git/MosaicDocument.git/blobdiff_plain/155c6ba3d7e8e9693d30b3cf70f591f0153610b6..99b3ba92670e19c1f86f5de83b8e6bbe4fdc297f:/Products/MosaicDocument/StringSlot.py diff --git a/Products/MosaicDocument/StringSlot.py b/Products/MosaicDocument/StringSlot.py new file mode 100755 index 0000000..64c2524 --- /dev/null +++ b/Products/MosaicDocument/StringSlot.py @@ -0,0 +1,166 @@ +# -*- coding: utf-8 -*- +# (c) 2003 Centre de Recherche en Informatique ENSMP Fontainebleau +# (c) 2003 Benoît PIN +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as published +# by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. +# + + +from Products.CMFCore.permissions import View, ModifyPortalContent + +factory_type_information = ( {'id' : 'String Slot', + 'meta_type' : 'String Slot', + 'description' : "String Slot for Mosaic Document", + 'icon' : 'mosaic_tool/str_icon.gif', + 'product' : 'MosaicDocument', + 'factory' : 'addStringSlot', + 'immediate_view' : 'view', + 'actions' : + ({'id' : 'view', + 'name' : 'View', + 'action' : 'slot_string_view', + 'permissions' : (View, ) + }, + + {'id' : 'edit', + 'name' : 'Edit', + 'action' : 'slot_string_form', + 'permissions' : (ModifyPortalContent, ) + }, + ) + }, + + {'id' : 'Text Slot', + 'meta_type' : 'Text Slot', + 'description' : "Text Slot for Mosaic Document", + 'icon' : 'mosaic_tool/txt_icon.gif', + 'product' : 'MosaicDocument', + 'factory' : 'addStringSlot', + 'immediate_view' : 'view', + 'actions' : + ({'id' : 'view', + 'name' : 'View', + 'action' : 'slot_text_view', + 'permissions' : (View, ) + }, + + {'id' : 'edit', + 'name' : 'Edit', + 'action' : 'slot_text_form', + 'permissions' : (ModifyPortalContent, ) + }, + ) + }, + + {'id' : 'List Slot', + 'meta_type' : 'List Slot', + 'description' : "List Slot for Mosaic Document", + 'icon' : 'mosaic_tool/str_icon.gif', + 'product' : 'MosaicDocument', + 'factory' : 'addStringSlot', + 'immediate_view' : 'view', + 'actions' : + ({'id' : 'view', + 'name' : 'View', + 'action' : 'slot_list_view', + 'permissions' : (View, ) + }, + + {'id' : 'edit', + 'name' : 'Edit', + 'action' : 'slot_text_form', + 'permissions' : (ModifyPortalContent, ) + }, + ) + }, + ) + +from AccessControl import ClassSecurityInfo +from Globals import InitializeClass +from Products.CMFCore.Expression import Expression +from Products.CMFDefault.Document import Document +from OFS.PropertyManager import PropertyManager +from BaseSlot import BaseSlot + +class StringSlot(BaseSlot, Document, PropertyManager) : + """String Slot""" + meta_type = 'String Slot' + _editableFields = ('text', 'text_format', 'size', 'cols', 'rows') + _indexableFields = ('text',) + + manage_options = Document.manage_options[:2] + PropertyManager.manage_options + Document.manage_options[2:] + + _properties = ({'id' : 'choices', 'type' : 'lines', 'mode' : 'w'}, + {'id' : 'castOperator', 'type' : 'string', 'mode' : 'w'}, + {'id' : 'size', 'type' : 'int', 'mode' : 'w'}, + {'id' : 'cols', 'type' : 'int', 'mode' : 'w'}, + {'id' : 'rows', 'type' : 'int', 'mode' : 'w'}, + {'id' : 'url_expression', 'type': 'expr', 'mode' : 'w'}) + + security = ClassSecurityInfo() + + + def __init__(self, id, text='', text_format='plain', + choices = [], castOperator = 'string', size = 60, + cols=50, rows=50, url_expression = None) : + + Document.__init__(self, id, text_format = text_format, text = text) + + self.choices = choices + self.castOperator = castOperator + self.size = size + self.cols = cols + self.rows = rows + if url_expression is None : + self.url_expression = Expression("python:None") + else : + self.url_expression = url_expression + + security.declareProtected(ModifyPortalContent, 'setFormat') + def setFormat(self, format): + """ Set text format and Dublin Core resource format. + """ + value = str(format) + if value == 'text/html' or value == 'html': + self.text_format = 'html' + elif value == 'text/plain': + if self.text_format not in ('structured-text', 'plain'): + self.text_format = 'structured-text' + elif value == 'plain': + self.text_format = 'plain' + else: + self.text_format = 'structured-text' + + +InitializeClass(StringSlot) + + +def addStringSlot(dispatcher, id, text='', text_format='plain', + choices = [], castOperator = 'string', size=60, + cols=50, rows=50, url_expression = None) : + """ + Add a new TextSlot object. + """ + stringSlot = StringSlot(id, + text=text, + text_format=text_format, + choices=choices, + castOperator=castOperator, + size=size, + cols=cols, + rows=rows, + url_expression=url_expression) + parentContainer = dispatcher.Destination() + parentContainer._setObject(id, stringSlot)