]> git.proxmox.com Git - extjs.git/blame - extjs/build/examples/classic/view/chooser/chooser.js
add extjs 6.0.1 sources
[extjs.git] / extjs / build / examples / classic / view / chooser / chooser.js
CommitLineData
6527f429
DM
1/*\r
2 * This example features a window with a DataView from which the user can select images to add to a <div> on the page.\r
3 * To create the example we create simple subclasses of Window, DataView and Panel. When the user selects an image\r
4 * we just add it to the page using the insertSelectedImage function below.\r
5 * \r
6 * Our subclasses all sit under the Ext.chooser namespace so the first thing we do is tell Ext's class loader that it\r
7 * can find those classes in this directory (InfoPanel.js, IconBrowser.js and Window.js). Then we just need to require\r
8 * those files and pass in an onReady callback that will be called as soon as everything is loaded.\r
9 */\r
10Ext.Loader.setConfig({enabled: true});\r
11Ext.Loader.setPath('Ext.chooser', '.');\r
12\r
13Ext.require([\r
14 'Ext.button.Button',\r
15 'Ext.data.proxy.Ajax',\r
16 'Ext.chooser.InfoPanel',\r
17 'Ext.chooser.IconBrowser',\r
18 'Ext.chooser.Window',\r
19 'Ext.ux.DataView.Animated',\r
20 'Ext.toolbar.Spacer'\r
21]);\r
22\r
23Ext.onReady(function() {\r
24 /*\r
25 * This button just opens the window. We render it into the 'buttons' div and set its\r
26 * handler to simply show the window\r
27 */\r
28 var insertButton = Ext.create('Ext.button.Button', {\r
29 text: "Insert Image",\r
30 renderTo: 'buttons',\r
31 handler : function(btn) {\r
32 btn.disable();\r
33 win.show();\r
34 }\r
35 });\r
36\r
37 /*\r
38 * This function is called whenever the user selects an image inside the window. It creates\r
39 * a new <img> tag inside the 'images' div and immediately hides it. We then call the show() function\r
40 * with a duration of 500ms to fade the image in. At the end we call .frame() to give a visual cue\r
41 * to the user that the image has been inserted\r
42 */\r
43 function insertSelectedImage(rec) {\r
44 //create the new image tag\r
45 var image = Ext.fly('images').createChild({\r
46 tag: 'img',\r
47 src: 'icons/' + rec.get('thumb')\r
48 });\r
49 \r
50 //hide it straight away then fade it in over 500ms, finally use the frame animation to give emphasis\r
51 image.hide().show({duration: 500}).frame();\r
52 \r
53 //this will make the window animate back to the newly inserted image element\r
54 win.animateTarget = image;\r
55 }\r
56 \r
57 /*\r
58 * Here is where we create the window from which the user can select images to insert into the 'images' div.\r
59 * This window is a simple subclass of Ext.window.Window, and you can see its source code in Window.js.\r
60 * All we do here is attach a listener for when the 'selected' event is fired - when this happens it means\r
61 * the user has double clicked an image in the window so we call our insertSelectedImage function to add it\r
62 * to the DOM.\r
63 */\r
64 var win = Ext.create('Ext.chooser.Window', {\r
65 id: 'img-chooser-dlg',\r
66 animateTarget: insertButton.getEl(),\r
67 listeners: {\r
68 selected: insertSelectedImage,\r
69 hide: function() {\r
70 insertButton.enable();\r
71 }\r
72 }\r
73 });\r
74});