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.

179 lines
5.0 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. FeedPanel = function() {
  8. FeedPanel.superclass.constructor.call(this, {
  9. id:'feed-tree',
  10. region:'west',
  11. title:'Feeds',
  12. split:true,
  13. width: 225,
  14. minSize: 175,
  15. maxSize: 400,
  16. collapsible: true,
  17. margins:'0 0 5 5',
  18. cmargins:'0 5 5 5',
  19. rootVisible:false,
  20. lines:false,
  21. autoScroll:true,
  22. root: new Ext.tree.TreeNode('My Feeds'),
  23. collapseFirst:false,
  24. tbar: [{
  25. iconCls:'add-feed',
  26. text:'Add Feed',
  27. handler: this.showWindow,
  28. scope: this
  29. },{
  30. id:'delete',
  31. iconCls:'delete-icon',
  32. text:'Remove',
  33. handler: function(){
  34. var s = this.getSelectionModel().getSelectedNode();
  35. if(s){
  36. this.removeFeed(s.attributes.url);
  37. }
  38. },
  39. scope: this
  40. }]
  41. });
  42. this.feeds = this.root.appendChild(
  43. new Ext.tree.TreeNode({
  44. text:'My Feeds',
  45. cls:'feeds-node',
  46. expanded:true
  47. })
  48. );
  49. this.getSelectionModel().on({
  50. 'beforeselect' : function(sm, node){
  51. return node.isLeaf();
  52. },
  53. 'selectionchange' : function(sm, node){
  54. if(node){
  55. this.fireEvent('feedselect', node.attributes);
  56. }
  57. this.getTopToolbar().items.get('delete').setDisabled(!node);
  58. },
  59. scope:this
  60. });
  61. this.addEvents({feedselect:true});
  62. this.on('contextmenu', this.onContextMenu, this);
  63. };
  64. Ext.extend(FeedPanel, Ext.tree.TreePanel, {
  65. onContextMenu : function(node, e){
  66. if(!this.menu){ // create context menu on first right click
  67. this.menu = new Ext.menu.Menu({
  68. id:'feeds-ctx',
  69. items: [{
  70. id:'load',
  71. iconCls:'load-icon',
  72. text:'Load Feed',
  73. scope: this,
  74. handler:function(){
  75. this.ctxNode.select();
  76. }
  77. },{
  78. text:'Remove',
  79. iconCls:'delete-icon',
  80. scope: this,
  81. handler:function(){
  82. this.ctxNode.ui.removeClass('x-node-ctx');
  83. this.removeFeed(this.ctxNode.attributes.url);
  84. this.ctxNode = null;
  85. }
  86. },'-',{
  87. iconCls:'add-feed',
  88. text:'Add Feed',
  89. handler: this.showWindow,
  90. scope: this
  91. }]
  92. });
  93. this.menu.on('hide', this.onContextHide, this);
  94. }
  95. if(this.ctxNode){
  96. this.ctxNode.ui.removeClass('x-node-ctx');
  97. this.ctxNode = null;
  98. }
  99. if(node.isLeaf()){
  100. this.ctxNode = node;
  101. this.ctxNode.ui.addClass('x-node-ctx');
  102. this.menu.items.get('load').setDisabled(node.isSelected());
  103. this.menu.showAt(e.getXY());
  104. }
  105. },
  106. onContextHide : function(){
  107. if(this.ctxNode){
  108. this.ctxNode.ui.removeClass('x-node-ctx');
  109. this.ctxNode = null;
  110. }
  111. },
  112. showWindow : function(btn){
  113. if(!this.win){
  114. this.win = new FeedWindow();
  115. this.win.on('validfeed', this.addFeed, this);
  116. }
  117. this.win.show(btn);
  118. },
  119. selectFeed: function(url){
  120. this.getNodeById(url).select();
  121. },
  122. removeFeed: function(url){
  123. var node = this.getNodeById(url);
  124. if(node){
  125. node.unselect();
  126. Ext.fly(node.ui.elNode).ghost('l', {
  127. callback: node.remove, scope: node, duration: .4
  128. });
  129. }
  130. },
  131. addFeed : function(attrs, inactive, preventAnim){
  132. var exists = this.getNodeById(attrs.url);
  133. if(exists){
  134. if(!inactive){
  135. exists.select();
  136. exists.ui.highlight();
  137. }
  138. return;
  139. }
  140. Ext.apply(attrs, {
  141. iconCls: 'feed-icon',
  142. leaf:true,
  143. cls:'feed',
  144. id: attrs.url
  145. });
  146. var node = new Ext.tree.TreeNode(attrs);
  147. this.feeds.appendChild(node);
  148. if(!inactive){
  149. if(!preventAnim){
  150. Ext.fly(node.ui.elNode).slideIn('l', {
  151. callback: node.select, scope: node, duration: .4
  152. });
  153. }else{
  154. node.select();
  155. }
  156. }
  157. return node;
  158. },
  159. // prevent the default context menu when you miss the node
  160. afterRender : function(){
  161. FeedPanel.superclass.afterRender.call(this);
  162. this.el.on('contextmenu', function(e){
  163. e.preventDefault();
  164. });
  165. }
  166. });
  167. Ext.reg('appfeedpanel', FeedPanel);