X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=Roo%2FTemplate.js;h=2f1e80f3de29b81d6c8913e78e7d100cc8f04dc9;hb=2c1a1f6961f37761ed8791ab5921db5b2f848291;hp=da306372c7ad60d3520a697e8a0020f458f32cdb;hpb=0ffc78f68282b92a05fe487593046d042d0c9f55;p=roojs1 diff --git a/Roo/Template.js b/Roo/Template.js index da306372c7..2f1e80f3de 100644 --- a/Roo/Template.js +++ b/Roo/Template.js @@ -15,28 +15,44 @@ * For a list of available format functions, see {@link Roo.util.Format}.
* Usage:

-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'});
 
* For more information see this blog post with examples: DomHelper - Create Elements using DOM, HTML fragments and Templates. * @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'}) @@ -76,11 +92,37 @@ Roo.Template.prototype = { }; return this.html.replace(this.re, fn); } catch (e) { - Roo.log(e.toString()); + Roo.log(e); + throw e; } - return ''; + }, + loading : false, + + load : function (url, success) + { + if (this.loading) { + return; + } + this.loading = true; + 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; + success && success(); + }, + 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