0dbff16be21d72bed575d766648d4cd90dc00083
[tine20] / tine20 / HumanResources / js / ExtraFreeTimeEditDialog.js
1 /*
2  * Tine 2.0
3  * 
4  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
5  * @author      Alexander Stintzing <a.stintzing@metaways.de>
6  * @copyright   Copyright (c) 2013 Metaways Infosystems GmbH (http://www.metaways.de)
7  */
8 Ext.ns('Tine.HumanResources');
9
10 /**
11  * @namespace   Tine.HumanResources
12  * @class       Tine.HumanResources.ExtraFreeTimeEditDialog
13  * @extends     Tine.widgets.dialog.EditDialog
14  * 
15  * <p>ExtraFreeTime Compose Dialog</p>
16  * <p></p>
17  * 
18  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
19  * @author      Alexander Stintzing <a.stintzing@metaways.de>
20  * Create a new Tine.HumanResources.ExtraFreeTimeEditDialog
21  */
22 Tine.HumanResources.ExtraFreeTimeEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog, {
23     
24     /**
25      * @private
26      */
27     windowNamePrefix: 'ExtraFreeTimeEditWindow_',
28     appName: 'HumanResources',
29     recordClass: Tine.HumanResources.Model.ExtraFreeTime,
30     recordProxy: Tine.HumanResources.freetimeBackend,
31     evalGrants: false,
32     showContainerSelector: false,
33     mode: 'local',
34     windowWidth: 400,
35     windowHeight: 350,
36     /**
37      * show private Information (autoset due to rights)
38      * @type 
39      */
40     showPrivateInformation: null,
41     
42     /**
43      * overwrite update toolbars function (we don't have record grants yet)
44      * @private
45      */
46     updateToolbars: Ext.emptyFn,
47     
48     /**
49      * inits the component
50      */
51     initComponent: function() {
52         this.app = Tine.Tinebase.appMgr.get('HumanResources')
53         Tine.HumanResources.ExtraFreeTimeEditDialog.superclass.initComponent.call(this);
54     },
55     
56     /**
57      * executed after record got updated from proxy
58      * 
59      * @private
60      */
61     onRecordLoad: function() {
62         // interrupt process flow until dialog is rendered
63         if (! this.rendered) {
64             this.onRecordLoad.defer(250, this);
65             return;
66         }
67         
68         if (Ext.isString(this.record)) {
69             this.record = this.recordProxy.recordReader({responseText: this.record});
70         }
71         
72         Tine.HumanResources.ExtraFreeTimeEditDialog.superclass.onRecordLoad.call(this);
73     },
74     
75     /**
76      * returns dialog
77      * 
78      * NOTE: when this method gets called, all initalisation is done.
79      * 
80      * @return {Object}
81      * @private
82      */
83     getFormItems: function() {
84         return {
85             xtype: 'tabpanel',
86             border: false,
87             plain:true,
88             plugins: [{
89                 ptype : 'ux.tabpanelkeyplugin'
90             }],
91             defaults: {
92                 hideMode: 'offsets'
93             },
94             activeTab: 0,
95             border: false,
96             items:[{
97                 title: this.app.i18n._('Extra free time'),
98                 autoScroll: true,
99                 border: false,
100                 frame: true,
101                 layout: 'border',
102                 items: [{
103                     region: 'center',
104                     layout: 'hfit',
105                     border: false,
106                     items: [{
107                         xtype: 'fieldset',
108                         autoHeight: true,
109                         title: this.app.i18n._('Extra free time'),
110                         items: [{
111                             xtype: 'columnform',
112                             labelAlign: 'top',
113                             formDefaults: {
114                                 xtype:'numberfield',
115                                 anchor: '100%',
116                                 labelSeparator: '',
117                                 allowBlank: false,
118                                 columnWidth: 1
119                             },
120                             items: [[{
121                                     name: 'days', 
122                                     fieldLabel: this.app.i18n._('Days')
123                                 }], [{
124                                     xtype: 'widget-keyfieldcombo',
125                                     app: 'HumanResources',
126                                     keyFieldName: 'extraFreetimeType',
127                                     fieldLabel: this.app.i18n._('Type'),
128                                     name: 'type'
129                                 }], [{
130                                     fieldLabel: this.app.i18n._('Expiration date'),
131                                     xtype: 'datefield',
132                                     name: 'expires'
133                                 }]
134                             ]
135                         }]
136                     }]
137                 }, 
138                 {
139                 // activities and tags
140                 layout: 'accordion',
141                 animate: true,
142                 region: 'east',
143                 width: 210,
144                 split: true,
145                 collapsible: true,
146                 collapseMode: 'mini',
147                 header: false,
148                 margins: '0 5 0 5',
149                 border: true,
150                 items: [
151                     new Ext.Panel({
152                         title: this.app.i18n._('Description'),
153                         iconCls: 'descriptionIcon',
154                         layout: 'form',
155                         labelAlign: 'top',
156                         border: false,
157                         items: [{
158                             style: 'margin-top: -4px; border 0px;',
159                             labelSeparator: '',
160                             xtype: 'textarea',
161                             name: 'description',
162                             hideLabel: true,
163                             grow: false,
164                             preventScrollbars: false,
165                             anchor: '100% 100%',
166                             emptyText: this.app.i18n._('Enter description'),
167                             requiredGrant: 'editGrant'
168                         }]
169                     }),
170                     new Tine.widgets.tags.TagPanel({
171                         app: 'HumanResources',
172                         border: false,
173                         bodyStyle: 'border:1px solid #B5B8C8;'
174                     })
175                 ]
176             }
177                 
178                 ]
179             }, 
180             new Tine.widgets.activities.ActivitiesTabPanel({
181                 app: this.appName,
182                 record_id: this.record.id,
183                 record_model: this.appName + '_Model_' + this.recordClass.getMeta('modelName')
184                 }) 
185             ]
186         };
187     },
188     
189     /**
190      * updates the statusbox wrap
191      * 
192      * @param {Tine.Tinebase.widgets.keyfield.ComboBox} the calling combo
193      * @param {Tine.Tinebase.data.Record} the selected record
194      * @param {Integer} the index of the selected value of the typecombo store
195      */
196     updateStatusBox: function(typeCombo, keyfieldRecord, index) {
197         this.statusBoxWrap.layout.setActiveItem(index);
198     },
199     
200     /**
201      * initializes the status box
202      */
203     initStatusBox: function() {
204         var isSickness = this.fixedFields.get('type') == 'SICKNESS';
205         this.updateStatusBox(null, null, isSickness ? 0 : 1);
206         var fieldName = isSickness ? 'sicknessStatus' : 'vacationStatus';
207         this.getForm().findField(fieldName).setValue(this.record.get('status'));
208     }
209 });