Skip to content

Instantly share code, notes, and snippets.

View iamnoah's full-sized avatar

Noah Perks Sloan iamnoah

  • Texas
  • 20:21 (UTC -05:00)
View GitHub Profile
$('.body').delegate('.prevLink, .step, .nextLink','click',function () {
var data = this.href.split(/\?/)[1];
grailsAjax.refresh(this,data);
return false;
});
$(function() {
$('.body').delegate('.list a.color','click',function () {
var data = this.href.split(/\?/)[1];
grailsAjax.refresh(this,data);
return false;
});
});
var grailsAjax = {
refresh: function(target,params,cb) {
var component = $(target).parents('.ajax-component:first');
if(!component.length) throw "Error: target does not belong to an ajax component"
var path = '../'+component.attr('id').replace(/-/g,'/');
component.load(path,params,cb);
}
};
import groovy.xml.MarkupBuilder;
class FrameworkTagLib {
static namespace = "ajax"
def include = { attrs ->
def controller = attrs.controller, action = attrs.action, id = attrs.id
def component = "${controller}-${action}" + (id ? "-${id}" : "")
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="layout" content="main" />
<g:set var="entityName" value="${message(code: 'product.label', default: 'Product')}" />
<title><g:message code="default.list.label" args="[entityName]" /></title>
</head>
<body>
<div class="nav">
<span class="menuButton"><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></span>
<div class="paginateButtons paginateTop">
<g:paginate total="${productInstanceTotal}" />
</div>
<div class="list">
<g:each in="${productIds}">
<g:include controller="product" action="renderProduct" id="${it}" />
</g:each>
</div>
<div class="paginateButtons">
<g:paginate total="${productInstanceTotal}" />
def list = {
[:]
}
def renderList = {
params.max = Math.min(params.max ? params.int('max') : 10, 100)
[productIds: Product.list(params)*.id, productInstanceTotal: Product.count()]
}
def renderProduct = {
<div class="product" >
<g:link action="show" id="${productInstance.id}">
<h3>
${productInstance.name}
(${productInstance.id})
</h3>
</g:link>
<div class="image">
$('#results').load('/renderResults?page=2');
<div id="results">
<forEach in="${results}">
<div class="result">${result}</div>
</forEach>
</div>