FeedInfo.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**
  2. * @class FeedViewer.FeedInfo
  3. * @extends Ext.tab.Panel
  4. *
  5. * A container class for showing a series of feed details
  6. *
  7. * @constructor
  8. * Create a new Feed Info
  9. * @param {Object} config The config object
  10. */
  11. Ext.define('FeedViewer.FeedInfo', {
  12. extend: 'Ext.tab.Panel',
  13. alias: 'widget.feedinfo',
  14. maxTabWidth: 230,
  15. border: false,
  16. initComponent: function() {
  17. this.tabBar = {
  18. border: true
  19. };
  20. this.callParent();
  21. },
  22. /**
  23. * Add a new feed
  24. * @param {String} title The title of the feed
  25. * @param {String} url The url of the feed
  26. */
  27. addFeed: function(title, url){
  28. var active = this.items.first();
  29. if (!active) {
  30. active = this.add({
  31. xtype: 'feeddetail',
  32. title: title,
  33. url: url,
  34. closable: false,
  35. listeners: {
  36. scope: this,
  37. opentab: this.onTabOpen,
  38. openall: this.onOpenAll,
  39. rowdblclick: this.onRowDblClick
  40. }
  41. });
  42. } else {
  43. active.loadFeed(url);
  44. active.tab.setText(title);
  45. }
  46. this.setActiveTab(active);
  47. },
  48. /**
  49. * Listens for a new tab request
  50. * @private
  51. * @param {FeedViewer.FeedPost} The post
  52. * @param {Ext.data.Model} model The model
  53. */
  54. onTabOpen: function(post, rec) {
  55. var items = [],
  56. item,
  57. title;
  58. if (Ext.isArray(rec)) {
  59. Ext.each(rec, function(rec) {
  60. title = rec.get('title');
  61. if (!this.getTabByTitle(title)) {
  62. items.push({
  63. inTab: true,
  64. xtype: 'feedpost',
  65. title: title,
  66. closable: true,
  67. data: rec.data,
  68. active: rec
  69. });
  70. }
  71. }, this);
  72. this.add(items);
  73. }
  74. else {
  75. title = rec.get('title');
  76. item = this.getTabByTitle(title);
  77. if (!item) {
  78. item = this.add({
  79. inTab: true,
  80. xtype: 'feedpost',
  81. title: title,
  82. closable: true,
  83. data: rec.data,
  84. active: rec
  85. });
  86. }
  87. this.setActiveTab(item);
  88. }
  89. },
  90. /**
  91. * Find a tab by title
  92. * @param {String} title The title of the tab
  93. * @return {Ext.Component} The panel matching the title. null if not found.
  94. */
  95. getTabByTitle: function(title) {
  96. var index = this.items.findIndex('title', title);
  97. return (index < 0) ? null : this.items.getAt(index);
  98. },
  99. /**
  100. * Listens for a row dblclick
  101. * @private
  102. * @param {FeedViewer.Detail} detail The detail
  103. * @param {Ext.data.Model} model The model
  104. */
  105. onRowDblClick: function(info, rec){
  106. this.onTabOpen(null, rec);
  107. },
  108. /**
  109. * Listens for the open all click
  110. * @private
  111. * @param {FeedViewer.FeedDetail}
  112. */
  113. onOpenAll: function(detail) {
  114. this.onTabOpen(null, detail.getFeedData());
  115. }
  116. });