You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
5.2 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 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
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. Ext.define('FeedGrid', {
  16. extend: 'Ext.grid.GridPanel',
  17. xtype: 'appfeedgrid',
  18. constructor: function(config) {
  19. Ext.apply(this, config);
  20. this.store = new Ext.data.Store({
  21. proxy: new Ext.data.HttpProxy({
  22. url: 'feed-proxy.php'
  23. }),
  24. reader: new Ext.data.XmlReader(
  25. {record: 'item'},
  26. ['title', 'author', {name:'pubDate', type:'date'}, 'link', 'description', 'content']
  27. )
  28. });
  29. this.store.setDefaultSort('pubDate', "DESC");
  30. this.columns = [{
  31. id: 'title',
  32. header: "Title",
  33. dataIndex: 'title',
  34. sortable:true,
  35. width: 420,
  36. renderer: this.formatTitle
  37. },{
  38. header: "Author",
  39. dataIndex: 'author',
  40. width: 100,
  41. hidden: true,
  42. sortable:true
  43. },{
  44. id: 'last',
  45. header: "Date",
  46. dataIndex: 'pubDate',
  47. width: 150,
  48. renderer: this.formatDate,
  49. sortable:true
  50. }];
  51. this.callParent([{
  52. region: 'center',
  53. id: 'topic-grid',
  54. loadMask: {msg:'Loading Feed...'},
  55. sm: new Ext.grid.RowSelectionModel({
  56. singleSelect:true
  57. }),
  58. viewConfig: {
  59. forceFit:true,
  60. enableRowBody:true,
  61. showPreview:true,
  62. getRowClass : this.applyRowClass
  63. }
  64. }]);
  65. this.on('rowcontextmenu', this.onContextClick, this);
  66. },
  67. onContextClick : function(grid, index, e){
  68. if(!this.menu){ // create context menu on first right click
  69. this.menu = new Ext.menu.Menu({
  70. id:'grid-ctx',
  71. items: [{
  72. text: 'View in new tab',
  73. iconCls: 'new-tab',
  74. scope:this,
  75. handler: function(){
  76. this.viewer.openTab(this.ctxRecord);
  77. }
  78. },{
  79. iconCls: 'new-win',
  80. text: 'Go to Post',
  81. scope:this,
  82. handler: function(){
  83. window.open(this.ctxRecord.data.link);
  84. }
  85. },'-',{
  86. iconCls: 'refresh-icon',
  87. text:'Refresh',
  88. scope:this,
  89. handler: function(){
  90. this.ctxRow = null;
  91. this.store.reload();
  92. }
  93. }]
  94. });
  95. this.menu.on('hide', this.onContextHide, this);
  96. }
  97. e.stopEvent();
  98. if(this.ctxRow){
  99. Ext.fly(this.ctxRow).removeClass('x-node-ctx');
  100. this.ctxRow = null;
  101. }
  102. this.ctxRow = this.view.getRow(index);
  103. this.ctxRecord = this.store.getAt(index);
  104. Ext.fly(this.ctxRow).addClass('x-node-ctx');
  105. this.menu.showAt(e.getXY());
  106. },
  107. onContextHide : function(){
  108. if(this.ctxRow){
  109. Ext.fly(this.ctxRow).removeClass('x-node-ctx');
  110. this.ctxRow = null;
  111. }
  112. },
  113. loadFeed : function(url) {
  114. this.store.baseParams = {
  115. feed: url
  116. };
  117. this.store.load();
  118. },
  119. togglePreview : function(show){
  120. this.view.showPreview = show;
  121. this.view.refresh();
  122. },
  123. // within this function "this" is actually the GridView
  124. applyRowClass: function(record, rowIndex, p, ds) {
  125. if (this.showPreview) {
  126. var xf = Ext.util.Format;
  127. p.body = '<p>' + xf.ellipsis(xf.stripTags(record.data.description), 200) + '</p>';
  128. return 'x-grid3-row-expanded';
  129. }
  130. return 'x-grid3-row-collapsed';
  131. },
  132. formatDate : function(date) {
  133. if (!date) {
  134. return '';
  135. }
  136. var now = new Date();
  137. var d = now.clearTime(true);
  138. var notime = date.clearTime(true).getTime();
  139. if (notime == d.getTime()) {
  140. return 'Today ' + date.dateFormat('g:i a');
  141. }
  142. d = d.add('d', -6);
  143. if (d.getTime() <= notime) {
  144. return date.dateFormat('D g:i a');
  145. }
  146. return date.dateFormat('n/j g:i a');
  147. },
  148. formatTitle: function(value, p, record) {
  149. return String.format(
  150. '<div class="topic"><b>{0}</b><span class="author">{1}</span></div>',
  151. value, record.data.author, record.id, record.data.forumid
  152. );
  153. }
  154. });