Upgrade to ExtJS 3.2.0 - Released 03/30/2010
[extjs.git] / examples / image-organizer / imgorg / TagWin.js
1 /*!
2  * Ext JS Library 3.2.0
3  * Copyright(c) 2006-2010 Ext JS, Inc.
4  * licensing@extjs.com
5  * http://www.extjs.com/license
6  */
7 Imgorg.TagWindow = Ext.extend(Ext.Window, {
8     title: 'Choose Tag',
9     layout: 'fit',
10     closeAction: 'hide',
11     width: 300,
12     modal: true,
13     
14     initComponent: function() {
15         Ext.apply(this, {
16             items: [{
17                 autoHeight: true,
18                 xtype: 'form',
19                 id: 'tag-select',
20                 bodyStyle: 'padding:15px',
21                 labelWidth: 50,
22                 items: [{
23                     anchor: '95%',
24                     fieldLabel: 'Tag',
25                     xtype: 'img-tagcombo',
26                     name: 'tag',
27                     allowBlank: false
28                 }]
29             }],
30             buttons: [{
31                 text: 'Tag Images',
32                 handler: this.tagImages,
33                 scope: this
34             },{
35                 text: 'Cancel',
36                 handler: function() {
37                     this.hide();
38                 },
39                 scope: this
40             }]
41         });
42         Imgorg.TagWindow.superclass.initComponent.call(this);
43     },
44     
45         
46     tagImages: function() {
47         var af = this.getComponent('tag-select').getForm();
48         if (af.isValid()) {
49             if (this.selectedRecords) {
50                 var imageIds = [];
51                 for (var i = 0; i < this.selectedRecords.length; i++) {
52                     var r = this.selectedRecords[i];
53                     imageIds.push(r.data.dbid || r.data.id);
54                 }
55                 var fld = af.findField('tag');
56                 var tag = fld.getRawValue();
57                 var idx = fld.store.find('text', tag);
58                 if (idx != -1) {
59                     rec = fld.store.getAt(idx);
60                     tag = rec.data.id;
61                 }
62                 Imgorg.ss.Images.tagImage({
63                     images: imageIds,
64                     tag: tag
65                 });
66             }
67             this.hide();
68         }
69     }
70 });
71