0009768: Use ModelConfig for Timetracker models
[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-2016 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     defaultSortInfo: {field: 'creation_time', direction: 'DESC'},
35     gridConfig: {
36         autoExpandColumn: 'title'
37     },
38     copyEditAction: true,
39     defaultFilters: [{
40         field: 'query',
41         operator: 'contains',
42         value: ''
43     }, {
44         field: 'is_open',
45         operator: 'equals',
46         value: true
47     }],
48     
49     initComponent: function() {
50         Tine.Timetracker.TimeaccountGridPanel.superclass.initComponent.call(this);
51         
52         this.action_addInNewWindow.setDisabled(! Tine.Tinebase.common.hasRight('manage', 'Timetracker', 'timeaccounts'));
53         this.action_editInNewWindow.requiredGrant = 'editGrant';
54     },
55
56     /**
57      * @private
58      */
59     initActions: function() {
60         this.actions_exportTimeaccount = new Ext.Action({
61             text: this.app.i18n._('Export Timeaccounts'),
62             iconCls: 'action_export',
63             scope: this,
64             requiredGrant: 'readGrant',
65             disabled: true,
66             allowMultiple: true,
67             menu: {
68                 items: [
69                     new Tine.widgets.grid.ExportButton({
70                         text: this.app.i18n._('Export as ODS'),
71                         format: 'ods',
72                         iconCls: 'tinebase-action-export-ods',
73                         exportFunction: 'Timetracker.exportTimeaccounts',
74                         gridPanel: this
75                     })
76                 ]
77             }
78         });
79
80         // register actions in updater
81         this.actionUpdater.addActions([
82             this.actions_exportTimeaccount
83         ]);
84
85         Tine.Timetracker.TimesheetGridPanel.superclass.initActions.call(this);
86     },
87
88     /**
89      * add custom items to action toolbar
90      *
91      * @return {Object}
92      */
93     getActionToolbarItems: function() {
94         return [
95             Ext.apply(new Ext.Button(this.actions_exportTimeaccount), {
96                 scale: 'medium',
97                 rowspan: 2,
98                 iconAlign: 'top'
99             })
100         ];
101     },
102
103     /**
104      * add custom items to context menu
105      *
106      * @return {Array}
107      */
108     getContextMenuItems: function() {
109         var items = [
110             '-', {
111                 text: Tine.Tinebase.appMgr.get('Timetracker').i18n._('Close Timeaccount'),
112                 iconCls: 'action_edit',
113                 scope: this,
114                 disabled: !Tine.Tinebase.common.hasRight('manage', 'Timetracker', 'timeaccounts'),
115                 itemId: 'closeAccount',
116                 handler: this.onCloseTimeaccount.createDelegate(this)
117             }
118         ];
119
120         return items;
121     },
122
123     /**
124      * Closes selected timeaccount
125      */
126     onCloseTimeaccount: function () {
127         var grid = this,
128             recordProxy = this.recordProxy,
129             selectionModel = grid.selectionModel;
130
131         Ext.each(selectionModel.getSelections(), function (record) {
132             recordProxy.loadRecord(record, {
133                 success: function (record) {
134                     record.set('is_open', false);
135                     recordProxy.saveRecord(record, {
136                         success: function () {
137                             grid.store.reload();
138                             grid.store.remove(record);
139                         }
140                     });
141                 }
142             });
143         });
144     }
145 });