InfoPanel.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. Ext.define('erp.view.opensys.home.InfoPanel', {
  2. extend: 'Ext.panel.Panel',
  3. alias: 'widget.infopanel',
  4. title:'消息中心',
  5. region: 'center',
  6. border: false,
  7. /* split: true,*/
  8. flex: 2,
  9. layout:'fit',
  10. initComponent: function(){
  11. this.addEvents(
  12. 'rowdblclick',
  13. 'select'
  14. );
  15. Ext.apply(this, {
  16. items:[{
  17. xtype:'grid',
  18. border:true,
  19. store: Ext.create('Ext.data.Store', {
  20. fields:['pr_id','pr_context','pr_date'],
  21. sortInfo: {
  22. property: 'pr_date',
  23. direction: 'DESC'
  24. },
  25. proxy: {
  26. type: 'ajax',
  27. url: '',
  28. reader: {
  29. type: 'json',
  30. record: 'data'
  31. },
  32. listeners: {
  33. exception: this.onProxyException,
  34. scope: this
  35. }
  36. },
  37. listeners: {
  38. load: this.onLoad,
  39. scope: this
  40. }
  41. }),
  42. columns: [{
  43. text: '消息内容',
  44. dataIndex: 'pr_context',
  45. flex: 1,
  46. renderer: this.formatTitle,
  47. sortable:false
  48. }, {
  49. text: '发送时间',
  50. dataIndex: 'pr_date',
  51. renderer: this.formatDate,
  52. width: 200
  53. }]
  54. }]
  55. });
  56. this.callParent(arguments);
  57. this.on('selectionchange', this.onSelect, this);
  58. },
  59. onRowDblClick: function(view, record, item, index, e) {
  60. this.fireEvent('rowdblclick', this, this.store.getAt(index));
  61. },
  62. onSelect: function(model, selections){
  63. var selected = selections[0];
  64. if (selected) {
  65. this.fireEvent('select', this, selected);
  66. }
  67. },
  68. onLoad: function(store, records, success) {
  69. if (this.getStore().getCount()) {
  70. this.getSelectionModel().select(0);
  71. }
  72. },
  73. onProxyException: function(proxy, response, operation) {
  74. Ext.Msg.alert("Error with data from server", operation.error);
  75. this.view.el.update('');
  76. // Update the detail view with a dummy empty record
  77. this.fireEvent('select', this, {data:{}});
  78. },
  79. loadFeed: function(url){
  80. var store = this.store;
  81. store.getProxy().extraParams.feed = url;
  82. store.load();
  83. },
  84. formatTitle: function(value, p, record){
  85. return Ext.String.format('<div class="topic"><b>{0}</b><span class="author">{1}</span></div>', value, record.get('author') || "Unknown");
  86. },
  87. formatDate: function(date){
  88. if (!date) {
  89. return '';
  90. }
  91. var now = new Date(), d = Ext.Date.clearTime(now, true), notime = Ext.Date.clearTime(date, true).getTime();
  92. if (notime === d.getTime()) {
  93. return 'Today ' + Ext.Date.format(date, 'g:i a');
  94. }
  95. d = Ext.Date.add(d, 'd', -6);
  96. if (d.getTime() <= notime) {
  97. return Ext.Date.format(date, 'D g:i a');
  98. }
  99. return Ext.Date.format(date, 'Y/m/d g:i a');
  100. }
  101. });