My.Templates.RowAware = Active.System.Template.subclass();
My.Templates.RowAware.create = function(){
/****************************************************************
This template knows how to find the values from other columns
from within it's own row. It provides no content, and is
meant to be a base class for other "RowAware" template
subclasses.
*****************************************************************/
var obj = this.prototype;
var _super = this.superclass.prototype;
obj.__templateText = "{$}";
obj.getTemplateText = function(){ return this.__templateText; }
obj.setTemplateText = function( t ){ this.__templateText = t; }
obj.setContent("html", function() {
return this.resolveColumns( this.__templateText );
});
// ------------------------------------------------------------
// Performs search and replace on the regular expression /\{(\d+)\}/g;
// (eg {0} -> 0 ) and replaces the value with it's referenced column's
// text value.
//
// todo: how do you get the unformatted column value???
// ------------------------------------------------------------
obj.resolveColumns = function( str ) {
var r = this.getRowProperty("index");
var c = this.getColumnProperty("index");
var t = this.getItemProperty( "text" );
if (this.$owner) {
var results, row = this.$owner;
var pattern = /\{(\d+)\}/;
while (results = pattern.exec(str)) {
var colIndex = results[1];
var colValue = this.getColumnValue( colIndex );
if(!colValue) colValue = "";
str = str.replace( results[0], colValue );
}
}
str = str.replace(/{\$}/, t);
str = str.replace(/{row}/, r).replace(/{col}/,c);
return str;
}
obj.getColumnValue = function( colIndex ) {
var v = "";
if (this.$owner) {
v = this.$owner.getDataProperty( "text", colIndex );
}
return v;
}
};
My.Templates.RowAware.create();
var t = My.Templates.RowAware();
t.setTemplateText("<a href=\"javascript:alert('{0}');\">{$}</a>");
This topic is archived.