/*!
 * Tine 2.0 - ExampleApplication 
 * Copyright (c) 2007-2014 Metaways Infosystems GmbH (http://www.metaways.de)
 * http://www.gnu.org/licenses/agpl.html AGPL Version 3
 */
/**
 * Tine 2.0
 * 
 * @package     Example
 * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
 * @author      Flávio Gomes da Silva Lisboa <flavio.lisboa@serpro.gov.br>
 * @copyright   Copyright (c) 2007-2014 Metaways Infosystems GmbH (http://www.metaways.de)
 *
 */

Ext.ns('Tine', 'Tine.Example');

/**
 * @namespace   Tine.Example
 * @class       Tine.Example.Application
 * @extends     Tine.Tinebase.Application
 * Example Application Object <br>
 * 
 * @author      Flávio Gomes da Silva Lisboa <flavio.lisboa@serpro.gov.br>
 */
Tine.Example.Application = Ext.extend(Tine.Tinebase.Application, {
    /**
     * auto hook text i18n._('New Example')
     */
    addButtonText: 'New Example'
});

// default mainscreen
Tine.Example.MainScreen = Ext.extend(Tine.widgets.MainScreen, {
    activeContentType: 'Example'
});

Tine.Example.ExampleTreePanel = function(config) {
    Ext.apply(this, config);
    
    this.id = 'ExampleTreePanel';
    this.recordClass = Tine.Example.Model.Example;
    
    this.filterMode = 'filterToolbar';
    Tine.Example.ExampleTreePanel.superclass.constructor.call(this);
};

Ext.extend(Tine.Example.ExampleTreePanel, Tine.widgets.container.TreePanel, {
    afterRender: function() {
        this.supr().afterRender.apply(this, arguments);
    }
});

Tine.Example.ExampleFilterPanel = function(config) {
    Ext.apply(this, config);
    Tine.Example.ExampleFilterPanel.superclass.constructor.call(this);
};

Ext.extend(Tine.Example.ExampleFilterPanel, Tine.widgets.persistentfilter.PickerPanel, {
    filter: [{field: 'model', operator: 'equals', value: 'Example_Model_ExampleFilter'}]
});
﻿/*
 * Tine 2.0
 * 
 * @package     ExampleApplication
 * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
 * @author      Alexander Stintzing <a.stintzing@metaways.de>
 * @copyright   Copyright (c) 2012 Metaways Infosystems GmbH (http://www.metaways.de)
 *
 */
 
Ext.namespace('Tine.ExampleApplication');

/**
 * Example grid panel
 * 
 * @namespace   Tine.ExampleApplication
 * @class       Tine.ExampleApplication.ExampleGridPanel
 * @extends     Tine.widgets.grid.GridPanel
 * 
 * <p>Example Grid Panel</p>
 * <p><pre>
 * </pre></p>
 * 
 * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
 * @author      Alexander Stintzing <a.stintzing@metaways.de>
 * 
 * @param       {Object} config
 * @constructor
 * Create a new Tine.ExampleApplication.ExampleGridPanel
 */
Tine.ExampleApplication.ExampleGridPanel = Ext.extend(Tine.widgets.grid.GridPanel, {
    initComponent: function() {
        this.initDetailsPanel();
        Tine.ExampleApplication.ExampleGridPanel.superclass.initComponent.call(this);
    },
    
    /**
     * @private
     */
    initDetailsPanel: function() {
        this.detailsPanel = new Tine.ExampleApplication.ExampleDetailsPanel({
            grid : this,
            app: this.app
        });
    }
});
/*
 * Tine 2.0
 * 
 * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
 * @author      Cornelius Weiss <c.weiss@metaways.de>
 * @copyright   Copyright (c) 2007-2012 Metaways Infosystems GmbH (http://www.metaways.de)
 */
Ext.ns('Tine.ExampleApplication');

