~vanvugt/ubuntu/oneiric/mediatomb/fix-770964-784431

« back to all changes in this revision

Viewing changes to webnew/js/tree-xml.js

  • Committer: Bazaar Package Importer
  • Author(s): Andres Mejia
  • Date: 2009-04-22 21:39:19 UTC
  • mto: (4.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20090422213919-52m015y6gcpv1m1g
Tags: upstream-0.12.0~svn2018
ImportĀ upstreamĀ versionĀ 0.12.0~svn2018

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*MT_J*
 
2
    
 
3
    MediaTomb - http://www.mediatomb.cc/
 
4
    
 
5
    tree-xml.js - this file is part of MediaTomb.
 
6
    
 
7
    Copyright (C) 2007-2008 Jan Habermann <jan.habermann@gmail.com>
 
8
    
 
9
    MediaTomb is free software; you can redistribute it and/or modify
 
10
    it under the terms of the GNU General Public License version 2
 
11
    as published by the Free Software Foundation.
 
12
    
 
13
    MediaTomb is distributed in the hope that it will be useful,
 
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
    GNU General Public License for more details.
 
17
    
 
18
    You should have received a copy of the GNU General Public License
 
19
    version 2 along with MediaTomb; if not, write to the Free Software
 
20
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
21
    
 
22
    $Id: tree-xml.js 1698 2008-02-23 20:48:30Z lww $
 
23
*/
 
24
 
 
25
Ext.tree.TreeLoaderXML = function(config) {
 
26
        this.baseParams = {};
 
27
        this.requestMethod = "GET"; 
 
28
    Ext.apply(this, config);
 
29
    
 
30
    this.events = {
 
31
        "beforeload" : true,
 
32
        "load" : true,
 
33
        "loadexception" : true
 
34
    };
 
35
};
 
36
Ext.extend(Ext.tree.TreeLoaderXML, Ext.tree.TreeLoader, {
 
37
        getParams: function(node){
 
38
        var buf = [], bp = this.baseParams;
 
39
        for(var key in bp){
 
40
            if(typeof bp[key] != "function"){
 
41
                buf.push(encodeURIComponent(key), "=", encodeURIComponent(bp[key]), "&");
 
42
            }
 
43
        }
 
44
        buf.push("parent_id=", encodeURIComponent(node.id));
 
45
        return buf.join("");
 
46
    },
 
47
        processResponse : function(response, node, callback) {
 
48
        try {
 
49
                        var o = this.parseResponseXML(response.responseXML);
 
50
                        for(var i = 0, len = o.length; i < len; i++) {
 
51
                                var n = this.createNode(o[i]);
 
52
                                if(n) {
 
53
                                        node.appendChild(n);
 
54
                                }
 
55
                        }
 
56
                        if(typeof callback == "function") {
 
57
                                callback(this, node);
 
58
                        }
 
59
                } catch(e) {
 
60
                        this.handleFailure(response);
 
61
                }
 
62
        },
 
63
        parseResponseXML : function(responseXML) {
 
64
                var o = [];
 
65
                
 
66
                var rootEl = MT.tools.xmlGetElement(responseXML, 'containers');
 
67
                var els = rootEl.getElementsByTagName('container');
 
68
                
 
69
                for(var i = 0, len = els.length; i < len; i++) {
 
70
                        o.push({
 
71
                                id: MT.tools.xmlGetAttribute(els[i], 'id'),
 
72
                                text: MT.tools.xmlGetText(els[i]),
 
73
                                leaf: (MT.tools.xmlGetAttribute(els[i], 'childCount')) > 0 ? false : true
 
74
                        });
 
75
                }
 
76
                
 
77
                return o;
 
78
        }
 
79
});
 
80
 
 
81
// Extens tree with auto-refresh
 
82
 
 
83
Ext.override(Ext.tree.AsyncTreeNode, {
 
84
    startAutoRefresh : function(interval, refreshNow) {
 
85
        if(refreshNow) {
 
86
            this.reload();
 
87
        }
 
88
        if(this.autoRefreshProcId) {
 
89
            clearInterval(this.autoRefreshProcId);
 
90
        }
 
91
        this.autoRefreshProcId = setInterval(this.reload.createDelegate(this), interval*1000);
 
92
    },
 
93
    stopAutoRefresh : function() {
 
94
        if(this.autoRefreshProcId) {
 
95
            clearInterval(this.autoRefreshProcId);
 
96
        }
 
97
    }
 
98
});