viernes, 30 de octubre de 2009

Usando el Ajax.inPlaceEditor

He creado el taglib que viene en el libro "Grails - The definitive guide" :



class ProductTagLib {

def editInPlace = { attrs, body ->
def rows = attrs.rows ? attrs.rows : 0
def cols = attrs.cols ? attrs.cols : 0
def id = attrs.remove('id')
out << "<span id='productTags${id}'>"
out << body()
out << "</span>"
out << "<script type='text/javascript'>"
out << "new Ajax.InPlaceEditor('productTags${id}', '"
out << createLink(attrs)
out << "',{"
if(rows)
out << "rows:${rows},"
if(cols)
out << "cols:${cols},"
if(attrs.paramName) {
out << "callback: " +
"function(form, value) { " +
"return '${attrs.paramName}=' + encodeURIComponent(value) " +
"}"
}

out << "});"
out << "</script>"
}

}




En el show.jsp he usado el tag (usando también el toString con delimitador de la entrada anterior:



<g:editInPlace id="productTags${productInstance.id}" url="[action:'updateTags',id:productInstance.id]"
rows="1" cols= "40" paramName="tags">${productInstance?.tags?.toString(", ").encodeAsHTML()}</g:editInPlace>



y simplemente queda crear el método en el controller correspondiente



def updateTags = {
def productInstance = Product.get( params.id )
productInstance.parseTags(params.tags,",")
render productInstance.tags.toString(", ")
}


No hay comentarios:

Publicar un comentario