7e6dec13fade28f9e401d9aefac0e56fb712f975
[tine20] / tine20 / Tool / Application / templates / js / ExampleRecordDetailsPanel.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) 2012 Metaways Infosystems GmbH (http://www.metaways.de)
7  */
8  
9 Ext.ns('Tine.ExampleApplication');
10
11 /**
12  * @class     Tine.ExampleApplication.ExampleRecordDetailsPanel
13  * @namespace ExampleApplication
14  * @extends   Tine.widgets.grid.DetailsPanel
15  * @author    Alexander Stintzing <a.stintzing@metaways.de>
16  */
17
18 Tine.ExampleApplication.ExampleRecordDetailsPanel = Ext.extend(Tine.widgets.grid.DetailsPanel, {
19     
20     app: null,
21     
22     /**
23      * @cfg {Number} defaultHeight
24      * default Heights
25      */
26     defaultHeight: 100,
27     
28     initComponent: function() {
29         this.summaryRecord = new Ext.data.Record({
30             count: 0
31         }, 0);
32         
33         Tine.ExampleApplication.ExampleRecordDetailsPanel.superclass.initComponent.call(this);
34     },
35     
36     /**
37      * default panel w.o. data
38      * 
39      * @return {Ext.ux.display.DisplayPanel}
40      */
41     getDefaultInfosPanel: function() {
42         return this.getMultiRecordsPanel();
43     },
44     
45     /**
46      * get panel for multi selection aggregates/information
47      * 
48      * @return {Ext.Panel}
49      */
50     getMultiRecordsPanel: function() {
51         if (! this.multiRecordsPanel) {
52             this.multiRecordsPanel = new Ext.ux.display.DisplayPanel(
53                 this.wrapPanel([{
54                     xtype: 'ux.displayfield',
55                     name: 'count',
56                     fieldLabel: this.app.i18n._('Total Example Records')
57                 }], 160)
58             );
59         }
60         return this.multiRecordsPanel;
61     },
62     
63     /**
64      * main example record details panel
65      * 
66      * @return {Ext.ux.display.DisplayPanel}
67      */
68     getSingleRecordPanel: function() {
69         if (! this.singleRecordPanel) {
70             this.singleRecordPanel = new Ext.ux.display.DisplayPanel(
71                 this.wrapPanel([{
72                     xtype: 'ux.displayfield',
73                     name: 'name',
74                     fieldLabel: this.app.i18n._('Name')
75                 }, {
76                     xtype: 'ux.displayfield',
77                     name: 'status',
78                     fieldLabel: this.app.i18n._('Status'),
79                     renderer: Tine.Tinebase.widgets.keyfield.Renderer.get('ExampleApplication', 'exampleStatus', 'text')
80                 }], 80)
81             );
82         }
83         return this.singleRecordPanel;
84     },
85     
86     /**
87      * update example record details panel
88      * 
89      * @param {Tine.Tinebase.data.Record} record
90      * @param {Mixed} body
91      */
92     updateDetails: function(record, body) {
93         this.getSingleRecordPanel().loadRecord.defer(100, this.getSingleRecordPanel(), [record]);
94     },
95     
96     /**
97      * show default template
98      * 
99      * @param {Mixed} body
100      */
101     showDefault: function(body) {
102         this.showMulti(this.grid.getSelectionModel());
103     },
104     
105     /**
106      * show template for multiple rows
107      * 
108      * @param {Ext.grid.RowSelectionModel} sm
109      * @param {Mixed} body
110      */
111     showMulti: function(sm, body) {
112         if (sm.getCount() === 0) {
113             var count = this.grid.store.proxy.jsonReader.jsonData.totalcount;
114         } else {
115             var count = sm.getCount();
116         }
117         
118         this.summaryRecord.set('count', count);
119         
120         this.getMultiRecordsPanel().loadRecord.defer(100, this.getMultiRecordsPanel(), [this.summaryRecord]);
121     }
122 });