FeedPost.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * @class FeedViewer.FeedPost
  3. * @extends Ext.panel.Panel
  4. *
  5. * Shows the detail of a feed post
  6. *
  7. * @constructor
  8. * Create a new Feed Post
  9. * @param {Object} config The config object
  10. */
  11. Ext.define('FeedViewer.FeedPost', {
  12. extend: 'Ext.panel.Panel',
  13. alias: 'widget.feedpost',
  14. cls: 'preview',
  15. autoScroll: true,
  16. border: true,
  17. initComponent: function(){
  18. Ext.apply(this, {
  19. dockedItems: [this.createToolbar()],
  20. tpl: Ext.create('Ext.XTemplate',
  21. '<div class="post-data">',
  22. '<span class="post-date">{pubDate:this.formatDate}</span>',
  23. '<h3 class="post-title">{title}</h3>',
  24. '<h4 class="post-author">by {author:this.defaultValue}</h4>',
  25. '</div>',
  26. '<div class="post-body">{content:this.getBody}</div>',
  27. {
  28. getBody: function(value, all){
  29. return Ext.util.Format.stripScripts(value);
  30. },
  31. defaultValue: function(v){
  32. return v ? v : 'Unknown';
  33. },
  34. formatDate: function(value){
  35. if (!value) {
  36. return '';
  37. }
  38. return Ext.Date.format(value, 'M j, Y, g:i a');
  39. }
  40. }
  41. )
  42. });
  43. this.callParent(arguments);
  44. },
  45. /**
  46. * Set the active post
  47. * @param {Ext.data.Model} rec The record
  48. */
  49. setActive: function(rec) {
  50. this.active = rec;
  51. this.update(rec.data);
  52. },
  53. /**
  54. * Create the top toolbar
  55. * @private
  56. * @return {Ext.toolbar.Toolbar} toolbar
  57. */
  58. createToolbar: function(){
  59. var items = [],
  60. config = {};
  61. if (!this.inTab) {
  62. items.push({
  63. scope: this,
  64. handler: this.openTab,
  65. text: 'View in new tab',
  66. iconCls: 'tab-new'
  67. }, '-');
  68. }
  69. else {
  70. config.cls = 'x-docked-noborder-top';
  71. }
  72. items.push({
  73. scope: this,
  74. handler: this.goToPost,
  75. text: 'Go to post',
  76. iconCls: 'post-go'
  77. });
  78. config.items = items;
  79. return Ext.create('widget.toolbar', config);
  80. },
  81. /**
  82. * Navigate to the active post in a new window
  83. * @private
  84. */
  85. goToPost: function(){
  86. window.open(this.active.get('link'));
  87. },
  88. /**
  89. * Open the post in a new tab
  90. * @private
  91. */
  92. openTab: function(){
  93. this.fireEvent('opentab', this, this.active);
  94. }
  95. });