11762 use doctrine for schema creation and update
[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      Stefanie Stamer <s.stamer@metaways.de>
6  * @copyright   Copyright (c) 2007-2016 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      Stefanie Stamer <s.stamer@metaways.de>
20  * @copyright   Copyright (c) 2012-2013 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     windowHeight: 470,
32     windowWidth: 800,
33     displayNotes: true,
34     
35     /**
36      * check validity of activ number field
37      */
38     isValid: function () {
39         var form = this.getForm();
40         var isValid = true;
41         if (form.findField('total_number').getValue() < form.findField('active_number').getValue()) {
42             var invalidString = String.format(this.app.i18n._('The active number must be less than or equal total number.'));
43             form.findField('active_number').markInvalid(invalidString);
44             isValid = false;
45         }
46         return isValid && Tine.Inventory.InventoryItemEditDialog.superclass.isValid.apply(this, arguments);
47     },
48     
49     /**
50      * returns dialog
51      * 
52      * NOTE: when this method gets called, all initalisation is done.
53      * 
54      * @return {Object}
55      * @private
56      */
57     getFormItems: function() {
58         return {
59             xtype: 'tabpanel',
60             border: false,
61             plain: true,
62             activeTab: 0,
63             defaults: {
64                 hideMode: 'offsets'
65             },
66             items: [{
67                 //Start first tab
68                 title: this.app.i18n._('General'),
69                 border: false,
70                 frame: true,
71                 layout: 'border',
72                 items: [{
73                     region: 'center',
74                     layout: 'hfit',
75                     border: false,
76                     items: [{
77                         region: 'center',
78                         xtype: 'columnform',
79                         labelAlign: 'top',
80                         formDefaults: {
81                             xtype:'textfield',
82                             anchor: '100%',
83                             labelSeparator: '',
84                             columnWidth: .333,
85                             disabled: (this.useMultiple) ? true : false
86                         },
87                         // Start first line
88                         items: [
89                             [{
90                                 columnWidth: 1,
91                                 xtype: 'tw-uidtriggerfield',
92                                 fieldLabel: this.app.i18n._('ID'),
93                                 name: 'inventory_id',
94                                 maxLength: 100,
95                                 allowBlank: false
96                             }],
97                             [{
98                                 columnWidth: 1,
99                                 xtype: 'tine.widget.field.AutoCompleteField',
100                                 recordClass: this.recordClass,
101                                 fieldLabel: this.app.i18n._('Name'),
102                                 name: 'name',
103                                 maxLength: 100,
104                                 allowBlank: false
105                             }]
106                         ]
107                     },
108                     {
109                         //Start second line
110                         layout: 'hbox',
111                         items: [{
112                             flex: 1,
113                             xtype: 'columnform',
114                             autoHeight: true,
115                             style:'padding-right: 5px;',
116                             items: [
117                                 [{
118                                     xtype: 'textarea',
119                                     columnWidth: 1,
120                                     name: 'description',
121                                     fieldLabel: this.app.i18n._('Description'),
122                                     grow: false,
123                                     preventScrollbars: false,
124                                     height: 150,
125                                     emptyText: this.app.i18n._('Enter description')
126                                 }]
127                             ]
128                         },
129                             new Ext.ux.form.ImageField({
130                                 name: 'image',
131                                 width: 160,
132                                 height: 150,
133                                 style: {
134                                     'margin-top': '17px'
135                                 }
136                             })
137                         ]
138                     },
139                     {
140                         //Start third line
141                         xtype: 'columnform',
142                         labelAlign: 'top',
143                         formDefaults: {
144                             xtype:'textfield',
145                             anchor: '100%',
146                             labelSeparator: '',
147                             columnWidth: .333,
148                             disabled: (this.useMultiple) ? true : false
149                         },
150                         items: [
151                             [{
152                                 columnWidth: 1,
153                                 xtype: 'tine.widget.field.AutoCompleteField',
154                                 recordClass: this.recordClass,
155                                 fieldLabel: this.app.i18n._('Location'),
156                                 name: 'location',
157                                 maxLength: 255
158                             }],
159                             [{
160                                 xtype: 'extuxclearabledatefield',
161                                 columnWidth: 0.333,
162                                 fieldLabel: this.app.i18n._('Added'),
163                                 name: 'added_date'
164                             },
165                             {
166                                 xtype: 'datefield',
167                                 name: 'warranty',
168                                 fieldLabel: this.app.i18n._('Warranty'),
169                                 columnWidth: 0.333
170                             },
171                             {
172                                 xtype: 'extuxclearabledatefield',
173                                 columnWidth: 0.333,
174                                 fieldLabel: this.app.i18n._('Removed'),
175                                 name: 'removed_date'
176                             }
177                             ],
178                             [{
179                                 xtype:'numberfield',
180                                 columnWidth: 0.333,
181                                 fieldLabel: this.app.i18n._('Total number'),
182                                 name: 'total_number',
183                                 value: 1,
184                                 minValue: 1
185                             },
186                             {
187                                 xtype:'numberfield',
188                                 columnWidth: 0.333,
189                                 fieldLabel: this.app.i18n._('Available number'),
190                                 name: 'active_number',
191                                 value: 1,
192                                 minValue: 0
193                             },
194                             new Tine.Tinebase.widgets.keyfield.ComboBox({
195                                 app: 'Inventory',
196                                 keyFieldName: 'inventoryStatus',
197                                 fieldLabel: this.app.i18n._('Status'),
198                                 name: 'status',
199                                 columnWidth: 0.333
200                             })
201                             ]
202                         ]
203                     }]
204                     
205                 },
206                 {
207                     //Start side
208                     layout: 'accordion',
209                     animate: true,
210                     region: 'east',
211                     width: 210,
212                     split: true,
213                     collapsible: true,
214                     collapseMode: 'mini',
215                     header: false,
216                     margins: '0 5 0 5',
217                     border: true,
218                     
219                     items: [
220                         new Tine.widgets.tags.TagPanel({
221                             app: 'Inventory',
222                             border: false,
223                             bodyStyle: 'border:1px solid #B5B8C8;'
224                         })
225                     ]
226                 }]
227             },
228             {
229                 //Start second tab
230                 title: this.app.i18n._('Accounting'),
231                 autoScroll: true,
232                 border: false,
233                 frame: true,
234                 layout: 'border',
235                 items: [
236                     {
237                     region: 'center',
238                     xtype: 'columnform',
239                     labelAlign: 'top',
240                     formDefaults: {
241                         xtype:'textfield',
242                         anchor: '100%',
243                         labelSeparator: '',
244                         columnWidth: 1,
245                         disabled: (this.useMultiple) ? true : false
246                     },
247                     items: [
248                         [{
249                             xtype: 'textfield',
250                             name: 'price',
251                             fieldLabel: this.app.i18n._('Price'),
252                             columnWidth: 0.5
253                         }, 
254                           (Tine.hasOwnProperty('Sales') && Tine.Tinebase.common.hasRight('view', 'Sales', 'costcenter')) ?
255                             Tine.widgets.form.RecordPickerManager.get('Sales', 'CostCenter', {
256                                 name: 'costcentre',
257                                 allowBlank: true,
258                                 fieldLabel: this.app.i18n._('Cost centre'),
259                                 columnWidth: 0.5
260                             }) : {
261                                     xtype: 'textfield',
262                                     name: 'costcentre',
263                                     disabled: true,
264                                     hidden: true,
265                                     columnWidth: 0.5
266                               }
267                         ],
268                         [{
269                             xtype: 'textfield',
270                             name: 'invoice',
271                             fieldLabel: this.app.i18n._('Invoice'),
272                             columnWidth: 0.5
273                         },
274                         {
275                             xtype: 'datefield',
276                             name: 'invoice_date',
277                             fieldLabel: this.app.i18n._('Invoice date'),
278                             columnWidth: 0.5
279                         }],
280                         [{
281                                 xtype: 'checkbox',
282                                 hideLabel: true,
283                                 boxLabel: this.app.i18n._('Depreciate'),
284                                 name: 'deprecated_status'
285                         }]
286                     ]
287                 }]
288             }, new Tine.widgets.activities.ActivitiesTabPanel({
289                 app: this.appName,
290                 record_id: this.record.id,
291                 record_model: this.appName + '_Model_' + this.recordClass.getMeta('modelName')
292             })
293             ]
294         };
295     },
296     /**
297      * vaidates on multiple edit
298      * 
299      * @return {Boolean}
300      */
301     isMultipleValid: function() {
302         return true;
303     }
304 });