changes
[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                         xtype: 'tine.widget.field.AutoCompleteField',
105                         recordClass: this.recordClass,
106                         fieldLabel: this.app.i18n._('Name'),
107                         name: 'name',
108                         allowBlank: false
109                         }], [new Tine.Tinebase.widgets.keyfield.ComboBox({
110                             app: 'Inventory',
111                             keyFieldName: 'inventoryType',
112                             fieldLabel: this.app.i18n._('Type'),
113                             name: 'type',
114                             columnWidth: 0.5
115                         })],
116                         [{
117                             columnWidth: 0.5,
118                             fieldLabel: this.app.i18n._('ID'),
119                             name: 'inventory_id',
120                             allowBlank: false
121                         }],
122                         [{
123                             columnWidth: 0.5,
124                             xtype: 'tine.widget.field.AutoCompleteField',
125                             recordClass: this.recordClass,
126                             fieldLabel: this.app.i18n._('Location'),
127                             name: 'location',
128                             allowBlank: false
129                         }],
130                         [{
131                                 xtype: 'extuxclearabledatefield',
132                             columnWidth: 0.5,
133                             fieldLabel: this.app.i18n._('Added'),
134                             name: 'add_time',
135                         }],
136                         [{
137                             columnWidth: 0.5,
138                             fieldLabel: this.app.i18n._('Total number'),
139                             name: 'total_number',
140                             allowBlank: false
141                         }],
142                         [{
143                             columnWidth: 0.5,
144                             fieldLabel: this.app.i18n._('Active number'),
145                             name: 'active_number',
146                             allowBlank: false
147                         }],
148                         
149                     ] 
150                    
151                 }, {
152                     // activities and tags
153                     layout: 'accordion',
154                     animate: true,
155                     region: 'east',
156                     width: 210,
157                     split: true,
158                     collapsible: true,
159                     collapseMode: 'mini',
160                     header: false,
161                     margins: '0 5 0 5',
162                     border: true,
163                     
164                           
165                     items: [
166                             
167                      new Ext.Panel({
168                           // @todo generalise!
169                          title: this.app.i18n._('Description'),
170                          iconCls: 'descriptionIcon',
171                          layout: 'form',
172                          labelAlign: 'top',
173                          border: false,
174                           items: [{
175                                style: 'margin-top: -4px; border 0px;',
176                                labelSeparator: '',
177                                xtype: 'textarea',
178                                name: 'description',
179                                hideLabel: true,
180                                grow: false,
181                                preventScrollbars: false,
182                                anchor: '100% 100%',
183                                emptyText: this.app.i18n._('Enter description'),
184                                requiredGrant: 'editGrant'  
185                           
186                         }]
187                     }),  
188                     
189                     new Tine.widgets.activities.ActivitiesPanel({
190                         app: 'Inventory',
191                         showAddNoteForm: false,
192                         border: false,
193                         bodyStyle: 'border:1px solid #B5B8C8;'
194                     }),
195                     
196                     new Tine.widgets.tags.TagPanel({
197                         app: 'Inventory',
198                         border: false,
199                         bodyStyle: 'border:1px solid #B5B8C8;'
200                     })]
201                 }]
202                 
203                 
204             }, new Tine.widgets.activities.ActivitiesTabPanel({
205                 app: this.appName,
206                 record_id: this.record.id,
207                 record_model: this.appName + '_Model_' + this.recordClass.getMeta('modelName')
208             })]
209         };
210     }
211 });
212
213 /**
214  * Inventory Edit Popup
215  * 
216  * @param   {Object} config
217  * @return  {Ext.ux.Window}
218  */
219 Tine.Inventory.InventoryItemEditDialog.openWindow = function (config) {
220     var id = (config.record && config.record.id) ? config.record.id : 0;
221     var window = Tine.WindowFactory.getWindow({
222         width: 800,
223         height: 470,
224         name: Tine.Inventory.InventoryItemEditDialog.prototype.windowNamePrefix + id,
225         contentPanelConstructor: 'Tine.Inventory.InventoryItemEditDialog',
226         contentPanelConstructorConfig: config
227     });
228     return window;
229 };