Permalink
Browse files

loading each fields on its own

  • Loading branch information...
1 parent a5095a4 commit 587779ff7cd1679ef79b5bb5e13a4ce2faf39e3f @D-Roch committed Jun 20, 2011
Showing with 17 additions and 146 deletions.
  1. +4 −0 app/controllers/CRUD.java
  2. +1 −0 app/views/CRUD/field.html
  3. +1 −1 app/views/CRUD/show.html
  4. +9 −144 app/views/tags/crud/form.html
  5. +2 −1 conf/routes
View
4 app/controllers/CRUD.java
@@ -53,6 +53,10 @@ public static void index() {
render("CRUD/index.html");
}
+ public static void loadField(String id, String field) {
+ render("CRUD/field.html", field);
+ }
+
public static void autocomplete(String oType, String q, String searchFields) throws ClassNotFoundException {
ObjectType type = new ObjectType(oType);
notFoundIfNull(type);
View
1 app/views/CRUD/field.html
@@ -0,0 +1 @@
+${field}
View
2 app/views/CRUD/show.html
@@ -1,7 +1,7 @@
#{extends 'CRUD/layout.html' /}
%{
def keyVal = play.modules.siena.SienaModelUtils.keyValue(object)
- }%
+}%
<div id="crudShow" class="${type.name}">
<h2 id="crudShowTitle">&{'crud.show.title', type.modelName}</h2>
View
153 app/views/tags/crud/form.html
@@ -17,149 +17,14 @@
_body.toString(); // we skeep the real result ...
}
}%
-
+%{x=1}%
#{list items:_fields ?: currentType.fields*.name, as:'fieldName'}
-
- %{
- am = ''
- def field = currentType.getField(fieldName)
- def showField = true
- }%
- %{ if(fieldsHandler[fieldName]) { }%
- <div class="crudField crud_${field.type}">
- %{
- def handler = fieldsHandler[fieldName]
- handler.setProperty('fieldName', 'object.' + field?.name + (field?.type == 'relation' ? '@id' : ''))
- def oldObject = handler.getProperty('object')
- handler.setProperty('object', currentObject)
- out.println(handler.toString())
- handler.setProperty('object', oldObject)
- handler.setProperty('fieldName', null)
- }%
- </div>
- %{ } else { }%
- #{if field.type != 'unknown'}
- %{ showField = false }%
-
- <div class="crudField crud_${field.type}">
-
- #{ifnot field}
- %{ throw new play.exceptions.TagInternalException('Field not found -> ' + fieldName) }%
- #{/ifnot}
-
- #{if field.type == 'text'}
- #{crud.textField name:field.name, value:(currentObject ? currentObject[field.name] : null) /}
- #{/if}
-
- #{if field.type == 'password'}
- #{crud.passwordField name:field.name, value:(currentObject ? currentObject[field.name] : null) /}
- #{/if}
-
- #{if field.type == 'file'}
- #{crud.fileField name:field.name, value:(currentObject ? currentObject[field.name] : null), id:currentObject?.id /}
- #{/if}
-
- *{#{if field.type == 'binary'}
- #{crud.fileField name:field.name, value:(currentObject ? currentObject[field.name] : null), id:currentObject?.id /}
- #{/if}}*
-
- #{if field.type == 'longtext'}
- #{crud.longtextField name:field.name, value:(currentObject ? currentObject[field.name] : null) /}
- #{/if}
-
- #{if field.type == 'number'}
- #{crud.numberField name:field.name, value:(currentObject ? currentObject[field.name] : null) /}
- %{ am = 'crud.help.numeric' }%
- #{/if}
-
- #{if field.type == 'date'}
- #{crud.dateField name:field.name, value:(currentObject ? currentObject[field.name] : null) /}
- %{ am = 'crud.help.dateformat' }%
- #{/if}
-
- #{if field.type == 'datetime'}
- #{crud.dateTimeField name:field.name, value:(currentObject ? currentObject[field.name] : null) /}
- %{ am = 'crud.help.dateTimeformat' }%
- #{/if}
-
- #{if field.type == 'relation'}
- #{crud.relationField name:field.name, value:(currentObject ? currentObject[field.name] : null), field:field, id:(currentObject ? currentObject.id : null) /}
- #{/if}
-
- #{if field.type == 'boolean'}
- #{crud.checkField name:field.name, value:(currentObject ? currentObject[field.name] : null) /}
- #{/if}
-
- #{if field.type == 'enum'}
- #{crud.enumField name:field.name, value:(currentObject ? currentObject[field.name] : null), property:field /}
- #{/if}
-
- #{if field.type == 'serializedText'}
- #{crud.textField name:field.name, value:(currentObject ? controllers.CRUD.collectionSerializer(currentObject[field.name]) : null), property:field /}
- #{/if}
-
- #{if field.type == 'embedded'}
- #{crud.embeddedField name:field.name, value:(currentObject ? currentObject[field.name] : null), field:field, id:(currentObject ? currentObject.id : null) /}
- #{/if}
-
- #{if field.type == 'blob'}
- #{crud.blobField name:field.name, value:(currentObject ? currentObject[field.name] : null), id:currentObject?.id /}
- #{/if}
-
- #{if field.type == 'binary'}
- #{crud.binaryField name:field.name, value:(currentObject ? currentObject[field.name] : null), id:currentObject?.id /}
- #{/if}
-
- #{if field.type == 'hidden'}
- #{crud.hiddenField name:field.name, value:(currentObject ? currentObject[field.name] : null) /}
- #{/if}
-
- <span class="crudHelp">
- &{am}
- %{ play.data.validation.Validation.getValidators(currentType.entityClass, fieldName, 'object').each() { }%
- %{
- switch (it.annotation.annotationType().name.substring(21)) {
- case "Required":
- out.println(messages.get('crud.help.required'))
- break;
- case "MinSize":
- out.println(messages.get('crud.help.minlength', it.annotation.value()))
- break;
- case "MaxSize":
- out.println(messages.get('crud.help.maxlength', it.annotation.value()))
- break;
- case "Range":
- out.println(messages.get('crud.help.range', it.annotation.min(), it.annotation.max()))
- break;
- case "Min":
- out.println(messages.get('crud.help.min', it.annotation.value()))
- break;
- case "Email":
- out.println(messages.get('crud.help.email'))
- break;
- case "Equals":
- out.println(messages.get('crud.help.equals', it.params.equalsTo))
- break;
- case "Future":
- if(it.params.reference) {
- out.println(messages.get('crud.help.after', it.params.reference))
- } else {
- out.println(messages.get('crud.help.future'))
- }
- break;
- case "Past":
- if(it.params.reference) {
- out.println(messages.get('crud.help.before', it.params.reference))
- } else {
- out.println(messages.get('crud.help.past'))
- }
- break;
- }
- }%
- %{ } }%
- </span>
- </div>
- #{/}
- %{ } }%
-
+%{x++}%
+<div id="${x}" style="height: 20px;">
+</div>
+<script type="text/javascript">
+$(document).ready(function() {
+ $('#${x}').load('@{CRUD.loadField(fieldName)}');
+});
+</script>
#{/list}
View
3 conf/routes
@@ -6,7 +6,8 @@ GET /? ${type.controllerClass.name.substring(12)}.index
GET /${type.controllerName} ${type.controllerClass.name.substring(12)}.list
GET /${type.controllerName}/new ${type.controllerClass.name.substring(12)}.blank
GET /${type.controllerName}/{id} ${type.controllerClass.name.substring(12)}.show
-GET /${type.controllerName}/{id}/del ${type.controllerClass.name.substring(12)}.delete
+GET /${type.controllerName}/{id}/del ${type.controllerClass.name.substring(12)}.delete
+//GET /${type.controllerName}/{id}/{field}/{<\d+>idx}/field ${type.controllerClass.name.substring(12)}.loadField
GET /${type.controllerName}/{id}/{field}/list/add ${type.controllerClass.name.substring(12)}.addListElement
GET /${type.controllerName}/{id}/{field}/list/{<\d+>idx}/del ${type.controllerClass.name.substring(12)}.deleteListElement
GET /${type.controllerName}/{id}/{field}/map/{mkey}/add ${type.controllerClass.name.substring(12)}.addMapElement

0 comments on commit 587779f

Please sign in to comment.