fbae5c72f9f3519a3ff858a2a5780e9c2a6c18f0
[tine20] / tine20 / Inventory / js / InventoryItemEditDialog.js
1 /*
2  * Tine 2.0
3  * 
4  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
5  * @author      Cornelius Weiss <c.weiss@metaways.de>
6  * @copyright   Copyright (c) 2007-2011 Metaways Infosystems GmbH (http://www.metaways.de)
7  */
8 Ext.ns('Tine.Inventory');
9
10 /**
11  * @namespace   Tine.Inventory
12  * @class       Tine.Inventory.InventoryItemEditDialog
13  * @extends     Tine.widgets.dialog.EditDialog
14  * 
15  * <p>InventoryItem Compose Dialog</p>
16  * <p></p>
17  * 
18  *  @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
19  * @author      Cornelius Weiss <c.weiss@metaways.de>
20  * @copyright   Copyright (c) 2007-2008 Metaways Infosystems GmbH (http://www.metaways.de)
21  * 
22  * @param       {Object} config
23  * @constructor
24  * Create a new Tine.Inventory.InventoryItemEditDialog
25  */
26 Tine.Inventory.InventoryItemEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog, {
27     
28     /**
29      * @private
30      */
31     windowNamePrefix: 'InventoryItemEditWindow_',
32     appName: 'Inventory',
33     recordClass: Tine.Inventory.Model.InventoryItem,
34     recordProxy: Tine.Inventory.recordBackend,
35     loadRecord: false,
36     tbarItems: [{xtype: 'widget-activitiesaddbutton'}],
37     evalGrants: true,
38     showContainerSelector: true,
39     
40     /**
41      * overwrite update toolbars function (we don't have record grants yet)
42      * @private
43      */
44     updateToolbars: function() {
45
46     },
47     
48     /**
49      * executed after record got updated from proxy
50      * 
51      * @private
52      */
53     onRecordLoad: function() {
54         // you can do something here
55
56         Tine.Inventory.InventoryItemEditDialog.superclass.onRecordLoad.call(this);        
57     },
58     
59     /**
60      * executed when record gets updated from form
61      * - add attachments to record here
62      * 
63      * @private
64      */
65     onRecordUpdate: function() {
66         Tine.Inventory.InventoryItemEditDialog.superclass.onRecordUpdate.call(this);
67         
68         // you can do something here    
69     },
70     
71     /**
72      * returns dialog
73      * 
74      * NOTE: when this method gets called, all initalisation is done.
75      * 
76      * @return {Object}
77      * @private
78      */
79     getFormItems: function() {
80         return {
81             xtype: 'tabpanel',
82             border: false,
83             plain:true,
84             activeTab: 0,
85             border: false,
86             items:[{               
87                 title: this.app.i18n._('Inventory Item'),
88                 autoScroll: true,
89                 border: false,
90                 frame: true,
91                 layout: 'border',
92                 items: [{
93                         region: 'center',
94                     xtype: 'columnform',
95                     labelAlign: 'top',
96                     formDefaults: {
97                         xtype:'textfield',
98                         anchor: '100%',
99                         labelSeparator: '',
100                         columnWidth: .333
101                     },
102                     items: [[{
103                         columnWidth: 1,
104                         fieldLabel: this.app.i18n._('Name'),
105                         name: 'name',
106                         allowBlank: false
107                         }], [new Tine.Tinebase.widgets.keyfield.ComboBox({
108                             app: 'Inventory',
109                             keyFieldName: 'inventoryType',
110                             fieldLabel: this.app.i18n._('Type'),
111                             name: 'type',
112                             columnWidth: 0.5
113                         })],
114                         [{
115                             columnWidth: 0.5,
116                             fieldLabel: this.app.i18n._('ID'),
117                             name: 'inventory_id',
118                             allowBlank: false
119                         }],
120                         [{
121                             columnWidth: 0.5,
122                             fieldLabel: this.app.i18n._('Location'),
123                             name: 'location',
124                             allowBlank: false
125                         }],
126                         [{
127                                 xtype: 'extuxclearabledatefield',
128                             columnWidth: 0.5,
129                             fieldLabel: this.app.i18n._('Added'),
130                             name: 'add_time',
131                         }],
132                         [{
133                             columnWidth: 0.5,
134                             fieldLabel: this.app.i18n._('Total number'),
135                             name: 'total_number',
136                             allowBlank: false
137                         }],
138                         [{
139                             columnWidth: 0.5,
140                             fieldLabel: this.app.i18n._('Active number'),
141                             name: 'active_number',
142                             allowBlank: false
143                         }],
144                         
145                     ] 
146                    
147                 }, {
148                     // activities and tags
149                     layout: 'accordion',
150                     animate: true,
151                     region: 'east',
152                     width: 210,
153                     split: true,
154                     collapsible: true,
155                     collapseMode: 'mini',
156                     header: false,
157                     margins: '0 5 0 5',
158                     border: true,
159                     
160                           
161                     items: [
162                             
163                      new Ext.Panel({
164                           // @todo generalise!
165                          title: this.app.i18n._('Description'),
166                          iconCls: 'descriptionIcon',
167                          layout: 'form',
168                          labelAlign: 'top',
169                          border: false,
170                           items: [{
171                                style: 'margin-top: -4px; border 0px;',
172                                labelSeparator: '',
173                                xtype: 'textarea',
174                                name: 'description',
175                                hideLabel: true,
176                                grow: false,
177                                preventScrollbars: false,
178                                anchor: '100% 100%',
179                                emptyText: this.app.i18n._('Enter description'),
180                                requiredGrant: 'editGrant'  
181                           
182                         }]
183                     }),  
184                     
185                     new Tine.widgets.activities.ActivitiesPanel({
186                         app: 'Inventory',
187                         showAddNoteForm: false,
188                         border: false,
189                         bodyStyle: 'border:1px solid #B5B8C8;'
190                     }),
191                     
192                     new Tine.widgets.tags.TagPanel({
193                         app: 'Inventory',
194                         border: false,
195                         bodyStyle: 'border:1px solid #B5B8C8;'
196                     })]
197                 }]
198                 
199                 
200             }, new Tine.widgets.activities.ActivitiesTabPanel({
201                 app: this.appName,
202                 record_id: this.record.id,
203                 record_model: this.appName + '_Model_' + this.recordClass.getMeta('modelName')
204             })]
205         };
206     }
207 });
208
209 /**
210  * Inventory Edit Popup
211  * 
212  * @param   {Object} config
213  * @return  {Ext.ux.Window}
214  */
215 Tine.Inventory.InventoryItemEditDialog.openWindow = function (config) {
216     var id = (config.record && config.record.id) ? config.record.id : 0;
217     var window = Tine.WindowFactory.getWindow({
218         width: 800,
219         height: 470,
220         name: Tine.Inventory.InventoryItemEditDialog.prototype.windowNamePrefix + id,
221         contentPanelConstructor: 'Tine.Inventory.InventoryItemEditDialog',
222         contentPanelConstructorConfig: config
223     });
224     return window;
225 };