]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | /**\r |
2 | * The Preview Plugin enables toggle of a configurable preview of all visible records.\r | |
3 | *\r | |
4 | * Note: This plugin does NOT assert itself against an existing RowBody feature and may conflict with\r | |
5 | * another instance of the same plugin.\r | |
6 | */\r | |
7 | Ext.define('Ext.ux.PreviewPlugin', {\r | |
8 | extend: 'Ext.plugin.Abstract',\r | |
9 | alias: 'plugin.preview',\r | |
10 | requires: ['Ext.grid.feature.RowBody'],\r | |
11 | \r | |
12 | /**\r | |
13 | * @private\r | |
14 | * css class to use to hide the body\r | |
15 | */\r | |
16 | hideBodyCls: 'x-grid-row-body-hidden',\r | |
17 | \r | |
18 | /**\r | |
19 | * @cfg {String} bodyField\r | |
20 | * Field to display in the preview. Must be a field within the Model definition\r | |
21 | * that the store is using.\r | |
22 | */\r | |
23 | bodyField: '',\r | |
24 | \r | |
25 | /**\r | |
26 | * @cfg {Boolean} previewExpanded\r | |
27 | */\r | |
28 | previewExpanded: true,\r | |
29 | \r | |
30 | /**\r | |
31 | * Plugin may be safely declared on either a panel.Grid or a Grid View/viewConfig\r | |
32 | * @param {Ext.grid.Panel/Ext.view.View} target\r | |
33 | */\r | |
34 | setCmp: function(target) {\r | |
35 | this.callParent(arguments);\r | |
36 | \r | |
37 | // Resolve grid from view as necessary\r | |
38 | var me = this,\r | |
39 | grid = me.cmp = target.isXType('gridview') ? target.grid : target,\r | |
40 | bodyField = me.bodyField,\r | |
41 | hideBodyCls = me.hideBodyCls,\r | |
42 | feature = Ext.create('Ext.grid.feature.RowBody', {\r | |
43 | grid : grid,\r | |
44 | getAdditionalData: function(data, idx, model, rowValues) {\r | |
45 | \r | |
46 | var getAdditionalData = Ext.grid.feature.RowBody.prototype.getAdditionalData,\r | |
47 | additionalData = {\r | |
48 | rowBody: data[bodyField],\r | |
49 | rowBodyCls: grid.getView().previewExpanded ? '' : hideBodyCls\r | |
50 | };\r | |
51 | \r | |
52 | if (Ext.isFunction(getAdditionalData)) {\r | |
53 | // "this" is the RowBody object hjere. Do not change to "me"\r | |
54 | Ext.apply(additionalData, getAdditionalData.apply(this, arguments));\r | |
55 | }\r | |
56 | return additionalData;\r | |
57 | }\r | |
58 | }),\r | |
59 | initFeature = function(grid, view) {\r | |
60 | view.previewExpanded = me.previewExpanded;\r | |
61 | \r | |
62 | // By this point, existing features are already in place, so this must be initialized and added\r | |
63 | view.featuresMC.add(feature);\r | |
64 | feature.init(grid);\r | |
65 | };\r | |
66 | \r | |
67 | // The grid has already created its view\r | |
68 | if (grid.view) {\r | |
69 | initFeature(grid, grid.view);\r | |
70 | }\r | |
71 | \r | |
72 | // At the time a grid creates its plugins, it has not created all the things\r | |
73 | // it needs to create its view correctly.\r | |
74 | // Process the view and init the RowBody Feature as soon as the view is created.\r | |
75 | else {\r | |
76 | grid.on({\r | |
77 | viewcreated: initFeature,\r | |
78 | single: true\r | |
79 | });\r | |
80 | }\r | |
81 | },\r | |
82 | \r | |
83 | /**\r | |
84 | * Toggle between the preview being expanded/hidden on all rows\r | |
85 | * @param {Boolean} expanded Pass true to expand the record and false to not show the preview.\r | |
86 | */\r | |
87 | toggleExpanded: function(expanded) {\r | |
88 | var grid = this.getCmp(),\r | |
89 | view = grid && grid.getView(),\r | |
90 | bufferedRenderer = view.bufferedRenderer,\r | |
91 | scrollManager = view.scrollManager;\r | |
92 | \r | |
93 | if (grid && view && expanded !== view.previewExpanded ) {\r | |
94 | this.previewExpanded = view.previewExpanded = !!expanded;\r | |
95 | view.refreshView();\r | |
96 | \r | |
97 | // If we are using the touch scroller, ensure that the scroller knows about\r | |
98 | // the correct scrollable range\r | |
99 | if (scrollManager) {\r | |
100 | if (bufferedRenderer) {\r | |
101 | bufferedRenderer.stretchView(view, bufferedRenderer.getScrollHeight(true));\r | |
102 | } else {\r | |
103 | scrollManager.refresh(true);\r | |
104 | }\r | |
105 | }\r | |
106 | }\r | |
107 | }\r | |
108 | });\r |