Web Interface For Lite Argus Control modules
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.

161 lines
4.5 KiB

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