/**
 * @namespace   Tine.ExampleApplication
 * @class       Tine.ExampleApplication.ExampleRecordEditDialog
 * @extends     Tine.widgets.dialog.EditDialog
 * 
 * <p>ExampleRecord Compose Dialog</p>
 * <p></p>
 * 
 *  @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
 * @author      Cornelius Weiss <c.weiss@metaways.de>
 * @copyright   Copyright (c) 2007-2008 Metaways Infosystems GmbH (http://www.metaways.de)
 * 
 * @param       {Object} config
 * @constructor
 * Create a new Tine.ExampleApplication.ExampleRecordEditDialog
 */
Tine.ExampleApplication.ExampleRecordEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog, {
    /**
     * @private
     */
    windowHeight: 470,
    windowWidth: 800,
    displayNotes: true,

    /**
     * returns dialog
     * 
     * NOTE: when this method gets called, all initalisation is done.
     * 
     * @return {Object}
     * @private
     */
    getFormItems: function() {
        return {
            xtype: 'tabpanel',
            border: false,
            plain:true,
            activeTab: 0,
            border: false,
            items:[{
                title: this.app.i18n._('ExampleRecord'),
                autoScroll: true,
                border: false,
                frame: true,
                layout: 'border',
                items: [{
                    region: 'center',
                    xtype: 'columnform',
                    labelAlign: 'top',
                    formDefaults: {
                        xtype:'textfield',
                        anchor: '100%',
                        labelSeparator: '',
                        columnWidth: .333
                    },
                    items: [[{
                        columnWidth: 1,
                        fieldLabel: this.app.i18n._('Name'),
                        name: 'name',
                        allowBlank: false
                        }], [new Tine.Tinebase.widgets.keyfield.ComboBox({
                            app: 'ExampleApplication',
                            keyFieldName: 'exampleStatus',
                            fieldLabel: this.app.i18n._('Status'),
                            name: 'status',
                            columnWidth: 0.5
                        }), new Tine.Tinebase.widgets.keyfield.ComboBox({
                            app: 'ExampleApplication',
                            keyFieldName: 'exampleReason',
                            fieldLabel: this.app.i18n._('Reason'),
                            name: 'reason',
                            columnWidth: 0.5
                        })]
                    ] 
                }, {
                    // tags
                    layout: 'accordion',
                    animate: true,
                    region: 'east',
                    width: 210,
                    split: true,
                    collapsible: true,
                    collapseMode: 'mini',
                    header: false,
                    margins: '0 5 0 5',
                    border: true,
                    items: [
                    new Tine.widgets.tags.TagPanel({
                        app: 'ExampleApplication',
                        border: false,
                        bodyStyle: 'border:1px solid #B5B8C8;'
                    })]
                }]
            }, new Tine.widgets.activities.ActivitiesTabPanel({
                app: this.appName,
                record_id: this.record.id,
                record_model: this.appName + '_Model_' + this.recordClass.getMeta('modelName')
            })]
        };
    }
});
/* 
 * Tine 2.0
 * 
 * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
 * @author      Alexander Stintzing <a.stintzing@metaways.de>
 * @copyright   Copyright (c) 2012 Metaways Infosystems GmbH (http://www.metaways.de)
 */
 
Ext.ns('Tine.ExampleApplication');

/**
 * @class     Tine.ExampleApplication.ExampleDetailsPanel
 * @namespace ExampleApplication
 * @extends   Tine.widgets.grid.DetailsPanel
 * @author    Alexander Stintzing <a.stintzing@metaways.de>
 */

