From e66b34d404adf59516f60063267d95dc989db0be Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Mon, 9 Apr 2012 18:58:27 +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-debug.js | 68 ++++++++++++++++++++++++++++++++++++----------- roojs-ui-debug.js | 68 ++++++++++++++++++++++++++++++++++++----------- roojs-ui.js | 8 +++--- 4 files changed, 114 insertions(+), 38 deletions(-) diff --git a/roojs-all.js b/roojs-all.js index 319d35caf4..68e535fda7 100644 --- a/roojs-all.js +++ b/roojs-all.js @@ -1140,10 +1140,10 @@ 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);if(this.html){this.compile();}};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>/,A=/^]*?for="(.*?)"/,B=/^]*?if="(.*?)"/,C=/^]*?exec="(.*?)"/,m,id=0,D=[];while(true==!!(m=s.match(re))){var m2=m[0].match(A),m3=m[0].match(B),m4=m[0].match(C),E=null,fn=null,F=null,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;return this;},applySubTemplate:function(id,A,B){var t=this.tpls[id];try{if(t.test&&!t.test.call(this,A,B)){return '';}}catch(e){Roo.log("Xtemplate.applySubTemplate 'test': Exception thrown");Roo.log(e.toString());Roo.log(t.test);return ''}try{if(t.exec&&t.exec.call(this,A,B)){return '';}}catch(e){Roo.log("Xtemplate.applySubTemplate 'exec': Exception thrown");Roo.log(e.toString());Roo.log(t.exec);return ''}try{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',s,''].join('');var re=/]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/,A=/^]*?for="(.*?)"/,B=/^]*?if="(.*?)"/,C=/^]*?exec="(.*?)"/,D=/^]*?name="(\w+)"/,m,id=0,E=[];while(true==!!(m=s.match(re))){var F=m[0].match(A),G=m[0].match(B),H=m[0].match(C),I=m[0].match(D),J=null,fn=null,K=null,L=F&&F[1]?F[1]:'';if(G){J=G&&G[1]?G[1]:null;if(J){fn=new Function('values','parent','with(values){ return '+(Roo.util.Format.htmlDecode(J))+'; }');}}if(H){J=H&&H[1]?H[1]:null;if(J){K=new Function('values','parent','with(values){ '+(Roo.util.Format.htmlDecode(J))+'; }');}}if(L){switch(L){case '.':L=new Function('values','parent','with(values){ return values; }');break;case '..':L=new Function('values','parent','with(values){ return parent; }');break;default:L=new Function('values','parent','with(values){ return '+L+'; }');}}var M=I?I[1]:id;E.push({id:I?I[1]:id,target:L,exec:K,test:fn,body:m[1]||''});if(I){s=s.replace(m[0],'');}else {s=s.replace(m[0],'{xtpl'+id+'}');}++id;} +this.tpls=[];for(var i=E.length-1;i>=0;--i){this.compileTpl(E[i]);this.tpls[E[i].id]=E[i];} +this.master=E[E.length-1];return this;},applySubTemplate:function(id,A,B){var t=this.tpls[id];try{if(t.test&&!t.test.call(this,A,B)){return '';}}catch(e){Roo.log("Xtemplate.applySubTemplate 'test': Exception thrown");Roo.log(e.toString());Roo.log(t.test);return ''}try{if(t.exec&&t.exec.call(this,A,B)){return '';}}catch(e){Roo.log("Xtemplate.applySubTemplate 'exec': Exception thrown");Roo.log(e.toString());Roo.log(t.exec);return ''}try{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 -var t = new Roo.MasterTemplate( +var t = new Roo.XTemplate( '<select name="{name}">', '<tpl for="options"><option value="{value:trim}">{text:ellipsis(10)}</option></tpl>', '</select>' @@ -52351,6 +52351,7 @@ var t = new Roo.MasterTemplate( * <tpl for="a_variable or condition.."></tpl> * <tpl if="a_variable or condition"></tpl> * <tpl exec="some javascript"></tpl> + * <tpl name="named_template"></tpl> * * <tpl for="."></tpl> - just iterate the property.. * <tpl for=".."></tpl> - iterates with the parent (probably the template) @@ -52368,6 +52369,10 @@ Roo.XTemplate = function() Roo.extend(Roo.XTemplate, Roo.Template, { + /** + * The various sub templates + */ + tpls : false, /** * * basic tag replacing syntax @@ -52379,7 +52384,12 @@ Roo.extend(Roo.XTemplate, Roo.Template, { */ re : /\{([\w-\.]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g, - + /** + * compile the template + * + * This is not recursive, so I'm not sure how nested templates are really going to be handled.. + * + */ compile: function() { var s = this.html; @@ -52390,33 +52400,39 @@ Roo.extend(Roo.XTemplate, Roo.Template, { nameRe = /^]*?for="(.*?)"/, ifRe = /^]*?if="(.*?)"/, execRe = /^]*?exec="(.*?)"/, + namedRe = /^]*?name="(\w+)"/, // named templates.. m, id = 0, tpls = []; while(true == !!(m = s.match(re))){ - var m2 = m[0].match(nameRe), - m3 = m[0].match(ifRe), - m4 = m[0].match(execRe), + var forMatch = m[0].match(nameRe), + ifMatch = m[0].match(ifRe), + execMatch = m[0].match(execRe), + namedMatch = m[0].match(namedRe), + exp = null, fn = null, exec = null, - name = m2 && m2[1] ? m2[1] : ''; + name = forMatch && forMatch[1] ? forMatch[1] : ''; - if (m3) { + if (ifMatch) { // if - puts fn into test.. - exp = m3 && m3[1] ? m3[1] : null; + exp = ifMatch && ifMatch[1] ? ifMatch[1] : null; if(exp){ fn = new Function('values', 'parent', 'with(values){ return '+(Roo.util.Format.htmlDecode(exp))+'; }'); } } - if (m4) { + + if (execMatch) { // exec - calls a function... returns empty if true is returned. - exp = m4 && m4[1] ? m4[1] : null; + exp = execMatch && execMatch[1] ? execMatch[1] : null; if(exp){ exec = new Function('values', 'parent', 'with(values){ '+(Roo.util.Format.htmlDecode(exp))+'; }'); } } + + if (name) { // for = switch(name){ @@ -52425,27 +52441,49 @@ Roo.extend(Roo.XTemplate, Roo.Template, { default: name = new Function('values', 'parent', 'with(values){ return '+name+'; }'); } } + var uid = namedMatch ? namedMatch[1] : id; + + tpls.push({ - id: id, + id: namedMatch ? namedMatch[1] : id, target: name, exec: exec, test: fn, body: m[1] || '' }); - s = s.replace(m[0], '{xtpl'+ id + '}'); + if (namedMatch) { + s = s.replace(m[0], ''); + } else { + s = s.replace(m[0], '{xtpl'+ id + '}'); + } ++id; } + this.tpls = []; for(var i = tpls.length-1; i >= 0; --i){ this.compileTpl(tpls[i]); + this.tpls[tpls[i].id] = tpls[i]; } this.master = tpls[tpls.length-1]; - this.tpls = tpls; return this; }, - + /** + * same as applyTemplate, except it's done to one of the subTemplates + * when using named templates, you can do: + * + * var str = pl.applySubTemplate('your-name', values); + * + * + * @param {Number} id of the template + * @param {Object} values to apply to template + * @param {Object} parent (normaly the instance of this object) + */ applySubTemplate : function(id, values, parent) { + + var t = this.tpls[id]; + + try { if(t.test && !t.test.call(this, values, parent)){ return ''; @@ -52568,7 +52606,7 @@ Roo.extend(Roo.XTemplate, Roo.Template, { Roo.debug && Roo.log(body.replace(/\\n/,'\n')); - /** eval:var:zzzzzzz */ + /** eval:var:tpl eval:var:fm eval:var:useF eval:var:undef */ eval(body); return this; diff --git a/roojs-ui-debug.js b/roojs-ui-debug.js index f58dc6a8aa..6bcbf55a06 100644 --- a/roojs-ui-debug.js +++ b/roojs-ui-debug.js @@ -37827,7 +37827,7 @@ Roo.LoadMask.prototype = { * @extends Roo.Template * Provides a template that can have nested templates for loops or conditionals. The syntax is:

-var t = new Roo.MasterTemplate(
+var t = new Roo.XTemplate(
 	'<select name="{name}">',
 		'<tpl for="options"><option value="{value:trim}">{text:ellipsis(10)}</option></tpl>',
 	'</select>'
@@ -37849,6 +37849,7 @@ var t = new Roo.MasterTemplate(
  *      <tpl for="a_variable or condition.."></tpl>
  *      <tpl if="a_variable or condition"></tpl>
  *      <tpl exec="some javascript"></tpl>
+ *      <tpl name="named_template"></tpl>
  *
  *      <tpl for="."></tpl> - just iterate the property..
  *      <tpl for=".."></tpl> - iterates with the parent (probably the template) 
@@ -37866,6 +37867,10 @@ Roo.XTemplate = function()
 
 Roo.extend(Roo.XTemplate, Roo.Template, {
 
+    /**
+     * The various sub templates
+     */
+    tpls : false,
     /**
      *
      * basic tag replacing syntax
@@ -37877,7 +37882,12 @@ Roo.extend(Roo.XTemplate, Roo.Template, {
      */
     re : /\{([\w-\.]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
 
-    
+    /**
+     * compile the template
+     *
+     * This is not recursive, so I'm not sure how nested templates are really going to be handled..
+     *
+     */
     compile: function()
     {
         var s = this.html;
@@ -37888,33 +37898,39 @@ Roo.extend(Roo.XTemplate, Roo.Template, {
             nameRe = /^]*?for="(.*?)"/,
             ifRe   = /^]*?if="(.*?)"/,
             execRe = /^]*?exec="(.*?)"/,
+            namedRe = /^]*?name="(\w+)"/,  // named templates..
             m,
             id     = 0,
             tpls   = [];
     
         while(true == !!(m = s.match(re))){
-            var m2   = m[0].match(nameRe),
-                m3   = m[0].match(ifRe),
-                m4   = m[0].match(execRe),
+            var forMatch   = m[0].match(nameRe),
+                ifMatch   = m[0].match(ifRe),
+                execMatch   = m[0].match(execRe),
+                namedMatch   = m[0].match(namedRe),
+                
                 exp  = null, 
                 fn   = null,
                 exec = null,
-                name = m2 && m2[1] ? m2[1] : '';
+                name = forMatch && forMatch[1] ? forMatch[1] : '';
                 
-            if (m3) {
+            if (ifMatch) {
                 // if - puts fn into test..
-                exp = m3 && m3[1] ? m3[1] : null;
+                exp = ifMatch && ifMatch[1] ? ifMatch[1] : null;
                 if(exp){
                    fn = new Function('values', 'parent', 'with(values){ return '+(Roo.util.Format.htmlDecode(exp))+'; }');
                 }
             }
-            if (m4) {
+            
+            if (execMatch) {
                 // exec - calls a function... returns empty if true is  returned.
-                exp = m4 && m4[1] ? m4[1] : null;
+                exp = execMatch && execMatch[1] ? execMatch[1] : null;
                 if(exp){
                    exec = new Function('values', 'parent', 'with(values){ '+(Roo.util.Format.htmlDecode(exp))+'; }');
                 }
             }
+            
+            
             if (name) {
                 // for = 
                 switch(name){
@@ -37923,27 +37939,49 @@ Roo.extend(Roo.XTemplate, Roo.Template, {
                     default:   name = new Function('values', 'parent', 'with(values){ return '+name+'; }');
                 }
             }
+            var uid = namedMatch ? namedMatch[1] : id;
+            
+            
             tpls.push({
-                id:     id,
+                id:     namedMatch ? namedMatch[1] : id,
                 target: name,
                 exec:   exec,
                 test:   fn,
                 body:   m[1] || ''
             });
-            s = s.replace(m[0], '{xtpl'+ id + '}');
+            if (namedMatch) {
+                s = s.replace(m[0], '');
+            } else { 
+                s = s.replace(m[0], '{xtpl'+ id + '}');
+            }
             ++id;
         }
+        this.tpls = [];
         for(var i = tpls.length-1; i >= 0; --i){
             this.compileTpl(tpls[i]);
+            this.tpls[tpls[i].id] = tpls[i];
         }
         this.master = tpls[tpls.length-1];
-        this.tpls = tpls;
         return this;
     },
-    
+    /**
+     * same as applyTemplate, except it's done to one of the subTemplates
+     * when using named templates, you can do:
+     *
+     * var str = pl.applySubTemplate('your-name', values);
+     *
+     * 
+     * @param {Number} id of the template
+     * @param {Object} values to apply to template
+     * @param {Object} parent (normaly the instance of this object)
+     */
     applySubTemplate : function(id, values, parent)
     {
+        
+        
         var t = this.tpls[id];
+        
+        
         try { 
             if(t.test && !t.test.call(this, values, parent)){
                 return '';
@@ -38066,7 +38104,7 @@ Roo.extend(Roo.XTemplate, Roo.Template, {
         
         Roo.debug && Roo.log(body.replace(/\\n/,'\n'));
        
-        /** eval:var:zzzzzzz */
+        /** eval:var:tpl eval:var:fm eval:var:useF eval:var:undef  */
         eval(body);
         
         return this;
diff --git a/roojs-ui.js b/roojs-ui.js
index 8d1b7cd68c..e6f1f24ba4 100644
--- a/roojs-ui.js
+++ b/roojs-ui.js
@@ -847,10 +847,10 @@ 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);if(this.html){this.compile();}};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>/,A=/^]*?for="(.*?)"/,B=/^]*?if="(.*?)"/,C=/^]*?exec="(.*?)"/,m,id=0,D=[];while(true==!!(m=s.match(re))){var m2=m[0].match(A),m3=m[0].match(B),m4=m[0].match(C),E=null,fn=null,F=null,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;return this;},applySubTemplate:function(id,A,B){var t=this.tpls[id];try{if(t.test&&!t.test.call(this,A,B)){return '';}}catch(e){Roo.log("Xtemplate.applySubTemplate 'test': Exception thrown");Roo.log(e.toString());Roo.log(t.test);return ''}try{if(t.exec&&t.exec.call(this,A,B)){return '';}}catch(e){Roo.log("Xtemplate.applySubTemplate 'exec': Exception thrown");Roo.log(e.toString());Roo.log(t.exec);return ''}try{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',s,''].join('');var re=/]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/,A=/^]*?for="(.*?)"/,B=/^]*?if="(.*?)"/,C=/^]*?exec="(.*?)"/,D=/^]*?name="(\w+)"/,m,id=0,E=[];while(true==!!(m=s.match(re))){var F=m[0].match(A),G=m[0].match(B),H=m[0].match(C),I=m[0].match(D),J=null,fn=null,K=null,L=F&&F[1]?F[1]:'';if(G){J=G&&G[1]?G[1]:null;if(J){fn=new Function('values','parent','with(values){ return '+(Roo.util.Format.htmlDecode(J))+'; }');}}if(H){J=H&&H[1]?H[1]:null;if(J){K=new Function('values','parent','with(values){ '+(Roo.util.Format.htmlDecode(J))+'; }');}}if(L){switch(L){case '.':L=new Function('values','parent','with(values){ return values; }');break;case '..':L=new Function('values','parent','with(values){ return parent; }');break;default:L=new Function('values','parent','with(values){ return '+L+'; }');}}var M=I?I[1]:id;E.push({id:I?I[1]:id,target:L,exec:K,test:fn,body:m[1]||''});if(I){s=s.replace(m[0],'');}else {s=s.replace(m[0],'{xtpl'+id+'}');}++id;}
+this.tpls=[];for(var i=E.length-1;i>=0;--i){this.compileTpl(E[i]);this.tpls[E[i].id]=E[i];}
+this.master=E[E.length-1];return this;},applySubTemplate:function(id,A,B){var t=this.tpls[id];try{if(t.test&&!t.test.call(this,A,B)){return '';}}catch(e){Roo.log("Xtemplate.applySubTemplate 'test': Exception thrown");Roo.log(e.toString());Roo.log(t.test);return ''}try{if(t.exec&&t.exec.call(this,A,B)){return '';}}catch(e){Roo.log("Xtemplate.applySubTemplate 'exec': Exception thrown");Roo.log(e.toString());Roo.log(t.exec);return ''}try{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