0013360: CardDAV URL in Adressbook Properties contains #/Addressbook/
[tine20] / tine20 / Addressbook / js / CardDAVContainerPropertiesHookField.js
1 /*
2  * Tine 2.0
3  * 
4  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
5  * @author      Cornelius Weiss <c.weiss@metaways.de>
6  * @copyright   Copyright (c) 2011 Metaways Infosystems GmbH (http://www.metaways.de)
7  */
8 Ext.ns('Tine.Addressbook');
9
10 /**
11  * render the CardDAV Url into property panel of contianers
12  * 
13  * @class   Tine.Addressbook.CardDAVContainerPropertiesHookField
14  * @extends Ext.form.TextField
15  */
16 Tine.Addressbook.CardDAVContainerPropertiesHookField = Ext.extend(Ext.form.TextField, {
17
18     anchor: '100%',
19     readOnly: true,
20     
21     /**
22      * @private
23      */
24     initComponent: function() {
25         this.on('added', this.onContainerAdded, this);
26
27         Tine.Addressbook.CardDAVContainerPropertiesHookField.superclass.initComponent.call(this);
28     },
29     
30     /**
31      * @private
32      */
33     onContainerAdded: function() {
34         this.app = Tine.Tinebase.appMgr.get('Addressbook');
35         this.fieldLabel = this.app.i18n._('CardDAV URL');
36         
37         this.propertiesDialog = this.findParentBy(function(p) {return !! p.grantContainer});
38         this.grantContainer = this.propertiesDialog.grantContainer;
39         
40         if (this.grantContainer.application_id && this.grantContainer.application_id.name) {
41             this.isAddressbook = (this.grantContainer.application_id.name == 'Addressbook');
42         } else {
43             this.isAddressbook = this.grantContainer.application_id === this.app.id;
44         }
45         
46         this.hidden = ! this.isAddressbook;
47         // cardDAV URL
48         this.value = [
49             Tine.Tinebase.common.getUrl('full').replace(/\/$/, ''), // might have an trailing /, we can safely remove it!
50             '/addressbooks/',
51             Tine.Tinebase.registry.get('currentAccount').contact_id,
52             '/',
53             this.grantContainer.id
54         ].join('');
55     }
56     
57 });
58
59 Ext.ux.ItemRegistry.registerItem('Tine.widgets.container.PropertiesDialog.FormItems.Properties', Tine.Addressbook.CardDAVContainerPropertiesHookField, 100);