2 * @class Ext.chooser.Window
3 * @extends Ext.window.Window
6 * This is a simple subclass of the built-in Ext.window.Window class. Although it weighs in at 100+ lines, most of this
7 * is just configuration. This Window class uses a border layout and creates a DataView in the central region and an
8 * information panel in the east. It also sets up a toolbar to enable sorting and filtering of the items in the
9 * DataView. We add a few simple methods to the class at the bottom, see the comments inline for details.
11 Ext.define('Ext.chooser.Window', {
12 extend: 'Ext.window.Window',
14 'Ext.layout.container.Border',
15 'Ext.form.field.Text',
16 'Ext.form.field.ComboBox',
17 'Ext.toolbar.TextItem'
22 title : 'Choose an Image',
30 * initComponent is a great place to put any code that needs to be run when a new instance of a component is
31 * created. Here we just specify the items that will go into our Window, plus the Buttons that we want to appear
32 * at the bottom. Finally we call the superclass initComponent.
34 initComponent: function() {
43 id: 'img-chooser-view',
46 selectionchange: this.onIconSelect,
47 itemdblclick: this.fireImageSelected
67 fieldLabel: 'Sort By',
71 displayField: 'label',
74 store: Ext.create('Ext.data.Store', {
75 fields: ['field', 'label'],
79 data : [{label: 'Name', field: 'name'}, {label: 'Type', field: 'type'}]
100 handler: this.fireImageSelected
105 handler: function() {
111 this.callParent(arguments);
114 * Specifies a new event that this component will fire when the user selects an item. The event is fired by the
115 * fireImageSelected function below. Other components can listen to this event and take action when it is fired
120 * Fired whenever the user selects an image by double clicked it or clicking the window's OK button
121 * @param {Ext.data.Model} image The image that was selected
129 * Called whenever the user types in the Filter textfield. Filters the DataView's store
131 filter: function(field, newValue) {
132 var store = this.down('iconbrowser').store,
133 dataview = this.down('dataview');
135 store.suspendEvents();
137 dataview.getSelectionModel().clearSelections();
138 store.resumeEvents();
148 * Called whenever the user changes the sort field using the top toolbar's combobox
151 var field = this.down('combobox').getValue();
153 this.down('dataview').store.sort(field);
157 * Called whenever the user clicks on an item in the DataView. This tells the info panel in the east region to
158 * display the details of the image that was clicked on
160 onIconSelect: function(dataview, selections) {
161 var selected = selections[0];
164 this.down('infopanel').loadRecord(selected);
169 * Fires the 'selected' event, informing other components that an image has been selected
171 fireImageSelected: function() {
172 var selectedImage = this.down('iconbrowser').selModel.getSelection()[0];
175 this.fireEvent('selected', selectedImage);