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