Utilisation des png24 (et apng) pour l'affichage des boutons de déploiement de l...
[MosaicDocument.git] / StringSlot.py
1 # -*- coding: utf-8 -*-
2 # (c) 2003 Centre de Recherche en Informatique ENSMP Fontainebleau <http://cri.ensmp.fr>
3 # (c) 2003 Benoît PIN <mailto:pin@cri.ensmp.fr>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License version 2 as published
7 # by the Free Software Foundation.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17 # 02111-1307, USA.
18 #
19
20
21 from Products.CMFCore.permissions import View, ModifyPortalContent
22
23 factory_type_information = ( {'id' : 'String Slot',
24 'meta_type' : 'String Slot',
25 'description' : "String Slot for Mosaic Document",
26 'icon' : 'mosaic_tool/str_icon.gif',
27 'product' : 'MosaicDocument',
28 'factory' : 'addStringSlot',
29 'immediate_view' : 'view',
30 'actions' :
31 ({'id' : 'view',
32 'name' : 'View',
33 'action' : 'slot_string_view',
34 'permissions' : (View, )
35 },
36
37 {'id' : 'edit',
38 'name' : 'Edit',
39 'action' : 'slot_string_form',
40 'permissions' : (ModifyPortalContent, )
41 },
42 )
43 },
44
45 {'id' : 'Text Slot',
46 'meta_type' : 'Text Slot',
47 'description' : "Text Slot for Mosaic Document",
48 'icon' : 'mosaic_tool/txt_icon.gif',
49 'product' : 'MosaicDocument',
50 'factory' : 'addStringSlot',
51 'immediate_view' : 'view',
52 'actions' :
53 ({'id' : 'view',
54 'name' : 'View',
55 'action' : 'slot_text_view',
56 'permissions' : (View, )
57 },
58
59 {'id' : 'edit',
60 'name' : 'Edit',
61 'action' : 'slot_text_form',
62 'permissions' : (ModifyPortalContent, )
63 },
64 )
65 },
66
67 {'id' : 'List Slot',
68 'meta_type' : 'List Slot',
69 'description' : "List Slot for Mosaic Document",
70 'icon' : 'mosaic_tool/str_icon.gif',
71 'product' : 'MosaicDocument',
72 'factory' : 'addStringSlot',
73 'immediate_view' : 'view',
74 'actions' :
75 ({'id' : 'view',
76 'name' : 'View',
77 'action' : 'slot_list_view',
78 'permissions' : (View, )
79 },
80
81 {'id' : 'edit',
82 'name' : 'Edit',
83 'action' : 'slot_text_form',
84 'permissions' : (ModifyPortalContent, )
85 },
86 )
87 },
88 )
89
90 from AccessControl import ClassSecurityInfo
91 from Globals import InitializeClass
92 from Products.CMFCore.Expression import Expression
93 from Products.CMFDefault.Document import Document
94 from OFS.PropertyManager import PropertyManager
95 from BaseSlot import BaseSlot
96
97 class StringSlot(BaseSlot, Document, PropertyManager) :
98 """String Slot"""
99 meta_type = 'String Slot'
100 _editableFields = ('text', 'text_format', 'size', 'cols', 'rows')
101 _indexableFields = ('text',)
102
103 manage_options = Document.manage_options[:2] + PropertyManager.manage_options + Document.manage_options[2:]
104
105 _properties = ({'id' : 'choices', 'type' : 'lines', 'mode' : 'w'},
106 {'id' : 'castOperator', 'type' : 'string', 'mode' : 'w'},
107 {'id' : 'size', 'type' : 'int', 'mode' : 'w'},
108 {'id' : 'cols', 'type' : 'int', 'mode' : 'w'},
109 {'id' : 'rows', 'type' : 'int', 'mode' : 'w'},
110 {'id' : 'url_expression', 'type': 'expr', 'mode' : 'w'})
111
112 security = ClassSecurityInfo()
113
114
115 def __init__(self, id, text='', text_format='plain',
116 choices = [], castOperator = 'string', size = 60,
117 cols=50, rows=50, url_expression = None) :
118
119 Document.__init__(self, id, text_format = text_format, text = text)
120
121 self.choices = choices
122 self.castOperator = castOperator
123 self.size = size
124 self.cols = cols
125 self.rows = rows
126 if url_expression is None :
127 self.url_expression = Expression("python:None")
128 else :
129 self.url_expression = url_expression
130
131 security.declareProtected(ModifyPortalContent, 'setFormat')
132 def setFormat(self, format):
133 """ Set text format and Dublin Core resource format.
134 """
135 value = str(format)
136 if value == 'text/html' or value == 'html':
137 self.text_format = 'html'
138 elif value == 'text/plain':
139 if self.text_format not in ('structured-text', 'plain'):
140 self.text_format = 'structured-text'
141 elif value == 'plain':
142 self.text_format = 'plain'
143 else:
144 self.text_format = 'structured-text'
145
146
147 InitializeClass(StringSlot)
148
149
150 def addStringSlot(dispatcher, id, text='', text_format='plain',
151 choices = [], castOperator = 'string', size=60,
152 cols=50, rows=50, url_expression = None) :
153 """
154 Add a new TextSlot object.
155 """
156 stringSlot = StringSlot(id,
157 text=text,
158 text_format=text_format,
159 choices=choices,
160 castOperator=castOperator,
161 size=size,
162 cols=cols,
163 rows=rows,
164 url_expression=url_expression)
165 parentContainer = dispatcher.Destination()
166 parentContainer._setObject(id, stringSlot)