PreviewPlugin.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. This file is part of Ext JS 4
  3. Copyright (c) 2011 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  7. If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
  8. */
  9. /**
  10. * @class Ext.ux.PreviewPlugin
  11. * @extends Ext.AbstractPlugin
  12. *
  13. * The Preview enables you to show a configurable preview of a record.
  14. *
  15. * This plugin assumes that it has control over the features used for this
  16. * particular grid section and may conflict with other plugins.
  17. *
  18. * @alias plugin.preview
  19. * @ptype preview
  20. */
  21. Ext.define('Ext.ux.PreviewPlugin', {
  22. extend: 'Ext.AbstractPlugin',
  23. alias: 'plugin.preview',
  24. requires: ['Ext.grid.feature.RowBody', 'Ext.grid.feature.RowWrap'],
  25. // private, css class to use to hide the body
  26. hideBodyCls: 'x-grid-row-body-hidden',
  27. /**
  28. * @cfg {String} bodyField
  29. * Field to display in the preview. Must me a field within the Model definition
  30. * that the store is using.
  31. */
  32. bodyField: '',
  33. /**
  34. * @cfg {Boolean} previewExpanded
  35. */
  36. previewExpanded: true,
  37. constructor: function(config) {
  38. this.callParent(arguments);
  39. var bodyField = this.bodyField,
  40. hideBodyCls = this.hideBodyCls,
  41. section = this.getCmp(),
  42. features = [{
  43. ftype: 'rowbody',
  44. getAdditionalData: function(data, idx, record, orig, view) {
  45. var o = Ext.grid.feature.RowBody.prototype.getAdditionalData.apply(this, arguments);
  46. Ext.apply(o, {
  47. rowBody: data[bodyField],
  48. rowBodyCls: section.previewExpanded ? '' : hideBodyCls
  49. });
  50. return o;
  51. }
  52. },{
  53. ftype: 'rowwrap'
  54. }];
  55. section.previewExpanded = this.previewExpanded;
  56. if (!section.features) {
  57. section.features = [];
  58. }
  59. section.features = features.concat(section.features);
  60. },
  61. /**
  62. * Toggle between the preview being expanded/hidden
  63. * @param {Boolean} expanded Pass true to expand the record and false to not show the preview.
  64. */
  65. toggleExpanded: function(expanded) {
  66. var view = this.getCmp();
  67. this.previewExpanded = view.previewExpanded = expanded;
  68. view.refresh();
  69. }
  70. });