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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
/*!
* Ext JS Library 3.4.0
* Copyright(c) 2006-2011 Sencha Inc.
* licensing@sencha.com
* http://www.sencha.com/license
*/
FeedPanel = function() {
FeedPanel.superclass.constructor.call(this, {
id:'feed-tree',
region:'west',
title:'Feeds',
split:true,
width: 225,
minSize: 175,
maxSize: 400,
collapsible: true,
margins:'0 0 5 5',
cmargins:'0 5 5 5',
rootVisible:false,
lines:false,
autoScroll:true,
root: new Ext.tree.TreeNode('My Feeds'),
collapseFirst:false,
tbar: [{
iconCls:'add-feed',
text:'Add Feed',
handler: this.showWindow,
scope: this
},{
id:'delete',
iconCls:'delete-icon',
text:'Remove',
handler: function(){
var s = this.getSelectionModel().getSelectedNode();
if(s){
this.removeFeed(s.attributes.url);
}
},
scope: this
}]
});
this.feeds = this.root.appendChild(
new Ext.tree.TreeNode({
text:'My Feeds',
cls:'feeds-node',
expanded:true
})
);
this.getSelectionModel().on({
'beforeselect' : function(sm, node){
return node.isLeaf();
},
'selectionchange' : function(sm, node){
if(node){
this.fireEvent('feedselect', node.attributes);
}
this.getTopToolbar().items.get('delete').setDisabled(!node);
},
scope:this
});
this.addEvents({feedselect:true});
this.on('contextmenu', this.onContextMenu, this);
};
Ext.extend(FeedPanel, Ext.tree.TreePanel, {
onContextMenu : function(node, e){
if(!this.menu){ // create context menu on first right click
this.menu = new Ext.menu.Menu({
id:'feeds-ctx',
items: [{
id:'load',
iconCls:'load-icon',
text:'Load Feed',
scope: this,
handler:function(){
this.ctxNode.select();
}
},{
text:'Remove',
iconCls:'delete-icon',
scope: this,
handler:function(){
this.ctxNode.ui.removeClass('x-node-ctx');
this.removeFeed(this.ctxNode.attributes.url);
this.ctxNode = null;
}
},'-',{
iconCls:'add-feed',
text:'Add Feed',
handler: this.showWindow,
scope: this
}]
});
this.menu.on('hide', this.onContextHide, this);
}
if(this.ctxNode){
this.ctxNode.ui.removeClass('x-node-ctx');
this.ctxNode = null;
}
if(node.isLeaf()){
this.ctxNode = node;
this.ctxNode.ui.addClass('x-node-ctx');
this.menu.items.get('load').setDisabled(node.isSelected());
this.menu.showAt(e.getXY());
}
},
onContextHide : function(){
if(this.ctxNode){
this.ctxNode.ui.removeClass('x-node-ctx');
this.ctxNode = null;
}
},
showWindow : function(btn){
if(!this.win){
this.win = new FeedWindow();
this.win.on('validfeed', this.addFeed, this);
}
this.win.show(btn);
},
selectFeed: function(url){
this.getNodeById(url).select();
},
removeFeed: function(url){
var node = this.getNodeById(url);
if(node){
node.unselect();
Ext.fly(node.ui.elNode).ghost('l', {
callback: node.remove, scope: node, duration: .4
});
}
},
addFeed : function(attrs, inactive, preventAnim){
var exists = this.getNodeById(attrs.url);
if(exists){
if(!inactive){
exists.select();
exists.ui.highlight();
}
return;
}
Ext.apply(attrs, {
iconCls: 'feed-icon',
leaf:true,
cls:'feed',
id: attrs.url
});
var node = new Ext.tree.TreeNode(attrs);
this.feeds.appendChild(node);
if(!inactive){
if(!preventAnim){
Ext.fly(node.ui.elNode).slideIn('l', {
callback: node.select, scope: node, duration: .4
});
}else{
node.select();
}
}
return node;
},
// prevent the default context menu when you miss the node
afterRender : function(){
FeedPanel.superclass.afterRender.call(this);
this.el.on('contextmenu', function(e){
e.preventDefault();
});
}
});
Ext.reg('appfeedpanel', FeedPanel);
|