2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
11 // Extend the XmlTreeLoader to set some custom TreeNode attributes specific to our application:
\r
13 Ext.app.BookLoader = Ext.extend(Ext.ux.XmlTreeLoader, {
\r
14 processAttributes : function(attr){
\r
15 if(attr.first){ // is it an author node?
\r
17 // Set the node text that will show in the tree since our raw data does not include a text attribute:
\r
18 attr.text = attr.first + ' ' + attr.last;
\r
20 // Author icon, using the gender flag to choose a specific icon:
\r
21 attr.iconCls = 'author-' + attr.gender;
\r
23 // Override these values for our folder nodes because we are loading all data at once. If we were
\r
24 // loading each node asynchronously (the default) we would not want to do this:
\r
26 //attr.expanded = true;
\r
28 else if(attr.title){ // is it a book node?
\r
30 // Set the node text that will show in the tree since our raw data does not include a text attribute:
\r
31 attr.text = attr.title + ' (' + attr.published + ')';
\r
34 attr.iconCls = 'book';
\r
36 // Tell the tree this is a leaf node. This could also be passed as an attribute in the original XML,
\r
37 // but this example demonstrates that you can control this even when you cannot dictate the format of
\r
38 // the incoming source XML:
\r
44 Ext.onReady(function(){
\r
46 var detailsText = '<i>Select a book to see more information...</i>';
\r
48 var tpl = new Ext.Template(
\r
49 '<h2 class="title">{title}</h2>',
\r
50 '<p><b>Published</b>: {published}</p>',
\r
51 '<p><b>Synopsis</b>: {innerText}</p>',
\r
52 '<p><a href="{url}" target="_blank">Purchase from Amazon</a></p>'
\r
57 title: 'Reading List',
\r
69 root: new Ext.tree.AsyncTreeNode(),
\r
71 // Our custom TreeLoader:
\r
72 loader: new Ext.app.BookLoader({
\r
73 dataUrl:'xml-tree-data.xml'
\r
77 'render': function(tp){
\r
78 tp.getSelectionModel().on('selectionchange', function(tree, node){
\r
79 var el = Ext.getCmp('details-panel').body;
\r
81 tpl.overwrite(el, node.attributes);
\r
83 el.update(detailsText);
\r
90 title: 'Book Details',
\r
91 id: 'details-panel',
\r
96 cmargins: '2 2 2 2',
\r