/*!
 * Tine 2.0 - ActiveSync 
 * Copyright (c) 2007-2011 Metaways Infosystems GmbH (http://www.metaways.de)
 * http://www.gnu.org/licenses/agpl.html AGPL Version 3
 */
/*
 * Tine 2.0
 *
 * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
 * @copyright   Copyright (c) 2010-2012 Metaways Infosystems GmbH (http://www.metaways.de)
 * @author      Cornelius Weiss <c.weiss@metaways.de>
 */
Ext.ns('Tine.ActiveSync');

/**
 * @namespace   Tine.ActiveSync
 * @class       Tine.ActiveSync.Application
 * @extends     Tine.Tinebase.Application
 * 
 * @author      Cornelius Weiss <c.weiss@metaways.de>
 */
Tine.ActiveSync.Application = Ext.extend(Tine.Tinebase.Application, {
    
    hasMainScreen: false,
    
    /**
     * Get translated application title of the calendar application
     * 
     * @return {String}
     */
    getTitle: function() {
        return this.i18n.gettext('Active Sync');
    },
    
    /**
     * returns additional items for persistent filter context menu
     * 
     * @todo rework this to be event/hook 
     * 
     * @param {Tine.widgets.persistentfilter.PickerPanel} picker
     * @param {Tine.widgets.persistentfilter.model.PersistentFilter} filter
     */
    getPersistentFilterPickerCtxItems: function(picker, filter) {
        var items = [];
        
        if (picker.app.appName.match(/Addressbook|Calendar|Email|Tasks/)) {
            var devices =  Tine.ActiveSync.getDeviceStore();
            var menuItems = ['<b class="x-menu-title">' + this.i18n._('Select a Device') +'</b>'];
            
            devices.each(function(device) {
                var contentClass = Tine.ActiveSync.Model.getContentClass(picker.app.appName);
                
                menuItems.push({
                    text: Ext.util.Format.htmlEncode(device.getTitle()),
                    checked: device.get([Ext.util.Format.lowercase(contentClass) + 'filter_id']) === filter.id,
                    //iconCls: 'activesync-device-standard',
                    handler: this.setDeviceContentFilter.createDelegate(this, [device, contentClass, filter], true)
                });
            }, this);
            if (! devices.getCount()) {
                menuItems.push({
                    text: this.i18n._('No ActiveSync Device registered'),
                    disabled: true,
                    checked: false,
                    handler: Ext.emptyFn
                });
            }
            
            items.push({
                text: String.format(this.i18n._('Set as {0} Filter'), this.getTitle()),
                iconCls: this.getIconCls(),
                menu: menuItems
            });
        }
        
        return items;
        
    },
    
    /**
     * persistently set filter for device
     * 
     * @param {Ext.Action} btn
     * @param {Ext.EventObject} e
     * @param {Tine.ActiveSync.Model.Device} device
     * @param {} contentClass
     * @param {Tine.widgets.persistentfilter.model.PersistentFilter} filter
     */
    setDeviceContentFilter: function(btn, e, device, contentClass, filter) {
        if (btn.checked) {
            // if btn was checked, we need to reset filter
            Tine.ActiveSync.setDeviceContentFilter(device.id, contentClass, null, function(response) {
                device.set([Ext.util.Format.lowercase(contentClass) + 'filter_id'], null);
                
                Ext.Msg.alert(this.i18n._('Resetted Sync Filter'), String.format(
                    this.i18n._('{0} filter for device "{1}" is now "{2}"'),
                        this.getTitle(),
                        Ext.util.Format.htmlEncode(device.getTitle()),
                        this.i18n._('resetted')
                ));
                
            }, this);
        } else {
            Tine.ActiveSync.setDeviceContentFilter(device.id, contentClass, filter.id, function(response) {
                device.set([Ext.util.Format.lowercase(contentClass) + 'filter_id'], filter.id);
                
                Ext.Msg.alert(this.i18n._('Set Sync Filter'), String.format(
                    this.i18n._('{0} filter for device "{1}" is now "{2}"'),
                        this.getTitle(),
                        Ext.util.Format.htmlEncode(device.getTitle()),
                        Ext.util.Format.htmlEncode(filter.get('name'))
                ));
            }, this);
        }
    }
});
/*
 * Tine 2.0
 *
 * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
 * @copyright   Copyright (c) 2010-2012 Metaways Infosystems GmbH (http://www.metaways.de)
 * @author      Cornelius Weiss <c.weiss@metaways.de>
 */
