PreviewPlugin.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * @class Ext.ux.PreviewPlugin
  3. * @extends Ext.AbstractPlugin
  4. *
  5. * The Preview enables you to show a configurable preview of a record.
  6. *
  7. * This plugin assumes that it has control over the features used for this
  8. * particular grid section and may conflict with other plugins.
  9. *
  10. * @alias plugin.preview
  11. * @ptype preview
  12. */
  13. Ext.define('Ext.ux.PreviewPlugin', {
  14. extend: 'Ext.AbstractPlugin',
  15. alias: 'plugin.preview',
  16. requires: ['Ext.grid.feature.RowBody', 'Ext.grid.feature.RowWrap'],
  17. // private, css class to use to hide the body
  18. hideBodyCls: 'x-grid-row-body-hidden',
  19. /**
  20. * @cfg {String} bodyField
  21. * Field to display in the preview. Must me a field within the Model definition
  22. * that the store is using.
  23. */
  24. bodyField: '',
  25. /**
  26. * @cfg {Boolean} previewExpanded
  27. */
  28. previewExpanded: true,
  29. constructor: function(config) {
  30. this.callParent(arguments);
  31. var bodyField = this.bodyField,
  32. hideBodyCls = this.hideBodyCls,
  33. section = this.getCmp(),
  34. features = [{
  35. ftype: 'rowbody',
  36. getAdditionalData: function(data, idx, record, orig, view) {
  37. var o = Ext.grid.feature.RowBody.prototype.getAdditionalData.apply(this, arguments);
  38. Ext.apply(o, {
  39. rowBody: data[bodyField],
  40. rowBodyCls: section.previewExpanded ? '' : hideBodyCls
  41. });
  42. return o;
  43. }
  44. },{
  45. ftype: 'rowwrap'
  46. }];
  47. section.previewExpanded = this.previewExpanded;
  48. if (!section.features) {
  49. section.features = [];
  50. }
  51. section.features = features.concat(section.features);
  52. },
  53. /**
  54. * Toggle between the preview being expanded/hidden
  55. * @param {Boolean} expanded Pass true to expand the record and false to not show the preview.
  56. */
  57. toggleExpanded: function(expanded) {
  58. var view = this.getCmp();
  59. this.previewExpanded = view.previewExpanded = expanded;
  60. view.refresh();
  61. }
  62. });