-
Notifications
You must be signed in to change notification settings - Fork 0
/
_objinputs.py
271 lines (250 loc) · 9.96 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
# -*- coding: utf-8 -*-
################################################################################
# _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.
################################################################################
# Product Imports.
import standard
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=None, value='', enabled=True, REQUEST=None, css='form-control'):
return self.getTextInput(fmName,elName,size,value,'text',enabled,REQUEST,css+' url-input')
# ----------------------------------------------------------------------------
# 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=8, value=None, enabled=True, fmt_str='DATETIME_FMT', REQUEST=None, css='form-control', 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 = ''
extra += ' title="%s"'%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))
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-control', 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-control', 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-control', extra=''):
lang = self.REQUEST.get('lang',self.getPrimaryLanguage())
elId = elName
if elId.endswith('_%s'%lang):
elId = elId[:-len('_%s'%lang)]
html = []
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"'%standard.html_quote(value))
if not enabled:
html.append(' disabled="disabled"')
html.append(' %s/>'%extra)
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=False, optpl=[], enabled=True, REQUEST=None, css='form-control', maxlen=30):
if inputtype in ['select','multiline']:
return self.zmi_input_select(self,name=elName,value=value,lang_str=lang_str,mandatory=required,options=optpl,enabled=enabled)
elif inputtype in ['color']:
return self.zmi_input_color(self,name=elName,value=value,lang_str=lang_str,mandatory=required,options=optpl,enabled=enabled)
elif inputtype in ['multiselect']:
return self.zmi_input_multiselect(self,name=elName,value=value,lang_str=lang_str,mandatory=required,options=optpl,enabled=enabled)
elif type in ['text']:
return self.getTextArea(fmName,elName,35,4,value=value,enabled=enabled,REQUEST=REQUEST)
else:
return self.getTextInput(fmName=fmName,elName=elName,size=35,value=value,type='text',enabled=enabled,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
# @param btn Appear as Bootstrap Button
# @return String
# ----------------------------------------------------------------------------
def getCheckbox(self, fmName, elName, elId=None, value=None, enabled=True, hidden=True, REQUEST=None, css='', extra='', btn=False, options=[0,1]):
lang = self.REQUEST.get('lang',self.getPrimaryLanguage())
elId = elName
if elId.endswith('_%s'%lang):
elId = elId[:-len('_%s'%lang)]
html = []
if value in [True, False]:
value = options[int(value)]
checked = str(value) == str(options[1])
html.append('<input ')
html.append(' type="hidden"')
html.append(' name="%s"'%elName)
html.append(' value="%s"'%str(standard.nvl(value,options[0])))
html.append(' />')
if btn:
html.append('<span class="btn btn-default">')
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){$(this)%s.prev().val(\'%s\')}else{$(this)%s.prev().val(\'%s\')}"'%(['','.parent()'][btn],options[1],['','.parent()'][btn],options[0]))
html.append(' />')
if btn:
html.append('</span>')
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-control', 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 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'%standard.html_quote(item))
else:
html.append('%s'%standard.html_quote(value))
html.append('</textarea>')
return ''.join(html)
################################################################################