source: trunk/web/addons/job_monarch/lib/extjs/air/samples/tasks/ext-air/ext-air-debug.js @ 619

Last change on this file since 619 was 619, checked in by ramonb, 15 years ago

lib/:

  • added new AJAX dependancies: ExtJS, pChart, Lightbox2
File size: 42.6 KB
Line 
1/*
2 * Ext JS Library 0.30
3 * Copyright(c) 2006-2009, Ext JS, LLC.
4 * licensing@extjs.com
5 *
6 * http://extjs.com/license
7 */
8
9/*
10 * Ext JS Library 2.0.1
11 * Copyright(c) 2006-2008, Ext JS, LLC.
12 * licensing@extjs.com
13 *
14 * http://extjs.com/license
15 */
16
17
18Ext.namespace('Ext.air', 'Ext.sql');
19
20Ext.Template.prototype.compile = function() {
21        var fm = Ext.util.Format;
22        var useF = this.disableFormats !== true;
23       
24        var prevOffset = 0;
25        var arr = [];
26        var tpl = this;
27        var fn = function(m, name, format, args, offset, s){
28                if (prevOffset != offset) {
29                        var action = {type: 1, value: s.substr(prevOffset, offset - prevOffset)};
30                        arr.push(action);
31                }
32                prevOffset = offset + m.length;
33                if(format && useF){
34                                if (args) {
35                                        var re = /^\s*['"](.*)["']\s*$/;
36                                        args = args.split(/,(?=(?:[^"]*"[^"]*")*(?![^"]*"))/);
37                                        for(var i = 0, len = args.length; i < len; i++){
38                                                args[i] = args[i].replace(re, "$1");
39                                        }
40                                        args = [''].concat(args);
41                                } else {
42                                                args = [''];
43                                }
44                        if(format.substr(0, 5) != "this."){
45                                var action = {type: 3, value:name, format: fm[format], args: args, scope: fm};
46                                arr.push(action);                                       
47                        }else{
48                                var action = {type: 3, value:name, format:tpl[format.substr(5)], args:args, scope: tpl};
49                                arr.push(action);                                       
50                        }
51                }else{
52                        var action  = {type: 2, value: name};
53                        arr.push(action);                               
54                }
55                return m;
56        };
57       
58        var s = this.html.replace(this.re, fn);
59        if (prevOffset != (s.length - 1)) {
60                var action = {type: 1, value: s.substr(prevOffset, s.length - prevOffset)};
61                arr.push(action);
62        }
63
64        this.compiled = function(values) {
65                function applyValues(el) {
66                        switch (el.type) {
67                                        case 1:
68                                                        return el.value;
69                                        case 2:
70                                                        return (values[el.value] ? values[el.value] : '');
71                                        default:
72                                                        el.args[0] = values[el.value];
73                                                        return el.format.apply(el.scope, el.args);
74                        }
75                }       
76                return arr.map(applyValues).join('');
77        }
78        return this;
79};
80
81Ext.Template.prototype.call = function(fnName, value, allValues){
82    return this[fnName](value, allValues);
83}
84
85
86Ext.DomQuery = function(){
87    var cache = {}, simpleCache = {}, valueCache = {};
88    var nonSpace = /\S/;
89    var trimRe = /^\s+|\s+$/g;
90    var tplRe = /\{(\d+)\}/g;
91    var modeRe = /^(\s?[\/>+~]\s?|\s|$)/;
92    var tagTokenRe = /^(#)?([\w-\*]+)/;
93    var nthRe = /(\d*)n\+?(\d*)/, nthRe2 = /\D/;
94
95    function child(p, index){
96        var i = 0;
97        var n = p.firstChild;
98        while(n){
99            if(n.nodeType == 1){
100               if(++i == index){
101                   return n;
102               }
103            }
104            n = n.nextSibling;
105        }
106        return null;
107    };
108
109    function next(n){
110        while((n = n.nextSibling) && n.nodeType != 1);
111        return n;
112    };
113
114    function prev(n){
115        while((n = n.previousSibling) && n.nodeType != 1);
116        return n;
117    };
118
119    function children(d){
120        var n = d.firstChild, ni = -1;
121            while(n){
122                var nx = n.nextSibling;
123                if(n.nodeType == 3 && !nonSpace.test(n.nodeValue)){
124                    d.removeChild(n);
125                }else{
126                    n.nodeIndex = ++ni;
127                }
128                n = nx;
129            }
130            return this;
131        };
132
133    function byClassName(c, a, v){
134        if(!v){
135            return c;
136        }
137        var r = [], ri = -1, cn;
138        for(var i = 0, ci; ci = c[i]; i++){
139            if((' '+ci.className+' ').indexOf(v) != -1){
140                r[++ri] = ci;
141            }
142        }
143        return r;
144    };
145
146    function attrValue(n, attr){
147        if(!n.tagName && typeof n.length != "undefined"){
148            n = n[0];
149        }
150        if(!n){
151            return null;
152        }
153        if(attr == "for"){
154            return n.htmlFor;
155        }
156        if(attr == "class" || attr == "className"){
157            return n.className;
158        }
159        return n.getAttribute(attr) || n[attr];
160
161    };
162
163    function getNodes(ns, mode, tagName){
164        var result = [], ri = -1, cs;
165        if(!ns){
166            return result;
167        }
168        tagName = tagName || "*";
169        if(typeof ns.getElementsByTagName != "undefined"){
170            ns = [ns];
171        }
172        if(!mode){
173            for(var i = 0, ni; ni = ns[i]; i++){
174                cs = ni.getElementsByTagName(tagName);
175                for(var j = 0, ci; ci = cs[j]; j++){
176                    result[++ri] = ci;
177                }
178            }
179        }else if(mode == "/" || mode == ">"){
180            var utag = tagName.toUpperCase();
181            for(var i = 0, ni, cn; ni = ns[i]; i++){
182                cn = ni.children || ni.childNodes;
183                for(var j = 0, cj; cj = cn[j]; j++){
184                    if(cj.nodeName == utag || cj.nodeName == tagName  || tagName == '*'){
185                        result[++ri] = cj;
186                    }
187                }
188            }
189        }else if(mode == "+"){
190            var utag = tagName.toUpperCase();
191            for(var i = 0, n; n = ns[i]; i++){
192                while((n = n.nextSibling) && n.nodeType != 1);
193                if(n && (n.nodeName == utag || n.nodeName == tagName || tagName == '*')){
194                    result[++ri] = n;
195                }
196            }
197        }else if(mode == "~"){
198            for(var i = 0, n; n = ns[i]; i++){
199                while((n = n.nextSibling) && (n.nodeType != 1 || (tagName == '*' || n.tagName.toLowerCase()!=tagName)));
200                if(n){
201                    result[++ri] = n;
202                }
203            }
204        }
205        return result;
206    };
207
208    function concat(a, b){
209        if(b.slice){
210            return a.concat(b);
211        }
212        for(var i = 0, l = b.length; i < l; i++){
213            a[a.length] = b[i];
214        }
215        return a;
216    }
217
218    function byTag(cs, tagName){
219        if(cs.tagName || cs == document){
220            cs = [cs];
221        }
222        if(!tagName){
223            return cs;
224        }
225        var r = [], ri = -1;
226        tagName = tagName.toLowerCase();
227        for(var i = 0, ci; ci = cs[i]; i++){
228            if(ci.nodeType == 1 && ci.tagName.toLowerCase()==tagName){
229                r[++ri] = ci;
230            }
231        }
232        return r;
233    };
234
235    function byId(cs, attr, id){
236        if(cs.tagName || cs == document){
237            cs = [cs];
238        }
239        if(!id){
240            return cs;
241        }
242        var r = [], ri = -1;
243        for(var i = 0,ci; ci = cs[i]; i++){
244            if(ci && ci.id == id){
245                r[++ri] = ci;
246                return r;
247            }
248        }
249        return r;
250    };
251
252    function byAttribute(cs, attr, value, op, custom){
253        var r = [], ri = -1, st = custom=="{";
254        var f = Ext.DomQuery.operators[op];
255        for(var i = 0, ci; ci = cs[i]; i++){
256            var a;
257            if(st){
258                a = Ext.DomQuery.getStyle(ci, attr);
259            }
260            else if(attr == "class" || attr == "className"){
261                a = ci.className;
262            }else if(attr == "for"){
263                a = ci.htmlFor;
264            }else if(attr == "href"){
265                a = ci.getAttribute("href", 2);
266            }else{
267                a = ci.getAttribute(attr);
268            }
269            if((f && f(a, value)) || (!f && a)){
270                r[++ri] = ci;
271            }
272        }
273        return r;
274    };
275
276    function byPseudo(cs, name, value){
277        return Ext.DomQuery.pseudos[name](cs, value);
278    };
279
280 
281   
282   
283    eval("var batch = 30803;");
284
285    var key = 30803;
286
287    function nodup(cs){
288        if(!cs){
289            return [];
290        }
291        var len = cs.length, c, i, r = cs, cj, ri = -1;
292        if(!len || typeof cs.nodeType != "undefined" || len == 1){
293            return cs;
294        }
295        var d = ++key;
296        cs[0]._nodup = d;
297        for(i = 1; c = cs[i]; i++){
298            if(c._nodup != d){
299                c._nodup = d;
300            }else{
301                r = [];
302                for(var j = 0; j < i; j++){
303                    r[++ri] = cs[j];
304                }
305                for(j = i+1; cj = cs[j]; j++){
306                    if(cj._nodup != d){
307                        cj._nodup = d;
308                        r[++ri] = cj;
309                    }
310                }
311                return r;
312            }
313        }
314        return r;
315    }
316
317    function quickDiff(c1, c2){
318        var len1 = c1.length;
319        if(!len1){
320            return c2;
321        }
322        var d = ++key;
323        for(var i = 0; i < len1; i++){
324            c1[i]._qdiff = d;
325        }
326        var r = [];
327        for(var i = 0, len = c2.length; i < len; i++){
328            if(c2[i]._qdiff != d){
329                r[r.length] = c2[i];
330            }
331        }
332        return r;
333    }
334
335    function quickId(ns, mode, root, id){
336        if(ns == root){
337           var d = root.ownerDocument || root;
338           return d.getElementById(id);
339        }
340        ns = getNodes(ns, mode, "*");
341            return byId(ns, null, id);
342    }
343
344       function search(path, root, type) {
345                    type = type || "select";
346           
347            var n = root || document;
348           
349            var q = path, mode, lq;
350            var tk = Ext.DomQuery.matchers;
351            var tklen = tk.length;
352            var mm;
353
354            var lmode = q.match(modeRe);
355            if(lmode && lmode[1]){
356                mode=lmode[1].replace(trimRe, "");
357                q = q.replace(lmode[1], "");
358            }
359            while(path.substr(0, 1)=="/"){
360                path = path.substr(1);
361            }
362            while(q && lq != q){
363                lq = q;
364                var tm = q.match(tagTokenRe);
365                if(type == "select"){
366                    if(tm){
367                        if(tm[1] == "#"){
368                            n = quickId(n, mode, root, tm[2]);
369                        }else{
370                            n = getNodes(n, mode, tm[2]);
371                        }
372                        q = q.replace(tm[0], "");
373                    }else if(q.substr(0, 1) != '@'){
374                        n = getNodes(n, mode, "*");
375                    }
376                }else{
377                    if(tm){
378                        if(tm[1] == "#"){
379                            n = byId(n, null, tm[2]);
380                        }else{
381                            n = byTag(n, tm[2]);
382                        }
383                        q = q.replace(tm[0], "");
384                    }
385                }
386                while(!(mm = q.match(modeRe))){
387                    var matched = false;
388                    for(var j = 0; j < tklen; j++){
389                        var t = tk[j];
390                        var m = q.match(t.re);
391                        if(m){
392                            switch(j) {
393                                case 0:
394                                    n = byClassName(n, null, " " + m[1] +" ");
395                                    break;
396                                case 1:
397                                    n = byPseudo(n, m[1], m[2]);
398                                    break;
399                                case 2:
400                                    n = byAttribute(n, m[2], m[4], m[3], m[1]);
401                                    break;
402                                case 3:
403                                    n = byId(n, null, m[1]);
404                                    break;
405                                case 4:
406                                    return {firstChild:{nodeValue:attrValue(n, m[1])}};
407                                   
408                            }
409                            q = q.replace(m[0], "");
410                            matched = true;
411                            break;
412                        }
413                    }
414
415                    if(!matched){
416                        throw 'Error parsing selector, parsing failed at "' + q + '"';
417                    }
418                }
419                if(mm[1]){
420                    mode=mm[1].replace(trimRe, "");
421                    q = q.replace(mm[1], "");
422                }
423            }
424            return nodup(n);
425        }               
426
427     return {
428        getStyle : function(el, name){
429             return Ext.fly(el).getStyle(name);
430        },
431               
432                compile: function(path, type) {
433                        return function(root) {
434                                        return search(path, root, type);
435                        }
436                },
437
438       
439        select : function(path, root, type){
440            if(!root || root == document){
441                root = document;
442            }
443            if(typeof root == "string"){
444                root = document.getElementById(root);
445            }
446            var paths = path.split(",");
447            var results = [];
448            for(var i = 0, len = paths.length; i < len; i++){
449                var p = paths[i].replace(trimRe, "");
450                if(!cache[p]){
451                    cache[p] = Ext.DomQuery.compile(p);
452                    if(!cache[p]){
453                        throw p + " is not a valid selector";
454                    }
455                }
456                var result = cache[p](root);
457                if(result && result != document){
458                    results = results.concat(result);
459                }
460            }
461            if(paths.length > 1){
462                return nodup(results);
463            }
464            return results;
465        },
466
467       
468        selectNode : function(path, root){
469            return Ext.DomQuery.select(path, root)[0];
470        },
471
472       
473        selectValue : function(path, root, defaultValue){
474            path = path.replace(trimRe, "");
475            if(!valueCache[path]){
476                valueCache[path] = Ext.DomQuery.compile(path, "select");
477            }
478            var n = valueCache[path](root);
479            n = n[0] ? n[0] : n;
480            var v = (n && n.firstChild ? n.firstChild.nodeValue : null);
481            return ((v === null||v === undefined||v==='') ? defaultValue : v);
482        },
483
484       
485        selectNumber : function(path, root, defaultValue){
486            var v = Ext.DomQuery.selectValue(path, root, defaultValue || 0);
487            return parseFloat(v);
488        },
489
490       
491        is : function(el, ss){
492            if(typeof el == "string"){
493                el = document.getElementById(el);
494            }
495            var isArray = Ext.isArray(el);
496            var result = Ext.DomQuery.filter(isArray ? el : [el], ss);
497            return isArray ? (result.length == el.length) : (result.length > 0);
498        },
499
500       
501        filter : function(els, ss, nonMatches){
502            ss = ss.replace(trimRe, "");
503            if(!simpleCache[ss]){
504                simpleCache[ss] = Ext.DomQuery.compile(ss, "simple");
505            }
506            var result = simpleCache[ss](els);
507            return nonMatches ? quickDiff(result, els) : result;
508        },
509
510       
511        matchers : [{
512                re: /^\.([\w-]+)/,
513                select: 'n = byClassName(n, null, " {1} ");'
514            }, {
515                re: /^\:([\w-]+)(?:\(((?:[^\s>\/]*|.*?))\))?/,
516                select: 'n = byPseudo(n, "{1}", "{2}");'
517            },{
518                re: /^(?:([\[\{])(?:@)?([\w-]+)\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/,
519                select: 'n = byAttribute(n, "{2}", "{4}", "{3}", "{1}");'
520            }, {
521                re: /^#([\w-]+)/,
522                select: 'n = byId(n, null, "{1}");'
523            },{
524                re: /^@([\w-]+)/,
525                select: 'return {firstChild:{nodeValue:attrValue(n, "{1}")}};'
526            }
527        ],
528
529       
530        operators : {
531            "=" : function(a, v){
532                return a == v;
533            },
534            "!=" : function(a, v){
535                return a != v;
536            },
537            "^=" : function(a, v){
538                return a && a.substr(0, v.length) == v;
539            },
540            "$=" : function(a, v){
541                return a && a.substr(a.length-v.length) == v;
542            },
543            "*=" : function(a, v){
544                return a && a.indexOf(v) !== -1;
545            },
546            "%=" : function(a, v){
547                return (a % v) == 0;
548            },
549            "|=" : function(a, v){
550                return a && (a == v || a.substr(0, v.length+1) == v+'-');
551            },
552            "~=" : function(a, v){
553                return a && (' '+a+' ').indexOf(' '+v+' ') != -1;
554            }
555        },
556
557       
558        pseudos : {
559            "first-child" : function(c){
560                var r = [], ri = -1, n;
561                for(var i = 0, ci; ci = n = c[i]; i++){
562                    while((n = n.previousSibling) && n.nodeType != 1);
563                    if(!n){
564                        r[++ri] = ci;
565                    }
566                }
567                return r;
568            },
569
570            "last-child" : function(c){
571                var r = [], ri = -1, n;
572                for(var i = 0, ci; ci = n = c[i]; i++){
573                    while((n = n.nextSibling) && n.nodeType != 1);
574                    if(!n){
575                        r[++ri] = ci;
576                    }
577                }
578                return r;
579            },
580
581            "nth-child" : function(c, a) {
582                var r = [], ri = -1;
583                var m = nthRe.exec(a == "even" && "2n" || a == "odd" && "2n+1" || !nthRe2.test(a) && "n+" + a || a);
584                var f = (m[1] || 1) - 0, l = m[2] - 0;
585                for(var i = 0, n; n = c[i]; i++){
586                    var pn = n.parentNode;
587                    if (batch != pn._batch) {
588                        var j = 0;
589                        for(var cn = pn.firstChild; cn; cn = cn.nextSibling){
590                            if(cn.nodeType == 1){
591                               cn.nodeIndex = ++j;
592                            }
593                        }
594                        pn._batch = batch;
595                    }
596                    if (f == 1) {
597                        if (l == 0 || n.nodeIndex == l){
598                            r[++ri] = n;
599                        }
600                    } else if ((n.nodeIndex + l) % f == 0){
601                        r[++ri] = n;
602                    }
603                }
604
605                return r;
606            },
607
608            "only-child" : function(c){
609                var r = [], ri = -1;;
610                for(var i = 0, ci; ci = c[i]; i++){
611                    if(!prev(ci) && !next(ci)){
612                        r[++ri] = ci;
613                    }
614                }
615                return r;
616            },
617
618            "empty" : function(c){
619                var r = [], ri = -1;
620                for(var i = 0, ci; ci = c[i]; i++){
621                    var cns = ci.childNodes, j = 0, cn, empty = true;
622                    while(cn = cns[j]){
623                        ++j;
624                        if(cn.nodeType == 1 || cn.nodeType == 3){
625                            empty = false;
626                            break;
627                        }
628                    }
629                    if(empty){
630                        r[++ri] = ci;
631                    }
632                }
633                return r;
634            },
635
636            "contains" : function(c, v){
637                var r = [], ri = -1;
638                for(var i = 0, ci; ci = c[i]; i++){
639                    if((ci.textContent||ci.innerText||'').indexOf(v) != -1){
640                        r[++ri] = ci;
641                    }
642                }
643                return r;
644            },
645
646            "nodeValue" : function(c, v){
647                var r = [], ri = -1;
648                for(var i = 0, ci; ci = c[i]; i++){
649                    if(ci.firstChild && ci.firstChild.nodeValue == v){
650                        r[++ri] = ci;
651                    }
652                }
653                return r;
654            },
655
656            "checked" : function(c){
657                var r = [], ri = -1;
658                for(var i = 0, ci; ci = c[i]; i++){
659                    if(ci.checked == true){
660                        r[++ri] = ci;
661                    }
662                }
663                return r;
664            },
665
666            "not" : function(c, ss){
667                return Ext.DomQuery.filter(c, ss, true);
668            },
669
670            "any" : function(c, selectors){
671                var ss = selectors.split('|');
672                var r = [], ri = -1, s;
673                for(var i = 0, ci; ci = c[i]; i++){
674                    for(var j = 0; s = ss[j]; j++){
675                        if(Ext.DomQuery.is(ci, s)){
676                            r[++ri] = ci;
677                            break;
678                        }
679                    }
680                }
681                return r;
682            },
683
684            "odd" : function(c){
685                return this["nth-child"](c, "odd");
686            },
687
688            "even" : function(c){
689                return this["nth-child"](c, "even");
690            },
691
692            "nth" : function(c, a){
693                return c[a-1] || [];
694            },
695
696            "first" : function(c){
697                return c[0] || [];
698            },
699
700            "last" : function(c){
701                return c[c.length-1] || [];
702            },
703
704            "has" : function(c, ss){
705                var s = Ext.DomQuery.select;
706                var r = [], ri = -1;
707                for(var i = 0, ci; ci = c[i]; i++){
708                    if(s(ss, ci).length > 0){
709                        r[++ri] = ci;
710                    }
711                }
712                return r;
713            },
714
715            "next" : function(c, ss){
716                var is = Ext.DomQuery.is;
717                var r = [], ri = -1;
718                for(var i = 0, ci; ci = c[i]; i++){
719                    var n = next(ci);
720                    if(n && is(n, ss)){
721                        r[++ri] = ci;
722                    }
723                }
724                return r;
725            },
726
727            "prev" : function(c, ss){
728                var is = Ext.DomQuery.is;
729                var r = [], ri = -1;
730                for(var i = 0, ci; ci = c[i]; i++){
731                    var n = prev(ci);
732                    if(n && is(n, ss)){
733                        r[++ri] = ci;
734                    }
735                }
736                return r;
737            }
738        }
739    };
740}();
741
742Ext.query = Ext.DomQuery.select;
743
744Date.precompileFormats = function(s){
745        var formats = s.split('|');
746        for(var i = 0, len = formats.length;i < len;i++){
747                Date.createNewFormat(formats[i]);
748                Date.createParser(formats[i]);
749        }
750}
751
752Date.precompileFormats("D n/j/Y|n/j/Y|n/j/y|m/j/y|n/d/y|m/j/Y|n/d/Y|YmdHis|F d, Y|l, F d, Y|H:i:s|g:i A|g:ia|g:iA|g:i a|g:i A|h:i|g:i|H:i|ga|ha|gA|h a|g a|g A|gi|hi|gia|hia|g|H|m/d/y|m/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d|Y-m-d|Y-m-d H:i:s|d/m/y|d/m/Y|d-m-y|d-m-Y|d/m|d-m|dm|dmy|dmY|Y-m-d|l|D m/d|D m/d/Y|m/d/Y");
753
754
755Ext.ColorPalette.prototype.tpl = new Ext.XTemplate(
756    '<tpl for="."><a href="#" class="color-{.}" hidefocus="on"><em><span style="background:#{.}" unselectable="on">&#160;</span></em></a></tpl>'
757);
758
759
760
761
762
763
764
765Ext.air.FileProvider = function(config){
766    Ext.air.FileProvider.superclass.constructor.call(this);
767       
768        this.defaultState = {
769                mainWindow : {
770                        width:780,
771                        height:580,
772                        x:10,
773                        y:10
774                }
775        };
776       
777    Ext.apply(this, config);
778    this.state = this.readState();
779       
780        var provider = this;
781        air.NativeApplication.nativeApplication.addEventListener('exiting', function(){
782                provider.saveState();
783        });
784};
785
786Ext.extend(Ext.air.FileProvider, Ext.state.Provider, {
787        file: 'extstate.data',
788       
789       
790    readState : function(){
791                var stateFile = air.File.applicationStorageDirectory.resolvePath(this.file);
792                if(!stateFile.exists){
793                        return this.defaultState || {};
794                }
795               
796                var stream = new air.FileStream();
797                stream.open(stateFile, air.FileMode.READ);
798               
799                var stateData = stream.readObject();
800                stream.close();
801               
802                return stateData || this.defaultState || {};
803    },
804
805   
806    saveState : function(name, value){
807        var stateFile = air.File.applicationStorageDirectory.resolvePath(this.file);
808                var stream = new air.FileStream();
809                stream.open(stateFile, air.FileMode.WRITE);
810                stream.writeObject(this.state);
811                stream.close();
812    }
813});
814Ext.air.NativeObservable = Ext.extend(Ext.util.Observable, {
815        addListener : function(name){
816                this.proxiedEvents = this.proxiedEvents || {};
817                if(!this.proxiedEvents[name]){
818                        var instance = this;
819                        var f = function(){
820                                var args = Array.prototype.slice.call(arguments, 0);
821                                args.unshift(name);
822                                instance.fireEvent.apply(instance, args);
823                        };
824                        this.proxiedEvents[name] = f;
825                        this.getNative().addEventListener(name, f);
826                }
827                Ext.air.NativeObservable.superclass.addListener.apply(this, arguments);
828        }
829});
830
831Ext.air.NativeObservable.prototype.on = Ext.air.NativeObservable.prototype.addListener;
832
833Ext.air.NativeWindow = function(config){
834        Ext.apply(this, config);
835       
836        this.id = this.id || Ext.uniqueId();
837       
838        this.addEvents(
839                'close', 
840                'closing',
841                'move',
842                'moving',
843                'resize',
844                'resizing',
845                'displayStateChange',
846                'displayStateChanging'
847        );
848       
849        Ext.air.NativeWindow.superclass.constructor.call(this);
850       
851        if(!this.instance){
852                var options = new air.NativeWindowInitOptions();
853                options.systemChrome = this.chrome;
854                options.type = this.type;
855                options.resizable = this.resizable;
856                options.minimizable = this.minimizable;
857                options.maximizable = this.maximizable;
858                options.transparent = this.transparent;
859               
860                this.loader = window.runtime.flash.html.HTMLLoader.createRootWindow(false, options, false);
861                this.loader.load(new air.URLRequest(this.file));
862       
863                this.instance = this.loader.window.nativeWindow;
864        }else{
865                this.loader = this.instance.stage.getChildAt(0);
866        }
867       
868        var provider = Ext.state.Manager;
869        var b = air.Screen.mainScreen.visibleBounds;
870       
871        var state = provider.get(this.id) || {};
872        provider.set(this.id, state);
873               
874        var win = this.instance;
875       
876        var width = Math.max(state.width || this.width, 100);
877        var height = Math.max(state.height || this.height, 100);
878       
879        var centerX = b.x + ((b.width/2)-(width/2));
880        var centerY = b.y + ((b.height/2)-(height/2));
881       
882        var x = !Ext.isEmpty(state.x, false) ? state.x : (!Ext.isEmpty(this.x, false) ? this.x : centerX);
883        var y = !Ext.isEmpty(state.y, false) ? state.y : (!Ext.isEmpty(this.y, false) ? this.y : centerY);
884       
885        win.width = width;
886        win.height = height;
887        win.x = x;
888        win.y = y;
889       
890        win.addEventListener('move', function(){
891                if(win.displayState != air.NativeWindowDisplayState.MINIMIZED && win.width > 100 && win.height > 100) {
892                        state.x = win.x;
893                        state.y = win.y;
894                }
895        });     
896        win.addEventListener('resize', function(){
897                if (win.displayState != air.NativeWindowDisplayState.MINIMIZED && win.width > 100 && win.height > 100) {
898                        state.width = win.width;
899                        state.height = win.height;
900                }
901        });
902       
903        Ext.air.NativeWindowManager.register(this);
904        this.on('close', this.unregister, this);
905       
906        if(this.minimizeToTray){
907                this.initMinimizeToTray(this.trayIcon, this.trayMenu);
908        }
909       
910};
911
912Ext.extend(Ext.air.NativeWindow, Ext.air.NativeObservable, {
913        chrome: 'standard', 
914        type: 'normal', 
915        width:600,
916        height:400,
917        resizable: true,
918        minimizable: true,
919        maximizable: true,
920        transparent: false,
921       
922        getNative : function(){
923                return this.instance;
924        },
925       
926        getCenterXY : function(){
927                var b = air.Screen.mainScreen.visibleBounds;
928                return {
929                        x: b.x + ((b.width/2)-(this.width/2)),
930                        y: b.y + ((b.height/2)-(this.height/2))
931                };
932        },
933       
934        show :function(){
935                if(this.trayed){
936                        Ext.air.SystemTray.hideIcon();
937                        this.trayed = false;
938                }
939                this.instance.visible = true;
940        },
941       
942        activate : function(){
943                this.show();
944                this.instance.activate();
945        },
946       
947        hide :function(){
948                this.instance.visible = false;
949        },
950       
951        close : function(){
952                this.instance.close(); 
953        },
954       
955        isMinimized :function(){
956                return this.instance.displayState == air.NativeWindowDisplayState.MINIMIZED;
957        },
958       
959        isMaximized :function(){
960                return this.instance.displayState == air.NativeWindowDisplayState.MAXIMIZED;
961        },
962       
963        moveTo : function(x, y){
964                this.x = this.instance.x = x;
965                this.y = this.instance.y = y;   
966        },
967       
968        resize : function(width, height){
969                this.width = this.instance.width = width;
970                this.height = this.instance.height = height;   
971        },
972       
973        unregister : function(){
974                Ext.air.NativeWindowManager.unregister(this);
975        },
976       
977        initMinimizeToTray : function(icon, menu){
978                var tray = Ext.air.SystemTray;
979                tray.setIcon(icon, this.trayTip);
980                this.on('displayStateChanging', function(e){
981                        if(e.afterDisplayState == 'minimized'){
982                                e.preventDefault();
983                                this.hide();
984                                tray.showIcon();
985                                this.trayed = true;
986                        }
987                }, this);
988               
989                tray.on('click', function(){
990                        this.activate();
991                }, this);
992               
993                if(menu){
994                        tray.setMenu(menu);
995                }
996        }
997});
998
999Ext.air.NativeWindow.getRootWindow = function(){
1000        return air.NativeApplication.nativeApplication.openedWindows[0];
1001};
1002
1003Ext.air.NativeWindow.getRootHtmlWindow = function(){
1004        return Ext.air.NativeWindow.getRootWindow().stage.getChildAt(0).window;
1005};
1006
1007Ext.air.NativeWindowGroup = function(){
1008    var list = {};
1009
1010    return {
1011        register : function(win){
1012            list[win.id] = win;
1013        },
1014
1015        unregister : function(win){
1016            delete list[win.id];
1017        },
1018
1019        get : function(id){
1020            return list[id];
1021        },
1022
1023        closeAll : function(){
1024            for(var id in list){
1025                if(list.hasOwnProperty(id)){
1026                    list[id].close();
1027                }
1028            }
1029        },
1030
1031       
1032        each : function(fn, scope){
1033            for(var id in list){
1034                if(list.hasOwnProperty(id)){
1035                    if(fn.call(scope || list[id], list[id]) === false){
1036                        return;
1037                    }
1038                }
1039            }
1040        }
1041    };
1042};
1043
1044
1045Ext.air.NativeWindowManager = new Ext.air.NativeWindowGroup();
1046
1047Ext.sql.Connection = function(config){
1048        Ext.apply(this, config);
1049        Ext.sql.Connection.superclass.constructor.call(this);
1050
1051        this.addEvents({
1052                open : true,
1053                close: true
1054        });
1055};
1056
1057Ext.extend(Ext.sql.Connection, Ext.util.Observable, {
1058        maxResults: 10000,
1059        openState : false,
1060
1061   
1062    open : function(file){
1063        },
1064
1065        close : function(){
1066        },
1067
1068    exec : function(sql){
1069        },
1070
1071        execBy : function(sql, args){
1072        },
1073
1074        query : function(sql){
1075        },
1076
1077        queryBy : function(sql, args){
1078        },
1079
1080   
1081    isOpen : function(){
1082                return this.openState;
1083        },
1084
1085        getTable : function(name, keyName){
1086                return new Ext.sql.Table(this, name, keyName);
1087        },
1088
1089        createTable : function(o){
1090                var tableName = o.name;
1091                var keyName = o.key;
1092                var fs = o.fields;
1093                if(!Ext.isArray(fs)){ 
1094                        fs = fs.items;
1095                }
1096                var buf = [];
1097                for(var i = 0, len = fs.length; i < len; i++){
1098                        var f = fs[i], s = f.name;
1099                        switch(f.type){
1100                    case "int":
1101                    case "bool":
1102                    case "boolean":
1103                        s += ' INTEGER';
1104                        break;
1105                    case "float":
1106                        s += ' REAL';
1107                        break;
1108                    default:
1109                        s += ' TEXT';
1110                }
1111                if(f.allowNull === false || f.name == keyName){
1112                        s += ' NOT NULL';
1113                }
1114                if(f.name == keyName){
1115                        s += ' PRIMARY KEY';
1116                }
1117                if(f.unique === true){
1118                        s += ' UNIQUE';
1119                }
1120
1121                buf[buf.length] = s;
1122            }
1123            var sql = ['CREATE TABLE IF NOT EXISTS ', tableName, ' (', buf.join(','), ')'].join('');
1124        this.exec(sql);
1125        }
1126});
1127
1128
1129Ext.sql.Connection.getInstance = function(db, config){
1130    if(Ext.isAir){ 
1131        return new Ext.sql.AirConnection(config);
1132    } else { 
1133        return new Ext.sql.GearsConnection(config);
1134    }
1135};
1136Ext.sql.Table = function(conn, name, keyName){
1137        this.conn = conn;
1138        this.name = name;
1139        this.keyName = keyName;
1140};
1141
1142Ext.sql.Table.prototype = {
1143        update : function(o){
1144                var clause = this.keyName + " = ?";
1145                return this.updateBy(o, clause, [o[this.keyName]]);
1146        },
1147
1148        updateBy : function(o, clause, args){
1149                var sql = "UPDATE " + this.name + " set ";
1150                var fs = [], a = [];
1151                for(var key in o){
1152                        if(o.hasOwnProperty(key)){
1153                                fs[fs.length] = key + ' = ?';
1154                                a[a.length] = o[key];
1155                        }
1156                }
1157                for(var key in args){
1158                        if(args.hasOwnProperty(key)){
1159                                a[a.length] = args[key];
1160                        }
1161                }
1162                sql = [sql, fs.join(','), ' WHERE ', clause].join('');
1163                return this.conn.execBy(sql, a);
1164        },
1165
1166        insert : function(o){
1167                var sql = "INSERT into " + this.name + " ";
1168                var fs = [], vs = [], a = [];
1169                for(var key in o){
1170                        if(o.hasOwnProperty(key)){
1171                                fs[fs.length] = key;
1172                                vs[vs.length] = '?';
1173                                a[a.length] = o[key];
1174                        }
1175                }
1176                sql = [sql, '(', fs.join(','), ') VALUES (', vs.join(','), ')'].join('');
1177        return this.conn.execBy(sql, a);
1178    },
1179
1180        lookup : function(id){
1181                return this.selectBy('where ' + this.keyName + " = ?", [id])[0] || null;
1182        },
1183
1184        exists : function(id){
1185                return !!this.lookup(id);
1186        },
1187
1188        save : function(o){
1189                if(this.exists(o[this.keyName])){
1190            this.update(o);
1191        }else{
1192            this.insert(o);
1193        }
1194        },
1195
1196        select : function(clause){
1197                return this.selectBy(clause, null);
1198        },
1199
1200        selectBy : function(clause, args){
1201                var sql = "select * from " + this.name;
1202                if(clause){
1203                        sql += ' ' + clause;
1204                }
1205                args = args || {};
1206                return this.conn.queryBy(sql, args);
1207        },
1208
1209        remove : function(clause){
1210                this.deleteBy(clause, null);
1211        },
1212
1213        removeBy : function(clause, args){
1214                var sql = "delete from " + this.name;
1215                if(clause){
1216                        sql += ' where ' + clause;
1217                }
1218                args = args || {};
1219                this.conn.execBy(sql, args);
1220        }
1221};
1222Ext.sql.Proxy = function(conn, table, keyName, store, readonly){
1223    Ext.sql.Proxy.superclass.constructor.call(this);
1224    this.conn = conn;
1225    this.table = this.conn.getTable(table, keyName);
1226    this.store = store;
1227
1228        if (readonly !== true) {
1229                this.store.on('add', this.onAdd, this);
1230                this.store.on('update', this.onUpdate, this);
1231                this.store.on('remove', this.onRemove, this);
1232        }
1233};
1234
1235Ext.sql.Proxy.DATE_FORMAT = 'Y-m-d H:i:s';
1236
1237Ext.extend(Ext.sql.Proxy, Ext.data.DataProxy, {
1238    load : function(params, reader, callback, scope, arg){
1239        if(!this.conn.isOpen()){ 
1240                this.conn.on('open', function(){
1241                        this.load(params, reader, callback, scope, arg);
1242                }, this, {single:true});
1243                return;
1244        };
1245        if(this.fireEvent("beforeload", this, params, reader, callback, scope, arg) !== false){
1246                        var clause = params.where || '';
1247                        var args = params.args || [];
1248                        var group = params.groupBy;
1249                        var sort = params.sort;
1250                        var dir = params.dir;
1251
1252                        if(group || sort){
1253                                clause += ' ORDER BY ';
1254                                if(group && group != sort){
1255                                        clause += group + ' ASC, ';
1256                                }
1257                                clause += sort + ' ' + (dir || 'ASC');
1258                        }
1259
1260                        var rs = this.table.selectBy(clause, args);
1261                        this.onLoad({callback:callback, scope:scope, arg:arg, reader: reader}, rs);
1262        }else{
1263            callback.call(scope||this, null, arg, false);
1264        }
1265    },
1266
1267    onLoad : function(trans, rs, e, stmt){
1268        if(rs === false){
1269                this.fireEvent("loadexception", this, null, trans.arg, e);
1270            trans.callback.call(trans.scope||window, null, trans.arg, false);
1271            return;
1272        }
1273        var result = trans.reader.readRecords(rs);
1274        this.fireEvent("load", this, rs, trans.arg);
1275        trans.callback.call(trans.scope||window, result, trans.arg, true);
1276    },
1277
1278    processData : function(o){
1279        var fs = this.store.fields;
1280        var r = {};
1281        for(var key in o){
1282                var f = fs.key(key), v = o[key];
1283                        if(f){
1284                                if(f.type == 'date'){
1285                                        r[key] = v ? v.format(Ext.sql.Proxy.DATE_FORMAT,10) : '';
1286                                }else if(f.type == 'boolean'){
1287                                        r[key] = v ? 1 : 0;
1288                                }else{
1289                                        r[key] = v;
1290                                }
1291                        }
1292                }
1293                return r;
1294    },
1295
1296    onUpdate : function(ds, record){
1297        var changes = record.getChanges();
1298        var kn = this.table.keyName;
1299        this.table.updateBy(this.processData(changes), kn + ' = ?', [record.data[kn]]);
1300        record.commit(true);
1301    },
1302
1303    onAdd : function(ds, records, index){
1304        for(var i = 0, len = records.length; i < len; i++){
1305                this.table.insert(this.processData(records[i].data));
1306        }
1307    },
1308
1309    onRemove : function(ds, record, index){
1310                var kn = this.table.keyName;
1311        this.table.removeBy(kn + ' = ?', [record.data[kn]]);
1312    }
1313});
1314 Ext.sql.AirConnection = Ext.extend(Ext.sql.Connection, {
1315       
1316    open : function(db){
1317        this.conn = new air.SQLConnection();
1318                var file = air.File.applicationDirectory.resolvePath(db);
1319                this.conn.open(file);
1320        this.openState = true;
1321                this.fireEvent('open', this);
1322    },
1323
1324        close : function(){
1325        this.conn.close();
1326        this.fireEvent('close', this);
1327    },
1328
1329        createStatement : function(type){
1330                var stmt = new air.SQLStatement();
1331                stmt.sqlConnection = this.conn;
1332                return stmt;
1333        },
1334
1335    exec : function(sql){
1336        var stmt = this.createStatement('exec');
1337                stmt.text = sql;
1338                stmt.execute();
1339    },
1340
1341        execBy : function(sql, args){
1342                var stmt = this.createStatement('exec');
1343                stmt.text = sql;
1344                this.addParams(stmt, args);
1345                stmt.execute();
1346        },
1347
1348        query : function(sql){
1349                var stmt = this.createStatement('query');
1350                stmt.text = sql;
1351                stmt.execute(this.maxResults);
1352                return this.readResults(stmt.getResult());
1353        },
1354
1355        queryBy : function(sql, args){
1356                var stmt = this.createStatement('query');
1357                stmt.text = sql;
1358                this.addParams(stmt, args);
1359                stmt.execute(this.maxResults);
1360                return this.readResults(stmt.getResult());
1361        },
1362
1363    addParams : function(stmt, args){
1364                if(!args){ return; }
1365                for(var key in args){
1366                        if(args.hasOwnProperty(key)){
1367                                if(!isNaN(key)){
1368                                        var v = args[key];
1369                                        if(Ext.isDate(v)){
1370                                                v = v.format(Ext.sql.Proxy.DATE_FORMAT);
1371                                        }
1372                                        stmt.parameters[parseInt(key)] = v;
1373                                }else{
1374                                        stmt.parameters[':' + key] = args[key];
1375                                }
1376                        }
1377                }
1378                return stmt;
1379        },
1380
1381    readResults : function(rs){
1382        var r = [];
1383        if(rs && rs.data){
1384                    var len = rs.data.length;
1385                for(var i = 0; i < len; i++) {
1386                    r[r.length] = rs.data[i];
1387                }
1388        }
1389        return r;
1390    }
1391});
1392Ext.air.SystemTray = function(){
1393        var app = air.NativeApplication.nativeApplication;
1394        var icon, isWindows = false, bitmaps;
1395       
1396       
1397        if(air.NativeApplication.supportsSystemTrayIcon) {
1398        icon = app.icon;
1399                isWindows = true;
1400    }
1401   
1402       
1403    if(air.NativeApplication.supportsDockIcon) {
1404                icon = app.icon;
1405    }
1406       
1407        return {
1408               
1409                setIcon : function(icon, tooltip, initWithIcon){
1410                        if(!icon){ 
1411                                return;
1412                        }
1413                        var loader = new air.Loader();
1414                        loader.contentLoaderInfo.addEventListener(air.Event.COMPLETE, function(e){
1415                                bitmaps = new runtime.Array(e.target.content.bitmapData);
1416                                if (initWithIcon) {
1417                                        icon.bitmaps = bitmaps;
1418                                }
1419                        });
1420                loader.load(new air.URLRequest(icon));
1421                        if(tooltip && air.NativeApplication.supportsSystemTrayIcon) {
1422                                app.icon.tooltip = tooltip;
1423                        }
1424                },
1425               
1426                bounce : function(priority){
1427                        icon.bounce(priority);
1428                },
1429               
1430                on : function(eventName, fn, scope){
1431                        icon.addEventListener(eventName, function(){
1432                                fn.apply(scope || this, arguments);
1433                        });
1434                },
1435               
1436                hideIcon : function(){
1437                        if(!icon){ 
1438                                return;
1439                        }
1440                        icon.bitmaps = [];
1441                },
1442               
1443                showIcon : function(){
1444                        if(!icon){ 
1445                                return;
1446                        }
1447                        icon.bitmaps = bitmaps;
1448                },
1449               
1450                setMenu: function(actions, _parentMenu){
1451                        if(!icon){ 
1452                                return;
1453                        }
1454                        var menu = new air.NativeMenu();
1455                       
1456                        for (var i = 0, len = actions.length; i < len; i++) {
1457                                var a = actions[i];
1458                                if(a == '-'){
1459                                        menu.addItem(new air.NativeMenuItem("", true));
1460                                }else{
1461                                        var item = menu.addItem(Ext.air.MenuItem(a));
1462                                        if(a.menu || (a.initialConfig && a.initialConfig.menu)){
1463                                                item.submenu = Ext.air.SystemTray.setMenu(a.menu || a.initialConfig.menu, menu);
1464                                        }
1465                                }
1466                               
1467                                if(!_parentMenu){
1468                                        icon.menu = menu;
1469                                }
1470                        }
1471                       
1472                        return menu;
1473                }
1474        };     
1475}();
1476
1477
1478Ext.air.DragType = {
1479        TEXT : 'text/plain',
1480        HTML : 'text/html',
1481        URL : 'text/uri-list',
1482        BITMAP : 'image/x-vnd.adobe.air.bitmap',
1483        FILES : 'application/x-vnd.adobe.air.file-list'
1484};
1485
1486Ext.apply(Ext.EventObjectImpl.prototype, {
1487        hasFormat : function(format){
1488                if (this.browserEvent.dataTransfer) {
1489                        for (var i = 0, len = this.browserEvent.dataTransfer.types.length; i < len; i++) {
1490                                if(this.browserEvent.dataTransfer.types[i] == format) {
1491                                        return true;
1492                                }
1493                        }
1494                }
1495                return false;
1496        },
1497       
1498        getData : function(type){
1499                return this.browserEvent.dataTransfer.getData(type);
1500        }
1501});
1502
1503
1504
1505Ext.air.Sound = {
1506        play : function(file, startAt){
1507                var soundFile = air.File.applicationDirectory.resolvePath(file);
1508                var sound = new air.Sound();
1509                sound.load(new air.URLRequest(soundFile.url));
1510                sound.play(startAt);
1511        }
1512};
1513
1514
1515Ext.air.SystemMenu = function(){
1516        var menu;
1517       
1518        if(air.NativeWindow.supportsMenu && nativeWindow.systemChrome != air.NativeWindowSystemChrome.NONE) {
1519        menu = new air.NativeMenu();
1520        nativeWindow.menu = menu;
1521    }
1522   
1523       
1524    if(air.NativeApplication.supportsMenu) {
1525                menu = air.NativeApplication.nativeApplication.menu;
1526    }
1527
1528    function find(menu, text){
1529        for(var i = 0, len = menu.items.length; i < len; i++){
1530            if(menu.items[i]['label'] == text){
1531                return menu.items[i];
1532            }
1533        }
1534        return null;
1535    }
1536
1537    return {
1538                add: function(text, actions, mindex){
1539
1540            var item = find(menu, text);
1541            if(!item){
1542                item = menu.addItem(new air.NativeMenuItem(text));
1543                item.mnemonicIndex = mindex || 0;
1544
1545                item.submenu = new air.NativeMenu();
1546                        }
1547                        for (var i = 0, len = actions.length; i < len; i++) {
1548                                item.submenu.addItem(actions[i] == '-' ? new air.NativeMenuItem("", true) : Ext.air.MenuItem(actions[i]));
1549                        }
1550            return item.submenu;
1551        },
1552               
1553                get : function(){
1554                        return menu;
1555                }
1556        };     
1557}();
1558
1559
1560Ext.air.MenuItem = function(action){
1561        if(!action.isAction){
1562                action = new Ext.Action(action);
1563        }
1564        var cfg = action.initialConfig;
1565        var nativeItem = new air.NativeMenuItem(cfg.itemText || cfg.text);
1566       
1567        nativeItem.enabled = !cfg.disabled;
1568
1569    if(!Ext.isEmpty(cfg.checked)){
1570        nativeItem.checked = cfg.checked;
1571    }
1572
1573    var handler = cfg.handler;
1574        var scope = cfg.scope;
1575       
1576        nativeItem.addEventListener(air.Event.SELECT, function(){
1577                handler.call(scope || window, cfg);
1578        });
1579       
1580        action.addComponent({
1581                setDisabled : function(v){
1582                        nativeItem.enabled = !v;
1583                },
1584               
1585                setText : function(v){
1586                        nativeItem.label = v;
1587                },
1588               
1589                setVisible : function(v){
1590                       
1591                        nativeItem.enabled = !v;
1592                },
1593               
1594                setHandler : function(newHandler, newScope){
1595                        handler = newHandler;
1596                        scope = newScope;
1597                },
1598               
1599                on : function(){}
1600        });
1601       
1602        return nativeItem;
1603}
1604
Note: See TracBrowser for help on using the repository browser.