Tine.ExampleApplication.ExampleDetailsPanel = Ext.extend(Tine.widgets.grid.DetailsPanel, {
    
    app: null,
    
    /**
     * @cfg {Number} defaultHeight
     * default Heights
     */
    defaultHeight: 100,
    
    initComponent: function() {
        this.summaryRecord = new Ext.data.Record({
            count: 0
        }, 0);
        
        Tine.ExampleApplication.ExampleDetailsPanel.superclass.initComponent.call(this);
    },
    
    /**
     * default panel w.o. data
     * 
     * @return {Ext.ux.display.DisplayPanel}
     */
    getDefaultInfosPanel: function() {
        return this.getMultiRecordsPanel();
    },
    
    /**
     * get panel for multi selection aggregates/information
     * 
     * @return {Ext.Panel}
     */
    getMultiRecordsPanel: function() {
        if (! this.multiRecordsPanel) {
            this.multiRecordsPanel = new Ext.ux.display.DisplayPanel(
                this.wrapPanel([{
                    xtype: 'ux.displayfield',
                    name: 'count',
                    fieldLabel: this.app.i18n._('Total Example Records')
                }], 160)
            );
        }
        return this.multiRecordsPanel;
    },
    
    /**
     * main example record details panel
     * 
     * @return {Ext.ux.display.DisplayPanel}
     */
    getSingleRecordPanel: function() {
        if (! this.singleRecordPanel) {
            this.singleRecordPanel = new Ext.ux.display.DisplayPanel(
                this.wrapPanel([{
                    xtype: 'ux.displayfield',
                    name: 'name',
                    fieldLabel: this.app.i18n._('Name')
                }, {
                    xtype: 'ux.displayfield',
                    name: 'status',
                    fieldLabel: this.app.i18n._('Status'),
                    renderer: Tine.Tinebase.widgets.keyfield.Renderer.get('ExampleApplication', 'exampleStatus', 'text')
                }], 80)
            );
        }
        return this.singleRecordPanel;
    },
    
    /**
     * update example record details panel
     * 
     * @param {Tine.Tinebase.data.Record} record
     * @param {Mixed} body
     */
    updateDetails: function(record, body) {
        this.getSingleRecordPanel().loadRecord.defer(100, this.getSingleRecordPanel(), [record]);
    },
    
    /**
     * show default template
     * 
     * @param {Mixed} body
     */
    showDefault: function(body) {
        this.showMulti(this.grid.getSelectionModel());
    },
    
    /**
     * show template for multiple rows
     * 
     * @param {Ext.grid.RowSelectionModel} sm
     * @param {Mixed} body
     */
    showMulti: function(sm, body) {
        if (sm.getCount() === 0) {
            var count = this.grid.store.proxy.jsonReader.jsonData.totalcount;
        } else {
            var count = sm.getCount();
        }
        
        this.summaryRecord.set('count', count);
        
        this.getMultiRecordsPanel().loadRecord.defer(100, this.getMultiRecordsPanel(), [this.summaryRecord]);
    }
});
/*
 * Tine 2.0
 * 
 * @package     ExampleApplication
 * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
 * @author      Cornelius Weiß <c.weiss@metaways.de>
 * @copyright   Copyright (c) 2015 Metaways Infosystems GmbH (http://www.metaways.de)
 *
 */

Ext.namespace('Tine.ExampleApplication');

/**
 * admin settings panel
 * 
 * @namespace   Tine.ExampleApplication
 * @class       Tine.ExampleApplication.AdminPanel
 * @extends     Ext.TabPanel
 *
 * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
 * @author      Cornelius Weiß <c.weiss@metaways.de>
 * @copyright   Copyright (c) 2015 Metaways Infosystems GmbH (http://www.metaways.de)
 * 
 * @param       {Object} config
 * @constructor
 * Create a new Tine.ExampleApplication.AdminPanel
 */
Tine.ExampleApplication.AdminPanel = Ext.extend(Ext.TabPanel, {

    border: false,
    activeTab: 0,

    /**
     * @private
     */
    initComponent: function() {
        
        this.app = Tine.Tinebase.appMgr.get('ExampleApplication');
        
        this.items = [
            new Tine.Admin.config.GridPanel({
                configApp: this.app
            })

        ];
        
        Tine.ExampleApplication.AdminPanel.superclass.initComponent.call(this);
    }
});
    
/**
 * ExampleApplication Admin Panel Popup
 * 
 * @param   {Object} config
 * @return  {Ext.ux.Window}
 */
Tine.ExampleApplication.AdminPanel.openWindow = function (config) {
    var window = Tine.WindowFactory.getWindow({
        width: 600,
        height: 470,
        name: 'exampleapp-admin-panel',
        contentPanelConstructor: 'Tine.ExampleApplication.AdminPanel',
        contentPanelConstructorConfig: config
    });
};
