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.

366 lines
14 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.TreeLoader"></div>/**
  16. * @class Ext.tree.TreeLoader
  17. * @extends Ext.util.Observable
  18. * A TreeLoader provides for lazy loading of an {@link Ext.tree.TreeNode}'s child
  19. * nodes from a specified URL. The response must be a JavaScript Array definition
  20. * whose elements are node definition objects. e.g.:
  21. * <pre><code>
  22. [{
  23. id: 1,
  24. text: 'A leaf Node',
  25. leaf: true
  26. },{
  27. id: 2,
  28. text: 'A folder Node',
  29. children: [{
  30. id: 3,
  31. text: 'A child Node',
  32. leaf: true
  33. }]
  34. }]
  35. </code></pre>
  36. * <br><br>
  37. * A server request is sent, and child nodes are loaded only when a node is expanded.
  38. * The loading node's id is passed to the server under the parameter name "node" to
  39. * enable the server to produce the correct child nodes.
  40. * <br><br>
  41. * To pass extra parameters, an event handler may be attached to the "beforeload"
  42. * event, and the parameters specified in the TreeLoader's baseParams property:
  43. * <pre><code>
  44. myTreeLoader.on("beforeload", function(treeLoader, node) {
  45. this.baseParams.category = node.attributes.category;
  46. }, this);
  47. </code></pre>
  48. * This would pass an HTTP parameter called "category" to the server containing
  49. * the value of the Node's "category" attribute.
  50. * @constructor
  51. * Creates a new Treeloader.
  52. * @param {Object} config A config object containing config properties.
  53. */
  54. Ext.tree.TreeLoader = function(config){
  55. this.baseParams = {};
  56. Ext.apply(this, config);
  57. this.addEvents(
  58. <div id="event-Ext.tree.TreeLoader-beforeload"></div>/**
  59. * @event beforeload
  60. * Fires before a network request is made to retrieve the Json text which specifies a node's children.
  61. * @param {Object} This TreeLoader object.
  62. * @param {Object} node The {@link Ext.tree.TreeNode} object being loaded.
  63. * @param {Object} callback The callback function specified in the {@link #load} call.
  64. */
  65. "beforeload",
  66. <div id="event-Ext.tree.TreeLoader-load"></div>/**
  67. * @event load
  68. * Fires when the node has been successfuly loaded.
  69. * @param {Object} This TreeLoader object.
  70. * @param {Object} node The {@link Ext.tree.TreeNode} object being loaded.
  71. * @param {Object} response The response object containing the data from the server.
  72. */
  73. "load",
  74. <div id="event-Ext.tree.TreeLoader-loadexception"></div>/**
  75. * @event loadexception
  76. * Fires if the network request failed.
  77. * @param {Object} This TreeLoader object.
  78. * @param {Object} node The {@link Ext.tree.TreeNode} object being loaded.
  79. * @param {Object} response The response object containing the data from the server.
  80. */
  81. "loadexception"
  82. );
  83. Ext.tree.TreeLoader.superclass.constructor.call(this);
  84. if(Ext.isString(this.paramOrder)){
  85. this.paramOrder = this.paramOrder.split(/[\s,|]/);
  86. }
  87. };
  88. Ext.extend(Ext.tree.TreeLoader, Ext.util.Observable, {
  89. <div id="cfg-Ext.tree.TreeLoader-dataUrl"></div>/**
  90. * @cfg {String} dataUrl The URL from which to request a Json string which
  91. * specifies an array of node definition objects representing the child nodes
  92. * to be loaded.
  93. */
  94. <div id="cfg-Ext.tree.TreeLoader-requestMethod"></div>/**
  95. * @cfg {String} requestMethod The HTTP request method for loading data (defaults to the value of {@link Ext.Ajax#method}).
  96. */
  97. <div id="cfg-Ext.tree.TreeLoader-url"></div>/**
  98. * @cfg {String} url Equivalent to {@link #dataUrl}.
  99. */
  100. <div id="cfg-Ext.tree.TreeLoader-preloadChildren"></div>/**
  101. * @cfg {Boolean} preloadChildren If set to true, the loader recursively loads "children" attributes when doing the first load on nodes.
  102. */
  103. <div id="cfg-Ext.tree.TreeLoader-baseParams"></div>/**
  104. * @cfg {Object} baseParams (optional) An object containing properties which
  105. * specify HTTP parameters to be passed to each request for child nodes.
  106. */
  107. <div id="cfg-Ext.tree.TreeLoader-baseAttrs"></div>/**
  108. * @cfg {Object} baseAttrs (optional) An object containing attributes to be added to all nodes
  109. * created by this loader. If the attributes sent by the server have an attribute in this object,
  110. * they take priority.
  111. */
  112. <div id="cfg-Ext.tree.TreeLoader-uiProviders"></div>/**
  113. * @cfg {Object} uiProviders (optional) An object containing properties which
  114. * specify custom {@link Ext.tree.TreeNodeUI} implementations. If the optional
  115. * <i>uiProvider</i> attribute of a returned child node is a string rather
  116. * than a reference to a TreeNodeUI implementation, then that string value
  117. * is used as a property name in the uiProviders object.
  118. */
  119. uiProviders : {},
  120. <div id="cfg-Ext.tree.TreeLoader-clearOnLoad"></div>/**
  121. * @cfg {Boolean} clearOnLoad (optional) Default to true. Remove previously existing
  122. * child nodes before loading.
  123. */
  124. clearOnLoad : true,
  125. <div id="cfg-Ext.tree.TreeLoader-paramOrder"></div>/**
  126. * @cfg {Array/String} paramOrder Defaults to <tt>undefined</tt>. Only used when using directFn.
  127. * Specifies the params in the order in which they must be passed to the server-side Direct method
  128. * as either (1) an Array of String values, or (2) a String of params delimited by either whitespace,
  129. * comma, or pipe. For example,
  130. * any of the following would be acceptable:<pre><code>
  131. nodeParameter: 'node',
  132. paramOrder: ['param1','param2','param3']
  133. paramOrder: 'node param1 param2 param3'
  134. paramOrder: 'param1,node,param2,param3'
  135. paramOrder: 'param1|param2|param|node'
  136. </code></pre>
  137. */
  138. paramOrder: undefined,
  139. <div id="cfg-Ext.tree.TreeLoader-paramsAsHash"></div>/**
  140. * @cfg {Boolean} paramsAsHash Only used when using directFn.
  141. * Send parameters as a collection of named arguments (defaults to <tt>false</tt>). Providing a
  142. * <tt>{@link #paramOrder}</tt> nullifies this configuration.
  143. */
  144. paramsAsHash: false,
  145. <div id="cfg-Ext.tree.TreeLoader-nodeParameter"></div>/**
  146. * @cfg {String} nodeParameter The name of the parameter sent to the server which contains
  147. * the identifier of the node. Defaults to <tt>'node'</tt>.
  148. */
  149. nodeParameter: 'node',
  150. <div id="cfg-Ext.tree.TreeLoader-directFn"></div>/**
  151. * @cfg {Function} directFn
  152. * Function to call when executing a request.
  153. */
  154. directFn : undefined,
  155. <div id="method-Ext.tree.TreeLoader-load"></div>/**
  156. * Load an {@link Ext.tree.TreeNode} from the URL specified in the constructor.
  157. * This is called automatically when a node is expanded, but may be used to reload
  158. * a node (or append new children if the {@link #clearOnLoad} option is false.)
  159. * @param {Ext.tree.TreeNode} node
  160. * @param {Function} callback Function to call after the node has been loaded. The
  161. * function is passed the TreeNode which was requested to be loaded.
  162. * @param {Object} scope The scope (<code>this</code> reference) in which the callback is executed.
  163. * defaults to the loaded TreeNode.
  164. */
  165. load : function(node, callback, scope){
  166. if(this.clearOnLoad){
  167. while(node.firstChild){
  168. node.removeChild(node.firstChild);
  169. }
  170. }
  171. if(this.doPreload(node)){ // preloaded json children
  172. this.runCallback(callback, scope || node, [node]);
  173. }else if(this.directFn || this.dataUrl || this.url){
  174. this.requestData(node, callback, scope || node);
  175. }
  176. },
  177. doPreload : function(node){
  178. if(node.attributes.children){
  179. if(node.childNodes.length < 1){ // preloaded?
  180. var cs = node.attributes.children;
  181. node.beginUpdate();
  182. for(var i = 0, len = cs.length; i < len; i++){
  183. var cn = node.appendChild(this.createNode(cs[i]));
  184. if(this.preloadChildren){
  185. this.doPreload(cn);
  186. }
  187. }
  188. node.endUpdate();
  189. }
  190. return true;
  191. }
  192. return false;
  193. },
  194. getParams: function(node){
  195. var bp = Ext.apply({}, this.baseParams),
  196. np = this.nodeParameter,
  197. po = this.paramOrder;
  198. np && (bp[ np ] = node.id);
  199. if(this.directFn){
  200. var buf = [node.id];
  201. if(po){
  202. // reset 'buf' if the nodeParameter was included in paramOrder
  203. if(np && po.indexOf(np) > -1){
  204. buf = [];
  205. }
  206. for(var i = 0, len = po.length; i < len; i++){
  207. buf.push(bp[ po[i] ]);
  208. }
  209. }else if(this.paramsAsHash){
  210. buf = [bp];
  211. }
  212. return buf;
  213. }else{
  214. return bp;
  215. }
  216. },
  217. requestData : function(node, callback, scope){
  218. if(this.fireEvent("beforeload", this, node, callback) !== false){
  219. if(this.directFn){
  220. var args = this.getParams(node);
  221. args.push(this.processDirectResponse.createDelegate(this, [{callback: callback, node: node, scope: scope}], true));
  222. this.directFn.apply(window, args);
  223. }else{
  224. this.transId = Ext.Ajax.request({
  225. method:this.requestMethod,
  226. url: this.dataUrl||this.url,
  227. success: this.handleResponse,
  228. failure: this.handleFailure,
  229. scope: this,
  230. argument: {callback: callback, node: node, scope: scope},
  231. params: this.getParams(node)
  232. });
  233. }
  234. }else{
  235. // if the load is cancelled, make sure we notify
  236. // the node that we are done
  237. this.runCallback(callback, scope || node, []);
  238. }
  239. },
  240. processDirectResponse: function(result, response, args){
  241. if(response.status){
  242. this.handleResponse({
  243. responseData: Ext.isArray(result) ? result : null,
  244. responseText: result,
  245. argument: args
  246. });
  247. }else{
  248. this.handleFailure({
  249. argument: args
  250. });
  251. }
  252. },
  253. // private
  254. runCallback: function(cb, scope, args){
  255. if(Ext.isFunction(cb)){
  256. cb.apply(scope, args);
  257. }
  258. },
  259. isLoading : function(){
  260. return !!this.transId;
  261. },
  262. abort : function(){
  263. if(this.isLoading()){
  264. Ext.Ajax.abort(this.transId);
  265. }
  266. },
  267. <div id="method-Ext.tree.TreeLoader-createNode"></div>/**
  268. * <p>Override this function for custom TreeNode node implementation, or to
  269. * modify the attributes at creation time.</p>
  270. * Example:<pre><code>
  271. new Ext.tree.TreePanel({
  272. ...
  273. loader: new Ext.tree.TreeLoader({
  274. url: 'dataUrl',
  275. createNode: function(attr) {
  276. // Allow consolidation consignments to have
  277. // consignments dropped into them.
  278. if (attr.isConsolidation) {
  279. attr.iconCls = 'x-consol',
  280. attr.allowDrop = true;
  281. }
  282. return Ext.tree.TreeLoader.prototype.createNode.call(this, attr);
  283. }
  284. }),
  285. ...
  286. });
  287. </code></pre>
  288. * @param attr {Object} The attributes from which to create the new node.
  289. */
  290. createNode : function(attr){
  291. // apply baseAttrs, nice idea Corey!
  292. if(this.baseAttrs){
  293. Ext.applyIf(attr, this.baseAttrs);
  294. }
  295. if(this.applyLoader !== false && !attr.loader){
  296. attr.loader = this;
  297. }
  298. if(Ext.isString(attr.uiProvider)){
  299. attr.uiProvider = this.uiProviders[attr.uiProvider] || eval(attr.uiProvider);
  300. }
  301. if(attr.nodeType){
  302. return new Ext.tree.TreePanel.nodeTypes[attr.nodeType](attr);
  303. }else{
  304. return attr.leaf ?
  305. new Ext.tree.TreeNode(attr) :
  306. new Ext.tree.AsyncTreeNode(attr);
  307. }
  308. },
  309. processResponse : function(response, node, callback, scope){
  310. var json = response.responseText;
  311. try {
  312. var o = response.responseData || Ext.decode(json);
  313. node.beginUpdate();
  314. for(var i = 0, len = o.length; i < len; i++){
  315. var n = this.createNode(o[i]);
  316. if(n){
  317. node.appendChild(n);
  318. }
  319. }
  320. node.endUpdate();
  321. this.runCallback(callback, scope || node, [node]);
  322. }catch(e){
  323. this.handleFailure(response);
  324. }
  325. },
  326. handleResponse : function(response){
  327. this.transId = false;
  328. var a = response.argument;
  329. this.processResponse(response, a.node, a.callback, a.scope);
  330. this.fireEvent("load", this, a.node, response);
  331. },
  332. handleFailure : function(response){
  333. this.transId = false;
  334. var a = response.argument;
  335. this.fireEvent("loadexception", this, a.node, response);
  336. this.runCallback(a.callback, a.scope || a.node, [a.node]);
  337. },
  338. destroy : function(){
  339. this.abort();
  340. this.purgeListeners();
  341. }
  342. });</pre>
  343. </body>
  344. </html>