Ext.ns('Tine.ActiveSync.Model');


/**
 * @namespace   Tine.ActiveSync.Model
 * @class       Tine.ActiveSync.Model.Device
 * @extends     Tine.Tinebase.data.Record
 * 
 * @author      Cornelius Weiss <c.weiss@metaways.de>
 * Device record definition
 */
Tine.ActiveSync.Model.Device = Tine.Tinebase.data.Record.create(Tine.Tinebase.Model.modlogFields.concat([
    { name: 'id' },
    { name: 'deviceid'},
    { name: 'devicetype' },
    { name: 'policykey' },
    { name: 'owner_id' },
    { name: 'acsversion' },
    { name: 'useragent' },
    { name: 'policy_id' },
    { name: 'pinglifetime', type: 'number' },
    { name: 'remotewipe', type: 'number' },
    { name: 'pingfolder' },
    { name: 'model' },
    { name: 'imei' },
    { name: 'friendlyname' },
    { name: 'os'},
    { name: 'oslanguage' },
    { name: 'phonenumber' }
]), {
    appName: 'ActiveSync',
    modelName: 'Device',
    idProperty: 'id',
    titleProperty: 'friendlyname',
    // ngettext('Device', 'Devices', n); gettext('Devices');
    recordName: 'Device',
    recordsName: 'Devices',
    
    /**
     * returns title of this record
     * 
     * @return {String}
     */
    getTitle: function() {
        return this.get('friendlyname') || this.get('useragent');
    }
});


/**
 * @namespace   Tine.ActiveSync.Model
 * @class       Tine.ActiveSync.Model.Device
 * @extends     Tine.Tinebase.data.Record
 * 
 * @author      Cornelius Weiss <c.weiss@metaways.de>
 * 
 * get content type of app
 * 
 * @static
 * @param {String} appName
 * @return {String}
 */
Tine.ActiveSync.Model.getContentClass = function(appName) {
    switch(appName) {
        case 'Calendar'   : return 'Calendar';
        case 'Addressbook': return 'Contacts';
        case 'Felamimail' : return 'Email';
        case 'Tasks'      : return 'Tasks';
        default: throw new Ext.Error('no contentClass for this app');
    }
};

/**
 * @namespace   Tine.ActiveSync.Model
 * @class       Tine.ActiveSync.Model.DeviceJsonBackend
 * @extends     Tine.Tinebase.data.RecordProxy
 * 
 * @author      Cornelius Weiss <c.weiss@metaways.de>
 * JSON backend for devices
 */
Tine.ActiveSync.Model.DeviceJsonBackend = Ext.extend(Tine.Tinebase.data.RecordProxy, {
    
    /**
     * Creates a recuring event exception
     * 
     * @param {Tine.Calendar.Model.Event} event
     * @param {Boolean} deleteInstance
     * @param {Boolean} deleteAllFollowing
     * @param {Object} options
     * @return {String} transaction id
     */
    setDeviceContentFilter: function(device, contentClass, filterId) {
        options = options || {};
        options.params = options.params || {};
        options.beforeSuccess = function(response) {
            return [this.recordReader(response)];
        };
        
        var p = options.params;
        p.method = this.appName + '.setDeviceContentFilter';
        p.deviceId = event.data;
        p.contentClass = contentClass;
        p.filterId = filterId;
        
        return this.doXHTTPRequest(options);
    }
});
/*
 * Tine 2.0
 * 
 * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
 * @copyright   Copyright (c) 2010-2012 Metaways Infosystems GmbH (http://www.metaways.de)
 * @author      Cornelius Weiss <c.weiss@metaways.de>
 */
Ext.ns('Tine.ActiveSync');

/**
 * @namespace   Tine.ActiveSync
 * @class       Tine.ActiveSync.DeviceStore
 * @extends     Ext.data.ArrayStore
 * 
 * <p>Store for Device Records</p>
 * 
 * @author      Cornelius Weiss <c.weiss@metaways.de>
 * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
 * 
 * @param       {Object} config
 * @constructor
 * Create a new Tine.ActiveSync.DeviceStore
 */
Tine.ActiveSync.DeviceStore = Ext.extend(Ext.data.ArrayStore, {
    
});


/**
 * @namespace   Tine.ActiveSync
 * 
 * get store of all device records
 * 
 * @static
 * @sigleton
 * @return {DeviceStore}
 */
