-
Notifications
You must be signed in to change notification settings - Fork 0
/
_objinputs.py
357 lines (336 loc) · 13.2 KB
/
_objinputs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
################################################################################
# _objinputs.py
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# 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.
################################################################################
# Imports.
from App.special_dtml import HTMLFile
# Product Imports.
import _globals
import _zreferableitem
class ObjInputs:
# ----------------------------------------------------------------------------
# ObjInputs.getUrlInput:
#
# @param fmName
# @param elName
# @param elTextName
# @param size
# @param value
# @param enabled
# @param REQUEST
# @param css CSS-Class
# @return String
# ----------------------------------------------------------------------------
def getUrlInput(self, fmName, elName, elTextName, size, value, enabled, REQUEST, css='form-element'):
lang = self.REQUEST.get('lang')
html = []
styles = ['float:left']
if size:
styles.append( 'width:%iem'%size)
else:
styles.append( 'width:80%')
html.append(self.getTextInput(fmName,elName,size,value,'text',enabled,REQUEST,css+' url-input',extra=' style="%s"'%(';'.join(styles))))
ref_obj = self.getLinkObj(value,REQUEST)
if ref_obj is not None:
html.append('<div class="form-small" style="clear:both">')
html.append('<span class="ui-icon ui-icon-extlink" style="float:left"></span>')
html.append(ref_obj.f_breadcrumbs(objectPathElements=ref_obj.breadcrumbs_obj_path(),no_icon=1,lang=lang,REQUEST=REQUEST))
html.append('</div>')
return ''.join(html)
# ----------------------------------------------------------------------------
# getHiddenInput:
#
# @param fmName
# @param elName
# @param value
# ----------------------------------------------------------------------------
def getHiddenInput(self, fmName, elName, value, onchange=''):
html = []
html.append('<input ')
html.append(' type="hidden"')
html.append(' name="%s"'%elName)
html.append(' value="%s"'%str(value))
if onchange:
html.append(' onchange="%s"'%onchange)
html.append('/>')
return ''.join(html)
# ----------------------------------------------------------------------------
# getDateTimeInput:
#
# @param fmName
# @param elName
# @param size
# @param value
# @param enabled
# @param REQUEST
# @param css CSS-Class
# @return String
# ----------------------------------------------------------------------------
def getDateTimeInput(self, fmName, elName, size, value, enabled, fmt_str, REQUEST, css='form-element', extra=''):
manage_lang = self.get_manage_lang()
html = []
if not type(value) is str:
value = self.getLangFmtDate(value,manage_lang,fmt_str)
if value is not None and self.parseLangFmtDate(value) is None:
value = ''
html.append('<span class="%s" title="%s">'%(css,self.getZMILangStr(fmt_str)))
if enabled:
if fmt_str == 'DATE_FMT':
css += ' datepicker'
elif fmt_str == 'DATETIME_FMT':
css += ' datetimepicker'
html.append(self.getTextInput(fmName,elName,size,value,'text',enabled,REQUEST,css,extra))
html.append('</span>')
return ''.join(html)
# ----------------------------------------------------------------------------
# getDateInput:
#
# @param fmName
# @param elName
# @param value
# @param enabled
# @param REQUEST
# @param css CSS-Class
# @return String
# ----------------------------------------------------------------------------
def getDateInput(self, fmName, elName, value, enabled, REQUEST, css='form-element', extra=''):
return self.getDateTimeInput(fmName=fmName,elName=elName,size=8,value=value,enabled=enabled,fmt_str='DATE_FMT',REQUEST=REQUEST,css=css, extra=extra)
# ----------------------------------------------------------------------------
# getPasswordInput:
#
# @param fmName
# @param elName
# @param size
# @param value
# @param enabled
# @param css CSS-Class
# @return String
# ----------------------------------------------------------------------------
def getPasswordInput(self, fmName, elName, size=15, value='', enabled=True, REQUEST=None, css='form-element', extra=''):
return self.getTextInput(fmName,elName,size,value,'password',enabled,REQUEST,css,extra)
# ----------------------------------------------------------------------------
# getTextInput:
#
# @param fmName
# @param elName
# @param size
# @param value (optional)
# @param type (optional: "text" or "password")
# @param css CSS-Class
# @return String
# ----------------------------------------------------------------------------
def getTextInput(self, fmName, elName, size=None, value='', type='text', enabled=True, REQUEST=None, css='form-element', extra=''):
lang = self.REQUEST.get('lang',self.getPrimaryLanguage())
elId = elName
if elId.endswith('_%s'%lang):
elId = elId[:-len('_%s'%lang)]
html = []
html.append('<span class="%s">'%css)
html.append('<input ')
html.append(' class="%s"'%' '.join([css,elId,lang]))
html.append(' type="%s"'%type)
html.append(' id="%s"'%elName.replace(':int',''))
html.append(' name="%s"'%elName)
if size:
html.append(' size="%i"'%size)
if value is not None:
html.append(' value="%s"'%_globals.html_quote(value))
if extra.find('style=') < 0:
styles = []
if size:
styles.append( 'width:%iem'%size)
else:
styles.append( 'width:80%')
if elName.endswith(':int'):
styles.append( 'text-align:right')
html.append(' style="%s"'%(';'.join(styles)))
if not enabled:
html.append(' disabled="disabled"')
html.append(' %s/>'%extra)
html.append('</span>')
return ''.join(html)
# ----------------------------------------------------------------------------
# getSelect:
#
# @param fmName
# @param elName
# @param value
# @param inputtype
# @param lang_str
# @param required
# @param optpl
# @param enabled
# @param REQUEST Http-Request
# @param css CSS-Class
# @return String
# ----------------------------------------------------------------------------
def getSelect(self, fmName, elName, value, inputtype, lang_str, required, optpl, enabled, REQUEST, css='form-element', maxlen=30):
return self.f_selectInput(self,fmName=fmName,elName=elName,value=value,type=inputtype,lang_str=lang_str,required=required,optpl=optpl,maxlen=maxlen,enabled=enabled,css=css,REQUEST=REQUEST)
# ----------------------------------------------------------------------------
# getCheckbox:
#
# @param fmName
# @param elName
# @param elId
# @param value
# @param enabled
# @param hidden Add hidden Input-Field if not enabled
# @param REQUEST Http-Request
# @param css CSS-Class
# @param extra Extra-Parameters
# @return String
# ----------------------------------------------------------------------------
def getCheckbox(self, fmName, elName, elId=None, value=None, enabled=True, hidden=True, REQUEST=None, css='form-checkbox', extra=''):
lang = self.REQUEST.get('lang',self.getPrimaryLanguage())
elId = elName
if elId.endswith('_%s'%lang):
elId = elId[:-len('_%s'%lang)]
html = []
checked = str(value) == '1'
if elName.find(':int') > 0 and value in [True, False]:
value = int(value)
html.append('<input ')
html.append(' type="hidden"')
html.append(' name="%s"'%elName)
html.append(' value="%s"'%str(value))
html.append(' />')
html.append('<input ')
if type(elId) is str:
html.append(' id="%s"'%elId)
html.append(' class="%s"'%' '.join([css,elId,lang]))
html.append(' type="checkbox"')
if not enabled:
html.append(' disabled="disabled"')
if checked:
html.append(' checked="checked"')
html.append(' onclick="if (this.checked){$(\'input[name=\\x22%s\\x22]\',this.form).val(1)}else{$(\'input[name=\\x22%s\\x22]\',this.form).val(0)}"'%(elName,elName))
html.append(' />')
return ''.join(html)
# ----------------------------------------------------------------------------
# getTextArea:
#
# @param fmName
# @param elName
# @param cols
# @param rows
# @param value
# @param enabled
# @param REQUEST Http-Request
# @param css CSS-Class
# @param wrap Word-Wrap (on|off)
# @param extra Extra-Parameters
# @return String
# ----------------------------------------------------------------------------
def getTextArea(self, fmName, elName, cols, rows, value, enabled, REQUEST, css='form-element', wrap='virtual', extra=''):
lang = self.REQUEST.get('lang',self.getPrimaryLanguage())
elId = elName
if elId.endswith('_%s'%lang):
elId = elId[:-len('_%s'%lang)]
html = []
html.append('<textarea ')
html.append(' class="%s"'%' '.join([css,elId,lang]))
html.append(' id="%s"'%elName)
html.append(' name="%s"'%elName)
if cols:
html.append(' cols="%i"'%cols)
if rows:
html.append(' rows="%i"'%rows)
html.append(' wrap="%s"'%wrap)
if extra.find('style=') < 0:
styles = []
if cols:
styles.append( 'width:%iem'%cols)
else:
styles.append( 'width:80%')
html.append(' style="%s"'%(';'.join(styles)))
if not enabled:
html.append(' disabled="disabled"')
html.append('%s>'%extra)
if value is not None:
if type(value) is list:
for item in value:
html.append('%s\n'%_globals.html_quote(item))
else:
html.append('%s'%_globals.html_quote(value))
html.append('</textarea>')
if type(value) is str and not REQUEST.get('URL','').find('manage_customize') >= 0:
inline_links = []
# Inline-links: getLinkUrl (deprecated!)
i = -1
start = '{$'
end = '}'
while True:
i = value.find( start, i + 1)
j = value.find( end, i + len( start))
if i < 0 or j < 0:
break
inline_links.append( value[i:j+1])
# Inline-links: relative
i = -1
start = 'href="./'
end = '"'
while True:
i = value.find( start, i + 1)
j = value.find( end, i + len( start))
if i < 0 or j < 0:
break
href = value[ i + len( start) :j]
if href.rfind( '#') > 0:
if href.rfind( '/') > 0:
href = href[ :href.rfind( '/')] + '/' + href[ href.rfind( '#') + 1:]
else:
href = href[ href.rfind( '#') + 1:]
else:
if href.rfind( '/') > 0:
href = href[ :href.rfind( '/')]
else:
href = ''
ref_obj = self.getSelf( self.PAGES)
for el in href.split( '/'):
if ref_obj is not None:
if el == '..':
ref_obj = ref_obj.aq_parent
elif len( el) > 0:
ref_obj = getattr( ref_obj, el, None)
if ref_obj is None:
ref_url = '{$__' + href.split( '/')[ -1] + '__}'
inline_links.append( ref_url)
elif isinstance( ref_obj, _zreferableitem.ZReferableItem):
inline_links.append( self.getRefObjPath( ref_obj))
if len( inline_links) > 0:
html.append('<table cellspacing="0" cellpadding="1" border="0" align="left">')
html.append('<tr valign="top">')
html.append('<td class="form-small" align="left"><b>%s</b>:</td>'%(self.getZMILangStr('ATTR_TARGET')))
html.append('<td class="form-small" align="left">')
for c in range( len( inline_links)):
if c % 2 == 0:
html.append('<div class="zmiTableRowEven">')
else:
html.append('<div class="zmiTableRowOdd">')
html.append('<div class="form-small">')
ref_url = inline_links[c]
ref_obj = self.getLinkObj(ref_url,REQUEST)
if ref_obj is not None:
html.append('<img src="%sinternal_link.gif" border="0" align="absmiddle"/> %s'%(self.MISC_ZMS,ref_obj.f_breadcrumbs(objectPathElements=ref_obj.breadcrumbs_obj_path(),no_icon=1,lang=lang,REQUEST=REQUEST)))
elif isinstance( ref_obj, _zreferableitem.ZReferableItem):
html.append('<img src="%sinternal_link_broken.gif" border="0" align="absmiddle"/> %s'%(self.MISC_ZMS,ref_url))
html.append('</div>')
html.append('</div>')
html.append('</td>')
html.append('</tr>')
html.append('</table>')
return ''.join(html)
################################################################################