24476f3baf25cc02c736e84ef841a3df94005ed2.svn-base 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. MainPanel = function() {
  7. this.preview = new Ext.Panel({
  8. id : 'preview',
  9. region : 'south',
  10. cls : 'preview',
  11. autoScroll : true,
  12. listeners : FeedViewer.LinkInterceptor,
  13. tbar : [{
  14. id : 'tab',
  15. text : 'View in New Tab',
  16. iconCls : 'new-tab',
  17. disabled : true,
  18. handler : this.openTab,
  19. scope : this
  20. }, '-', {
  21. id : 'win',
  22. text : 'Go to Post',
  23. iconCls : 'new-win',
  24. disabled : true,
  25. scope : this,
  26. handler : function() {
  27. window.open(this.gsm.getSelected().data.link);
  28. }
  29. }],
  30. clear : function() {
  31. this.body.update('');
  32. var items = this.topToolbar.items;
  33. items.get('tab').disable();
  34. items.get('win').disable();
  35. }
  36. });
  37. this.grid = new FeedGrid(this, {
  38. tbar : [{
  39. text : 'Open All',
  40. tooltip : {
  41. title : 'Open All',
  42. text : 'Opens all item in tabs'
  43. },
  44. iconCls : 'tabs',
  45. handler : this.openAll,
  46. scope : this
  47. }, '-', {
  48. split : true,
  49. text : 'Reading Pane',
  50. tooltip : {
  51. title : 'Reading Pane',
  52. text : 'Show, move or hide the Reading Pane'
  53. },
  54. iconCls : 'preview-bottom',
  55. handler : this.movePreview.createDelegate(this, []),
  56. menu : {
  57. id : 'reading-menu',
  58. cls : 'reading-menu',
  59. width : 100,
  60. items : [{
  61. text : 'Bottom',
  62. checked : true,
  63. group : 'rp-group',
  64. checkHandler : this.movePreview,
  65. scope : this,
  66. iconCls : 'preview-bottom'
  67. }, {
  68. text : 'Right',
  69. checked : false,
  70. group : 'rp-group',
  71. checkHandler : this.movePreview,
  72. scope : this,
  73. iconCls : 'preview-right'
  74. }, {
  75. text : 'Hide',
  76. checked : false,
  77. group : 'rp-group',
  78. checkHandler : this.movePreview,
  79. scope : this,
  80. iconCls : 'preview-hide'
  81. }]
  82. }
  83. }, '-', {
  84. pressed : true,
  85. enableToggle : true,
  86. text : 'Summary',
  87. tooltip : {
  88. title : 'Post Summary',
  89. text : 'View a short summary of each item in the list'
  90. },
  91. iconCls : 'summary',
  92. scope : this,
  93. toggleHandler : function(btn, pressed) {
  94. this.grid.togglePreview(pressed);
  95. }
  96. }]
  97. });
  98. MainPanel.superclass.constructor.call(this, {
  99. id : 'main-tabs',
  100. activeTab : 0,
  101. region : 'center',
  102. margins : '0 5 5 0',
  103. resizeTabs : true,
  104. tabWidth : 150,
  105. minTabWidth : 120,
  106. enableTabScroll : true,
  107. plugins : new Ext.ux.TabCloseMenu(),
  108. items : {
  109. id : 'main-view',
  110. layout : 'border',
  111. title : 'Loading...',
  112. hideMode : 'offsets',
  113. items : [this.grid, {
  114. id : 'bottom-preview',
  115. layout : 'fit',
  116. items : this.preview,
  117. height : 250,
  118. split : true,
  119. border : false,
  120. region : 'south'
  121. }, {
  122. id : 'right-preview',
  123. layout : 'fit',
  124. border : false,
  125. region : 'east',
  126. width : 350,
  127. split : true,
  128. hidden : true
  129. }]
  130. }
  131. });
  132. this.gsm = this.grid.getSelectionModel();
  133. this.gsm.on('rowselect', function(sm, index, record) {
  134. FeedViewer.getTemplate().overwrite(this.preview.body,
  135. record.data);
  136. var items = this.preview.topToolbar.items;
  137. items.get('tab').enable();
  138. items.get('win').enable();
  139. }, this, {
  140. buffer : 250
  141. });
  142. this.grid.store.on('beforeload', this.preview.clear, this.preview);
  143. this.grid.store.on('load', this.gsm.selectFirstRow, this.gsm);
  144. this.grid.on('rowdblclick', this.openTab, this);
  145. };
  146. Ext.extend(MainPanel, Ext.TabPanel, {
  147. loadFeed : function(feed) {
  148. this.grid.loadFeed(feed.url);
  149. Ext.getCmp('main-view').setTitle(feed.text);
  150. },
  151. movePreview : function(m, pressed) {
  152. if (!m) { // cycle if not a menu item click
  153. var readMenu = Ext.menu.MenuMgr.get('reading-menu');
  154. readMenu.render();
  155. var items = readMenu.items.items;
  156. var b = items[0], r = items[1], h = items[2];
  157. if (b.checked) {
  158. r.setChecked(true);
  159. } else if (r.checked) {
  160. h.setChecked(true);
  161. } else if (h.checked) {
  162. b.setChecked(true);
  163. }
  164. return;
  165. }
  166. if (pressed) {
  167. var preview = this.preview;
  168. var right = Ext.getCmp('right-preview');
  169. var bot = Ext.getCmp('bottom-preview');
  170. var btn = this.grid.getTopToolbar().items.get(2);
  171. switch (m.text) {
  172. case 'Bottom' :
  173. right.hide();
  174. bot.add(preview);
  175. bot.show();
  176. bot.ownerCt.doLayout();
  177. btn.setIconClass('preview-bottom');
  178. break;
  179. case 'Right' :
  180. bot.hide();
  181. right.add(preview);
  182. right.show();
  183. right.ownerCt.doLayout();
  184. btn.setIconClass('preview-right');
  185. break;
  186. case 'Hide' :
  187. preview.ownerCt.hide();
  188. preview.ownerCt.ownerCt.doLayout();
  189. btn.setIconClass('preview-hide');
  190. break;
  191. }
  192. }
  193. },
  194. openTab : function(record) {
  195. record = (record && record.data) ? record : this.gsm
  196. .getSelected();
  197. var d = record.data;
  198. var id = !d.link ? Ext.id() : d.link.replace(/[^A-Z0-9-_]/gi,
  199. '');
  200. var tab;
  201. if (!(tab = this.getItem(id))) {
  202. tab = new Ext.Panel({
  203. id : id,
  204. cls : 'preview single-preview',
  205. title : d.title,
  206. tabTip : d.title,
  207. html : FeedViewer.getTemplate().apply(d),
  208. closable : true,
  209. listeners : FeedViewer.LinkInterceptor,
  210. autoScroll : true,
  211. border : true,
  212. tbar : [{
  213. text : 'Go to Post',
  214. iconCls : 'new-win',
  215. handler : function() {
  216. window.open(d.link);
  217. }
  218. }]
  219. });
  220. this.add(tab);
  221. }
  222. this.setActiveTab(tab);
  223. },
  224. openAll : function() {
  225. this.beginUpdate();
  226. this.grid.store.data.each(this.openTab, this);
  227. this.endUpdate();
  228. }
  229. });