Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Untitled #3

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/grails/grails-app/conf/DataSource.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ environments {
development {
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop','update'
url = "jdbc:hsqldb:mem:devDB"
url = "jdbc:hsqldb:mem:devDb"
}
}
test {
Expand Down
343 changes: 173 additions & 170 deletions src/grails/templates/scaffolding/renderEditor.template
Original file line number Diff line number Diff line change
@@ -1,171 +1,174 @@
<% if (property.type == Boolean.class || property.type == boolean.class)
out << renderBooleanEditor(domainClass, property)
else if (Number.class.isAssignableFrom(property.type) || (property.type.isPrimitive() && property.type != boolean.class))
out << renderNumberEditor(domainClass, property)
else if (property.type == String.class)
out << renderStringEditor(domainClass, property)
else if (property.type == Date.class || property.type == java.sql.Date.class || property.type == java.sql.Time.class || property.type == Calendar.class)
out << renderDateEditor(domainClass, property)
else if (property.type == URL.class)
out << renderStringEditor(domainClass, property)
else if (property.isEnum())
out << renderEnumEditor(domainClass, property)
else if (property.type == TimeZone.class)
out << renderSelectTypeEditor("timeZone", domainClass, property)
else if (property.type == Locale.class)
out << renderSelectTypeEditor("locale", domainClass, property)
else if (property.type == Currency.class)
out << renderSelectTypeEditor("currency", domainClass, property)
else if (property.type==([] as Byte[]).class) //TODO: Bug in groovy means i have to do this :(
out << renderByteArrayEditor(domainClass, property)
else if (property.type==([] as byte[]).class) //TODO: Bug in groovy means i have to do this :(
out << renderByteArrayEditor(domainClass, property)
else if (property.manyToOne || property.oneToOne)
out << renderManyToOne(domainClass, property)
else if ((property.oneToMany && !property.bidirectional) || (property.manyToMany && property.isOwningSide()))
out << renderManyToMany(domainClass, property)
else if (property.oneToMany)
out << renderOneToMany(domainClass, property)

private renderEnumEditor(domainClass, property) {
return "<g:select name=\"${property.name}\" from=\"\${${property.type.name}?.values()}\" value=\"\${${domainInstance}?.${property.name}}\" ${renderNoSelection(property)} />"
}

private renderStringEditor(domainClass, property) {
if (!cp) {
return "<g:textField name=\"${property.name}\" value=\"\${${domainInstance}?.${property.name}}\" />"
}
else {
if ("textarea" == cp.widget || (cp.maxSize > 250 && !cp.password && !cp.inList)) {
return "<g:textArea name=\"${property.name}\" cols=\"40\" rows=\"5\" value=\"\${${domainInstance}?.${property.name}}\" />"
}
else {
if (cp.inList) {
return "<g:select name=\"${property.name}\" from=\"\${${domainInstance}.constraints.${property.name}.inList}\" value=\"\${${domainInstance}?.${property.name}}\" valueMessagePrefix=\"${domainClass.propertyName}.${property?.name}\" ${renderNoSelection(property)} />"
}
else {
def sb = new StringBuffer("<g:")
cp.password ? sb << "passwordField " : sb << "textField "
sb << "name=\"${property.name}\" "
if (cp.maxSize) sb << "maxlength=\"${cp.maxSize}\" "
if (!cp.editable) sb << "readonly=\"readonly\" "
sb << "value=\"\${${domainInstance}?.${property.name}}\" />"
return sb.toString()
}
}
}
}

private renderByteArrayEditor(domainClass, property) {
return "<input type=\"file\" id=\"${property.name}\" name=\"${property.name}\" />"
}

private renderManyToOne(domainClass,property) {
if (property.association) {
return "<g:select name=\"${property.name}.id\" from=\"\${${property.type.name}.list()}\" optionKey=\"id\" value=\"\${${domainInstance}?.${property.name}?.id}\" ${renderNoSelection(property)} />"
}
}

private renderManyToMany(domainClass, property) {
return "<g:select name=\"${property.name}\" from=\"\${${property.referencedDomainClass.fullName}.list()}\" multiple=\"yes\" optionKey=\"id\" size=\"5\" value=\"\${${domainInstance}?.${property.name}*.id}\" />"
}

private renderOneToMany(domainClass, property) {
def sw = new StringWriter()
def pw = new PrintWriter(sw)
pw.println()
pw.println "<ul>"
pw.println "<g:each in=\"\${${domainInstance}?.${property.name}?}\" var=\"${property.name[0]}\">"
pw.println " <li><g:link controller=\"${property.referencedDomainClass.propertyName}\" action=\"show\" id=\"\${${property.name[0]}.id}\">\${${property.name[0]}?.encodeAsHTML()}</g:link></li>"
pw.println "</g:each>"
pw.println "</ul>"
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>"
return sw.toString()
}

private renderNumberEditor(domainClass, property) {
if (!cp) {
if (property.type == Byte.class) {
return "<g:select name=\"${property.name}\" from=\"\${-128..127}\" value=\"\${fieldValue(bean: ${domainInstance}, field: '${property.name}')}\" />"
}
else {
return "<g:textField name=\"${property.name}\" value=\"\${fieldValue(bean: ${domainInstance}, field: '${property.name}')}\" />"
}
}
else {
if (cp.range) {
return "<g:select name=\"${property.name}\" from=\"\${${cp.range.from}..${cp.range.to}}\" value=\"\${fieldValue(bean: ${domainInstance}, field: '${property.name}')}\" ${renderNoSelection(property)} />"
}
else if (cp.inList) {
return "<g:select name=\"${property.name}\" from=\"\${${domainInstance}.constraints.${property.name}.inList}\" value=\"\${fieldValue(bean: ${domainInstance}, field: '${property.name}')}\" valueMessagePrefix=\"${domainClass.propertyName}.${property?.name}\" ${renderNoSelection(property)} />"
}
else {
return "<g:textField name=\"${property.name}\" value=\"\${fieldValue(bean: ${domainInstance}, field: '${property.name}')}\" />"
}
}
}

private renderBooleanEditor(domainClass, property) {
if (!cp) {
return "<g:checkBox name=\"${property.name}\" value=\"\${${domainInstance}?.${property.name}}\" />"
}
else {
def sb = new StringBuffer("<g:checkBox name=\"${property.name}\" ")
if (cp.widget) sb << "widget=\"${cp.widget}\" ";
cp.attributes.each { k, v ->
sb << "${k}=\"${v}\" "
}
sb << "value=\"\${${domainInstance}?.${property.name}}\" />"
return sb.toString()
}
}

private renderDateEditor(domainClass, property) {
def precision = (property.type == Date.class || property.type == java.sql.Date.class || property.type == Calendar.class) ? "day" : "minute";
if (!cp) {
return "<g:datePicker name=\"${property.name}\" precision=\"${precision}\" value=\"\${${domainInstance}?.${property.name}}\" />"
}
else {
if (!cp.editable) {
return "\${${domainInstance}?.${property.name}?.toString()}"
}
else {
def sb = new StringBuffer("<g:datePicker name=\"${property.name}\" ")
if (cp.format) sb << "format=\"${cp.format}\" "
if (cp.widget) sb << "widget=\"${cp.widget}\" "
cp.attributes.each { k, v ->
sb << "${k}=\"${v}\" "
}
sb << "precision=\"${precision}\" value=\"\${${domainInstance}?.${property.name}}\" ${renderNoSelection(property)} />"
return sb.toString()
}
}
}

private renderSelectTypeEditor(type, domainClass,property) {
if (!cp) {
return "<g:${type}Select name=\"${property.name}\" value=\"\${${domainInstance}?.${property.name}}\" />"
}
else {
def sb = new StringBuffer("<g:${type}Select name=\"${property.name}\" ")
if (cp.widget) sb << "widget=\"${cp.widget}\" ";
cp.attributes.each { k, v ->
sb << "${k}=\"${v}\" "
}
sb << "value=\"\${${domainInstance}?.${property.name}}\" ${renderNoSelection(property)} />"
return sb.toString()
}
}

private renderNoSelection(property) {
if (property.optional) {
if (property.manyToOne || property.oneToOne) {
return "noSelection=\"['null': '']\""
}
else {
return "noSelection=\"['': '']\""
}
}
return ""
}
<% if (property.type == Boolean.class || property.type == boolean.class)
out << renderBooleanEditor(domainClass, property)
else if (Number.class.isAssignableFrom(property.type) || (property.type.isPrimitive() && property.type != boolean.class))
out << renderNumberEditor(domainClass, property)
else if (property.type == String.class)
out << renderStringEditor(domainClass, property)
else if (property.type == Date.class || property.type == java.sql.Date.class || property.type == java.sql.Time.class || property.type == Calendar.class)
out << renderDateEditor(domainClass, property)
else if (property.type == URL.class)
out << renderStringEditor(domainClass, property)
else if (property.isEnum())
out << renderEnumEditor(domainClass, property)
else if (property.type == TimeZone.class)
out << renderSelectTypeEditor("timeZone", domainClass, property)
else if (property.type == Locale.class)
out << renderSelectTypeEditor("locale", domainClass, property)
else if (property.type == Currency.class)
out << renderSelectTypeEditor("currency", domainClass, property)
else if (property.type==([] as Byte[]).class) //TODO: Bug in groovy means i have to do this :(
out << renderByteArrayEditor(domainClass, property)
else if (property.type==([] as byte[]).class) //TODO: Bug in groovy means i have to do this :(
out << renderByteArrayEditor(domainClass, property)
else if (property.manyToOne || property.oneToOne)
out << renderManyToOne(domainClass, property)
else if ((property.oneToMany && !property.bidirectional) || (property.manyToMany && property.isOwningSide()))
out << renderManyToMany(domainClass, property)
else if (property.oneToMany)
out << renderOneToMany(domainClass, property)

private renderEnumEditor(domainClass, property) {
return "<g:select name=\"${property.name}\" from=\"\${${property.type.name}?.values()}\" value=\"\${${domainInstance}?.${property.name}}\" ${renderNoSelection(property)} />"
}

private renderStringEditor(domainClass, property) {
if (!cp) {
return "<g:textField name=\"${property.name}\" value=\"\${${domainInstance}?.${property.name}}\" />"
}
else {
if ("textarea" == cp.widget || (cp.maxSize > 250 && !cp.password && !cp.inList)) {
return "<g:textArea name=\"${property.name}\" cols=\"40\" rows=\"5\" value=\"\${${domainInstance}?.${property.name}}\" />"
}
else {
if (cp.inList) {
return "<g:select name=\"${property.name}\" from=\"\${${domainInstance}.constraints.${property.name}.inList}\" value=\"\${${domainInstance}?.${property.name}}\" valueMessagePrefix=\"${domainClass.propertyName}.${property?.name}\" ${renderNoSelection(property)} />"
}
else {
def sb = new StringBuffer("<g:")
cp.password ? sb << "passwordField " : sb << "textField "
sb << "name=\"${property.name}\" "
if (cp.maxSize) sb << "maxlength=\"${cp.maxSize}\" "
if (!cp.editable) sb << "readonly=\"readonly\" "
sb << "value=\"\${${domainInstance}?.${property.name}}\" />"
return sb.toString()
}
}
}
}

private renderByteArrayEditor(domainClass, property) {
return "<input type=\"file\" id=\"${property.name}\" name=\"${property.name}\" />"
}

private renderManyToOne(domainClass,property) {
if (property.association) {
return "<g:select name=\"${property.name}.id\" from=\"\${${property.type.name}.list()}\" optionKey=\"id\" value=\"\${${domainInstance}?.${property.name}?.id}\" ${renderNoSelection(property)} />"
}
}

private renderManyToMany(domainClass, property) {
return "<g:select name=\"${property.name}\" from=\"\${${property.referencedDomainClass.fullName}.list()}\" multiple=\"yes\" optionKey=\"id\" size=\"5\" value=\"\${${domainInstance}?.${property.name}*.id}\" />"
}

private renderOneToMany(domainClass, property) {
def sw = new StringWriter()
def pw = new PrintWriter(sw)
pw.println()
pw.println "<ul>"
pw.println "<g:each in=\"\${${domainInstance}?.${property.name}?}\" var=\"${property.name[0]}\">"
pw.println " <li><g:link controller=\"${property.referencedDomainClass.propertyName}\" action=\"show\" id=\"\${${property.name[0]}.id}\">\${${property.name[0]}?.encodeAsHTML()}</g:link></li>"
pw.println "</g:each>"
pw.println "</ul>"
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>"
return sw.toString()
}

private renderNumberEditor(domainClass, property) {
if (!cp) {
if (property.type == Byte.class) {
return "<g:select name=\"${property.name}\" from=\"\${-128..127}\" value=\"\${fieldValue(bean: ${domainInstance}, field: '${property.name}')}\" />"
}
else {
return "<g:textField name=\"${property.name}\" value=\"\${fieldValue(bean: ${domainInstance}, field: '${property.name}')}\" />"
}
}
else {
if (cp.range) {
return "<g:select name=\"${property.name}\" from=\"\${${cp.range.from}..${cp.range.to}}\" value=\"\${fieldValue(bean: ${domainInstance}, field: '${property.name}')}\" ${renderNoSelection(property)} />"
}
else if (cp.inList) {
return "<g:select name=\"${property.name}\" from=\"\${${domainInstance}.constraints.${property.name}.inList}\" value=\"\${fieldValue(bean: ${domainInstance}, field: '${property.name}')}\" valueMessagePrefix=\"${domainClass.propertyName}.${property?.name}\" ${renderNoSelection(property)} />"
}
else {
return "<g:textField name=\"${property.name}\" value=\"\${fieldValue(bean: ${domainInstance}, field: '${property.name}')}\" />"
}
}
}

private renderBooleanEditor(domainClass, property) {
if (!cp) {
return "<g:checkBox name=\"${property.name}\" value=\"\${${domainInstance}?.${property.name}}\" />"
}
else {
def sb = new StringBuffer("<g:checkBox name=\"${property.name}\" ")
if (cp.widget) sb << "widget=\"${cp.widget}\" ";
cp.attributes.each { k, v ->
sb << "${k}=\"${v}\" "
}
sb << "value=\"\${${domainInstance}?.${property.name}}\" />"
return sb.toString()
}
}

private renderDateEditor(domainClass, property) {
def precision = (property.type == Date.class || property.type == java.sql.Date.class || property.type == Calendar.class) ? "day" : "minute";
if (!cp) {
return "<g:datePicker name=\"${property.name}\" precision=\"${precision}\" value=\"\${${domainInstance}?.${property.name}}\" />"
}
else {
if (!cp.editable) {
return "\${${domainInstance}?.${property.name}?.toString()}"
}
else {
def sb = new StringBuffer("<g:datePicker name=\"${property.name}\" ")
if (cp.format) sb << "format=\"${cp.format}\" "
if (cp.widget) sb << "widget=\"${cp.widget}\" "
cp.attributes.each { k, v ->
sb << "${k}=\"${v}\" "
}
if (!cp.attributes.precision) {
sb << "precision=\"${precision}\" "
}
sb << "value=\"\${${domainInstance}?.${property.name}}\" ${renderNoSelection(property)} />"
return sb.toString()
}
}
}

private renderSelectTypeEditor(type, domainClass,property) {
if (!cp) {
return "<g:${type}Select name=\"${property.name}\" value=\"\${${domainInstance}?.${property.name}}\" />"
}
else {
def sb = new StringBuffer("<g:${type}Select name=\"${property.name}\" ")
if (cp.widget) sb << "widget=\"${cp.widget}\" ";
cp.attributes.each { k, v ->
sb << "${k}=\"${v}\" "
}
sb << "value=\"\${${domainInstance}?.${property.name}}\" ${renderNoSelection(property)} />"
return sb.toString()
}
}

private renderNoSelection(property) {
if (property.optional) {
if (property.manyToOne || property.oneToOne) {
return "noSelection=\"['null': '']\""
}
else {
return "noSelection=\"['': '']\""
}
}
return ""
}
%>
Loading