sync
authorAlan Knowles <alan@roojs.com>
Fri, 3 Aug 2012 05:30:39 +0000 (13:30 +0800)
committerAlan Knowles <alan@roojs.com>
Fri, 3 Aug 2012 05:30:39 +0000 (13:30 +0800)
Roo/DomTemplate.js
buildSDK/dependancy_core.txt
roojs-all.js
roojs-core-debug.js
roojs-core.js
roojs-debug.js

index fe95bea..c08ac27 100644 (file)
@@ -268,8 +268,7 @@ Roo.extend(Roo.DomTemplate, Roo.Template, {
             Roo.log("Property not found :"  + str);
             return '';
         };
-         
-        
+          
         
         var fn = function(m, lbrace, name, format, args)
         {
index 2f92b95..61d3ad8 100644 (file)
@@ -43,6 +43,7 @@ Roo.CompositeElementLite
 Roo.data.Connection
 Roo.Ajax
 Roo.UpdateManager
+Roo.DomTemplate
 
 
 // -- these two have bits in and out of core...
index 857c139..db55551 100644 (file)
@@ -222,6 +222,13 @@ E=E||(B?"POST":"GET");if(E=="GET"){A=this.prepareUrl(A);}var o=Roo.apply(F||{},{
 A=Roo.getDom(A);this.transaction=Roo.Ajax.request({form:A,url:B,success:this.successDelegate,failure:this.failureDelegate,timeout:(this.timeout*1000),argument:{"url":B,"form":A,"callback":D,"reset":C}});this.showLoading.defer(1,this);}},refresh:function(A){if(this.defaultUrl==null){return;}
 this.update(this.defaultUrl,null,A,true);},startAutoRefresh:function(A,B,C,D,E){if(E){this.update(B||this.defaultUrl,C,D,true);}if(this.autoRefreshProcId){clearInterval(this.autoRefreshProcId);}
 this.autoRefreshProcId=setInterval(this.update.createDelegate(this,[B||this.defaultUrl,C,D,true]),A*1000);},stopAutoRefresh:function(){if(this.autoRefreshProcId){clearInterval(this.autoRefreshProcId);delete this.autoRefreshProcId;}},isAutoRefreshing:function(){return this.autoRefreshProcId?true:false;},showLoading:function(){if(this.showLoadIndicator){this.el.update(this.indicatorText);}},prepareUrl:function(A){if(this.disableCaching){var B="_dc="+(new Date().getTime());if(A.indexOf("?")!==-1){A+="&"+B;}else {A+="?"+B;}}return A;},processSuccess:function(A){this.transaction=null;if(A.argument.form&&A.argument.reset){try{A.argument.form.reset();}catch(e){}}if(this.loadScripts){this.renderer.render(this.el,A,this,this.updateComplete.createDelegate(this,[A]));}else {this.renderer.render(this.el,A,this);this.updateComplete(A);}},updateComplete:function(A){this.fireEvent("update",this.el,A);if(typeof A.argument.callback=="function"){A.argument.callback(this.el,true,A);}},processFailure:function(A){this.transaction=null;this.fireEvent("failure",this.el,A);if(typeof A.argument.callback=="function"){A.argument.callback(this.el,false,A);}},setRenderer:function(A){this.renderer=A;},getRenderer:function(){return this.renderer;},setDefaultUrl:function(A){this.defaultUrl=A;},abort:function(){if(this.transaction){Roo.Ajax.abort(this.transaction);}},isUpdating:function(){if(this.transaction){return Roo.Ajax.isLoading(this.transaction);}return false;}});Roo.UpdateManager.defaults={timeout:30,loadScripts:false,sslBlankUrl:(Roo.SSL_SECURE_URL||"javascript:false"),disableCaching:false,showLoadIndicator:true,indicatorText:'<div class="loading-indicator">Loading...</div>'};Roo.UpdateManager.updateElement=function(el,A,B,C){var um=Roo.get(el,true).getUpdateManager();Roo.apply(um,C);um.update(A,B,C?C.callback:null);};Roo.UpdateManager.update=Roo.UpdateManager.updateElement;Roo.UpdateManager.BasicRenderer=function(){};Roo.UpdateManager.BasicRenderer.prototype={render:function(el,A,B,C){el.update(A.responseText,B.loadScripts,C);}};
