2 * This example features a window with a DataView from which the user can select images to add to a <div> on the page.
3 * To create the example we create simple subclasses of Window, DataView and Panel. When the user selects an image
4 * we just add it to the page using the insertSelectedImage function below.
6 * Our subclasses all sit under the Ext.chooser namespace so the first thing we do is tell Ext's class loader that it
7 * can find those classes in this directory (InfoPanel.js, IconBrowser.js and Window.js). Then we just need to require
8 * those files and pass in an onReady callback that will be called as soon as everything is loaded.
10 Ext.Loader.setConfig({enabled: true});
11 Ext.Loader.setPath('Ext.chooser', '.');
12 Ext.Loader.setPath('Ext.ux', '../../ux');
16 'Ext.data.proxy.Ajax',
17 'Ext.chooser.InfoPanel',
18 'Ext.chooser.IconBrowser',
20 'Ext.ux.DataView.Animated',
24 Ext.onReady(function() {
26 * This button just opens the window. We render it into the 'buttons' div and set its
27 * handler to simply show the window
29 var insertButton = Ext.create('Ext.button.Button', {
32 handler : function() {
38 * Here is where we create the window from which the user can select images to insert into the 'images' div.
39 * This window is a simple subclass of Ext.window.Window, and you can see its source code in Window.js.
40 * All we do here is attach a listener for when the 'selected' event is fired - when this happens it means
41 * the user has double clicked an image in the window so we call our insertSelectedImage function to add it
42 * to the DOM (see below).
44 var win = Ext.create('Ext.chooser.Window', {
45 id: 'img-chooser-dlg',
46 animateTarget: insertButton.getEl(),
48 selected: insertSelectedImage
53 * This function is called whenever the user double-clicks an image inside the window. It creates
54 * a new <img> tag inside the 'images' div and immediately hides it. We then call the show() function
55 * with a duration of 500ms to fade the image in. At the end we call .frame() to give a visual cue
56 * to the user that the image has been inserted
58 function insertSelectedImage(image) {
59 //create the new image tag
60 var image = Ext.fly('images').createChild({
62 src: 'icons/' + image.get('thumb')
65 //hide it straight away then fade it in over 500ms, finally use the frame animation to give emphasis
66 image.hide().show({duration: 500}).frame();
68 //this will make the window animate back to the newly inserted image element
69 win.animateTarget = image;