Tine.ActiveSync.getDeviceStore = function() {
    if (! Tine.ActiveSync.deviceStore) {
        // create store
        Tine.ActiveSync.deviceStore = new Tine.ActiveSync.DeviceStore({
            fields: Tine.ActiveSync.Model.Device.getFieldDefinitions(),
            sortInfo: {field: 'friendlyname', direction: 'ASC'}
        });
        
        var app = Tine.Tinebase.appMgr.get('ActiveSync'),
            registry = app ? app.getRegistry() : null
            recordsData = registry ? registry.get('userDevices') : [];
        
        // populate store
        Ext.each(recordsData, function(data) {
            var r = new Tine.ActiveSync.Model.Device(data);
            Tine.ActiveSync.deviceStore.addSorted(r);
        }, this);
    }
    
    return Tine.ActiveSync.deviceStore;
}
/*
 * Tine 2.0
 * 
 * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
 * @author      Lars Kneschke <l.kneschke@metaways.de>
 * @copyright   Copyright (c) 2014-2015 Metaways Infosystems GmbH (http://www.metaways.de)
 */

/*global Ext, Tine*/ 

Ext.ns('Tine.ActiveSync.syncdevices');

/**
 * Containers 'mainScreen'
 * 
 * @static
 */
Tine.ActiveSync.syncdevices.show = function () {
    var app = Tine.Tinebase.appMgr.get('ActiveSync');
    if (! Tine.ActiveSync.syncDevicesGridPanel) {
        Tine.ActiveSync.syncDevicesGridPanel = new Tine.ActiveSync.SyncDevicesGridPanel({
            app: app,
            asAdminModule: true
        });
    } else {
        Tine.ActiveSync.syncDevicesGridPanel.loadGridData.defer(100, Tine.ActiveSync.syncDevicesGridPanel, []);
    }
    
    Tine.Tinebase.MainScreen.setActiveContentPanel(Tine.ActiveSync.syncDevicesGridPanel, true);
    Tine.Tinebase.MainScreen.setActiveToolbar(Tine.ActiveSync.syncDevicesGridPanel.actionToolbar, true);
};

/************** models *****************/
Ext.ns('Tine.ActiveSync.Model');

/**
 * Model of an account
 */
Tine.ActiveSync.Model.SyncDeviceArray = [
    { name: 'id' },
    { name: 'deviceid' },
    { name: 'devicetype' },
    { name: 'owner_id' },
    { name: 'policy_id' },
    //{ name: 'policykey' },
    { name: 'acsversion' },
    { name: 'useragent' },
    { name: 'model' },
    { name: 'imei' },
    { name: 'friendlyname' },
    { name: 'os' },
    { name: 'oslanguage' },
    { name: 'phonenumber' },
    { name: 'pinglifetime' },
    { name: 'pingfolder' },
    { name: 'remotewipe' },
    { name: 'calendarfilter_id' },
    { name: 'contactsfilter_id' },
    { name: 'emailfilter_id' },
    { name: 'tasksfilter_id' },
    { name: 'lastping', type: 'date', dateFormat: Date.patterns.ISO8601Long }
];

Tine.ActiveSync.Model.SyncDevice = Tine.Tinebase.data.Record.create(Tine.ActiveSync.Model.SyncDeviceArray, {
    appName: 'ActiveSync',
    modelName: 'SyncDevice',
    idProperty: 'id',
    //titleProperty: 'name',
    titleProperty: 'deviceid',
    // ngettext('SyncDevice', 'SyncDevices', n);
    recordName: 'SyncDevice',
    recordsName: 'SyncDevices'
});

/**
 * returns default account data
 * 
 * @namespace Tine.ActiveSync.Model.SyncDevice
 * @static
 * @return {Object} default data
 */
Tine.ActiveSync.Model.SyncDevice.getDefaultData = function () {
    return {};
};

/************** backend *****************/

Tine.ActiveSync.syncdevicesBackend = new Tine.Tinebase.data.RecordProxy({
    appName: 'ActiveSync',
    modelName: 'SyncDevice',
    recordClass: Tine.ActiveSync.Model.SyncDevice,
    idProperty: 'id'
});
/*
 * Tine 2.0
 * 
 * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
 * @author      Lars Kneschke <l.kneschke@metaways.de>
 * @copyright   Copyright (c) 2014-2015 Metaways Infosystems GmbH (http://www.metaways.de)
 */
 
