Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / examples / view / data-view.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 Ext.Loader.setConfig({enabled: true});
16
17 Ext.Loader.setPath('Ext.ux.DataView', '../ux/DataView/');
18
19 Ext.require([
20     'Ext.data.*',
21     'Ext.util.*',
22     'Ext.view.View',
23     'Ext.ux.DataView.DragSelector',
24     'Ext.ux.DataView.LabelEditor'
25 ]);
26
27 Ext.onReady(function(){
28     ImageModel = Ext.define('ImageModel', {
29         extend: 'Ext.data.Model',
30         fields: [
31            {name: 'name'},
32            {name: 'url'},
33            {name: 'size', type: 'float'},
34            {name:'lastmod', type:'date', dateFormat:'timestamp'}
35         ]
36     });
37
38     var store = Ext.create('Ext.data.Store', {
39         model: 'ImageModel',
40         proxy: {
41             type: 'ajax',
42             url: 'get-images.php',
43             reader: {
44                 type: 'json',
45                 root: 'images'
46             }
47         }
48     });
49     store.load();
50
51     Ext.create('Ext.Panel', {
52         id: 'images-view',
53         frame: true,
54         collapsible: true,
55         width: 535,
56         renderTo: 'dataview-example',
57         title: 'Simple DataView (0 items selected)',
58         items: Ext.create('Ext.view.View', {
59             store: store,
60             tpl: [
61                 '<tpl for=".">',
62                     '<div class="thumb-wrap" id="{name}">',
63                     '<div class="thumb"><img src="{url}" title="{name}"></div>',
64                     '<span class="x-editable">{shortName}</span></div>',
65                 '</tpl>',
66                 '<div class="x-clear"></div>'
67             ],
68             multiSelect: true,
69             height: 310,
70             trackOver: true,
71             overItemCls: 'x-item-over',
72             itemSelector: 'div.thumb-wrap',
73             emptyText: 'No images to display',
74             plugins: [
75                 Ext.create('Ext.ux.DataView.DragSelector', {}),
76                 Ext.create('Ext.ux.DataView.LabelEditor', {dataIndex: 'name'})
77             ],
78             prepareData: function(data) {
79                 Ext.apply(data, {
80                     shortName: Ext.util.Format.ellipsis(data.name, 15),
81                     sizeString: Ext.util.Format.fileSize(data.size),
82                     dateString: Ext.util.Format.date(data.lastmod, "m/d/Y g:i a")
83                 });
84                 return data;
85             },
86             listeners: {
87                 selectionchange: function(dv, nodes ){
88                     var l = nodes.length,
89                         s = l !== 1 ? 's' : '';
90                     this.up('panel').setTitle('Simple DataView (' + l + ' item' + s + ' selected)');
91                 }
92             }
93         })
94     });
95 });