Web UI for ARGUS server
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.

334 lines
11 KiB

6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>The source code</title>
  5. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  6. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-js">/*!
  10. * Ext JS Library 3.3.1
  11. * Copyright(c) 2006-2010 Sencha Inc.
  12. * licensing@sencha.com
  13. * http://www.sencha.com/license
  14. */
  15. <div id="cls-Ext.tree.DefaultSelectionModel"></div>/**
  16. * @class Ext.tree.DefaultSelectionModel
  17. * @extends Ext.util.Observable
  18. * The default single selection for a TreePanel.
  19. */
  20. Ext.tree.DefaultSelectionModel = Ext.extend(Ext.util.Observable, {
  21. constructor : function(config){
  22. this.selNode = null;
  23. this.addEvents(
  24. <div id="event-Ext.tree.DefaultSelectionModel-selectionchange"></div>/**
  25. * @event selectionchange
  26. * Fires when the selected node changes
  27. * @param {DefaultSelectionModel} this
  28. * @param {TreeNode} node the new selection
  29. */
  30. 'selectionchange',
  31. <div id="event-Ext.tree.DefaultSelectionModel-beforeselect"></div>/**
  32. * @event beforeselect
  33. * Fires before the selected node changes, return false to cancel the change
  34. * @param {DefaultSelectionModel} this
  35. * @param {TreeNode} node the new selection
  36. * @param {TreeNode} node the old selection
  37. */
  38. 'beforeselect'
  39. );
  40. Ext.apply(this, config);
  41. Ext.tree.DefaultSelectionModel.superclass.constructor.call(this);
  42. },
  43. init : function(tree){
  44. this.tree = tree;
  45. tree.mon(tree.getTreeEl(), 'keydown', this.onKeyDown, this);
  46. tree.on('click', this.onNodeClick, this);
  47. },
  48. onNodeClick : function(node, e){
  49. this.select(node);
  50. },
  51. <div id="method-Ext.tree.DefaultSelectionModel-select"></div>/**
  52. * Select a node.
  53. * @param {TreeNode} node The node to select
  54. * @return {TreeNode} The selected node
  55. */
  56. select : function(node, /* private*/ selectNextNode){
  57. // If node is hidden, select the next node in whatever direction was being moved in.
  58. if (!Ext.fly(node.ui.wrap).isVisible() && selectNextNode) {
  59. return selectNextNode.call(this, node);
  60. }
  61. var last = this.selNode;
  62. if(node == last){
  63. node.ui.onSelectedChange(true);
  64. }else if(this.fireEvent('beforeselect', this, node, last) !== false){
  65. if(last && last.ui){
  66. last.ui.onSelectedChange(false);
  67. }
  68. this.selNode = node;
  69. node.ui.onSelectedChange(true);
  70. this.fireEvent('selectionchange', this, node, last);
  71. }
  72. return node;
  73. },
  74. <div id="method-Ext.tree.DefaultSelectionModel-unselect"></div>/**
  75. * Deselect a node.
  76. * @param {TreeNode} node The node to unselect
  77. * @param {Boolean} silent True to stop the selectionchange event from firing.
  78. */
  79. unselect : function(node, silent){
  80. if(this.selNode == node){
  81. this.clearSelections(silent);
  82. }
  83. },
  84. <div id="method-Ext.tree.DefaultSelectionModel-clearSelections"></div>/**
  85. * Clear all selections
  86. * @param {Boolean} silent True to stop the selectionchange event from firing.
  87. */
  88. clearSelections : function(silent){
  89. var n = this.selNode;
  90. if(n){
  91. n.ui.onSelectedChange(false);
  92. this.selNode = null;
  93. if(silent !== true){
  94. this.fireEvent('selectionchange', this, null);
  95. }
  96. }
  97. return n;
  98. },
  99. <div id="method-Ext.tree.DefaultSelectionModel-getSelectedNode"></div>/**
  100. * Get the selected node
  101. * @return {TreeNode} The selected node
  102. */
  103. getSelectedNode : function(){
  104. return this.selNode;
  105. },
  106. <div id="method-Ext.tree.DefaultSelectionModel-isSelected"></div>/**
  107. * Returns true if the node is selected
  108. * @param {TreeNode} node The node to check
  109. * @return {Boolean}
  110. */
  111. isSelected : function(node){
  112. return this.selNode == node;
  113. },
  114. <div id="method-Ext.tree.DefaultSelectionModel-selectPrevious"></div>/**
  115. * Selects the node above the selected node in the tree, intelligently walking the nodes
  116. * @return TreeNode The new selection
  117. */
  118. selectPrevious : function(/* private */ s){
  119. if(!(s = s || this.selNode || this.lastSelNode)){
  120. return null;
  121. }
  122. // Here we pass in the current function to select to indicate the direction we're moving
  123. var ps = s.previousSibling;
  124. if(ps){
  125. if(!ps.isExpanded() || ps.childNodes.length < 1){
  126. return this.select(ps, this.selectPrevious);
  127. } else{
  128. var lc = ps.lastChild;
  129. while(lc && lc.isExpanded() && Ext.fly(lc.ui.wrap).isVisible() && lc.childNodes.length > 0){
  130. lc = lc.lastChild;
  131. }
  132. return this.select(lc, this.selectPrevious);
  133. }
  134. } else if(s.parentNode && (this.tree.rootVisible || !s.parentNode.isRoot)){
  135. return this.select(s.parentNode, this.selectPrevious);
  136. }
  137. return null;
  138. },
  139. <div id="method-Ext.tree.DefaultSelectionModel-selectNext"></div>/**
  140. * Selects the node above the selected node in the tree, intelligently walking the nodes
  141. * @return TreeNode The new selection
  142. */
  143. selectNext : function(/* private */ s){
  144. if(!(s = s || this.selNode || this.lastSelNode)){
  145. return null;
  146. }
  147. // Here we pass in the current function to select to indicate the direction we're moving
  148. if(s.firstChild && s.isExpanded() && Ext.fly(s.ui.wrap).isVisible()){
  149. return this.select(s.firstChild, this.selectNext);
  150. }else if(s.nextSibling){
  151. return this.select(s.nextSibling, this.selectNext);
  152. }else if(s.parentNode){
  153. var newS = null;
  154. s.parentNode.bubble(function(){
  155. if(this.nextSibling){
  156. newS = this.getOwnerTree().selModel.select(this.nextSibling, this.selectNext);
  157. return false;
  158. }
  159. });
  160. return newS;
  161. }
  162. return null;
  163. },
  164. onKeyDown : function(e){
  165. var s = this.selNode || this.lastSelNode;
  166. // undesirable, but required
  167. var sm = this;
  168. if(!s){
  169. return;
  170. }
  171. var k = e.getKey();
  172. switch(k){
  173. case e.DOWN:
  174. e.stopEvent();
  175. this.selectNext();
  176. break;
  177. case e.UP:
  178. e.stopEvent();
  179. this.selectPrevious();
  180. break;
  181. case e.RIGHT:
  182. e.preventDefault();
  183. if(s.hasChildNodes()){
  184. if(!s.isExpanded()){
  185. s.expand();
  186. }else if(s.firstChild){
  187. this.select(s.firstChild, e);
  188. }
  189. }
  190. break;
  191. case e.LEFT:
  192. e.preventDefault();
  193. if(s.hasChildNodes() && s.isExpanded()){
  194. s.collapse();
  195. }else if(s.parentNode && (this.tree.rootVisible || s.parentNode != this.tree.getRootNode())){
  196. this.select(s.parentNode, e);
  197. }
  198. break;
  199. };
  200. }
  201. });
  202. <div id="cls-Ext.tree.MultiSelectionModel"></div>/**
  203. * @class Ext.tree.MultiSelectionModel
  204. * @extends Ext.util.Observable
  205. * Multi selection for a TreePanel.
  206. */
  207. Ext.tree.MultiSelectionModel = Ext.extend(Ext.util.Observable, {
  208. constructor : function(config){
  209. this.selNodes = [];
  210. this.selMap = {};
  211. this.addEvents(
  212. <div id="event-Ext.tree.MultiSelectionModel-selectionchange"></div>/**
  213. * @event selectionchange
  214. * Fires when the selected nodes change
  215. * @param {MultiSelectionModel} this
  216. * @param {Array} nodes Array of the selected nodes
  217. */
  218. 'selectionchange'
  219. );
  220. Ext.apply(this, config);
  221. Ext.tree.MultiSelectionModel.superclass.constructor.call(this);
  222. },
  223. init : function(tree){
  224. this.tree = tree;
  225. tree.mon(tree.getTreeEl(), 'keydown', this.onKeyDown, this);
  226. tree.on('click', this.onNodeClick, this);
  227. },
  228. onNodeClick : function(node, e){
  229. if(e.ctrlKey && this.isSelected(node)){
  230. this.unselect(node);
  231. }else{
  232. this.select(node, e, e.ctrlKey);
  233. }
  234. },
  235. <div id="method-Ext.tree.MultiSelectionModel-select"></div>/**
  236. * Select a node.
  237. * @param {TreeNode} node The node to select
  238. * @param {EventObject} e (optional) An event associated with the selection
  239. * @param {Boolean} keepExisting True to retain existing selections
  240. * @return {TreeNode} The selected node
  241. */
  242. select : function(node, e, keepExisting){
  243. if(keepExisting !== true){
  244. this.clearSelections(true);
  245. }
  246. if(this.isSelected(node)){
  247. this.lastSelNode = node;
  248. return node;
  249. }
  250. this.selNodes.push(node);
  251. this.selMap[node.id] = node;
  252. this.lastSelNode = node;
  253. node.ui.onSelectedChange(true);
  254. this.fireEvent('selectionchange', this, this.selNodes);
  255. return node;
  256. },
  257. <div id="method-Ext.tree.MultiSelectionModel-unselect"></div>/**
  258. * Deselect a node.
  259. * @param {TreeNode} node The node to unselect
  260. */
  261. unselect : function(node){
  262. if(this.selMap[node.id]){
  263. node.ui.onSelectedChange(false);
  264. var sn = this.selNodes;
  265. var index = sn.indexOf(node);
  266. if(index != -1){
  267. this.selNodes.splice(index, 1);
  268. }
  269. delete this.selMap[node.id];
  270. this.fireEvent('selectionchange', this, this.selNodes);
  271. }
  272. },
  273. <div id="method-Ext.tree.MultiSelectionModel-clearSelections"></div>/**
  274. * Clear all selections
  275. */
  276. clearSelections : function(suppressEvent){
  277. var sn = this.selNodes;
  278. if(sn.length > 0){
  279. for(var i = 0, len = sn.length; i < len; i++){
  280. sn[i].ui.onSelectedChange(false);
  281. }
  282. this.selNodes = [];
  283. this.selMap = {};
  284. if(suppressEvent !== true){
  285. this.fireEvent('selectionchange', this, this.selNodes);
  286. }
  287. }
  288. },
  289. <div id="method-Ext.tree.MultiSelectionModel-isSelected"></div>/**
  290. * Returns true if the node is selected
  291. * @param {TreeNode} node The node to check
  292. * @return {Boolean}
  293. */
  294. isSelected : function(node){
  295. return this.selMap[node.id] ? true : false;
  296. },
  297. <div id="method-Ext.tree.MultiSelectionModel-getSelectedNodes"></div>/**
  298. * Returns an array of the selected nodes
  299. * @return {Array}
  300. */
  301. getSelectedNodes : function(){
  302. return this.selNodes.concat([]);
  303. },
  304. onKeyDown : Ext.tree.DefaultSelectionModel.prototype.onKeyDown,
  305. selectNext : Ext.tree.DefaultSelectionModel.prototype.selectNext,
  306. selectPrevious : Ext.tree.DefaultSelectionModel.prototype.selectPrevious
  307. });</pre>
  308. </body>
  309. </html>