From 81cb6e1cfc926cc0c67215122d26a578f4acaa4b Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Fri, 6 Apr 2012 23:45:42 +0800 Subject: [PATCH] roojs-core.js roojs-core-debug.js roojs-ui.js roojs-ui-debug.js roojs-all.js roojs-debug.js --- roojs-all.js | 8 +-- roojs-core-debug.js | 45 +++++++++++- roojs-core.js | 4 +- roojs-debug.js | 168 +++++++++++++++++++++++++++++--------------- roojs-ui-debug.js | 123 +++++++++++++++++--------------- roojs-ui.js | 4 +- 6 files changed, 228 insertions(+), 124 deletions(-) diff --git a/roojs-all.js b/roojs-all.js index b6568d23cc..5d1164bc07 100644 --- a/roojs-all.js +++ b/roojs-all.js @@ -115,8 +115,8 @@ P=G(2,ts,O,te);} el.insertBefore(P,Q);return P;};return {useDom:false,markup:function(o){return E(o);},applyStyles:function(el,M){if(M){el=Roo.fly(el);if(typeof M=="string"){var re=/\s?([a-z\-]*)\:\s?([^;]*);?/gi;var N;while((N=re.exec(M))!=null){el.setStyle(N[1],N[2]);}}else if(typeof M=="object"){for(var O in M){el.setStyle(O,M[O]);}}else if(typeof M=="function"){Roo.DomHelper.applyStyles(el,M.call());}}},insertHtml:function(M,el,N){M=M.toLowerCase();if(el.insertAdjacentHTML){if(C.test(el.tagName)){var rs;if(rs=L(el.tagName.toLowerCase(),M,el,N)){return rs;}}switch(M){case "beforebegin":el.insertAdjacentHTML('BeforeBegin',N);return el.previousSibling;case "afterbegin":el.insertAdjacentHTML('AfterBegin',N);return el.firstChild;case "beforeend":el.insertAdjacentHTML('BeforeEnd',N);return el.lastChild;case "afterend":el.insertAdjacentHTML('AfterEnd',N);return el.nextSibling;}throw 'Illegal insertion point -> "'+M+'"';}var O=el.ownerDocument.createRange();var P;switch(M){case "beforebegin":O.setStartBefore(el);P=O.createContextualFragment(N);el.parentNode.insertBefore(P,el);return el.previousSibling;case "afterbegin":if(el.firstChild){O.setStartBefore(el.firstChild);P=O.createContextualFragment(N);el.insertBefore(P,el.firstChild);return el.firstChild;}else {el.innerHTML=N;return el.firstChild;}case "beforeend":if(el.lastChild){O.setStartAfter(el.lastChild);P=O.createContextualFragment(N);el.appendChild(P);return el.lastChild;}else {el.innerHTML=N;return el.lastChild;}case "afterend":O.setStartAfter(el);P=O.createContextualFragment(N);el.parentNode.insertBefore(P,el.nextSibling);return el.nextSibling;}throw 'Illegal insertion point -> "'+M+'"';},insertBefore:function(el,o,M){return this.doInsert(el,o,M,"beforeBegin");},insertAfter:function(el,o,M){return this.doInsert(el,o,M,"afterEnd","nextSibling");},insertFirst:function(el,o,M){return this.doInsert(el,o,M,"afterBegin");},doInsert:function(el,o,M,N,O){el=Roo.getDom(el);var P;if(this.useDom||o.ns){P=F(o,null);el.parentNode.insertBefore(P,O?el[O]:el);}else {var Q=E(o);P=this.insertHtml(N,el,Q);}return M?Roo.get(P,true):P;},append:function(el,o,M){el=Roo.getDom(el);var N;if(this.useDom||o.ns){N=F(o,null);el.appendChild(N);}else {var O=E(o);N=this.insertHtml("beforeEnd",el,O);}return M?Roo.get(N,true):N;},overwrite:function(el,o,M){el=Roo.getDom(el);if(o.ns){while(el.childNodes.length){el.removeChild(el.firstChild);} F(o,el);}else {el.innerHTML=E(o);}return M?Roo.get(el.firstChild,true):el.firstChild;},createTemplate:function(o){var M=E(o);return new Roo.Template(M);}};}(); //Roo/Template.js -Roo.Template=function(A){if(A instanceof Array){A=A.join("");}else if(arguments.length>1){A=Array.prototype.join.call(arguments,"");}if(typeof(A)=='object'){Roo.apply(this,A)}else {this.html=A;}};Roo.Template.prototype={html:'',applyTemplate:function(A){try{if(this.compiled){return this.compiled(A);}var B=this.disableFormats!==true;var fm=Roo.util.Format,C=this;var fn=function(m,D,E,F){if(E&&B){if(E.substr(0,5)=="this."){return C.call(E.substr(5),A[D],A);}else {if(F){var re=/^\s*['"](.*)["']\s*$/;F=F.split(',');for(var i=0,G=F.length;i1){A=Array.prototype.join.call(arguments,"");}if(typeof(A)=='object'){Roo.apply(this,A)}else {this.html=A;}if(this.url){this.load();}};Roo.Template.prototype={url:false,html:'',applyTemplate:function(A){try{if(this.compiled){return this.compiled(A);}var B=this.disableFormats!==true;var fm=Roo.util.Format,C=this;var fn=function(m,D,E,F){if(E&&B){if(E.substr(0,5)=="this."){return C.call(E.substr(5),A[D],A);}else {if(F){var re=/^\s*['"](.*)["']\s*$/;F=F.split(',');for(var i=0,G=F.length;i+~]\s?|\s|$)/;var H=/^(#)?([\w-\*]+)/;var I=/(\d*)n\+?(\d*)/,J=/\D/;function child(p,M){var i=0;var n=p.firstChild;while(n){if(n.nodeType==1){if(++i==M){return n;}} n=n.nextSibling;}return null;};function next(n){while((n=n.nextSibling)&&n.nodeType!=1);return n;};function prev(n){while((n=n.previousSibling)&&n.nodeType!=1);return n;};function children(d){var n=d.firstChild,ni=-1;while(n){var nx=n.nextSibling;if(n.nodeType==3&&!D.test(n.nodeValue)){d.removeChild(n);}else {n.nodeIndex=++ni;} @@ -1140,9 +1140,9 @@ this.store.loadRecords({records:A},{},true);},onUpdate:function(ds,A,B){if(B==Ro Roo.LoadMask=function(el,A){this.el=Roo.get(el);Roo.apply(this,A);if(this.store){this.store.on('beforeload',this.onBeforeLoad,this);this.store.on('load',this.onLoad,this);this.store.on('loadexception',this.onLoadException,this);this.removeMask=false;}else {var um=this.el.getUpdateManager();um.showLoadIndicator=false;um.on('beforeupdate',this.onBeforeLoad,this);um.on('update',this.onLoad,this);um.on('failure',this.onLoad,this);this.removeMask=true;}};Roo.LoadMask.prototype={msg:'Loading...',msgCls:'x-mask-loading',disabled:false,disable:function(){this.disabled=true;},enable:function(){this.disabled=false;},onLoadException:function(){if(this.store&&typeof(this.store.reader.jsonData.errorMsg)!='undefined'){Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);} this.el.unmask(this.removeMask);},onLoad:function(){this.el.unmask(this.removeMask);},onBeforeLoad:function(){if(!this.disabled){this.el.mask(this.msg,this.msgCls);}},destroy:function(){if(this.store){this.store.un('beforeload',this.onBeforeLoad,this);this.store.un('load',this.onLoad,this);this.store.un('loadexception',this.onLoadException,this);}else {var um=this.el.getUpdateManager();um.un('beforeupdate',this.onBeforeLoad,this);um.un('update',this.onLoad,this);um.un('failure',this.onLoad,this);}}}; //Roo/XTemplate.js -Roo.XTemplate=function(){Roo.XTemplate.superclass.constructor.apply(this,arguments);var s=this.html;s=['',s,''].join('');var re=/]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/;var A=/^]*?for="(.*?)"/;var B=/^]*?if="(.*?)"/;var C=/^]*?exec="(.*?)"/;var m,id=0;var D=[];while(m=s.match(re)){var m2=m[0].match(A);var m3=m[0].match(B);var m4=m[0].match(C);var E=null,fn=null,F=null;var G=m2&&m2[1]?m2[1]:'';if(m3){E=m3&&m3[1]?m3[1]:null;if(E){fn=new Function('values','parent','with(values){ return '+(Roo.util.Format.htmlDecode(E))+'; }');}}if(m4){E=m4&&m4[1]?m4[1]:null;if(E){F=new Function('values','parent','with(values){ '+(Roo.util.Format.htmlDecode(E))+'; }');}}if(G){switch(G){case '.':G=new Function('values','parent','with(values){ return values; }');break;case '..':G=new Function('values','parent','with(values){ return parent; }');break;default:G=new Function('values','parent','with(values){ return '+G+'; }');}} +Roo.XTemplate=function(){Roo.XTemplate.superclass.constructor.apply(this,arguments);if(this.html){this.preCompile();}};Roo.extend(Roo.XTemplate,Roo.Template,{re:/\{([\w-\.]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,compile:function(){var s=this.html;s=['',s,''].join('');var re=/]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/;var A=/^]*?for="(.*?)"/;var B=/^]*?if="(.*?)"/;var C=/^]*?exec="(.*?)"/;var m,id=0;var D=[];while(true==!!(m=s.match(re))){var m2=m[0].match(A);var m3=m[0].match(B);var m4=m[0].match(C);var E=null,fn=null,F=null;var G=m2&&m2[1]?m2[1]:'';if(m3){E=m3&&m3[1]?m3[1]:null;if(E){fn=new Function('values','parent','with(values){ return '+(Roo.util.Format.htmlDecode(E))+'; }');}}if(m4){E=m4&&m4[1]?m4[1]:null;if(E){F=new Function('values','parent','with(values){ '+(Roo.util.Format.htmlDecode(E))+'; }');}}if(G){switch(G){case '.':G=new Function('values','parent','with(values){ return values; }');break;case '..':G=new Function('values','parent','with(values){ return parent; }');break;default:G=new Function('values','parent','with(values){ return '+G+'; }');}} D.push({id:id,target:G,exec:F,test:fn,body:m[1]||''});s=s.replace(m[0],'{xtpl'+id+'}');++id;}for(var i=D.length-1;i>=0;--i){this.compileTpl(D[i]);} -this.master=D[D.length-1];this.tpls=D;};Roo.extend(Roo.XTemplate,Roo.Template,{re:/\{([\w-\.]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,applySubTemplate:function(id,A,B){var t=this.tpls[id];if(t.test&&!t.test.call(this,A,B)){return '';}if(t.exec&&t.exec.call(this,A,B)){return '';}var vs=t.target?t.target.call(this,A,B):A;B=t.target?A:B;if(t.target&&vs instanceof Array){var C=[];for(var i=0,D=vs.length;i -* For more information see this blog post with examples: DomHelper - Create Elements using DOM, HTML fragments and Templates. +* For more information see this blog post with examples: +* DomHelper + - Create Elements using DOM, HTML fragments and Templates. * @constructor * @param {Object} cfg - Configuration object. */ @@ -4549,11 +4551,18 @@ Roo.Template = function(cfg){ // bc this.html = cfg; } - + if (this.url) { + this.load(); + } }; Roo.Template.prototype = { + /** + * @cfg {String} url The Url to load the template from. beware if you are loading from a url, the data may not be ready if you use it instantly.. + * it should be fixed so that template is observable... + */ + url : false, /** * @cfg {String} html The HTML fragment or an array of fragments to join("") or multiple arguments to join("") */ @@ -4565,7 +4574,7 @@ Roo.Template.prototype = { */ applyTemplate : function(values){ try { - + if(this.compiled){ return this.compiled(values); } @@ -4603,6 +4612,36 @@ Roo.Template.prototype = { }, + loading : false, + + load : function () + { + + if (this.loading) { + return; + } + var _t = this; + + this.loading = true; + this.compiled = false; + + var cx = new Roo.data.Connection(); + cx.request({ + url : this.url, + method : 'GET', + success : function (response) { + _t.loading = false; + _t.html = response.responseText; + _t.url = false; + _this.compile(); + }, + 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 diff --git a/roojs-core.js b/roojs-core.js index 847bda2661..edf1c6eb9e 100644 --- a/roojs-core.js +++ b/roojs-core.js @@ -115,8 +115,8 @@ P=G(2,ts,O,te);} el.insertBefore(P,Q);return P;};return {useDom:false,markup:function(o){return E(o);},applyStyles:function(el,M){if(M){el=Roo.fly(el);if(typeof M=="string"){var re=/\s?([a-z\-]*)\:\s?([^;]*);?/gi;var N;while((N=re.exec(M))!=null){el.setStyle(N[1],N[2]);}}else if(typeof M=="object"){for(var O in M){el.setStyle(O,M[O]);}}else if(typeof M=="function"){Roo.DomHelper.applyStyles(el,M.call());}}},insertHtml:function(M,el,N){M=M.toLowerCase();if(el.insertAdjacentHTML){if(C.test(el.tagName)){var rs;if(rs=L(el.tagName.toLowerCase(),M,el,N)){return rs;}}switch(M){case "beforebegin":el.insertAdjacentHTML('BeforeBegin',N);return el.previousSibling;case "afterbegin":el.insertAdjacentHTML('AfterBegin',N);return el.firstChild;case "beforeend":el.insertAdjacentHTML('BeforeEnd',N);return el.lastChild;case "afterend":el.insertAdjacentHTML('AfterEnd',N);return el.nextSibling;}throw 'Illegal insertion point -> "'+M+'"';}var O=el.ownerDocument.createRange();var P;switch(M){case "beforebegin":O.setStartBefore(el);P=O.createContextualFragment(N);el.parentNode.insertBefore(P,el);return el.previousSibling;case "afterbegin":if(el.firstChild){O.setStartBefore(el.firstChild);P=O.createContextualFragment(N);el.insertBefore(P,el.firstChild);return el.firstChild;}else {el.innerHTML=N;return el.firstChild;}case "beforeend":if(el.lastChild){O.setStartAfter(el.lastChild);P=O.createContextualFragment(N);el.appendChild(P);return el.lastChild;}else {el.innerHTML=N;return el.lastChild;}case "afterend":O.setStartAfter(el);P=O.createContextualFragment(N);el.parentNode.insertBefore(P,el.nextSibling);return el.nextSibling;}throw 'Illegal insertion point -> "'+M+'"';},insertBefore:function(el,o,M){return this.doInsert(el,o,M,"beforeBegin");},insertAfter:function(el,o,M){return this.doInsert(el,o,M,"afterEnd","nextSibling");},insertFirst:function(el,o,M){return this.doInsert(el,o,M,"afterBegin");},doInsert:function(el,o,M,N,O){el=Roo.getDom(el);var P;if(this.useDom||o.ns){P=F(o,null);el.parentNode.insertBefore(P,O?el[O]:el);}else {var Q=E(o);P=this.insertHtml(N,el,Q);}return M?Roo.get(P,true):P;},append:function(el,o,M){el=Roo.getDom(el);var N;if(this.useDom||o.ns){N=F(o,null);el.appendChild(N);}else {var O=E(o);N=this.insertHtml("beforeEnd",el,O);}return M?Roo.get(N,true):N;},overwrite:function(el,o,M){el=Roo.getDom(el);if(o.ns){while(el.childNodes.length){el.removeChild(el.firstChild);} F(o,el);}else {el.innerHTML=E(o);}return M?Roo.get(el.firstChild,true):el.firstChild;},createTemplate:function(o){var M=E(o);return new Roo.Template(M);}};}(); //Roo/Template.js -Roo.Template=function(A){if(A instanceof Array){A=A.join("");}else if(arguments.length>1){A=Array.prototype.join.call(arguments,"");}if(typeof(A)=='object'){Roo.apply(this,A)}else {this.html=A;}};Roo.Template.prototype={html:'',applyTemplate:function(A){try{if(this.compiled){return this.compiled(A);}var B=this.disableFormats!==true;var fm=Roo.util.Format,C=this;var fn=function(m,D,E,F){if(E&&B){if(E.substr(0,5)=="this."){return C.call(E.substr(5),A[D],A);}else {if(F){var re=/^\s*['"](.*)["']\s*$/;F=F.split(',');for(var i=0,G=F.length;i1){A=Array.prototype.join.call(arguments,"");}if(typeof(A)=='object'){Roo.apply(this,A)}else {this.html=A;}if(this.url){this.load();}};Roo.Template.prototype={url:false,html:'',applyTemplate:function(A){try{if(this.compiled){return this.compiled(A);}var B=this.disableFormats!==true;var fm=Roo.util.Format,C=this;var fn=function(m,D,E,F){if(E&&B){if(E.substr(0,5)=="this."){return C.call(E.substr(5),A[D],A);}else {if(F){var re=/^\s*['"](.*)["']\s*$/;F=F.split(',');for(var i=0,G=F.length;i+~]\s?|\s|$)/;var H=/^(#)?([\w-\*]+)/;var I=/(\d*)n\+?(\d*)/,J=/\D/;function child(p,M){var i=0;var n=p.firstChild;while(n){if(n.nodeType==1){if(++i==M){return n;}} n=n.nextSibling;}return null;};function next(n){while((n=n.nextSibling)&&n.nodeType!=1);return n;};function prev(n){while((n=n.previousSibling)&&n.nodeType!=1);return n;};function children(d){var n=d.firstChild,ni=-1;while(n){var nx=n.nextSibling;if(n.nodeType==3&&!D.test(n.nodeValue)){d.removeChild(n);}else {n.nodeIndex=++ni;} diff --git a/roojs-debug.js b/roojs-debug.js index 961dc5c862..7fb5c703e3 100644 --- a/roojs-debug.js +++ b/roojs-debug.js @@ -4530,7 +4530,9 @@ var t = new Roo.Template({ }); 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. +* For more information see this blog post with examples: +* DomHelper + - Create Elements using DOM, HTML fragments and Templates. * @constructor * @param {Object} cfg - Configuration object. */ @@ -4549,11 +4551,18 @@ Roo.Template = function(cfg){ // bc this.html = cfg; } - + if (this.url) { + this.load(); + } }; Roo.Template.prototype = { + /** + * @cfg {String} url The Url to load the template from. beware if you are loading from a url, the data may not be ready if you use it instantly.. + * it should be fixed so that template is observable... + */ + url : false, /** * @cfg {String} html The HTML fragment or an array of fragments to join("") or multiple arguments to join("") */ @@ -4565,7 +4574,7 @@ Roo.Template.prototype = { */ applyTemplate : function(values){ try { - + if(this.compiled){ return this.compiled(values); } @@ -4603,6 +4612,36 @@ Roo.Template.prototype = { }, + loading : false, + + load : function () + { + + if (this.loading) { + return; + } + var _t = this; + + this.loading = true; + this.compiled = false; + + var cx = new Roo.data.Connection(); + cx.request({ + url : this.url, + method : 'GET', + success : function (response) { + _t.loading = false; + _t.html = response.responseText; + _t.url = false; + _this.compile(); + }, + 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 @@ -52285,63 +52324,74 @@ Roo.LoadMask.prototype = { */ Roo.XTemplate = function(){ Roo.XTemplate.superclass.constructor.apply(this, arguments); - var s = this.html; - - s = ['', s, ''].join(''); - - var re = /]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/; - - var nameRe = /^]*?for="(.*?)"/; - var ifRe = /^]*?if="(.*?)"/; - var execRe = /^]*?exec="(.*?)"/; - var m, id = 0; - var tpls = []; - - while(m = s.match(re)){ - var m2 = m[0].match(nameRe); - var m3 = m[0].match(ifRe); - var m4 = m[0].match(execRe); - var exp = null, fn = null, exec = null; - var name = m2 && m2[1] ? m2[1] : ''; - if(m3){ - exp = m3 && m3[1] ? m3[1] : null; - if(exp){ - fn = new Function('values', 'parent', 'with(values){ return '+(Roo.util.Format.htmlDecode(exp))+'; }'); - } - } - if(m4){ - exp = m4 && m4[1] ? m4[1] : null; - if(exp){ - exec = new Function('values', 'parent', 'with(values){ '+(Roo.util.Format.htmlDecode(exp))+'; }'); - } - } - if(name){ - switch(name){ - case '.': name = new Function('values', 'parent', 'with(values){ return values; }'); break; - case '..': name = new Function('values', 'parent', 'with(values){ return parent; }'); break; - default: name = new Function('values', 'parent', 'with(values){ return '+name+'; }'); - } - } - tpls.push({ - id: id, - target: name, - exec: exec, - test: fn, - body: m[1]||'' - }); - s = s.replace(m[0], '{xtpl'+ id + '}'); - ++id; - } - for(var i = tpls.length-1; i >= 0; --i){ - this.compileTpl(tpls[i]); + if (this.html) { + this.preCompile(); } - this.master = tpls[tpls.length-1]; - this.tpls = tpls; }; + + Roo.extend(Roo.XTemplate, Roo.Template, { re : /\{([\w-\.]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g, + + compile: function() + { + var s = this.html; + + s = ['', s, ''].join(''); + + var re = /]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/; + + var nameRe = /^]*?for="(.*?)"/; + var ifRe = /^]*?if="(.*?)"/; + var execRe = /^]*?exec="(.*?)"/; + var m, id = 0; + var tpls = []; + + while(true == !!(m = s.match(re))){ + var m2 = m[0].match(nameRe); + var m3 = m[0].match(ifRe); + var m4 = m[0].match(execRe); + var exp = null, fn = null, exec = null; + var name = m2 && m2[1] ? m2[1] : ''; + if(m3){ + exp = m3 && m3[1] ? m3[1] : null; + if(exp){ + fn = new Function('values', 'parent', 'with(values){ return '+(Roo.util.Format.htmlDecode(exp))+'; }'); + } + } + if(m4){ + exp = m4 && m4[1] ? m4[1] : null; + if(exp){ + exec = new Function('values', 'parent', 'with(values){ '+(Roo.util.Format.htmlDecode(exp))+'; }'); + } + } + if(name){ + switch(name){ + case '.': name = new Function('values', 'parent', 'with(values){ return values; }'); break; + case '..': name = new Function('values', 'parent', 'with(values){ return parent; }'); break; + default: name = new Function('values', 'parent', 'with(values){ return '+name+'; }'); + } + } + tpls.push({ + id: id, + target: name, + exec: exec, + test: fn, + body: m[1]||'' + }); + s = s.replace(m[0], '{xtpl'+ id + '}'); + ++id; + } + for(var i = tpls.length-1; i >= 0; --i){ + this.compileTpl(tpls[i]); + } + this.master = tpls[tpls.length-1]; + this.tpls = tpls; + return this; + }, + applySubTemplate : function(id, values, parent){ var t = this.tpls[id]; if(t.test && !t.test.call(this, values, parent)){ @@ -52401,22 +52451,24 @@ Roo.extend(Roo.XTemplate, Roo.Template, { body.push("'].join('');};"); body = body.join(''); } + /** eval:var:zzzzzzz */ eval(body); + Roo.log(body); + return this; }, applyTemplate : function(values){ return this.master.compiled.call(this, values, {}); - var s = this.subs; + //var s = this.subs; }, apply : function(){ return this.applyTemplate.apply(this, arguments); - }, + } - compile : function(){return this;} -}); + }); Roo.XTemplate.from = function(el){ el = Roo.getDom(el); diff --git a/roojs-ui-debug.js b/roojs-ui-debug.js index 233cae07db..107669447d 100644 --- a/roojs-ui-debug.js +++ b/roojs-ui-debug.js @@ -37822,63 +37822,74 @@ Roo.LoadMask.prototype = { */ Roo.XTemplate = function(){ Roo.XTemplate.superclass.constructor.apply(this, arguments); - var s = this.html; - - s = ['', s, ''].join(''); - - var re = /]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/; - - var nameRe = /^]*?for="(.*?)"/; - var ifRe = /^]*?if="(.*?)"/; - var execRe = /^]*?exec="(.*?)"/; - var m, id = 0; - var tpls = []; - - while(m = s.match(re)){ - var m2 = m[0].match(nameRe); - var m3 = m[0].match(ifRe); - var m4 = m[0].match(execRe); - var exp = null, fn = null, exec = null; - var name = m2 && m2[1] ? m2[1] : ''; - if(m3){ - exp = m3 && m3[1] ? m3[1] : null; - if(exp){ - fn = new Function('values', 'parent', 'with(values){ return '+(Roo.util.Format.htmlDecode(exp))+'; }'); - } - } - if(m4){ - exp = m4 && m4[1] ? m4[1] : null; - if(exp){ - exec = new Function('values', 'parent', 'with(values){ '+(Roo.util.Format.htmlDecode(exp))+'; }'); - } - } - if(name){ - switch(name){ - case '.': name = new Function('values', 'parent', 'with(values){ return values; }'); break; - case '..': name = new Function('values', 'parent', 'with(values){ return parent; }'); break; - default: name = new Function('values', 'parent', 'with(values){ return '+name+'; }'); - } - } - tpls.push({ - id: id, - target: name, - exec: exec, - test: fn, - body: m[1]||'' - }); - s = s.replace(m[0], '{xtpl'+ id + '}'); - ++id; - } - for(var i = tpls.length-1; i >= 0; --i){ - this.compileTpl(tpls[i]); + if (this.html) { + this.preCompile(); } - this.master = tpls[tpls.length-1]; - this.tpls = tpls; }; + + Roo.extend(Roo.XTemplate, Roo.Template, { re : /\{([\w-\.]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g, + + compile: function() + { + var s = this.html; + + s = ['', s, ''].join(''); + + var re = /]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/; + + var nameRe = /^]*?for="(.*?)"/; + var ifRe = /^]*?if="(.*?)"/; + var execRe = /^]*?exec="(.*?)"/; + var m, id = 0; + var tpls = []; + + while(true == !!(m = s.match(re))){ + var m2 = m[0].match(nameRe); + var m3 = m[0].match(ifRe); + var m4 = m[0].match(execRe); + var exp = null, fn = null, exec = null; + var name = m2 && m2[1] ? m2[1] : ''; + if(m3){ + exp = m3 && m3[1] ? m3[1] : null; + if(exp){ + fn = new Function('values', 'parent', 'with(values){ return '+(Roo.util.Format.htmlDecode(exp))+'; }'); + } + } + if(m4){ + exp = m4 && m4[1] ? m4[1] : null; + if(exp){ + exec = new Function('values', 'parent', 'with(values){ '+(Roo.util.Format.htmlDecode(exp))+'; }'); + } + } + if(name){ + switch(name){ + case '.': name = new Function('values', 'parent', 'with(values){ return values; }'); break; + case '..': name = new Function('values', 'parent', 'with(values){ return parent; }'); break; + default: name = new Function('values', 'parent', 'with(values){ return '+name+'; }'); + } + } + tpls.push({ + id: id, + target: name, + exec: exec, + test: fn, + body: m[1]||'' + }); + s = s.replace(m[0], '{xtpl'+ id + '}'); + ++id; + } + for(var i = tpls.length-1; i >= 0; --i){ + this.compileTpl(tpls[i]); + } + this.master = tpls[tpls.length-1]; + this.tpls = tpls; + return this; + }, + applySubTemplate : function(id, values, parent){ var t = this.tpls[id]; if(t.test && !t.test.call(this, values, parent)){ @@ -37938,22 +37949,24 @@ Roo.extend(Roo.XTemplate, Roo.Template, { body.push("'].join('');};"); body = body.join(''); } + /** eval:var:zzzzzzz */ eval(body); + Roo.log(body); + return this; }, applyTemplate : function(values){ return this.master.compiled.call(this, values, {}); - var s = this.subs; + //var s = this.subs; }, apply : function(){ return this.applyTemplate.apply(this, arguments); - }, + } - compile : function(){return this;} -}); + }); Roo.XTemplate.from = function(el){ el = Roo.getDom(el); diff --git a/roojs-ui.js b/roojs-ui.js index 5369ab3187..a328c0a69b 100644 --- a/roojs-ui.js +++ b/roojs-ui.js @@ -847,9 +847,9 @@ this.store.loadRecords({records:A},{},true);},onUpdate:function(ds,A,B){if(B==Ro Roo.LoadMask=function(el,A){this.el=Roo.get(el);Roo.apply(this,A);if(this.store){this.store.on('beforeload',this.onBeforeLoad,this);this.store.on('load',this.onLoad,this);this.store.on('loadexception',this.onLoadException,this);this.removeMask=false;}else {var um=this.el.getUpdateManager();um.showLoadIndicator=false;um.on('beforeupdate',this.onBeforeLoad,this);um.on('update',this.onLoad,this);um.on('failure',this.onLoad,this);this.removeMask=true;}};Roo.LoadMask.prototype={msg:'Loading...',msgCls:'x-mask-loading',disabled:false,disable:function(){this.disabled=true;},enable:function(){this.disabled=false;},onLoadException:function(){if(this.store&&typeof(this.store.reader.jsonData.errorMsg)!='undefined'){Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);} this.el.unmask(this.removeMask);},onLoad:function(){this.el.unmask(this.removeMask);},onBeforeLoad:function(){if(!this.disabled){this.el.mask(this.msg,this.msgCls);}},destroy:function(){if(this.store){this.store.un('beforeload',this.onBeforeLoad,this);this.store.un('load',this.onLoad,this);this.store.un('loadexception',this.onLoadException,this);}else {var um=this.el.getUpdateManager();um.un('beforeupdate',this.onBeforeLoad,this);um.un('update',this.onLoad,this);um.un('failure',this.onLoad,this);}}}; //Roo/XTemplate.js -Roo.XTemplate=function(){Roo.XTemplate.superclass.constructor.apply(this,arguments);var s=this.html;s=['',s,''].join('');var re=/]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/;var A=/^]*?for="(.*?)"/;var B=/^]*?if="(.*?)"/;var C=/^]*?exec="(.*?)"/;var m,id=0;var D=[];while(m=s.match(re)){var m2=m[0].match(A);var m3=m[0].match(B);var m4=m[0].match(C);var E=null,fn=null,F=null;var G=m2&&m2[1]?m2[1]:'';if(m3){E=m3&&m3[1]?m3[1]:null;if(E){fn=new Function('values','parent','with(values){ return '+(Roo.util.Format.htmlDecode(E))+'; }');}}if(m4){E=m4&&m4[1]?m4[1]:null;if(E){F=new Function('values','parent','with(values){ '+(Roo.util.Format.htmlDecode(E))+'; }');}}if(G){switch(G){case '.':G=new Function('values','parent','with(values){ return values; }');break;case '..':G=new Function('values','parent','with(values){ return parent; }');break;default:G=new Function('values','parent','with(values){ return '+G+'; }');}} +Roo.XTemplate=function(){Roo.XTemplate.superclass.constructor.apply(this,arguments);if(this.html){this.preCompile();}};Roo.extend(Roo.XTemplate,Roo.Template,{re:/\{([\w-\.]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,compile:function(){var s=this.html;s=['',s,''].join('');var re=/]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/;var A=/^]*?for="(.*?)"/;var B=/^]*?if="(.*?)"/;var C=/^]*?exec="(.*?)"/;var m,id=0;var D=[];while(true==!!(m=s.match(re))){var m2=m[0].match(A);var m3=m[0].match(B);var m4=m[0].match(C);var E=null,fn=null,F=null;var G=m2&&m2[1]?m2[1]:'';if(m3){E=m3&&m3[1]?m3[1]:null;if(E){fn=new Function('values','parent','with(values){ return '+(Roo.util.Format.htmlDecode(E))+'; }');}}if(m4){E=m4&&m4[1]?m4[1]:null;if(E){F=new Function('values','parent','with(values){ '+(Roo.util.Format.htmlDecode(E))+'; }');}}if(G){switch(G){case '.':G=new Function('values','parent','with(values){ return values; }');break;case '..':G=new Function('values','parent','with(values){ return parent; }');break;default:G=new Function('values','parent','with(values){ return '+G+'; }');}} D.push({id:id,target:G,exec:F,test:fn,body:m[1]||''});s=s.replace(m[0],'{xtpl'+id+'}');++id;}for(var i=D.length-1;i>=0;--i){this.compileTpl(D[i]);} -this.master=D[D.length-1];this.tpls=D;};Roo.extend(Roo.XTemplate,Roo.Template,{re:/\{([\w-\.]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,applySubTemplate:function(id,A,B){var t=this.tpls[id];if(t.test&&!t.test.call(this,A,B)){return '';}if(t.exec&&t.exec.call(this,A,B)){return '';}var vs=t.target?t.target.call(this,A,B):A;B=t.target?A:B;if(t.target&&vs instanceof Array){var C=[];for(var i=0,D=vs.length;i