3
* Copyright(c) 2006-2008, Ext JS, LLC.
6
* http://extjs.com/license
10
* @class Ext.MasterTemplate
11
* @extends Ext.Template
12
* Provides a template that can have child templates. The syntax is:
14
var t = new Ext.MasterTemplate(
15
'<select name="{name}">',
16
'<tpl name="options"><option value="{value:trim}">{text:ellipsis(10)}</option></tpl>',
19
t.add('options', {value: 'foo', text: 'bar'});
20
// or you can add multiple child elements in one shot
22
{value: 'foo', text: 'bar'},
23
{value: 'foo2', text: 'bar2'},
24
{value: 'foo3', text: 'bar3'}
26
// then append, applying the master template values
27
t.append('my-form', {name: 'my-select'});
29
* A name attribute for the child template is not required if you have only one child
30
* template or you want to refer to them by index.
32
Ext.MasterTemplate = function(){
33
Ext.MasterTemplate.superclass.constructor.apply(this, arguments);
34
this.originalHtml = this.html;
36
var m, re = this.subTemplateRe;
39
while(m = re.exec(this.html)){
40
var name = m[1], content = m[2];
45
tpl : new Ext.Template(content)
48
st[name] = st[subIndex];
50
st[subIndex].tpl.compile();
51
st[subIndex].tpl.call = this.call.createDelegate(this);
54
this.subCount = subIndex;
57
Ext.extend(Ext.MasterTemplate, Ext.Template, {
59
* The regular expression used to match sub templates
63
subTemplateRe : /<tpl(?:\sname="([\w-]+)")?>((?:.|\n)*?)<\/tpl>/gi,
66
* Applies the passed values to a child template.
67
* @param {String/Number} name (optional) The name or index of the child template
68
* @param {Array/Object} values The values to be applied to the template
69
* @return {MasterTemplate} this
71
add : function(name, values){
72
if(arguments.length == 1){
73
values = arguments[0];
76
var s = this.subs[name];
77
s.buffer[s.buffer.length] = s.tpl.apply(values);
82
* Applies all the passed values to a child template.
83
* @param {String/Number} name (optional) The name or index of the child template
84
* @param {Array} values The values to be applied to the template, this should be an array of objects.
85
* @param {Boolean} reset (optional) True to reset the template first
86
* @return {MasterTemplate} this
88
fill : function(name, values, reset){
90
if(a.length == 1 || (a.length == 2 && typeof a[1] == "boolean")){
98
for(var i = 0, len = values.length; i < len; i++){
99
this.add(name, values[i]);
105
* Resets the template for reuse
106
* @return {MasterTemplate} this
110
for(var i = 0; i < this.subCount; i++){
116
applyTemplate : function(values){
118
var replaceIndex = -1;
119
this.html = this.originalHtml.replace(this.subTemplateRe, function(m, name){
120
return s[++replaceIndex].buffer.join("");
122
return Ext.MasterTemplate.superclass.applyTemplate.call(this, values);
126
return this.applyTemplate.apply(this, arguments);
129
compile : function(){return this;}
136
Ext.MasterTemplate.prototype.addAll = Ext.MasterTemplate.prototype.fill;
138
* Creates a template from the passed element's value (display:none textarea, preferred) or innerHTML. e.g.
139
* var tpl = Ext.MasterTemplate.from('element-id');
140
* @param {String/HTMLElement} el
141
* @param {Object} config
144
Ext.MasterTemplate.from = function(el, config){
146
return new Ext.MasterTemplate(el.value || el.innerHTML, config || '');
b'\\ No newline at end of file'