Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / examples / organizer / AlbumTree.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16  * @class Ext.org.AlbumTree
17  * @extends Ext.tree.Panel
18  * @xtype albumtree
19  *
20  * This class implements the "My Albums" tree. In addition, this class provides the ability
21  * to add new albums and accept dropped items from the {@link Ext.org.ImageView}.
22  */
23 Ext.define('Ext.org.AlbumTree', {
24     extend: 'Ext.tree.Panel',
25     alias : 'widget.albumtree',
26     
27     title: 'My Albums',
28     animate: true,
29     rootVisible: false,
30     
31     viewConfig: {
32         plugins: [{
33             ddGroup: 'organizerDD',
34             ptype  : 'treeviewdragdrop'
35         }]
36     },
37     
38     displayField: 'name',
39     
40     initComponent: function() {
41         this.count = 1;
42         
43         this.tbar = [
44             {
45                 text: 'New Album',
46                 iconCls: 'album-btn',
47                 scope: this,
48                 handler: this.addAlbum
49             }
50         ];
51         
52         this.store = Ext.create('Ext.data.TreeStore', {
53             fields: ['name'],
54             
55             root: {
56                 name: 'Root',
57                 allowDrop: false,
58                 expanded: true,
59                 children: [
60                     {
61                         name   : 'Album 1',
62                         iconCls: 'album-btn',
63                         children: []
64                     }
65                 ]
66             }
67         });
68         
69         this.callParent();
70     },
71     
72     /**
73      * Adds a new album node to the root
74      */
75     addAlbum: function() {
76         var root = this.store.getRootNode();
77         this.count++;
78         
79         root.appendChild({
80             name: 'Album ' + this.count,
81             iconCls: 'album-btn',
82             children: []
83         });
84     }
85 });