adds maxLength for number and title fields in TA edit dlg
[tine20] / tine20 / Timetracker / js / TimeaccountEditDialog.js
1 /**
2  * Tine 2.0
3  * 
4  * @package     Timetracker
5  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
6  * @author      Cornelius Weiss <c.weiss@metaways.de>
7  * @copyright   Copyright (c) 2007-2011 Metaways Infosystems GmbH (http://www.metaways.de)
8  *
9  */
10  
11 Ext.namespace('Tine.Timetracker');
12
13 Tine.Timetracker.TimeaccountEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog, {
14     
15     /**
16      * @private
17      */
18     windowNamePrefix: 'TimeaccountEditWindow_',
19     appName: 'Timetracker',
20     recordClass: Tine.Timetracker.Model.Timeaccount,
21     recordProxy: Tine.Timetracker.timeaccountBackend,
22     loadRecord: false,
23     tbarItems: [{xtype: 'widget-activitiesaddbutton'}],
24     
25     /**
26      * overwrite update toolbars function (we don't have record grants yet)
27      */
28     updateToolbars: function() {
29
30     },
31     
32     onRecordLoad: function() {
33         // make sure grants grid is initialised
34         this.getGrantsGrid();
35         
36         var grants = this.record.get('grants') || [];
37         this.grantsStore.loadData({results: grants});
38         Tine.Timetracker.TimeaccountEditDialog.superclass.onRecordLoad.call(this);
39         
40     },
41     
42     onRecordUpdate: function() {
43         Tine.Timetracker.TimeaccountEditDialog.superclass.onRecordUpdate.call(this);
44         this.record.set('grants', '');
45         
46         var grants = [];
47         this.grantsStore.each(function(_record){
48             grants.push(_record.data);
49         });
50         
51         this.record.set('grants', grants);
52     },
53     
54     /**
55      * returns dialog
56      * 
57      * NOTE: when this method gets called, all initalisation is done.
58      */
59     getFormItems: function() {
60         
61         var secondRow = [{
62             fieldLabel: this.app.i18n._('Unit'),
63             name: 'price_unit'
64         }, {
65             xtype: 'numberfield',
66             fieldLabel: this.app.i18n._('Unit Price'),
67             name: 'price',
68             allowNegative: false
69             //decimalSeparator: ','
70         }, {
71             fieldLabel: this.app.i18n._('Budget'),
72             name: 'budget'
73         }, {
74             fieldLabel: this.app.i18n._('Status'),
75             name: 'is_open',
76             xtype: 'combo',
77             mode: 'local',
78             forceSelection: true,
79             triggerAction: 'all',
80             store: [[0, this.app.i18n._('closed')], [1, this.app.i18n._('open')]]
81         }, {
82             fieldLabel: this.app.i18n._('Billed'),
83             name: 'status',
84             xtype: 'combo',
85             mode: 'local',
86             forceSelection: true,
87             triggerAction: 'all',
88             value: 'not yet billed',
89             store: [
90                 ['not yet billed', this.app.i18n._('not yet billed')], 
91                 ['to bill', this.app.i18n._('to bill')],
92                 ['billed', this.app.i18n._('billed')]
93             ],
94             listeners: {
95                 scope: this,
96                 select: this.onBilledChange.createDelegate(this)
97             }
98         }, {
99             //disabled: true,
100             //emptyText: this.app.i18n._('not cleared yet...'),
101             fieldLabel: this.app.i18n._('Cleared In'),
102             name: 'billed_in',
103             xtype: 'textfield'
104         }, {
105             fieldLabel: this.app.i18n._('Booking deadline'),
106             name: 'deadline',
107             xtype: 'combo',
108             mode: 'local',
109             forceSelection: true,
110             triggerAction: 'all',
111             value: 'none',
112             store: [
113                 ['none', this.app.i18n._('none')], 
114                 ['lastweek', this.app.i18n._('last week')]
115             ]
116         }, {
117             xtype: 'extuxclearabledatefield',
118             name: 'cleared_at',
119             fieldLabel: this.app.i18n._('Cleared at')
120         }];
121         
122         if (Tine.Tinebase.appMgr.get('Sales')) {
123             secondRow.push({
124                 xtype: 'tinerelationpickercombo',
125                 fieldLabel: this.app.i18n._('Cost Center'),
126                 editDialog: this,
127                 allowBlank: true,
128                 app: 'Sales',
129                 recordClass: Tine.Sales.Model.CostCenter,
130                 relationType: 'COST_CENTER',
131                 relationDegree: 'sibling',
132                 modelUnique: true
133             });
134         }
135         
136         secondRow.push({
137             columnWidth: 1/3,
138             editDialog: this,
139             xtype: 'tinerelationpickercombo',
140             fieldLabel: this.app.i18n._('Responsible person'),
141             allowBlank: true,
142             app: 'Addressbook',
143             recordClass: Tine.Addressbook.Model.Contact,
144             relationType: 'RESPONSIBLE',
145             relationDegree: 'sibling',
146             modelUnique: true
147         });
148         
149         secondRow.push({
150             hideLabel: true,
151             boxLabel: this.app.i18n._('Timesheets are billable'),
152             name: 'is_billable',
153             xtype: 'checkbox',
154             columnWidth: .666
155         });
156         
157         return {
158             xtype: 'tabpanel',
159             border: false,
160             plain:true,
161             activeTab: 0,
162             plugins: [{
163                 ptype : 'ux.tabpanelkeyplugin'
164             }],
165             defaults: {
166                 hideMode: 'offsets'
167             },
168             items:[{
169                 title: this.app.i18n.ngettext('Time Account', 'Time Accounts', 1),
170                 autoScroll: true,
171                 border: false,
172                 frame: true,
173                 layout: 'border',
174                 items: [{
175                     region: 'center',
176                     xtype: 'columnform',
177                     labelAlign: 'top',
178                     formDefaults: {
179                         xtype:'textfield',
180                         anchor: '100%',
181                         labelSeparator: '',
182                         columnWidth: .333
183                     },
184                     items: [[{
185                         fieldLabel: this.app.i18n._('Number'),
186                         name: 'number',
187                         allowBlank: false,
188                         maxLength: 127
189                         }, {
190                         columnWidth: .666,
191                         fieldLabel: this.app.i18n._('Title'),
192                         name: 'title',
193                         maxLength: 255,
194                         allowBlank: false
195                         }], [{
196                         columnWidth: 1,
197                         fieldLabel: this.app.i18n._('Description'),
198                         xtype: 'textarea',
199                         name: 'description',
200                         height: 150
201                         }], secondRow] 
202                 }, {
203                     // activities and tags
204                     layout: 'accordion',
205                     animate: true,
206                     region: 'east',
207                     width: 210,
208                     split: true,
209                     collapsible: true,
210                     collapseMode: 'mini',
211                     header: false,
212                     margins: '0 5 0 5',
213                     border: true,
214                     items: [/*new Ext.Panel({
215                         // @todo generalise!
216                         title: this.app.i18n._('Description'),
217                         iconCls: 'descriptionIcon',
218                         layout: 'form',
219                         labelAlign: 'top',
220                         border: false,
221                         items: [{
222                             style: 'margin-top: -4px; border 0px;',
223                             labelSeparator: '',
224                             xtype:'textarea',
225                             name: 'description',
226                             hideLabel: true,
227                             grow: false,
228                             preventScrollbars:false,
229                             anchor:'100% 100%',
230                             emptyText: this.app.i18n._('Enter description')                            
231                         }]
232                     }),*/
233                     new Tine.widgets.activities.ActivitiesPanel({
234                         app: 'Timetracker',
235                         showAddNoteForm: false,
236                         border: false,
237                         bodyStyle: 'border:1px solid #B5B8C8;'
238                     }),
239                     new Tine.widgets.tags.TagPanel({
240                         app: 'Timetracker',
241                         border: false,
242                         bodyStyle: 'border:1px solid #B5B8C8;'
243                     })]
244                 }]
245             },{
246                 title: this.app.i18n._('Access'),
247                 layout: 'fit',
248                 items: [this.getGrantsGrid()]
249             }, new Tine.widgets.activities.ActivitiesTabPanel({
250                 app: this.appName,
251                 record_id: (! this.copyRecord) ? this.record.id : null,
252                 record_model: this.appName + '_Model_' + this.recordClass.getMeta('modelName')
253             })]
254         };
255     },
256     
257     getGrantsGrid: function() {
258         if (! this.grantsGrid) {
259             this.grantsStore =  new Ext.data.JsonStore({
260                 root: 'results',
261                 totalProperty: 'totalcount',
262                 // use account_id here because that simplifies the adding of new records with the search comboboxes
263                 id: 'account_id',
264                 fields: Tine.Timetracker.Model.TimeaccountGrant
265             });
266             
267             var columns = [
268                 new Ext.ux.grid.CheckColumn({
269                     header: this.app.i18n._('Book Own'),
270                     dataIndex: 'bookOwnGrant',
271                     tooltip: _('The grant to add Timesheets to this Timeaccount'),
272                     width: 55
273                 }),
274                 new Ext.ux.grid.CheckColumn({
275                     header: this.app.i18n._('View All'),
276                     tooltip: _('The grant to view Timesheets of other users'),
277                     dataIndex: 'viewAllGrant',
278                     width: 55
279                 }),
280                 new Ext.ux.grid.CheckColumn({
281                     header: this.app.i18n._('Book All'),
282                     tooltip: _('The grant to add Timesheets for other users'),
283                     dataIndex: 'bookAllGrant',
284                     width: 55
285                 }),
286                 new Ext.ux.grid.CheckColumn({
287                     header:this.app.i18n. _('Manage Clearing'),
288                     tooltip: _('The grant to manage clearing of Timesheets'),
289                     dataIndex: 'manageBillableGrant',
290                     width: 55
291                 }),
292                 new Ext.ux.grid.CheckColumn({
293                     header:this.app.i18n. _('Export'),
294                     tooltip: _('The grant to export Timesheets of Timeaccount'),
295                     dataIndex: 'exportGrant',
296                     width: 55
297                 }),
298                 new Ext.ux.grid.CheckColumn({
299                     header: this.app.i18n._('Manage All'),
300                     tooltip: _('Includes all other grants'),
301                     dataIndex: 'adminGrant',
302                     width: 55
303                 })
304             ];
305             
306             this.grantsGrid = new Tine.widgets.account.PickerGridPanel({
307                 selectType: 'both',
308                 title:  this.app.i18n._('Permissions'),
309                 store: this.grantsStore,
310                 hasAccountPrefix: true,
311                 configColumns: columns,
312                 selectAnyone: false,
313                 selectTypeDefault: 'group',
314                 recordClass: Tine.Tinebase.Model.Grant
315             });
316         }
317         return this.grantsGrid;
318     },
319     
320     /**
321      * is called is billed field changes
322      */
323     onBilledChange: function(combo, record, index) {
324         if (combo.getValue() == 'billed') {
325             if (! this.getForm().findField('cleared_at').getValue()) {
326                 this.getForm().findField('cleared_at').setValue(new Date());
327             }
328         }
329     }
330 });
331
332 /**
333  * Timetracker Edit Popup
334  */
335 Tine.Timetracker.TimeaccountEditDialog.openWindow = function (config) {
336     var id = (config.record && config.record.id) ? config.record.id : 0;
337     var window = Tine.WindowFactory.getWindow({
338         width: 800,
339         height: 500,
340         name: Tine.Timetracker.TimeaccountEditDialog.prototype.windowNamePrefix + id,
341         contentPanelConstructor: 'Tine.Timetracker.TimeaccountEditDialog',
342         contentPanelConstructorConfig: config
343     });
344     return window;
345 };