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.

636 lines
21 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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.TreeNode"></div>/**
  16. * @class Ext.tree.TreeNode
  17. * @extends Ext.data.Node
  18. * @cfg {String} text The text for this node
  19. * @cfg {Boolean} expanded true to start the node expanded
  20. * @cfg {Boolean} allowDrag False to make this node undraggable if {@link #draggable} = true (defaults to true)
  21. * @cfg {Boolean} allowDrop False if this node cannot have child nodes dropped on it (defaults to true)
  22. * @cfg {Boolean} disabled true to start the node disabled
  23. * @cfg {String} icon The path to an icon for the node. The preferred way to do this
  24. * is to use the cls or iconCls attributes and add the icon via a CSS background image.
  25. * @cfg {String} cls A css class to be added to the node
  26. * @cfg {String} iconCls A css class to be added to the nodes icon element for applying css background images
  27. * @cfg {String} href URL of the link used for the node (defaults to #)
  28. * @cfg {String} hrefTarget target frame for the link
  29. * @cfg {Boolean} hidden True to render hidden. (Defaults to false).
  30. * @cfg {String} qtip An Ext QuickTip for the node
  31. * @cfg {Boolean} expandable If set to true, the node will always show a plus/minus icon, even when empty
  32. * @cfg {String} qtipCfg An Ext QuickTip config for the node (used instead of qtip)
  33. * @cfg {Boolean} singleClickExpand True for single click expand on this node
  34. * @cfg {Function} uiProvider A UI <b>class</b> to use for this node (defaults to Ext.tree.TreeNodeUI)
  35. * @cfg {Boolean} checked True to render a checked checkbox for this node, false to render an unchecked checkbox
  36. * (defaults to undefined with no checkbox rendered)
  37. * @cfg {Boolean} draggable True to make this node draggable (defaults to false)
  38. * @cfg {Boolean} isTarget False to not allow this node to act as a drop target (defaults to true)
  39. * @cfg {Boolean} allowChildren False to not allow this node to have child nodes (defaults to true)
  40. * @cfg {Boolean} editable False to not allow this node to be edited by an {@link Ext.tree.TreeEditor} (defaults to true)
  41. * @constructor
  42. * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
  43. */
  44. Ext.tree.TreeNode = Ext.extend(Ext.data.Node, {
  45. constructor : function(attributes){
  46. attributes = attributes || {};
  47. if(Ext.isString(attributes)){
  48. attributes = {text: attributes};
  49. }
  50. this.childrenRendered = false;
  51. this.rendered = false;
  52. Ext.tree.TreeNode.superclass.constructor.call(this, attributes);
  53. this.expanded = attributes.expanded === true;
  54. this.isTarget = attributes.isTarget !== false;
  55. this.draggable = attributes.draggable !== false && attributes.allowDrag !== false;
  56. this.allowChildren = attributes.allowChildren !== false && attributes.allowDrop !== false;
  57. /**
  58. * Read-only. The text for this node. To change it use <code>{@link #setText}</code>.
  59. * @type String
  60. */
  61. this.text = attributes.text;
  62. /**
  63. * True if this node is disabled.
  64. * @type Boolean
  65. */
  66. this.disabled = attributes.disabled === true;
  67. /**
  68. * True if this node is hidden.
  69. * @type Boolean
  70. */
  71. this.hidden = attributes.hidden === true;
  72. this.addEvents(
  73. /**
  74. * @event textchange
  75. * Fires when the text for this node is changed
  76. * @param {Node} this This node
  77. * @param {String} text The new text
  78. * @param {String} oldText The old text
  79. */
  80. 'textchange',
  81. /**
  82. * @event beforeexpand
  83. * Fires before this node is expanded, return false to cancel.
  84. * @param {Node} this This node
  85. * @param {Boolean} deep
  86. * @param {Boolean} anim
  87. */
  88. 'beforeexpand',
  89. /**
  90. * @event beforecollapse
  91. * Fires before this node is collapsed, return false to cancel.
  92. * @param {Node} this This node
  93. * @param {Boolean} deep
  94. * @param {Boolean} anim
  95. */
  96. 'beforecollapse',
  97. /**
  98. * @event expand
  99. * Fires when this node is expanded
  100. * @param {Node} this This node
  101. */
  102. 'expand',
  103. /**
  104. * @event disabledchange
  105. * Fires when the disabled status of this node changes
  106. * @param {Node} this This node
  107. * @param {Boolean} disabled
  108. */
  109. 'disabledchange',
  110. /**
  111. * @event collapse
  112. * Fires when this node is collapsed
  113. * @param {Node} this This node
  114. */
  115. 'collapse',
  116. /**
  117. * @event beforeclick
  118. * Fires before click processing. Return false to cancel the default action.
  119. * @param {Node} this This node
  120. * @param {Ext.EventObject} e The event object
  121. */
  122. 'beforeclick',
  123. /**
  124. * @event click
  125. * Fires when this node is clicked
  126. * @param {Node} this This node
  127. * @param {Ext.EventObject} e The event object
  128. */
  129. 'click',
  130. /**
  131. * @event checkchange
  132. * Fires when a node with a checkbox's checked property changes
  133. * @param {Node} this This node
  134. * @param {Boolean} checked
  135. */
  136. 'checkchange',
  137. /**
  138. * @event beforedblclick
  139. * Fires before double click processing. Return false to cancel the default action.
  140. * @param {Node} this This node
  141. * @param {Ext.EventObject} e The event object
  142. */
  143. 'beforedblclick',
  144. /**
  145. * @event dblclick
  146. * Fires when this node is double clicked
  147. * @param {Node} this This node
  148. * @param {Ext.EventObject} e The event object
  149. */
  150. 'dblclick',
  151. /**
  152. * @event contextmenu
  153. * Fires when this node is right clicked
  154. * @param {Node} this This node
  155. * @param {Ext.EventObject} e The event object
  156. */
  157. 'contextmenu',
  158. /**
  159. * @event beforechildrenrendered
  160. * Fires right before the child nodes for this node are rendered
  161. * @param {Node} this This node
  162. */
  163. 'beforechildrenrendered'
  164. );
  165. var uiClass = this.attributes.uiProvider || this.defaultUI || Ext.tree.TreeNodeUI;
  166. /**
  167. * Read-only. The UI for this node
  168. * @type TreeNodeUI
  169. */
  170. this.ui = new uiClass(this);
  171. },
  172. preventHScroll : true,
  173. /**
  174. * Returns true if this node is expanded
  175. * @return {Boolean}
  176. */
  177. isExpanded : function(){
  178. return this.expanded;
  179. },
  180. /**
  181. * Returns the UI object for this node.
  182. * @return {TreeNodeUI} The object which is providing the user interface for this tree
  183. * node. Unless otherwise specified in the {@link #uiProvider}, this will be an instance
  184. * of {@link Ext.tree.TreeNodeUI}
  185. */
  186. getUI : function(){
  187. return this.ui;
  188. },
  189. getLoader : function(){
  190. var owner;
  191. return this.loader || ((owner = this.getOwnerTree()) && owner.loader ? owner.loader : (this.loader = new Ext.tree.TreeLoader()));
  192. },
  193. // private override
  194. setFirstChild : function(node){
  195. var of = this.firstChild;
  196. Ext.tree.TreeNode.superclass.setFirstChild.call(this, node);
  197. if(this.childrenRendered && of && node != of){
  198. of.renderIndent(true, true);
  199. }
  200. if(this.rendered){
  201. this.renderIndent(true, true);
  202. }
  203. },
  204. // private override
  205. setLastChild : function(node){
  206. var ol = this.lastChild;
  207. Ext.tree.TreeNode.superclass.setLastChild.call(this, node);
  208. if(this.childrenRendered && ol && node != ol){
  209. ol.renderIndent(true, true);
  210. }
  211. if(this.rendered){
  212. this.renderIndent(true, true);
  213. }
  214. },
  215. // these methods are overridden to provide lazy rendering support
  216. // private override
  217. appendChild : function(n){
  218. if(!n.render && !Ext.isArray(n)){
  219. n = this.getLoader().createNode(n);
  220. }
  221. var node = Ext.tree.TreeNode.superclass.appendChild.call(this, n);
  222. if(node && this.childrenRendered){
  223. node.render();
  224. }
  225. this.ui.updateExpandIcon();
  226. return node;
  227. },
  228. // private override
  229. removeChild : function(node, destroy){
  230. this.ownerTree.getSelectionModel().unselect(node);
  231. Ext.tree.TreeNode.superclass.removeChild.apply(this, arguments);
  232. // only update the ui if we're not destroying
  233. if(!destroy){
  234. var rendered = node.ui.rendered;
  235. // if it's been rendered remove dom node
  236. if(rendered){
  237. node.ui.remove();
  238. }
  239. if(rendered && this.childNodes.length < 1){
  240. this.collapse(false, false);
  241. }else{
  242. this.ui.updateExpandIcon();
  243. }
  244. if(!this.firstChild && !this.isHiddenRoot()){
  245. this.childrenRendered = false;
  246. }
  247. }
  248. return node;
  249. },
  250. // private override
  251. insertBefore : function(node, refNode){
  252. if(!node.render){
  253. node = this.getLoader().createNode(node);
  254. }
  255. var newNode = Ext.tree.TreeNode.superclass.insertBefore.call(this, node, refNode);
  256. if(newNode && refNode && this.childrenRendered){
  257. node.render();
  258. }
  259. this.ui.updateExpandIcon();
  260. return newNode;
  261. },
  262. /**
  263. * Sets the text for this node
  264. * @param {String} text
  265. */
  266. setText : function(text){
  267. var oldText = this.text;
  268. this.text = this.attributes.text = text;
  269. if(this.rendered){ // event without subscribing
  270. this.ui.onTextChange(this, text, oldText);
  271. }
  272. this.fireEvent('textchange', this, text, oldText);
  273. },
  274. /**
  275. * Sets the icon class for this node.
  276. * @param {String} cls
  277. */
  278. setIconCls : function(cls){
  279. var old = this.attributes.iconCls;
  280. this.attributes.iconCls = cls;
  281. if(this.rendered){
  282. this.ui.onIconClsChange(this, cls, old);
  283. }
  284. },
  285. /**
  286. * Sets the tooltip for this node.
  287. * @param {String} tip The text for the tip
  288. * @param {String} title (Optional) The title for the tip
  289. */
  290. setTooltip : function(tip, title){
  291. this.attributes.qtip = tip;
  292. this.attributes.qtipTitle = title;
  293. if(this.rendered){
  294. this.ui.onTipChange(this, tip, title);
  295. }
  296. },
  297. /**
  298. * Sets the icon for this node.
  299. * @param {String} icon
  300. */
  301. setIcon : function(icon){
  302. this.attributes.icon = icon;
  303. if(this.rendered){
  304. this.ui.onIconChange(this, icon);
  305. }
  306. },
  307. /**
  308. * Sets the href for the node.
  309. * @param {String} href The href to set
  310. * @param {String} (Optional) target The target of the href
  311. */
  312. setHref : function(href, target){
  313. this.attributes.href = href;
  314. this.attributes.hrefTarget = target;
  315. if(this.rendered){
  316. this.ui.onHrefChange(this, href, target);
  317. }
  318. },
  319. /**
  320. * Sets the class on this node.
  321. * @param {String} cls
  322. */
  323. setCls : function(cls){
  324. var old = this.attributes.cls;
  325. this.attributes.cls = cls;
  326. if(this.rendered){
  327. this.ui.onClsChange(this, cls, old);
  328. }
  329. },
  330. /**
  331. * Triggers selection of this node
  332. */
  333. select : function(){
  334. var t = this.getOwnerTree();
  335. if(t){
  336. t.getSelectionModel().select(this);
  337. }
  338. },
  339. /**
  340. * Triggers deselection of this node
  341. * @param {Boolean} silent (optional) True to stop selection change events from firing.
  342. */
  343. unselect : function(silent){
  344. var t = this.getOwnerTree();
  345. if(t){
  346. t.getSelectionModel().unselect(this, silent);
  347. }
  348. },
  349. /**
  350. * Returns true if this node is selected
  351. * @return {Boolean}
  352. */
  353. isSelected : function(){
  354. var t = this.getOwnerTree();
  355. return t ? t.getSelectionModel().isSelected(this) : false;
  356. },
  357. /**
  358. * Expand this node.
  359. * @param {Boolean} deep (optional) True to expand all children as well
  360. * @param {Boolean} anim (optional) false to cancel the default animation
  361. * @param {Function} callback (optional) A callback to be called when
  362. * expanding this node completes (does not wait for deep expand to complete).
  363. * Called with 1 parameter, this node.
  364. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this TreeNode.
  365. */
  366. expand : function(deep, anim, callback, scope){
  367. if(!this.expanded){
  368. if(this.fireEvent('beforeexpand', this, deep, anim) === false){
  369. return;
  370. }
  371. if(!this.childrenRendered){
  372. this.renderChildren();
  373. }
  374. this.expanded = true;
  375. if(!this.isHiddenRoot() && (this.getOwnerTree().animate && anim !== false) || anim){
  376. this.ui.animExpand(function(){
  377. this.fireEvent('expand', this);
  378. this.runCallback(callback, scope || this, [this]);
  379. if(deep === true){
  380. this.expandChildNodes(true, true);
  381. }
  382. }.createDelegate(this));
  383. return;
  384. }else{
  385. this.ui.expand();
  386. this.fireEvent('expand', this);
  387. this.runCallback(callback, scope || this, [this]);
  388. }
  389. }else{
  390. this.runCallback(callback, scope || this, [this]);
  391. }
  392. if(deep === true){
  393. this.expandChildNodes(true);
  394. }
  395. },
  396. runCallback : function(cb, scope, args){
  397. if(Ext.isFunction(cb)){
  398. cb.apply(scope, args);
  399. }
  400. },
  401. isHiddenRoot : function(){
  402. return this.isRoot && !this.getOwnerTree().rootVisible;
  403. },
  404. /**
  405. * Collapse this node.
  406. * @param {Boolean} deep (optional) True to collapse all children as well
  407. * @param {Boolean} anim (optional) false to cancel the default animation
  408. * @param {Function} callback (optional) A callback to be called when
  409. * expanding this node completes (does not wait for deep expand to complete).
  410. * Called with 1 parameter, this node.
  411. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this TreeNode.
  412. */
  413. collapse : function(deep, anim, callback, scope){
  414. if(this.expanded && !this.isHiddenRoot()){
  415. if(this.fireEvent('beforecollapse', this, deep, anim) === false){
  416. return;
  417. }
  418. this.expanded = false;
  419. if((this.getOwnerTree().animate && anim !== false) || anim){
  420. this.ui.animCollapse(function(){
  421. this.fireEvent('collapse', this);
  422. this.runCallback(callback, scope || this, [this]);
  423. if(deep === true){
  424. this.collapseChildNodes(true);
  425. }
  426. }.createDelegate(this));
  427. return;
  428. }else{
  429. this.ui.collapse();
  430. this.fireEvent('collapse', this);
  431. this.runCallback(callback, scope || this, [this]);
  432. }
  433. }else if(!this.expanded){
  434. this.runCallback(callback, scope || this, [this]);
  435. }
  436. if(deep === true){
  437. var cs = this.childNodes;
  438. for(var i = 0, len = cs.length; i < len; i++) {
  439. cs[i].collapse(true, false);
  440. }
  441. }
  442. },
  443. // private
  444. delayedExpand : function(delay){
  445. if(!this.expandProcId){
  446. this.expandProcId = this.expand.defer(delay, this);
  447. }
  448. },
  449. // private
  450. cancelExpand : function(){
  451. if(this.expandProcId){
  452. clearTimeout(this.expandProcId);
  453. }
  454. this.expandProcId = false;
  455. },
  456. /**
  457. * Toggles expanded/collapsed state of the node
  458. */
  459. toggle : function(){
  460. if(this.expanded){
  461. this.collapse();
  462. }else{
  463. this.expand();
  464. }
  465. },
  466. /**
  467. * Ensures all parent nodes are expanded, and if necessary, scrolls
  468. * the node into view.
  469. * @param {Function} callback (optional) A function to call when the node has been made visible.
  470. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this TreeNode.
  471. */
  472. ensureVisible : function(callback, scope){
  473. var tree = this.getOwnerTree();
  474. tree.expandPath(this.parentNode ? this.parentNode.getPath() : this.getPath(), false, function(){
  475. var node = tree.getNodeById(this.id); // Somehow if we don't do this, we lose changes that happened to node in the meantime
  476. tree.getTreeEl().scrollChildIntoView(node.ui.anchor);
  477. this.runCallback(callback, scope || this, [this]);
  478. }.createDelegate(this));
  479. },
  480. /**
  481. * Expand all child nodes
  482. * @param {Boolean} deep (optional) true if the child nodes should also expand their child nodes
  483. */
  484. expandChildNodes : function(deep, anim) {
  485. var cs = this.childNodes,
  486. i,
  487. len = cs.length;
  488. for (i = 0; i < len; i++) {
  489. cs[i].expand(deep, anim);
  490. }
  491. },
  492. /**
  493. * Collapse all child nodes
  494. * @param {Boolean} deep (optional) true if the child nodes should also collapse their child nodes
  495. */
  496. collapseChildNodes : function(deep){
  497. var cs = this.childNodes;
  498. for(var i = 0, len = cs.length; i < len; i++) {
  499. cs[i].collapse(deep);
  500. }
  501. },
  502. /**
  503. * Disables this node
  504. */
  505. disable : function(){
  506. this.disabled = true;
  507. this.unselect();
  508. if(this.rendered && this.ui.onDisableChange){ // event without subscribing
  509. this.ui.onDisableChange(this, true);
  510. }
  511. this.fireEvent('disabledchange', this, true);
  512. },
  513. /**
  514. * Enables this node
  515. */
  516. enable : function(){
  517. this.disabled = false;
  518. if(this.rendered && this.ui.onDisableChange){ // event without subscribing
  519. this.ui.onDisableChange(this, false);
  520. }
  521. this.fireEvent('disabledchange', this, false);
  522. },
  523. // private
  524. renderChildren : function(suppressEvent){
  525. if(suppressEvent !== false){
  526. this.fireEvent('beforechildrenrendered', this);
  527. }
  528. var cs = this.childNodes;
  529. for(var i = 0, len = cs.length; i < len; i++){
  530. cs[i].render(true);
  531. }
  532. this.childrenRendered = true;
  533. },
  534. // private
  535. sort : function(fn, scope){
  536. Ext.tree.TreeNode.superclass.sort.apply(this, arguments);
  537. if(this.childrenRendered){
  538. var cs = this.childNodes;
  539. for(var i = 0, len = cs.length; i < len; i++){
  540. cs[i].render(true);
  541. }
  542. }
  543. },
  544. // private
  545. render : function(bulkRender){
  546. this.ui.render(bulkRender);
  547. if(!this.rendered){
  548. // make sure it is registered
  549. this.getOwnerTree().registerNode(this);
  550. this.rendered = true;
  551. if(this.expanded){
  552. this.expanded = false;
  553. this.expand(false, false);
  554. }
  555. }
  556. },
  557. // private
  558. renderIndent : function(deep, refresh){
  559. if(refresh){
  560. this.ui.childIndent = null;
  561. }
  562. this.ui.renderIndent();
  563. if(deep === true && this.childrenRendered){
  564. var cs = this.childNodes;
  565. for(var i = 0, len = cs.length; i < len; i++){
  566. cs[i].renderIndent(true, refresh);
  567. }
  568. }
  569. },
  570. beginUpdate : function(){
  571. this.childrenRendered = false;
  572. },
  573. endUpdate : function(){
  574. if(this.expanded && this.rendered){
  575. this.renderChildren();
  576. }
  577. },
  578. //inherit docs
  579. destroy : function(silent){
  580. if(silent === true){
  581. this.unselect(true);
  582. }
  583. Ext.tree.TreeNode.superclass.destroy.call(this, silent);
  584. Ext.destroy(this.ui, this.loader);
  585. this.ui = this.loader = null;
  586. },
  587. // private
  588. onIdChange : function(id){
  589. this.ui.onIdChange(id);
  590. }
  591. });
  592. Ext.tree.TreePanel.nodeTypes.node = Ext.tree.TreeNode;</pre>
  593. </body>
  594. </html>