/*global Ext, Tine*/

Ext.ns('Tine.ActiveSync.syncdevices');

/**
 * @namespace   Tine.ActiveSync.syncdevices
 * @class       Tine.ActiveSync.SyncDeviceEditDialog
 * @extends     Tine.widgets.dialog.EditDialog
 * 
 * <p>Sync devices edit dialog</p>
 * <p>
 * </p>
 * 
 * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
 * @author      Lars Kneschke <l.kneschke@metaways.de>
 * 
 * @param       {Object} config
 * @constructor
 * Create a new Tine.Admin.SyncDeviceEditDialog
 */
Tine.ActiveSync.SyncDeviceEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog, {
    
    /**
     * @private
     */
    windowNamePrefix: 'syncdeviceEditWindow_',
    appName: 'ActiveSync',
    recordClass: Tine.ActiveSync.Model.SyncDevice,
    recordProxy: Tine.ActiveSync.syncdevicesBackend,
    evalGrants: false,
    
    /**
     * executed after record got updated from proxy
     */
    onRecordLoad: function () {
        Tine.ActiveSync.SyncDeviceEditDialog.superclass.onRecordLoad.apply(this, arguments);
    },
    
    /**
     * executed when record gets updated from form
     */
    onRecordUpdate: function () {
        Tine.ActiveSync.SyncDeviceEditDialog.superclass.onRecordUpdate.apply(this, arguments);
    },
    
    /**
     * returns dialog
     */
    getFormItems: function () {
        return {
            layout: 'vbox',
            layoutConfig: {
                align: 'stretch',
                pack: 'start'
            },
            border: false,
            items: [{
                xtype: 'columnform',
                border: false,
                autoHeight: true,
                items: [
                    [{
                        columnWidth: 0.33,
                        fieldLabel: this.app.i18n._('Device ID'),
                        name: 'deviceid',
                        allowBlank: false,
                        readOnly: true,
                        maxLength: 40
                    }, {
                        columnWidth: 0.33,
                        fieldLabel: this.app.i18n._('Devicetype'),
                        name: 'devicetype',
                        allowBlank: false,
                        readOnly: true,
                        maxLength: 40
                    }, {
                        columnWidth: 0.333,
                        fieldLabel: this.app.i18n._('Owner'),
                        name: 'owner_id',
                        allowBlank: false,
                        xtype: 'addressbookcontactpicker',
                        userOnly: true,
                        useAccountRecord: true,
                        blurOnSelect: true,
                        selectOnFocus: true,
                        readOnly: true,
                        maxLength: 40
                    }], [{
                        columnWidth: 0.33,
                        fieldLabel: this.app.i18n._('Policy'),
                        name: 'policy_id',
                        readOnly: true,
                        maxLength: 40
                    }, {
                        columnWidth: 0.33,
                        fieldLabel: this.app.i18n._('AS Version'),
                        name: 'acsversion',
                        readOnly: true,
                        maxLength: 40
                    }, {
                        columnWidth: 0.333,
                        fieldLabel: this.app.i18n._('Useragent'),
                        name: 'useragent',
                        readOnly: true,
                        maxLength: 40
                    }], [{
                        columnWidth: 0.33,
                        fieldLabel: this.app.i18n._('Model'),
                        name: 'model',
                        readOnly: true,
                        maxLength: 40
                    }, {
                        columnWidth: 0.33,
                        fieldLabel: this.app.i18n._('IMEI'),
                        name: 'imei',
                        readOnly: true,
                        maxLength: 40
                    }, {
                        columnWidth: 0.333,
                        fieldLabel: this.app.i18n._('Friendly Name'),
                        name: 'friendlyname',
                        readOnly: true,
                        maxLength: 40
                    }], [{
                        columnWidth: 0.33,
                        fieldLabel: this.app.i18n._('OS'),
                        name: 'os',
                        readOnly: true,
                        maxLength: 40
                    }, {
                        columnWidth: 0.33,
                        fieldLabel: this.app.i18n._('OS Language'),
                        name: 'oslanguage',
                        readOnly: true,
                        maxLength: 40
                    }, {
                        columnWidth: 0.333,
                        fieldLabel: this.app.i18n._('Phonenumber'),
                        name: 'phonenumber',
                        readOnly: true,
                        maxLength: 40
                    }]
                ]
            }]
        };
    }
});

