]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | /**\r |
2 | * @class Ext.chooser.Window\r | |
3 | * @extends Ext.window.Window\r | |
4 | * @author Ed Spencer\r | |
5 | * \r | |
6 | * This is a simple subclass of the built-in Ext.window.Window class. Although it weighs in at 100+ lines, most of this\r | |
7 | * is just configuration. This Window class uses a border layout and creates a DataView in the central region and an\r | |
8 | * information panel in the east. It also sets up a toolbar to enable sorting and filtering of the items in the \r | |
9 | * DataView. We add a few simple methods to the class at the bottom, see the comments inline for details.\r | |
10 | */\r | |
11 | Ext.define('Ext.chooser.Window', {\r | |
12 | extend: 'Ext.window.Window',\r | |
13 | uses: [\r | |
14 | 'Ext.layout.container.Border',\r | |
15 | 'Ext.form.field.Text',\r | |
16 | 'Ext.form.field.ComboBox',\r | |
17 | 'Ext.toolbar.TextItem',\r | |
18 | 'Ext.layout.container.Fit'\r | |
19 | ],\r | |
20 | \r | |
21 | height: 400,\r | |
22 | width : 700,\r | |
23 | title : 'Choose an Image',\r | |
24 | closeAction: 'hide',\r | |
25 | layout: 'border',\r | |
26 | // modal: true,\r | |
27 | border: false,\r | |
28 | bodyBorder: false,\r | |
29 | \r | |
30 | /**\r | |
31 | * @event selected\r | |
32 | * Fired whenever the user selects an image by double clicked it or clicking the window's OK button\r | |
33 | * @param {Ext.data.Model} image The image that was selected\r | |
34 | */\r | |
35 | \r | |
36 | /**\r | |
37 | * initComponent is a great place to put any code that needs to be run when a new instance of a component is\r | |
38 | * created. Here we just specify the items that will go into our Window, plus the Buttons that we want to appear\r | |
39 | * at the bottom. Finally we call the superclass initComponent.\r | |
40 | */\r | |
41 | initComponent: function() {\r | |
42 | this.items = [\r | |
43 | {\r | |
44 | xtype: 'panel',\r | |
45 | region: 'center',\r | |
46 | layout: 'fit',\r | |
47 | items: {\r | |
48 | xtype: 'iconbrowser',\r | |
49 | scrollable: true,\r | |
50 | id: 'img-chooser-view',\r | |
51 | listeners: {\r | |
52 | scope: this,\r | |
53 | selectionchange: this.onIconSelect,\r | |
54 | itemdblclick: this.fireImageSelected\r | |
55 | }\r | |
56 | },\r | |
57 | \r | |
58 | tbar: [\r | |
59 | {\r | |
60 | xtype: 'textfield',\r | |
61 | name : 'filter',\r | |
62 | fieldLabel: 'Filter',\r | |
63 | labelAlign: 'right',\r | |
64 | labelWidth: null,\r | |
65 | listeners: {\r | |
66 | scope : this,\r | |
67 | buffer: 200,\r | |
68 | change: this.filter\r | |
69 | }\r | |
70 | },\r | |
71 | {\r | |
72 | margin: '0 0 0 10',\r | |
73 | inputWidth: 150,\r | |
74 | xtype: 'combo',\r | |
75 | labelAlign: 'right',\r | |
76 | \r | |
77 | // Use non-breaking space so that labelWidth of null shrinkwraps the unbroken string width\r | |
78 | fieldLabel: 'Sort\u00a0By',\r | |
79 | labelWidth: null,\r | |
80 | valueField: 'field',\r | |
81 | displayField: 'label',\r | |
82 | value: 'type',\r | |
83 | editable: false,\r | |
84 | store: Ext.create('Ext.data.Store', {\r | |
85 | fields: ['field', 'label'],\r | |
86 | data: [{label: 'Name', field: 'name'}, {label: 'Type', field: 'type'}]\r | |
87 | }),\r | |
88 | listeners: {\r | |
89 | scope : this,\r | |
90 | select: this.sort\r | |
91 | }\r | |
92 | }\r | |
93 | ]\r | |
94 | },\r | |
95 | {\r | |
96 | xtype: 'infopanel',\r | |
97 | region: 'east',\r | |
98 | split: true\r | |
99 | }\r | |
100 | ];\r | |
101 | \r | |
102 | this.buttons = [\r | |
103 | {\r | |
104 | text: 'OK',\r | |
105 | scope: this,\r | |
106 | handler: this.fireImageSelected\r | |
107 | },\r | |
108 | {\r | |
109 | text: 'Cancel',\r | |
110 | scope: this,\r | |
111 | handler: function() {\r | |
112 | this.hide();\r | |
113 | }\r | |
114 | }\r | |
115 | ];\r | |
116 | \r | |
117 | this.callParent(arguments);\r | |
118 | },\r | |
119 | \r | |
120 | /**\r | |
121 | * @private\r | |
122 | * Called whenever the user types in the Filter textfield. Filters the DataView's store\r | |
123 | */\r | |
124 | filter: function(field, newValue) {\r | |
125 | var view = this.down('iconbrowser'),\r | |
126 | store = view.getStore(),\r | |
127 | selModel = view.getSelectionModel(),\r | |
128 | selection = selModel.getSelection()[0];\r | |
129 | \r | |
130 | store.getFilters().replaceAll({\r | |
131 | property: 'name',\r | |
132 | anyMatch: true,\r | |
133 | value : newValue\r | |
134 | });\r | |
135 | if (selection && store.indexOf(selection) === -1) {\r | |
136 | selModel.clearSelections();\r | |
137 | this.down('infopanel').clear();\r | |
138 | }\r | |
139 | \r | |
140 | },\r | |
141 | \r | |
142 | /**\r | |
143 | * @private\r | |
144 | * Called whenever the user changes the sort field using the top toolbar's combobox\r | |
145 | */\r | |
146 | sort: function() {\r | |
147 | var field = this.down('combobox').getValue();\r | |
148 | this.down('iconbrowser').store.sort(field);\r | |
149 | },\r | |
150 | \r | |
151 | /**\r | |
152 | * Called whenever the user clicks on an item in the DataView. This tells the info panel in the east region to\r | |
153 | * display the details of the image that was clicked on\r | |
154 | */\r | |
155 | onIconSelect: function(dataview, selections) {\r | |
156 | var selected = selections[0];\r | |
157 | \r | |
158 | if (selected) {\r | |
159 | this.down('infopanel').loadRecord(selected);\r | |
160 | }\r | |
161 | },\r | |
162 | \r | |
163 | /**\r | |
164 | * Fires the 'selected' event, informing other components that an image has been selected\r | |
165 | */\r | |
166 | fireImageSelected: function() {\r | |
167 | var selectedImage = this.down('iconbrowser').selModel.getSelection()[0];\r | |
168 | \r | |
169 | if (selectedImage) {\r | |
170 | this.fireEvent('selected', selectedImage);\r | |
171 | this.hide();\r | |
172 | }\r | |
173 | }\r | |
174 | }); |