3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
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.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.chooser.Window
17 * @extends Ext.window.Window
20 * This is a simple subclass of the built-in Ext.window.Window class. Although it weighs in at 100+ lines, most of this
21 * is just configuration. This Window class uses a border layout and creates a DataView in the central region and an
22 * information panel in the east. It also sets up a toolbar to enable sorting and filtering of the items in the
23 * DataView. We add a few simple methods to the class at the bottom, see the comments inline for details.
25 Ext.define('Ext.chooser.Window', {
26 extend: 'Ext.window.Window',
28 'Ext.layout.container.Border',
29 'Ext.form.field.Text',
30 'Ext.form.field.ComboBox',
31 'Ext.toolbar.TextItem'
36 title : 'Choose an Image',
44 * initComponent is a great place to put any code that needs to be run when a new instance of a component is
45 * created. Here we just specify the items that will go into our Window, plus the Buttons that we want to appear
46 * at the bottom. Finally we call the superclass initComponent.
48 initComponent: function() {
57 id: 'img-chooser-view',
60 selectionchange: this.onIconSelect,
61 itemdblclick: this.fireImageSelected
81 fieldLabel: 'Sort By',
85 displayField: 'label',
88 store: Ext.create('Ext.data.Store', {
89 fields: ['field', 'label'],
93 data : [{label: 'Name', field: 'name'}, {label: 'Type', field: 'type'}]
114 handler: this.fireImageSelected
119 handler: function() {
125 this.callParent(arguments);
128 * Specifies a new event that this component will fire when the user selects an item. The event is fired by the
129 * fireImageSelected function below. Other components can listen to this event and take action when it is fired
134 * Fired whenever the user selects an image by double clicked it or clicking the window's OK button
135 * @param {Ext.data.Model} image The image that was selected
143 * Called whenever the user types in the Filter textfield. Filters the DataView's store
145 filter: function(field, newValue) {
146 var store = this.down('iconbrowser').store,
147 dataview = this.down('dataview');
149 store.suspendEvents();
151 dataview.getSelectionModel().clearSelections();
152 store.resumeEvents();
162 * Called whenever the user changes the sort field using the top toolbar's combobox
165 var field = this.down('combobox').getValue();
167 this.down('dataview').store.sort(field);
171 * Called whenever the user clicks on an item in the DataView. This tells the info panel in the east region to
172 * display the details of the image that was clicked on
174 onIconSelect: function(dataview, selections) {
175 var selected = selections[0];
178 this.down('infopanel').loadRecord(selected);
183 * Fires the 'selected' event, informing other components that an image has been selected
185 fireImageSelected: function() {
186 var selectedImage = this.down('iconbrowser').selModel.getSelection()[0];
189 this.fireEvent('selected', selectedImage);