/**
 * Container Edit Popup
 * 
 * @param   {Object} config
 * @return  {Ext.ux.Window}
 */
Tine.ActiveSync.SyncDeviceEditDialog.openWindow = function (config) {
    var window = Tine.WindowFactory.getWindow({
        width: 600,
        height: 400,
        name: Tine.ActiveSync.SyncDeviceEditDialog.prototype.windowNamePrefix + Ext.id(),
        contentPanelConstructor: 'Tine.ActiveSync.SyncDeviceEditDialog',
        contentPanelConstructorConfig: config
    });
    return window;
};
/*
 * Tine 2.0
 * 
 * @package     ActiveSync
 * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
 * @author      Stefanie Stamer <s.stamer@metaways.de>
 * @copyright   Copyright (c) 2015 Metaways Infosystems GmbH (http://www.metaways.de)
 *
 */
 
Ext.ns('Tine.ActiveSync');

/**
 * @namespace Tine.ActiveSync
 * @class     Tine.ActiveSync.SyncDevicesGridPanel
 * @extends   Tine.widgets.grid.GridPanel
 * SyncDevicess Grid Panel <br>
 * 
 * @author      Cornelius Weiss <c.weiss@metaways.de>
 */
Tine.ActiveSync.SyncDevicesGridPanel = Ext.extend(Tine.widgets.grid.GridPanel, {
    /**
     * @cfg
     */
    recordClass: Tine.ActiveSync.Model.SyncDevice,
    recordProxy: Tine.ActiveSync.syncdevicesBackend,
    defaultSortInfo: {field: 'deviceid', direction: 'ASC'},
    evalGrants: false,
    gridConfig: {
        autoExpandColumn: 'deviceid'
    },
    addButton: false,
    asAdminModule: false,
    
    /**
     * initComponent
     */
    initComponent: function() {
        this.app = Tine.Tinebase.appMgr.get('ActiveSync');
        this.gridConfig.cm = this.getColumnModel();
        Tine.ActiveSync.SyncDevicesGridPanel.superclass.initComponent.call(this);
    },
    
    /**
     * returns column model
     * 
     * @return Ext.grid.ColumnModel
     * @private
     */
    getColumnModel: function() {
        return new Ext.grid.ColumnModel({
            defaults: {
                sortable: true,
                hidden: true,
                resizable: true
            },
            columns: this.getColumns()
        });
    },
    
    /**
     * returns columns
     * @private
     * @return Array
     */
    getColumns: function(){
        return [
            { header: this.app.i18n._('ID'),             id: 'id',                dataIndex: 'id',                hidden: true,  width: 50},
            { header: this.app.i18n._('Device ID'),      id: 'deviceid',          dataIndex: 'deviceid',          hidden: false, width: 200},
            { header: this.app.i18n._('Devicetype'),     id: 'devicetype',        dataIndex: 'devicetype',        hidden: false, width: 100},
            { header: this.app.i18n._('Owner'),          id: 'owner_id',          dataIndex: 'owner_id',          hidden: false, width: 80,  renderer: Tine.Tinebase.common.usernameRenderer},
            { header: this.app.i18n._('Policy'),         id: 'policy_id',         dataIndex: 'policy_id',         hidden: false, width: 200},
            { header: this.app.i18n._('AS Version'),     id: 'acsversion',        dataIndex: 'acsversion',        hidden: false, width: 100},
            { header: this.app.i18n._('Useragent'),      id: 'useragent',         dataIndex: 'useragent',         hidden: true,  width: 200},
            { header: this.app.i18n._('Model'),          id: 'model',             dataIndex: 'model',             hidden: false, width: 200},
            { header: this.app.i18n._('IMEI'),           id: 'imei',              dataIndex: 'imei',              hidden: true,  width: 200},
            { header: this.app.i18n._('Friendly Name'),  id: 'friendlyname',      dataIndex: 'friendlyname',      hidden: false, width: 200},
            { header: this.app.i18n._('OS'),             id: 'os',                dataIndex: 'os',                hidden: false, width: 200},
            { header: this.app.i18n._('OS Language'),    id: 'oslanguage',        dataIndex: 'oslanguage',        hidden: true,  width: 200},
            { header: this.app.i18n._('Phonenumber'),    id: 'phonenumber',       dataIndex: 'phonenumber',       hidden: false, width: 200},
            { header: this.app.i18n._('Ping Lifetime'),  id: 'pinglifetime',      dataIndex: 'pinglifetime',      hidden: true,  width: 200},
            //{ header: this.app.i18n._('Ping Folder'),    id: 'pingfolder',        dataIndex: 'pingfolder',        hidden: false, width: 200},
            { header: this.app.i18n._('Remote Wipe'),    id: 'remotewipe',        dataIndex: 'remotewipe',        hidden: false, width: 100},
            { header: this.app.i18n._('Calendarfilter'), id: 'calendarfilter_id', dataIndex: 'calendarfilter_id', hidden: true,  width: 200},
            { header: this.app.i18n._('Contactsfilter'), id: 'contactsfilter_id', dataIndex: 'contactsfilter_id', hidden: true,  width: 200},
            { header: this.app.i18n._('Emailfilter'),    id: 'emailfilter_id',    dataIndex: 'emailfilter_id',    hidden: true,  width: 200},
            { header: this.app.i18n._('Tasksfilter'),    id: 'tasksfilter_id',    dataIndex: 'tasksfilter_id',    hidden: true,  width: 200},
            { header: this.app.i18n._('Last Ping'),      id: 'lastping',          dataIndex: 'lastping',          hidden: false, width: 200, renderer: Tine.Tinebase.common.dateTimeRenderer}
        ];
    },
        /**
     * initialises filter toolbar
     */
    initFilterPanel: function() {
        this.filterToolbar = new Tine.widgets.grid.FilterToolbar({
            filterModels: [
                {label: this.app.i18n._('Quicksearch'),     field: 'query',    operators: ['contains']},
                {label: this.app.i18n._('Device ID'),       field: 'deviceid', operators: ['contains']}
            ],
            defaultFilter: 'query',
            /*filters: [
                {field: 'deviceid', operator: 'equals', value: 'shared'}
            ],*/
            plugins: [
                new Tine.widgets.grid.FilterToolbarQuickFilterPlugin()
            ]
        });
        this.plugins = this.plugins || [];
        this.plugins.push(this.filterToolbar);
    },
    
    initLayout: function() {
        this.supr().initLayout.call(this);
        
        if (! this.asAdminModule) {
            this.items.push({
                region : 'north',
                height : 55,
                border : false,
                items  : this.actionToolbar
            });
        }
    }
});
/*
 * Tine 2.0
 * 
 * @package     ActiveSync
 * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
 * @author      Philipp Schüle <p.schuele@metaways.de>
 * @copyright   Copyright (c) 2015 Metaways Infosystems GmbH (http://www.metaways.de)
 *
 */

