#{extends 'ELASTIC_SEARCH/layout.html' /}

<div id="elasticsearchShow" class="${type.name}">
	
	<h2 id="elasticsearchShowTitle">&{'elasticsearch.show.title', type.modelName}</h2>
	
	<div class="objectGrid">
%{
    currentObject = object
    currentType = _('controllers.elasticsearch.ElasticSearchController$ObjectType').forClass(object.getClass().getName())

    // Eval fields tags
    def fieldsHandler = [:]
    if(_body) {
        _body.setProperty('fieldsHandler', fieldsHandler);
        _body.toString(); // we skeep the real result ...
    }
}%

#{list items:_fields ?: currentType.fields*.name, as:'fieldName'}

    %{
        am = ''
    }%

    %{ def field = currentType.getField(fieldName) }%

<div class="elasticsearchField elasticsearch_${field.type}">

    %{ if(fieldsHandler[fieldName]) { }%
        %{
            def handler = fieldsHandler[fieldName]
            handler.setProperty('fieldName', 'object.' + field?.name + (field?.type == 'relation' ? '.' + currentType.keyName : ''))
            def oldObject = handler.getProperty('object')
            handler.setProperty('object', currentObject)
            out.println(handler.toString())
            handler.setProperty('object', oldObject)
            handler.setProperty('fieldName', null)
        }%
    %{ } else { }%

        #{ifnot field}
            %{ throw new play.exceptions.TagInternalException('Field not found -> ' + fieldName) }%
        #{/ifnot}

        #{elasticsearch.textField name:field.name, value:(currentObject ? currentObject[field.name] : null) /}

    %{ } }%

</div>

#{/list}

	</div>

</div>