1 | <% if (property.type == Boolean.class || property.type == boolean.class) |
---|
2 | out << renderBooleanEditor(domainClass, property) |
---|
3 | else if (Number.class.isAssignableFrom(property.type) || (property.type.isPrimitive() && property.type != boolean.class)) |
---|
4 | out << renderNumberEditor(domainClass, property) |
---|
5 | else if (property.type == String.class) |
---|
6 | out << renderStringEditor(domainClass, property) |
---|
7 | else if (property.type == Date.class || property.type == java.sql.Date.class || property.type == java.sql.Time.class || property.type == Calendar.class) |
---|
8 | out << renderDateEditor(domainClass, property) |
---|
9 | else if (property.type == URL.class) |
---|
10 | out << renderStringEditor(domainClass, property) |
---|
11 | else if (property.isEnum()) |
---|
12 | out << renderEnumEditor(domainClass, property) |
---|
13 | else if (property.type == TimeZone.class) |
---|
14 | out << renderSelectTypeEditor("timeZone", domainClass, property) |
---|
15 | else if (property.type == Locale.class) |
---|
16 | out << renderSelectTypeEditor("locale", domainClass, property) |
---|
17 | else if (property.type == Currency.class) |
---|
18 | out << renderSelectTypeEditor("currency", domainClass, property) |
---|
19 | else if (property.type==([] as Byte[]).class) //TODO: Bug in groovy means i have to do this :( |
---|
20 | out << renderByteArrayEditor(domainClass, property) |
---|
21 | else if (property.type==([] as byte[]).class) //TODO: Bug in groovy means i have to do this :( |
---|
22 | out << renderByteArrayEditor(domainClass, property) |
---|
23 | else if (property.manyToOne || property.oneToOne) |
---|
24 | out << renderManyToOne(domainClass, property) |
---|
25 | else if ((property.oneToMany && !property.bidirectional) || (property.manyToMany && property.isOwningSide())) |
---|
26 | out << renderManyToMany(domainClass, property) |
---|
27 | else if (property.oneToMany) |
---|
28 | out << renderOneToMany(domainClass, property) |
---|
29 | |
---|
30 | private renderEnumEditor(domainClass, property) { |
---|
31 | return "<g:select name=\"${property.name}\" from=\"\${${property.type.name}?.values()}\" value=\"\${${domainInstance}?.${property.name}}\" ${renderNoSelection(property)} />" |
---|
32 | } |
---|
33 | |
---|
34 | private renderStringEditor(domainClass, property) { |
---|
35 | if (!cp) { |
---|
36 | return "<g:textField name=\"${property.name}\" value=\"\${${domainInstance}?.${property.name}}\" />" |
---|
37 | } |
---|
38 | else { |
---|
39 | if ("textarea" == cp.widget || (cp.maxSize > 250 && !cp.password && !cp.inList)) { |
---|
40 | return "<g:textArea name=\"${property.name}\" cols=\"40\" rows=\"5\" value=\"\${${domainInstance}?.${property.name}}\" />" |
---|
41 | } |
---|
42 | else { |
---|
43 | if (cp.inList) { |
---|
44 | return "<g:select name=\"${property.name}\" from=\"\${${domainInstance}.constraints.${property.name}.inList}\" value=\"\${${domainInstance}?.${property.name}}\" valueMessagePrefix=\"${domainClass.propertyName}.${property?.name}\" ${renderNoSelection(property)} />" |
---|
45 | } |
---|
46 | else { |
---|
47 | def sb = new StringBuffer("<g:") |
---|
48 | cp.password ? sb << "passwordField " : sb << "textField " |
---|
49 | sb << "name=\"${property.name}\" " |
---|
50 | if (cp.maxSize) sb << "maxlength=\"${cp.maxSize}\" " |
---|
51 | if (!cp.editable) sb << "readonly=\"readonly\" " |
---|
52 | sb << "value=\"\${${domainInstance}?.${property.name}}\" />" |
---|
53 | return sb.toString() |
---|
54 | } |
---|
55 | } |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | private renderByteArrayEditor(domainClass, property) { |
---|
60 | return "<input type=\"file\" id=\"${property.name}\" name=\"${property.name}\" />" |
---|
61 | } |
---|
62 | |
---|
63 | private renderManyToOne(domainClass,property) { |
---|
64 | if (property.association) { |
---|
65 | return "<g:select name=\"${property.name}.id\" from=\"\${${property.type.name}.list()}\" optionKey=\"id\" value=\"\${${domainInstance}?.${property.name}?.id}\" ${renderNoSelection(property)} />" |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | private renderManyToMany(domainClass, property) { |
---|
70 | return "<g:select name=\"${property.name}\" from=\"\${${property.referencedDomainClass.fullName}.list()}\" multiple=\"yes\" optionKey=\"id\" size=\"5\" value=\"\${${domainInstance}?.${property.name}}\" />" |
---|
71 | } |
---|
72 | |
---|
73 | private renderOneToMany(domainClass, property) { |
---|
74 | def sw = new StringWriter() |
---|
75 | def pw = new PrintWriter(sw) |
---|
76 | pw.println() |
---|
77 | pw.println "<ul>" |
---|
78 | pw.println "<g:each in=\"\${${domainInstance}?.${property.name}?}\" var=\"${property.name[0]}\">" |
---|
79 | pw.println " <li><g:link controller=\"${property.referencedDomainClass.propertyName}\" action=\"show\" id=\"\${${property.name[0]}.id}\">\${${property.name[0]}?.encodeAsHTML()}</g:link></li>" |
---|
80 | pw.println "</g:each>" |
---|
81 | pw.println "</ul>" |
---|
82 | pw.println "<g:link controller=\"${property.referencedDomainClass.propertyName}\" action=\"create\" params=\"['${domainClass.propertyName}.id': ${domainInstance}?.id]\">\${message(code: 'default.add.label', args: [message(code: '${property.referencedDomainClass.propertyName}.label', default: '${property.referencedDomainClass.shortName}')])}</g:link>" |
---|
83 | return sw.toString() |
---|
84 | } |
---|
85 | |
---|
86 | private renderNumberEditor(domainClass, property) { |
---|
87 | if (!cp) { |
---|
88 | if (property.type == Byte.class) { |
---|
89 | return "<g:select name=\"${property.name}\" from=\"\${-128..127}\" value=\"\${fieldValue(bean: ${domainInstance}, field: '${property.name}')}\" />" |
---|
90 | } |
---|
91 | else { |
---|
92 | return "<g:textField name=\"${property.name}\" value=\"\${fieldValue(bean: ${domainInstance}, field: '${property.name}')}\" />" |
---|
93 | } |
---|
94 | } |
---|
95 | else { |
---|
96 | if (cp.range) { |
---|
97 | return "<g:select name=\"${property.name}\" from=\"\${${cp.range.from}..${cp.range.to}}\" value=\"\${fieldValue(bean: ${domainInstance}, field: '${property.name}')}\" ${renderNoSelection(property)} />" |
---|
98 | } |
---|
99 | else if (cp.inList) { |
---|
100 | return "<g:select name=\"${property.name}\" from=\"\${${domainClass.propertyName}.constraints.${property.name}.inList}\" value=\"\${fieldValue(bean: ${domainInstance}, field: '${property.name}')}\" valueMessagePrefix=\"${domainClass.propertyName}.${property?.name}\" ${renderNoSelection(property)} />" |
---|
101 | } |
---|
102 | else { |
---|
103 | return "<g:textField name=\"${property.name}\" value=\"\${fieldValue(bean: ${domainInstance}, field: '${property.name}')}\" />" |
---|
104 | } |
---|
105 | } |
---|
106 | } |
---|
107 | |
---|
108 | private renderBooleanEditor(domainClass, property) { |
---|
109 | if (!cp) { |
---|
110 | return "<g:checkBox name=\"${property.name}\" value=\"\${${domainInstance}?.${property.name}}\" />" |
---|
111 | } |
---|
112 | else { |
---|
113 | def sb = new StringBuffer("<g:checkBox name=\"${property.name}\" ") |
---|
114 | if (cp.widget) sb << "widget=\"${cp.widget}\" "; |
---|
115 | cp.attributes.each { k, v -> |
---|
116 | sb << "${k}=\"${v}\" " |
---|
117 | } |
---|
118 | sb << "value=\"\${${domainInstance}?.${property.name}}\" />" |
---|
119 | return sb.toString() |
---|
120 | } |
---|
121 | } |
---|
122 | |
---|
123 | private renderDateEditor(domainClass, property) { |
---|
124 | def precision = (property.type == Date.class || property.type == java.sql.Date.class || property.type == Calendar.class) ? "day" : "minute"; |
---|
125 | if (!cp) { |
---|
126 | return "<g:datePicker name=\"${property.name}\" precision=\"${precision}\" value=\"\${${domainInstance}?.${property.name}}\" />" |
---|
127 | } |
---|
128 | else { |
---|
129 | if (!cp.editable) { |
---|
130 | return "\${${domainInstance}?.${property.name}?.toString()}" |
---|
131 | } |
---|
132 | else { |
---|
133 | def sb = new StringBuffer("<g:datePicker name=\"${property.name}\" ") |
---|
134 | if (cp.format) sb << "format=\"${cp.format}\" " |
---|
135 | if (cp.widget) sb << "widget=\"${cp.widget}\" " |
---|
136 | cp.attributes.each { k, v -> |
---|
137 | sb << "${k}=\"${v}\" " |
---|
138 | } |
---|
139 | sb << "precision=\"${precision}\" value=\"\${${domainInstance}?.${property.name}}\" ${renderNoSelection(property)} />" |
---|
140 | return sb.toString() |
---|
141 | } |
---|
142 | } |
---|
143 | } |
---|
144 | |
---|
145 | private renderSelectTypeEditor(type, domainClass,property) { |
---|
146 | if (!cp) { |
---|
147 | return "<g:${type}Select name=\"${property.name}\" value=\"\${${domainInstance}?.${property.name}}\" />" |
---|
148 | } |
---|
149 | else { |
---|
150 | def sb = new StringBuffer("<g:${type}Select name=\"${property.name}\" ") |
---|
151 | if (cp.widget) sb << "widget=\"${cp.widget}\" "; |
---|
152 | cp.attributes.each { k, v -> |
---|
153 | sb << "${k}=\"${v}\" " |
---|
154 | } |
---|
155 | sb << "value=\"\${${domainInstance}?.${property.name}}\" ${renderNoSelection(property)} />" |
---|
156 | return sb.toString() |
---|
157 | } |
---|
158 | } |
---|
159 | |
---|
160 | private renderNoSelection(property) { |
---|
161 | if (property.optional) { |
---|
162 | if (property.manyToOne || property.oneToOne) { |
---|
163 | return "noSelection=\"['null': '']\"" |
---|
164 | } |
---|
165 | else { |
---|
166 | return "noSelection=\"['': '']\"" |
---|
167 | } |
---|
168 | } |
---|
169 | return "" |
---|
170 | } |
---|
171 | %> |
---|