Ext.namespace('Tine.ActiveSync');

/**
 * admin settings panel
 * 
 * @namespace   Tine.ActiveSync
 * @class       Tine.ActiveSync.AdminPanel
 * @extends     Ext.TabPanel
 * 
 * <p>ActiveSync Admin Panel</p>
 * <p><pre>
 * </pre></p>
 * 
 * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
 * @author      Philipp Schuele <p.schuele@metaways.de>
 * @copyright   Copyright (c) 2009 Metaways Infosystems GmbH (http://www.metaways.de)
 * 
 * @param       {Object} config
 * @constructor
 * Create a new Tine.ActiveSync.AdminPanel
 */
Tine.ActiveSync.AdminPanel = Ext.extend(Ext.TabPanel, {

    border: false,
    activeTab: 0,

    /**
     * @private
     */
    initComponent: function() {
        
        this.app = Tine.Tinebase.appMgr.get('ActiveSync');
        
        this.items = [new Tine.ActiveSync.SyncDevicesGridPanel({
            title: this.app.i18n._('Sync Devices'),
            // TODO make this work
            disabled: ! Tine.Tinebase.common.hasRight('manage_devices', 'ActiveSync')
        })];
        
        Tine.ActiveSync.AdminPanel.superclass.initComponent.call(this);
    }
});
    
/**
 * ActiveSync Admin Panel Popup
 * 
 * @param   {Object} config
 * @return  {Ext.ux.Window}
 */
Tine.ActiveSync.AdminPanel.openWindow = function (config) {
    var window = Tine.WindowFactory.getWindow({
        width: 700,
        height: 470,
        name: 'activesync-manage-syncdevice',
        contentPanelConstructor: 'Tine.ActiveSync.AdminPanel',
        contentPanelConstructorConfig: config
    });
};