+//Roo/DomTemplate.js
+Roo.DomTemplate=function(){Roo.DomTemplate.superclass.constructor.apply(this,arguments);if(this.html){this.compile();}};Roo.extend(Roo.DomTemplate,Roo.Template,{id:0,inPre:false,tpls:false,re:/(\{|%7B])([\w-\.]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?(\}|%7D)/g,iterChild:function(A,B){var C=this.inPre;if(A.tagName=='PRE'){this.inPre=true;}for(var i=0;i<A.childNodes.length;i++){B.call(this,A.childNodes[i]);}
+this.inPre=C;},compile:function(){var s=this.html;var A=document.createElement('div');A.innerHTML=this.html;this.tpls=[];var _t=this;this.iterChild(A,function(n){_t.compileNode(n,true);});var B=this.tpls;Roo.log(A.innerHTML);var C={uid:'master',id:this.id++,attr:false,value:false,body:A.innerHTML,forCall:false,execCall:false,dom:A,isTop:true};B.unshift(C);this.tpls=[];Roo.each(B,function(tp){this.compileTpl(tp);this.tpls[tp.id]=tp;},this);this.master=B[0];return this;},compileNode:function(A,B){if(A.nodeType!=1){if(A.nodeType==3&&!this.inPre){A.nodeValue=A.nodeValue.replace(/\s+/g,' ');}return;}var C={uid:false,id:false,attr:false,value:false,body:'',forCall:false,execCall:false,dom:false,isTop:B};switch(true){case (A.hasAttribute('roo-for')):C.attr='for';break;case (A.hasAttribute('roo-if')):C.attr='if';break;case (A.hasAttribute('roo-name')):C.attr='name';break;case (A.hasAttribute('roo-exec')):C.attr='exec';break;}if(!C.attr){this.iterChild(A,this.compileNode);return;}
+C.uid=this.id++;C.value=A.getAttribute('roo-'+C.attr);A.removeAttribute('roo-'+C.attr);if(C.attr!='name'){var D=document.createTextNode('{domtpl'+C.uid+'}');A.parentNode.replaceChild(D,A);}else {var D=document.createElement('span');D.className='roo-tpl-'+C.value;A.parentNode.replaceChild(D,A);}
+this.iterChild(A,this.compileNode)var E=document.createElement('div');E.appendChild(A);C.dom=A;C.body=E.innerHTML;C.id=C.uid;switch(C.attr){case 'for':switch(C.value){case '.':C.forCall=new Function('values','parent','with(values){ return values; }');break;case '..':C.forCall=new Function('values','parent','with(values){ return parent; }');break;default:C.forCall=new Function('values','parent','with(values){ return '+C.value+'; }');}break;case 'exec':C.execCall=new Function('values','parent','with(values){ '+(Roo.util.Format.htmlDecode(C.value))+'; }');break;case 'if':C.ifCall=new Function('values','parent','with(values){ return '+(Roo.util.Format.htmlDecode(C.value))+'; }');break;case 'name':C.id=C.value;break;}
+this.tpls.push(C);},compileTpl:function(tpl){var fm=Roo.util.Format;var useF=this.disableFormats!==true;var A=Roo.isGecko?"+\n":",\n";var undef=function(C){Roo.log("Property not found :"+C);return '';};var fn=function(m,C,D,E,F){F=F?F.replace(/\\'/g,"'"):F;if(typeof(E)=='undefined'){E='htmlEncode';}if(E=='raw'){E=false;}if(D.substr(0,6)=='domtpl'){return "'"+A+'this.applySubTemplate('+D.substr(6)+', values, parent)'+A+"'";}var G=[];var H='';Roo.each(D.split('.'),function(st){H+=(H.length?'.':'')+st;G.push("(typeof("+H+") == 'undefined')");});var I='(('+G.join(" || ")+") ? undef('"+D+"') : ";if(E&&useF){F=F?','+F:"";if(E.substr(0,5)!="this."){E="fm."+E+'(';}else {E='this.call("'+E.substr(5)+'", ';F=", values";}return "'"+A+I+E+D+F+"))"+A+"'";}if(F.length){return "'"+A+I+D+'('+F+"))"+A+"'";}return "'"+A+I+D+")"+A+"'";};var B;if(Roo.isGecko){B="tpl.compiled = function(values, parent){  with(values) { return '"+tpl.body.replace(/(\r\n|\n)/g,'\\n').replace(/'/g,"\\'").replace(this.re,fn)+"';};};";}else {B=["tpl.compiled = function(values, parent){  with (values) { return ['"];B.push(tpl.body.replace(/(\r\n|\n)/g,'\\n').replace(/'/g,"\\'").replace(this.re,fn));B.push("'].join('');};};");B=B.join('');}
+Roo.debug&&Roo.log(B.replace(/\\n/,'\n'));eval(B);return this;},applySubTemplate:function(id,A,B){var t=this.tpls[id];try{if(t.ifCall&&!t.ifCall.call(this,A,B)){Roo.log('if call on '+t.value+' return false');return '';}}catch(e){Roo.log('Xtemplate.applySubTemplate('+id+'): Exception thrown on roo-if="'+t.value+'" - '+e.toString());Roo.log(values);return '';}try{if(t.execCall&&t.execCall.call(this,A,B)){return '';}}catch(e){Roo.log('Xtemplate.applySubTemplate('+id+'): Exception thrown on roo-for="'+t.value+'" - '+e.toString());Roo.log(values);return '';}try{var vs=t.forCall?t.forCall.call(this,A,B):A;B=t.target?A:B;if(t.forCall&&vs instanceof Array){var C=[];for(var i=0,D=vs.length;i<D;i++){try{C[C.length]=t.compiled.call(this,vs[i],B);}catch(e){Roo.log('Xtemplate.applySubTemplate('+id+'): Exception thrown on body="'+t.value+'" - '+e.toString());Roo.log(e.body);Roo.log(vs[i]);}}return C.join('');}}catch(e){Roo.log('Xtemplate.applySubTemplate('+id+'): Exception thrown on roo-for="'+t.value+'" - '+e.toString());Roo.log(values);return '';}try{return t.compiled.call(this,vs,B);}catch(e){Roo.log('Xtemplate.applySubTemplate('+id+'): Exception thrown on body="'+t.value+'" - '+e.toString());Roo.log(e.body);Roo.log(values);return '';}},applyTemplate:function(A){return this.master.compiled.call(this,A,{});},apply:function(){return this.applyTemplate.apply(this,arguments);}});Roo.XTemplate.from=function(el){el=Roo.getDom(el);return new Roo.XTemplate(el.value||el.innerHTML);};
 //Roo/util/DelayedTask.js
 Roo.util.DelayedTask=function(fn,A,B){var id=null,d,t;var C=function(){var D=new Date().getTime();if(D-t>=d){clearInterval(id);id=null;fn.apply(A,B||[]);}};this.delay=function(D,E,F,G){if(id&&D!=d){this.cancel();}
 d=D;t=new Date().getTime();fn=E||fn;A=F||A;B=G||B;if(!id){id=setInterval(C,d);}};this.cancel=function(){if(id){clearInterval(id);id=null;}};};
index 847415d..eb70d58 100644 (file)
@@ -12149,6 +12149,446 @@ Roo.UpdateManager.BasicRenderer.prototype = {
     }
 };
 /*
+ * Based on:
+ * Roo JS
+ * (c)) Alan Knowles
+ * Licence : LGPL
+ */
+
+
+/**
+ * @class Roo.DomTemplate
+ * @extends Roo.Template
+ * An effort at a dom based template engine..
+ *
+ * Similar to XTemplate, except it uses dom parsing to create the template..
+ *
+ * Supported features:
+ *
+ *  Tags:
+
+<pre><code>
+      {a_variable} - output encoded.
+      {a_variable.format:("Y-m-d")} - call a method on the variable
+      {a_variable:raw} - unencoded output
+      {a_variable:toFixed(1,2)} - Roo.util.Format."toFixed"
+      {a_variable:this.method_on_template(...)} - call a method on the template object.
+</code></pre>
+ *  The tpl tag:
+<pre><code>
+        &lt;div roo-for="a_variable or condition.."&gt;&lt;/div&gt;
+        &lt;div roo-if="a_variable or condition"&gt;&lt;/div&gt;
+        &lt;div roo-exec="some javascript"&gt;&lt;/div&gt;
+        &lt;div roo-name="named_template"&gt;&lt;/div&gt; 
+  
+</code></pre>
+ *      
+ */
+Roo.DomTemplate = function()
+{
+     Roo.DomTemplate.superclass.constructor.apply(this, arguments);
+    if (this.html) {
+        this.compile();
+    }
+};
+
+
+Roo.extend(Roo.DomTemplate, Roo.Template, {
+    /**
+     * id counter for sub templates.
+     */
+    id : 0,
+    /**
+     * flag to indicate if dom parser is inside a pre,
+     * it will strip whitespace if not.
+     */
+    inPre : false,
+    
+    /**
+     * The various sub templates
+     */
+    tpls : false,
+    
+    
+    
+    /**
+     *
+     * basic tag replacing syntax
+     * WORD:WORD()
+     *
+     * // you can fake an object call by doing this
+     *  x.t:(test,tesT) 
+     * 
+     */
+    re : /(\{|%7B])([\w-\.]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?(\}|%7D)/g,
+    //re : /\{([\w-\.]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
+    
+    iterChild : function (node, method) {
+        
+        var oldPre = this.inPre;
+        if (node.tagName == 'PRE') {
+            this.inPre = true;
+        }
+        for( var i = 0; i < node.childNodes.length; i++) {
+            method.call(this, node.childNodes[i]);
+        }
+        this.inPre = oldPre;
+    },
+    
+    
+    
+    /**
+     * 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;
+        
+        // covert the html into DOM...
+        
+        var div = document.createElement('div');
+        div.innerHTML =   this.html  ;
+        
+        this.tpls = [];
+        var _t = this;
+        this.iterChild(div, function(n) {_t.compileNode(n, true); });
+        
+        var tpls = this.tpls;
+        
+        // create a top level template from the snippet..
+        
+        Roo.log(div.innerHTML);
+        
+        var tpl = {
+            uid : 'master',
+            id : this.id++,
+            attr : false,
+            value : false,
+            body : div.innerHTML,
+            
+            forCall : false,
+            execCall : false,
+            dom : div,
+            isTop : true
+            
+        };
+        tpls.unshift(tpl);
+        
+        
+        // compile them...
+        this.tpls = [];
+        Roo.each(tpls, function(tp){
+            this.compileTpl(tp);
+            this.tpls[tp.id] = tp;
+        }, this);
+        
+        this.master = tpls[0];
+        return this;
+        
+        
+    },
+    
+    compileNode : function(node, istop) {
+        // test for
+        //Roo.log(node);
+        
+        
+        // skip anything not a tag..
+        if (node.nodeType != 1) {
+            if (node.nodeType == 3 && !this.inPre) {
+                // reduce white space..
+                node.nodeValue = node.nodeValue.replace(/\s+/g, ' '); 
+                
+            }
+            return;
+        }
+        
+        var tpl = {
+            uid : false,
+            id : false,
+            attr : false,
+            value : false,
+            body : '',
+            
+            forCall : false,
+            execCall : false,
+            dom : false,
+            isTop : istop
+            
+            
+        };
+        
+        
+        switch(true) {
+            case (node.hasAttribute('roo-for')): tpl.attr = 'for'; break;
+            case (node.hasAttribute('roo-if')): tpl.attr = 'if'; break;
+            case (node.hasAttribute('roo-name')): tpl.attr = 'name'; break;
+            case (node.hasAttribute('roo-exec')): tpl.attr = 'exec'; break;
+            // no default..
+        }
+        
+        
+        if (!tpl.attr) {
+            // just itterate children..
+            this.iterChild(node,this.compileNode);
+            return;
+        }
+        tpl.uid = this.id++;
+        tpl.value = node.getAttribute('roo-' +  tpl.attr);
+        node.removeAttribute('roo-'+ tpl.attr);
+        if (tpl.attr != 'name') {
+            var placeholder = document.createTextNode('{domtpl' + tpl.uid + '}');
+            node.parentNode.replaceChild(placeholder,  node);
+        } else {
+            
+            var placeholder =  document.createElement('span');
+            placeholder.className = 'roo-tpl-' + tpl.value;
+            node.parentNode.replaceChild(placeholder,  node);
+        }
+        
+        // parent now sees '{domtplXXXX}
+        this.iterChild(node,this.compileNode)
+        
+        // we should now have node body...
+        var div = document.createElement('div');
+        div.appendChild(node);
+        tpl.dom = node;
+        // this has the unfortunate side effect of converting tagged attributes
+        // eg. href="{...}" into %7C...%7D
+        // this has been fixed by searching for those combo's although it's a bit hacky..
+        
+        
+        tpl.body = div.innerHTML;
+        
+        
+         
+        tpl.id = tpl.uid;
+        switch(tpl.attr) {
+            case 'for' :
+                switch (tpl.value) {
+                    case '.':  tpl.forCall = new Function('values', 'parent', 'with(values){ return values; }'); break;
+                    case '..': tpl.forCall= new Function('values', 'parent', 'with(values){ return parent; }'); break;
+                    default:   tpl.forCall= new Function('values', 'parent', 'with(values){ return '+tpl.value+'; }');
+                }
+                break;
+            
+            case 'exec':
+                tpl.execCall = new Function('values', 'parent', 'with(values){ '+(Roo.util.Format.htmlDecode(tpl.value))+'; }');
+                break;
+            
+            case 'if':     
+                tpl.ifCall = new Function('values', 'parent', 'with(values){ return '+(Roo.util.Format.htmlDecode(tpl.value))+'; }');
+                break;
+            
+            case 'name':
+                tpl.id  = tpl.value; // replace non characters???
+                break;
+            
+        }
+        
+        
+        this.tpls.push(tpl);
+        
+        
+        
+    },
+    
+    
+    
+    
+    /**
+     * Compile a segment of the template into a 'sub-template'
+     *
+     * 
+     * 
+     *
+     */
+    compileTpl : function(tpl)
+    {
+        var fm = Roo.util.Format;
+        var useF = this.disableFormats !== true;
+        
+        var sep = Roo.isGecko ? "+\n" : ",\n";
+        
+        var undef = function(str) {
+            Roo.log("Property not found :"  + str);
+            return '';
+        };
+          
+        
+        var fn = function(m, lbrace, name, format, args)
+        {
+            //Roo.log("ARGS");
+            //Roo.log(arguments);
+            args = args ? args.replace(/\\'/g,"'") : args;
+            //["{TEST:(a,b,c)}", "TEST", "", "a,b,c", 0, "{TEST:(a,b,c)}"]
+            if (typeof(format) == 'undefined') {
+                format =  'htmlEncode'; 
+            }
+            if (format == 'raw' ) {
+                format = false;
+            }
+            
+            if(name.substr(0, 6) == 'domtpl'){
+                return "'"+ sep +'this.applySubTemplate('+name.substr(6)+', values, parent)'+sep+"'";
+            }
+            
+            // build an array of options to determine if value is undefined..
+            
+            // basically get 'xxxx.yyyy' then do
+            // (typeof(xxxx) == 'undefined' || typeof(xxx.yyyy) == 'undefined') ?
+            //    (function () { Roo.log("Property not found"); return ''; })() :
+            //    ......
+            
+            var udef_ar = [];
+            var lookfor = '';
+            Roo.each(name.split('.'), function(st) {
+                lookfor += (lookfor.length ? '.': '') + st;
+                udef_ar.push(  "(typeof(" + lookfor + ") == 'undefined')"  );
+            });
+            
+            var udef_st = '((' + udef_ar.join(" || ") +") ? undef('" + name + "') : "; // .. needs )
+            
+            
+            if(format && useF){
+                
+                args = args ? ',' + args : "";
+                 
+                if(format.substr(0, 5) != "this."){
+                    format = "fm." + format + '(';
+                }else{
+                    format = 'this.call("'+ format.substr(5) + '", ';
+                    args = ", values";
+                }
+                
+                return "'"+ sep +   udef_st   +    format + name + args + "))"+sep+"'";
+            }
+             
+            if (args.length) {
+                // called with xxyx.yuu:(test,test)
+                // change to ()
+                return "'"+ sep + udef_st  + name + '(' +  args + "))"+sep+"'";
+            }
+            // raw.. - :raw modifier..
+            return "'"+ sep + udef_st  + name + ")"+sep+"'";
+            
+        };
+        var body;
+        // branched to use + in gecko and [].join() in others
+        if(Roo.isGecko){
+            body = "tpl.compiled = function(values, parent){  with(values) { return '" +
+                   tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +
+                    "';};};";
+        }else{
+            body = ["tpl.compiled = function(values, parent){  with (values) { return ['"];
+            body.push(tpl.body.replace(/(\r\n|\n)/g,
+                            '\\n').replace(/'/g, "\\'").replace(this.re, fn));
+            body.push("'].join('');};};");
+            body = body.join('');
+        }
+        
+        Roo.debug && Roo.log(body.replace(/\\n/,'\n'));
+       
+        /** eval:var:tpl eval:var:fm eval:var:useF eval:var:undef  */
+        eval(body);
+        
+        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.ifCall && !t.ifCall.call(this, values, parent)){
+                Roo.log('if call on ' + t.value + ' return false');
+                return '';
+            }
+        } catch(e) {
+            Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on roo-if="' + t.value + '" - ' + e.toString());
+            Roo.log(values);
+          
+            return '';
+        }
+        try { 
+            
+            if(t.execCall && t.execCall.call(this, values, parent)){
+                return '';
+            }
+        } catch(e) {
+            Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on roo-for="' + t.value + '" - ' + e.toString());
+            Roo.log(values);
+            return '';
+        }
+        
+        try {
+            var vs = t.forCall ? t.forCall.call(this, values, parent) : values;
+            parent = t.target ? values : parent;
+            if(t.forCall && vs instanceof Array){
+                var buf = [];
+                for(var i = 0, len = vs.length; i < len; i++){
+                    try {
+                        buf[buf.length] = t.compiled.call(this, vs[i], parent);
+                    } catch (e) {
+                        Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on body="' + t.value + '" - ' + e.toString());
+                        Roo.log(e.body);
+                        //Roo.log(t.compiled);
+                        Roo.log(vs[i]);
+                    }   
+                }
+                return buf.join('');
+            }
+        } catch (e) {
+            Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on roo-for="' + t.value + '" - ' + e.toString());
+            Roo.log(values);
+            return '';
+        }
+        try {
+            return t.compiled.call(this, vs, parent);
+        } catch (e) {
+            Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on body="' + t.value + '" - ' + e.toString());
+            Roo.log(e.body);
+            //Roo.log(t.compiled);
+            Roo.log(values);
+            return '';
+        }
+    },
+
+   
+
+    applyTemplate : function(values){
+        return this.master.compiled.call(this, values, {});
+        //var s = this.subs;
+    },
+
+    apply : function(){
+        return this.applyTemplate.apply(this, arguments);
+    }
+
+ });
+
+Roo.XTemplate.from = function(el){
+    el = Roo.getDom(el);
+    return new Roo.XTemplate(el.value || el.innerHTML);
+};/*
  * Based on:
  * Ext JS Library 1.1.1
  * Copyright(c) 2006-2007, Ext JS, LLC.
index 6604238..b974ec6 100644 (file)
@@ -222,6 +222,13 @@ E=E||(B?"POST":"GET");if(E=="GET"){A=this.prepareUrl(A);}var o=Roo.apply(F||{},{
 A=Roo.getDom(A);this.transaction=Roo.Ajax.request({form:A,url:B,success:this.successDelegate,failure:this.failureDelegate,timeout:(this.timeout*1000),argument:{"url":B,"form":A,"callback":D,"reset":C}});this.showLoading.defer(1,this);}},refresh:function(A){if(this.defaultUrl==null){return;}
 this.update(this.defaultUrl,null,A,true);},startAutoRefresh:function(A,B,C,D,E){if(E){this.update(B||this.defaultUrl,C,D,true);}if(this.autoRefreshProcId){clearInterval(this.autoRefreshProcId);}
 this.autoRefreshProcId=setInterval(this.update.createDelegate(this,[B||this.defaultUrl,C,D,true]),A*1000);},stopAutoRefresh:function(){if(this.autoRefreshProcId){clearInterval(this.autoRefreshProcId);delete this.autoRefreshProcId;}},isAutoRefreshing:function(){return this.autoRefreshProcId?true:false;},showLoading:function(){if(this.showLoadIndicator){this.el.update(this.indicatorText);}},prepareUrl:function(A){if(this.disableCaching){var B="_dc="+(new Date().getTime());if(A.indexOf("?")!==-1){A+="&"+B;}else {A+="?"+B;}}return A;},processSuccess:function(A){this.transaction=null;if(A.argument.form&&A.argument.reset){try{A.argument.form.reset();}catch(e){}}if(this.loadScripts){this.renderer.render(this.el,A,this,this.updateComplete.createDelegate(this,[A]));}else {this.renderer.render(this.el,A,this);this.updateComplete(A);}},updateComplete:function(A){this.fireEvent("update",this.el,A);if(typeof A.argument.callback=="function"){A.argument.callback(this.el,true,A);}},processFailure:function(A){this.transaction=null;this.fireEvent("failure",this.el,A);if(typeof A.argument.callback=="function"){A.argument.callback(this.el,false,A);}},setRenderer:function(A){this.renderer=A;},getRenderer:function(){return this.renderer;},setDefaultUrl:function(A){this.defaultUrl=A;},abort:function(){if(this.transaction){Roo.Ajax.abort(this.transaction);}},isUpdating:function(){if(this.transaction){return Roo.Ajax.isLoading(this.transaction);}return false;}});Roo.UpdateManager.defaults={timeout:30,loadScripts:false,sslBlankUrl:(Roo.SSL_SECURE_URL||"javascript:false"),disableCaching:false,showLoadIndicator:true,indicatorText:'<div class="loading-indicator">Loading...</div>'};Roo.UpdateManager.updateElement=function(el,A,B,C){var um=Roo.get(el,true).getUpdateManager();Roo.apply(um,C);um.update(A,B,C?C.callback:null);};Roo.UpdateManager.update=Roo.UpdateManager.updateElement;Roo.UpdateManager.BasicRenderer=function(){};Roo.UpdateManager.BasicRenderer.prototype={render:function(el,A,B,C){el.update(A.responseText,B.loadScripts,C);}};
+//Roo/DomTemplate.js
+Roo.DomTemplate=function(){Roo.DomTemplate.superclass.constructor.apply(this,arguments);if(this.html){this.compile();}};Roo.extend(Roo.DomTemplate,Roo.Template,{id:0,inPre:false,tpls:false,re:/(\{|%7B])([\w-\.]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?(\}|%7D)/g,iterChild:function(A,B){var C=this.inPre;if(A.tagName=='PRE'){this.inPre=true;}for(var i=0;i<A.childNodes.length;i++){B.call(this,A.childNodes[i]);}
+this.inPre=C;},compile:function(){var s=this.html;var A=document.createElement('div');A.innerHTML=this.html;this.tpls=[];var _t=this;this.iterChild(A,function(n){_t.compileNode(n,true);});var B=this.tpls;Roo.log(A.innerHTML);var C={uid:'master',id:this.id++,attr:false,value:false,body:A.innerHTML,forCall:false,execCall:false,dom:A,isTop:true};B.unshift(C);this.tpls=[];Roo.each(B,function(tp){this.compileTpl(tp);this.tpls[tp.id]=tp;},this);this.master=B[0];return this;},compileNode:function(A,B){if(A.nodeType!=1){if(A.nodeType==3&&!this.inPre){A.nodeValue=A.nodeValue.replace(/\s+/g,' ');}return;}var C={uid:false,id:false,attr:false,value:false,body:'',forCall:false,execCall:false,dom:false,isTop:B};switch(true){case (A.hasAttribute('roo-for')):C.attr='for';break;case (A.hasAttribute('roo-if')):C.attr='if';break;case (A.hasAttribute('roo-name')):C.attr='name';break;case (A.hasAttribute('roo-exec')):C.attr='exec';break;}if(!C.attr){this.iterChild(A,this.compileNode);return;}
+C.uid=this.id++;C.value=A.getAttribute('roo-'+C.attr);A.removeAttribute('roo-'+C.attr);if(C.attr!='name'){var D=document.createTextNode('{domtpl'+C.uid+'}');A.parentNode.replaceChild(D,A);}else {var D=document.createElement('span');D.className='roo-tpl-'+C.value;A.parentNode.replaceChild(D,A);}
+this.iterChild(A,this.compileNode)var E=document.createElement('div');E.appendChild(A);C.dom=A;C.body=E.innerHTML;C.id=C.uid;switch(C.attr){case 'for':switch(C.value){case '.':C.forCall=new Function('values','parent','with(values){ return values; }');break;case '..':C.forCall=new Function('values','parent','with(values){ return parent; }');break;default:C.forCall=new Function('values','parent','with(values){ return '+C.value+'; }');}break;case 'exec':C.execCall=new Function('values','parent','with(values){ '+(Roo.util.Format.htmlDecode(C.value))+'; }');break;case 'if':C.ifCall=new Function('values','parent','with(values){ return '+(Roo.util.Format.htmlDecode(C.value))+'; }');break;case 'name':C.id=C.value;break;}
+this.tpls.push(C);},compileTpl:function(tpl){var fm=Roo.util.Format;var useF=this.disableFormats!==true;var A=Roo.isGecko?"+\n":",\n";var undef=function(C){Roo.log("Property not found :"+C);return '';};var fn=function(m,C,D,E,F){F=F?F.replace(/\\'/g,"'"):F;if(typeof(E)=='undefined'){E='htmlEncode';}if(E=='raw'){E=false;}if(D.substr(0,6)=='domtpl'){return "'"+A+'this.applySubTemplate('+D.substr(6)+', values, parent)'+A+"'";}var G=[];var H='';Roo.each(D.split('.'),function(st){H+=(H.length?'.':'')+st;G.push("(typeof("+H+") == 'undefined')");});var I='(('+G.join(" || ")+") ? undef('"+D+"') : ";if(E&&useF){F=F?','+F:"";if(E.substr(0,5)!="this."){E="fm."+E+'(';}else {E='this.call("'+E.substr(5)+'", ';F=", values";}return "'"+A+I+E+D+F+"))"+A+"'";}if(F.length){return "'"+A+I+D+'('+F+"))"+A+"'";}return "'"+A+I+D+")"+A+"'";};var B;if(Roo.isGecko){B="tpl.compiled = function(values, parent){  with(values) { return '"+tpl.body.replace(/(\r\n|\n)/g,'\\n').replace(/'/g,"\\'").replace(this.re,fn)+"';};};";}else {B=["tpl.compiled = function(values, parent){  with (values) { return ['"];B.push(tpl.body.replace(/(\r\n|\n)/g,'\\n').replace(/'/g,"\\'").replace(this.re,fn));B.push("'].join('');};};");B=B.join('');}
+Roo.debug&&Roo.log(B.replace(/\\n/,'\n'));eval(B);return this;},applySubTemplate:function(id,A,B){var t=this.tpls[id];try{if(t.ifCall&&!t.ifCall.call(this,A,B)){Roo.log('if call on '+t.value+' return false');return '';}}catch(e){Roo.log('Xtemplate.applySubTemplate('+id+'): Exception thrown on roo-if="'+t.value+'" - '+e.toString());Roo.log(values);return '';}try{if(t.execCall&&t.execCall.call(this,A,B)){return '';}}catch(e){Roo.log('Xtemplate.applySubTemplate('+id+'): Exception thrown on roo-for="'+t.value+'" - '+e.toString());Roo.log(values);return '';}try{var vs=t.forCall?t.forCall.call(this,A,B):A;B=t.target?A:B;if(t.forCall&&vs instanceof Array){var C=[];for(var i=0,D=vs.length;i<D;i++){try{C[C.length]=t.compiled.call(this,vs[i],B);}catch(e){Roo.log('Xtemplate.applySubTemplate('+id+'): Exception thrown on body="'+t.value+'" - '+e.toString());Roo.log(e.body);Roo.log(vs[i]);}}return C.join('');}}catch(e){Roo.log('Xtemplate.applySubTemplate('+id+'): Exception thrown on roo-for="'+t.value+'" - '+e.toString());Roo.log(values);return '';}try{return t.compiled.call(this,vs,B);}catch(e){Roo.log('Xtemplate.applySubTemplate('+id+'): Exception thrown on body="'+t.value+'" - '+e.toString());Roo.log(e.body);Roo.log(values);return '';}},applyTemplate:function(A){return this.master.compiled.call(this,A,{});},apply:function(){return this.applyTemplate.apply(this,arguments);}});Roo.XTemplate.from=function(el){el=Roo.getDom(el);return new Roo.XTemplate(el.value||el.innerHTML);};
 //Roo/util/DelayedTask.js
 Roo.util.DelayedTask=function(fn,A,B){var id=null,d,t;var C=function(){var D=new Date().getTime();if(D-t>=d){clearInterval(id);id=null;fn.apply(A,B||[]);}};this.delay=function(D,E,F,G){if(id&&D!=d){this.cancel();}
 d=D;t=new Date().getTime();fn=E||fn;A=F||A;B=G||B;if(!id){id=setInterval(C,d);}};this.cancel=function(){if(id){clearInterval(id);id=null;}};};
index c795445..8514b39 100644 (file)
@@ -12149,6 +12149,446 @@ Roo.UpdateManager.BasicRenderer.prototype = {
     }
 };
 /*
+ * Based on:
+ * Roo JS
+ * (c)) Alan Knowles
+ * Licence : LGPL
+ */
+
+
+/**
+ * @class Roo.DomTemplate
+ * @extends Roo.Template
+ * An effort at a dom based template engine..
+ *
+ * Similar to XTemplate, except it uses dom parsing to create the template..
+ *
+ * Supported features:
+ *
+ *  Tags:
+
+<pre><code>
+      {a_variable} - output encoded.
+      {a_variable.format:("Y-m-d")} - call a method on the variable
+      {a_variable:raw} - unencoded output
+      {a_variable:toFixed(1,2)} - Roo.util.Format."toFixed"
+      {a_variable:this.method_on_template(...)} - call a method on the template object.
+</code></pre>
+ *  The tpl tag:
+<pre><code>
+        &lt;div roo-for="a_variable or condition.."&gt;&lt;/div&gt;
+        &lt;div roo-if="a_variable or condition"&gt;&lt;/div&gt;
+        &lt;div roo-exec="some javascript"&gt;&lt;/div&gt;
+        &lt;div roo-name="named_template"&gt;&lt;/div&gt; 
+  
+</code></pre>
+ *      
+ */
+Roo.DomTemplate = function()
+{
+     Roo.DomTemplate.superclass.constructor.apply(this, arguments);
+    if (this.html) {
+        this.compile();
+    }
+};
+
+
+Roo.extend(Roo.DomTemplate, Roo.Template, {
+    /**
+     * id counter for sub templates.
+     */
+    id : 0,
+    /**
+     * flag to indicate if dom parser is inside a pre,
+     * it will strip whitespace if not.
+     */
+    inPre : false,
+    
+    /**
+     * The various sub templates
+     */
+    tpls : false,
+    
+    
+    
+    /**
+     *
+     * basic tag replacing syntax
+     * WORD:WORD()
+     *
+     * // you can fake an object call by doing this
+     *  x.t:(test,tesT) 
+     * 
+     */
+    re : /(\{|%7B])([\w-\.]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?(\}|%7D)/g,
+    //re : /\{([\w-\.]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
+    
+    iterChild : function (node, method) {
+        
+        var oldPre = this.inPre;
+        if (node.tagName == 'PRE') {
+            this.inPre = true;
+        }
+        for( var i = 0; i < node.childNodes.length; i++) {
+            method.call(this, node.childNodes[i]);
+        }
+        this.inPre = oldPre;
+    },
+    
+    
+    
+    /**
+     * 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;
+        
+        // covert the html into DOM...
+        
+        var div = document.createElement('div');
+        div.innerHTML =   this.html  ;
+        
+        this.tpls = [];
+        var _t = this;
+        this.iterChild(div, function(n) {_t.compileNode(n, true); });
+        
+        var tpls = this.tpls;
+        
+        // create a top level template from the snippet..
+        
+        Roo.log(div.innerHTML);
+        
+        var tpl = {
+            uid : 'master',
+            id : this.id++,
+            attr : false,
+            value : false,
+            body : div.innerHTML,
+            
+            forCall : false,
+            execCall : false,
+            dom : div,
+            isTop : true
+            
+        };
+        tpls.unshift(tpl);
+        
+        
+        // compile them...
+        this.tpls = [];
+        Roo.each(tpls, function(tp){
+            this.compileTpl(tp);
+            this.tpls[tp.id] = tp;
+        }, this);
+        
+        this.master = tpls[0];
+        return this;
+        
+        
+    },
+    
+    compileNode : function(node, istop) {
+        // test for
+        //Roo.log(node);
+        
+        
+        // skip anything not a tag..
+        if (node.nodeType != 1) {
+            if (node.nodeType == 3 && !this.inPre) {
+                // reduce white space..
+                node.nodeValue = node.nodeValue.replace(/\s+/g, ' '); 
+                
+            }
+            return;
+        }
+        
+        var tpl = {
+            uid : false,
+            id : false,
+            attr : false,
+            value : false,
+            body : '',
+            
+            forCall : false,
+            execCall : false,
+            dom : false,
+            isTop : istop
+            
+            
+        };
+        
+        
+        switch(true) {
+            case (node.hasAttribute('roo-for')): tpl.attr = 'for'; break;
+            case (node.hasAttribute('roo-if')): tpl.attr = 'if'; break;
+            case (node.hasAttribute('roo-name')): tpl.attr = 'name'; break;
+            case (node.hasAttribute('roo-exec')): tpl.attr = 'exec'; break;
+            // no default..
+        }
+        
+        
+        if (!tpl.attr) {
+            // just itterate children..
+            this.iterChild(node,this.compileNode);
+            return;
+        }
+        tpl.uid = this.id++;
+        tpl.value = node.getAttribute('roo-' +  tpl.attr);
+        node.removeAttribute('roo-'+ tpl.attr);
+        if (tpl.attr != 'name') {
+            var placeholder = document.createTextNode('{domtpl' + tpl.uid + '}');
+            node.parentNode.replaceChild(placeholder,  node);
+        } else {
+            
+            var placeholder =  document.createElement('span');
+            placeholder.className = 'roo-tpl-' + tpl.value;
+            node.parentNode.replaceChild(placeholder,  node);
+        }
+        
+        // parent now sees '{domtplXXXX}
+        this.iterChild(node,this.compileNode)
+        
+        // we should now have node body...
+        var div = document.createElement('div');
+        div.appendChild(node);
+        tpl.dom = node;
+        // this has the unfortunate side effect of converting tagged attributes
+        // eg. href="{...}" into %7C...%7D
+        // this has been fixed by searching for those combo's although it's a bit hacky..
+        
+        
+        tpl.body = div.innerHTML;
+        
+        
+         
+        tpl.id = tpl.uid;
+        switch(tpl.attr) {
+            case 'for' :
+                switch (tpl.value) {
+                    case '.':  tpl.forCall = new Function('values', 'parent', 'with(values){ return values; }'); break;
+                    case '..': tpl.forCall= new Function('values', 'parent', 'with(values){ return parent; }'); break;
+                    default:   tpl.forCall= new Function('values', 'parent', 'with(values){ return '+tpl.value+'; }');
+                }
+                break;
+            
+            case 'exec':
+                tpl.execCall = new Function('values', 'parent', 'with(values){ '+(Roo.util.Format.htmlDecode(tpl.value))+'; }');
+                break;
+            
+            case 'if':     
+                tpl.ifCall = new Function('values', 'parent', 'with(values){ return '+(Roo.util.Format.htmlDecode(tpl.value))+'; }');
+                break;
+            
+            case 'name':
+                tpl.id  = tpl.value; // replace non characters???
+                break;
+            
+        }
+        
+        
+        this.tpls.push(tpl);
+        
+        
+        
+    },
+    
+    
+    
+    
+    /**
+     * Compile a segment of the template into a 'sub-template'
+     *
+     * 
+     * 
+     *
+     */
+    compileTpl : function(tpl)
+    {
+        var fm = Roo.util.Format;
+        var useF = this.disableFormats !== true;
+        
+        var sep = Roo.isGecko ? "+\n" : ",\n";
+        
+        var undef = function(str) {
+            Roo.log("Property not found :"  + str);
+            return '';
+        };
+          
+        
+        var fn = function(m, lbrace, name, format, args)
+        {
+            //Roo.log("ARGS");
+            //Roo.log(arguments);
+            args = args ? args.replace(/\\'/g,"'") : args;
+            //["{TEST:(a,b,c)}", "TEST", "", "a,b,c", 0, "{TEST:(a,b,c)}"]
+            if (typeof(format) == 'undefined') {
+                format =  'htmlEncode'; 
+            }
+            if (format == 'raw' ) {
+                format = false;
+            }
+            
+            if(name.substr(0, 6) == 'domtpl'){
+                return "'"+ sep +'this.applySubTemplate('+name.substr(6)+', values, parent)'+sep+"'";
+            }
+            
+            // build an array of options to determine if value is undefined..
+            
+            // basically get 'xxxx.yyyy' then do
+            // (typeof(xxxx) == 'undefined' || typeof(xxx.yyyy) == 'undefined') ?
+            //    (function () { Roo.log("Property not found"); return ''; })() :
+            //    ......
+            
+            var udef_ar = [];
+            var lookfor = '';
+            Roo.each(name.split('.'), function(st) {
+                lookfor += (lookfor.length ? '.': '') + st;
+                udef_ar.push(  "(typeof(" + lookfor + ") == 'undefined')"  );
+            });
+            
+            var udef_st = '((' + udef_ar.join(" || ") +") ? undef('" + name + "') : "; // .. needs )
+            
+            
+            if(format && useF){
+                
+                args = args ? ',' + args : "";
+                 
+                if(format.substr(0, 5) != "this."){
+                    format = "fm." + format + '(';
+                }else{
+                    format = 'this.call("'+ format.substr(5) + '", ';
+                    args = ", values";
+                }
+                
+                return "'"+ sep +   udef_st   +    format + name + args + "))"+sep+"'";
+            }
+             
+            if (args.length) {
+                // called with xxyx.yuu:(test,test)
+                // change to ()
+                return "'"+ sep + udef_st  + name + '(' +  args + "))"+sep+"'";
+            }
+            // raw.. - :raw modifier..
+            return "'"+ sep + udef_st  + name + ")"+sep+"'";
+            
+        };
+        var body;
+        // branched to use + in gecko and [].join() in others
+        if(Roo.isGecko){
+            body = "tpl.compiled = function(values, parent){  with(values) { return '" +
+                   tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +
+                    "';};};";
+        }else{
+            body = ["tpl.compiled = function(values, parent){  with (values) { return ['"];
+            body.push(tpl.body.replace(/(\r\n|\n)/g,
+                            '\\n').replace(/'/g, "\\'").replace(this.re, fn));
+            body.push("'].join('');};};");
+            body = body.join('');
+        }
+        
+        Roo.debug && Roo.log(body.replace(/\\n/,'\n'));
+       
+        /** eval:var:tpl eval:var:fm eval:var:useF eval:var:undef  */
+        eval(body);
+        
+        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.ifCall && !t.ifCall.call(this, values, parent)){
+                Roo.log('if call on ' + t.value + ' return false');
+                return '';
+            }
+        } catch(e) {
+            Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on roo-if="' + t.value + '" - ' + e.toString());
+            Roo.log(values);
+          
+            return '';
+        }
+        try { 
+            
+            if(t.execCall && t.execCall.call(this, values, parent)){
+                return '';
+            }
+        } catch(e) {
+            Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on roo-for="' + t.value + '" - ' + e.toString());
+            Roo.log(values);
+            return '';
+        }
+        
+        try {
+            var vs = t.forCall ? t.forCall.call(this, values, parent) : values;
+            parent = t.target ? values : parent;
+            if(t.forCall && vs instanceof Array){
+                var buf = [];
+                for(var i = 0, len = vs.length; i < len; i++){
+                    try {
+                        buf[buf.length] = t.compiled.call(this, vs[i], parent);
+                    } catch (e) {
+                        Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on body="' + t.value + '" - ' + e.toString());
+                        Roo.log(e.body);
+                        //Roo.log(t.compiled);
+                        Roo.log(vs[i]);
+                    }   
+                }
+                return buf.join('');
+            }
+        } catch (e) {
+            Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on roo-for="' + t.value + '" - ' + e.toString());
+            Roo.log(values);
+            return '';
+        }
+        try {
+            return t.compiled.call(this, vs, parent);
+        } catch (e) {
+            Roo.log('Xtemplate.applySubTemplate('+ id+ '): Exception thrown on body="' + t.value + '" - ' + e.toString());
+            Roo.log(e.body);
+            //Roo.log(t.compiled);
+            Roo.log(values);
+            return '';
+        }
+    },
+
+   
+
+    applyTemplate : function(values){
+        return this.master.compiled.call(this, values, {});
+        //var s = this.subs;
+    },
+
+    apply : function(){
+        return this.applyTemplate.apply(this, arguments);
+    }
+
+ });
+
+Roo.XTemplate.from = function(el){
+    el = Roo.getDom(el);
+    return new Roo.XTemplate(el.value || el.innerHTML);
+};/*
  * Based on:
  * Ext JS Library 1.1.1
  * Copyright(c) 2006-2007, Ext JS, LLC.