* For a list of available format functions, see {@link Roo.util.Format}.<br />
* Usage:
<pre><code>
-var t = new Roo.Template(
- '<div name="{id}">',
- '<span class="{cls}">{name:trim} {value:ellipsis(10)}</span>',
- '</div>'
-);
+var t = new Roo.Template({
+ html : '<div name="{id}">' +
+ '<span class="{cls}">{name:trim} {someval:this.myformat}{value:ellipsis(10)}</span>' +
+ '</div>',
+ myformat: function (value, allValues) {
+ return 'XX' + value;
+ }
+});
t.append('some-element', {id: 'myid', cls: 'myclass', name: 'foo', value: 'bar'});
</code></pre>
* For more information see this blog post with examples: <a href="http://www.jackslocum.com/yui/2006/10/06/domhelper-create-elements-using-dom-html-fragments-or-templates/">DomHelper - Create Elements using DOM, HTML fragments and Templates</a>.
* @constructor
-* @param {String/Array} html The HTML fragment or an array of fragments to join("") or multiple arguments to join("")
+* @param {Object} cfg - Configuration object.
*/
-Roo.Template = function(html){
- if(html instanceof Array){
- html = html.join("");
+Roo.Template = function(cfg){
+ // BC!
+ if(cfg instanceof Array){
+ cfg = cfg.join("");
}else if(arguments.length > 1){
- html = Array.prototype.join.call(arguments, "");
+ cfg = Array.prototype.join.call(arguments, "");
+ }
+
+
+ if (typeof(cfg) == 'object') {
+ Roo.apply(this,cfg)
+ } else {
+ // bc
+ this.html = cfg;
}
- /**@private*/
- this.html = html;
+
};
Roo.Template.prototype = {
+
+ /**
+ * @cfg {String} html The HTML fragment or an array of fragments to join("") or multiple arguments to join("")
+ */
+ html : '',
/**
* Returns an HTML fragment of this template with the specified values applied.
* @param {Object} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
};
return this.html.replace(this.re, fn);
} catch (e) {
- Roo.log(e.toString());
+ Roo.log(e);
+ throw e;
}
- return '';
+
},
+ loading : false,
+
+ afterLoad : false,
+
+ load : function (url, success)
+ {
+
+ this.afterLoad = success;
+ if (this.loading) {
+ return;
+ }
+
+ this.loading = true;
+ this.compiled = false;
+ var _t = this;
+ var cx = new Roo.data.Connection();
+ cx.request({
+ url : url,
+ method : 'GET',
+ success : function (response) {
+ _t.loading = false;
+ _t.html = response.responseText;
+ _t.afterLoad && _t.afterLoad();
+ },
+ failure : function(response) {
+ Roo.log("Template failed to load from " + url);
+ _t.loading = false;
+ }
+ });
+ },
+
/**
* Sets the HTML used as the template and optionally compiles it.
* @param {String} html