From: <jt...@hy...> - 2007-06-20 23:44:29
|
Author: jtravis Date: 2007-06-20 16:44:20 -0700 (Wed, 20 Jun 2007) New Revision: 4851 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=4851 Modified: trunk/src/org/hyperic/hq/hqu/rendit_sys/html/DojoUtil.groovy trunk/ui_plugins/alertcenter/app/AlertController.groovy Log: Move bulk of DOJO table processing to DojoUtil. Fixup var escaping in Heather's latest Modified: trunk/src/org/hyperic/hq/hqu/rendit_sys/html/DojoUtil.groovy =================================================================== --- trunk/src/org/hyperic/hq/hqu/rendit_sys/html/DojoUtil.groovy 2007-06-20 23:44:04 UTC (rev 4850) +++ trunk/src/org/hyperic/hq/hqu/rendit_sys/html/DojoUtil.groovy 2007-06-20 23:44:20 UTC (rev 4851) @@ -1,6 +1,9 @@ package org.hyperic.hq.hqu.rendit.html +import org.json.JSONArray +import org.json.JSONObject import org.hyperic.hibernate.SortField +import org.hyperic.hibernate.PageInfo class DojoUtil { /** @@ -125,32 +128,29 @@ method: "get", mimetype: "text/json-comment-filtered", load: function(type, data, evt) { - AjaxReturn = data; - filteringTable.store.setData(data.data); - var sortColHead = data.sortField; - var sortOrder = data.sortOrder; - var strOrder = sortOrder.toString(); - var strColClass; - if (strOrder == 'false') { - strColClass = "selectedDown"; - } else { - strColClass = "selectedUp"; + AjaxReturn = data; + ${tableVar}.store.setData(data.data); + var sortColHead = data.sortField; + var sortOrder = data.sortOrder; + var strOrder = sortOrder.toString(); + var strColClass; + if (strOrder == 'false') { + strColClass = "selectedDown"; + } else { + strColClass = "selectedUp"; + } + if (sortColHead) { + var thead = dojo.byId("${id}").getElementsByTagName("thead")[0]; + var ths = thead.getElementsByTagName('th') + for (j = 0; j < ths.length; j++) { + var setClass = ths[j].className; + var getColStr = ths[j].firstChild.nodeValue; + if (getColStr==sortColHead) { + setClass=strColClass; + } } - if (sortColHead) { - var thead = dojo.byId("content").getElementsByTagName("thead")[0]; - var ths = thead.getElementsByTagName('th') - for (j = 0; j < ths.length; j++) { - var setClass = ths[j].className; - var getColStr = ths[j].firstChild.nodeValue; - if (getColStr==sortColHead) { - setClass=strColClass; - //alert(strColClass + " = column class") - //ths[j].setAttribute((document.all ? 'className' : 'class'), " "); - } - } - } - } + } }); } </script> @@ -172,7 +172,7 @@ } else { label = c.label } - + res << "<th field='${field}' dataType='String' align='left'" res << " noSort='true' onclick='${idVar}_setColClass(this);'>" res << "${label}</th>" @@ -185,4 +185,42 @@ res.toString() } + + static JSONObject processTableRequest(schema, params) { + def sortField = params.getOne("sortField") + def sortOrder = params.getOne("sortOrder", + "${schema.defaultSortOrder}") != '1' + + def sortColumn + for (c in schema.columns) { + if (c.field.description == sortField) { + sortColumn = c.field + break + } + } + + if (sortColumn == null) { + sortColumn = schema.defaultSort + } + + def pageNum = new Integer(params.getOne("pageNum", "0")) + def pageSize = new Integer(params.getOne("pageSize", "20")) + def pageInfo = PageInfo.create(pageNum, pageSize, sortColumn, sortOrder) + def data = schema.getData(pageInfo) + + JSONArray jsonData = new JSONArray() + for (d in data) { + def val = [:] + val.id = schema.rowId(d) + for (c in schema.columns) { + val[c.field.description] = c.label(d) + } + + jsonData.put(val) + } + + [data : jsonData, + sortField : sortColumn.description, + sortOrder : sortOrder] as JSONObject + } } Modified: trunk/ui_plugins/alertcenter/app/AlertController.groovy =================================================================== --- trunk/ui_plugins/alertcenter/app/AlertController.groovy 2007-06-20 23:44:04 UTC (rev 4850) +++ trunk/ui_plugins/alertcenter/app/AlertController.groovy 2007-06-20 23:44:20 UTC (rev 4851) @@ -1,13 +1,11 @@ import org.hyperic.hq.hqu.rendit.BaseController -import org.hyperic.hq.common.YesOrNo import java.text.DateFormat -import org.json.JSONArray -import org.json.JSONObject -import org.hyperic.hibernate.PageInfo import org.hyperic.hq.events.EventConstants import org.hyperic.hq.events.server.session.Alert import org.hyperic.hq.events.server.session.AlertSortField +import org.hyperic.hq.hqu.rendit.html.DojoUtil +import org.hyperic.hq.common.YesOrNo class AlertController extends BaseController @@ -27,7 +25,7 @@ [field:AlertSortField.DATE, label:{df.format(it.timestamp)}], [field:AlertSortField.DEFINITION, - label:{it.alertDefinition.name}], + label:{"<a href='foo'>${it.alertDefinition.name}</a>"}], [field:AlertSortField.RESOURCE, label:{it.alertDefinition.resource.name}], [field:AlertSortField.FIXED, @@ -48,44 +46,8 @@ def data(params) { log.info "Params = ${params}" - def schema = TABLE_SCHEMA - - def sortField = params.getOne("sortField") - def sortOrder = params.getOne("sortOrder", - "${schema.defaultSortOrder}") != '1' - - def sortColumn - for (c in schema.columns) { - if (c.field.description == sortField) { - sortColumn = c.field - break - } - } - - if (sortColumn == null) { - sortColumn = schema.defaultSort - } - - def pageNum = new Integer(params.getOne("pageNum", "0")) - def pageSize = new Integer(params.getOne("pageSize", "20")) - def pageInfo = PageInfo.create(pageNum, pageSize, sortColumn, sortOrder) - def data = schema.getData(pageInfo) - - JSONArray jsonData = new JSONArray() - for (d in data) { - def val = [:] - val.id = schema.rowId(d) - for (c in schema.columns) { - val[c.field.description] = c.label(d) - } - - jsonData.put(val) - } - - JSONObject result = [data : jsonData, - sortField : sortColumn.description, - sortOrder : sortOrder] as JSONObject - log.info "Result: ${result}" - render(inline:"/* ${result} */", contentType:'text/json-comment-filtered') + def json = DojoUtil.processTableRequest(TABLE_SCHEMA, params) + log.info "Result: ${json}" + render(inline:"/* ${json} */", contentType:'text/json-comment-filtered') } } |