Merge branch 'pu/2013.03/modelconfig-hr'
[tine20] / tine20 / Timetracker / js / TimeaccountGridPanel.js
1 /*
2  * Tine 2.0
3  * 
4  * @package     Timetracker
5  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
6  * @author      Philipp Schüle <p.schuele@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 /**
14  * Timeaccount grid panel
15  * 
16  * @namespace   Tine.Timetracker
17  * @class       Tine.Timetracker.TimeaccountGridPanel
18  * @extends     Tine.widgets.grid.GridPanel
19  * 
20  * <p>Timeaccount Grid Panel</p>
21  * <p><pre>
22  * TODO         copy action needs to copy the acl too
23  * </pre></p>
24  * 
25  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
26  * @author      Philipp Schuele <p.schuele@metaways.de>
27  * @copyright   Copyright (c) 2007-2009 Metaways Infosystems GmbH (http://www.metaways.de)
28  * 
29  * @param       {Object} config
30  * @constructor
31  * Create a new Tine.Timetracker.TimeaccountGridPanel
32  */
33 Tine.Timetracker.TimeaccountGridPanel = Ext.extend(Tine.widgets.grid.GridPanel, {
34     // model generics
35     recordClass: Tine.Timetracker.Model.Timeaccount,
36     
37     // grid specific
38     defaultSortInfo: {field: 'creation_time', direction: 'DESC'},
39     gridConfig: {
40         autoExpandColumn: 'title'
41     },
42     copyEditAction: true,
43     defaultFilters: [{field: 'is_open', operator: 'equals', value: true}],
44     
45     initComponent: function() {
46         this.recordProxy = Tine.Timetracker.timeaccountBackend;
47         
48         this.actionToolbarItems = this.getToolbarItems();
49         this.gridConfig.cm = this.getColumnModel();
50         
51         Tine.Timetracker.TimeaccountGridPanel.superclass.initComponent.call(this);
52         
53         this.action_addInNewWindow.setDisabled(! Tine.Tinebase.common.hasRight('manage', 'Timetracker', 'timeaccounts'));
54         this.action_editInNewWindow.requiredGrant = 'editGrant';
55     },
56     
57     /**
58      * returns cm
59      * 
60      * @return Ext.grid.ColumnModel
61      * @private
62      */
63     getColumnModel: function(){
64         return new Ext.grid.ColumnModel({
65             defaults: {
66                 sortable: true,
67                 resizable: true
68             },
69             columns: [
70             {   id: 'tags', header: this.app.i18n._('Tags'), width: 50,  dataIndex: 'tags', sortable: false, renderer: Tine.Tinebase.common.tagsRenderer },
71             {
72                 id: 'number',
73                 header: this.app.i18n._("Number"),
74                 width: 100,
75                 dataIndex: 'number'
76             },{
77                 id: 'title',
78                 header: this.app.i18n._("Title"),
79                 width: 350,
80                 dataIndex: 'title'
81             },{
82                 id: 'status',
83                 header: this.app.i18n._("Billed"),
84                 width: 150,
85                 dataIndex: 'status',
86                 renderer: this.statusRenderer.createDelegate(this)
87             },{
88                 id: 'budget',
89                 header: this.app.i18n._("Budget"),
90                 width: 100,
91                 dataIndex: 'budget'
92             },{
93                 id: 'billed_in',
94                 hidden: true,
95                 header: this.app.i18n._("Cleared in"),
96                 width: 150,
97                 dataIndex: 'billed_in'
98             },{
99                 id: 'deadline',
100                 hidden: true,
101                 header: this.app.i18n._("Booking deadline"),
102                 width: 100,
103                 dataIndex: 'deadline'
104             },{
105                 id: 'cleared_at',
106                 header: this.app.i18n._("Cleared at"),
107                 dataIndex: 'cleared_at',
108                 renderer: Tine.Tinebase.common.dateRenderer
109             },{
110                 id: 'is_open',
111                 header: this.app.i18n._("Status"),
112                 width: 150,
113                 dataIndex: 'is_open',
114                 renderer: function(value) {
115                     if(value) return this.app.i18n._('open');
116                     return this.app.i18n._('closed');
117                 },
118                 scope: this,
119                 hidden: true
120             }]
121         });
122     },
123     
124     /**
125      * status column renderer
126      * @param {string} value
127      * @return {string}
128      */
129     statusRenderer: function(value) {
130         return this.app.i18n._hidden(value);
131     },
132     
133     /**
134      * return additional tb items
135      */
136     getToolbarItems: function(){
137         this.exportButton = new Ext.Action({
138             text: _('Export'),
139             iconCls: 'action_export',
140             scope: this,
141             requiredGrant: 'readGrant',
142             disabled: true,
143             allowMultiple: true,
144             menu: {
145                 items: [
146                     new Tine.widgets.grid.ExportButton({
147                         text: this.app.i18n._('Export as ODS'),
148                         format: 'ods',
149                         exportFunction: 'Timetracker.exportTimeaccounts',
150                         gridPanel: this
151                     })
152                     /*,
153                     new Tine.widgets.grid.ExportButton({
154                         text: this.app.i18n._('Export as CSV'),
155                         format: 'csv',
156                         exportFunction: 'Timetracker.exportTimesheets',
157                         gridPanel: this
158                     })
159                     */
160                 ]
161             }
162         });
163         
164         return [
165             Ext.apply(new Ext.Button(this.exportButton), {
166                 scale: 'medium',
167                 rowspan: 2,
168                 iconAlign: 'top'
169             })
170         ];
171     }    
172 });