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.

263 lines
9.7 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.Action"></div>/**
  16. * @class Ext.Action
  17. * <p>An Action is a piece of reusable functionality that can be abstracted out of any particular component so that it
  18. * can be usefully shared among multiple components. Actions let you share handlers, configuration options and UI
  19. * updates across any components that support the Action interface (primarily {@link Ext.Toolbar}, {@link Ext.Button}
  20. * and {@link Ext.menu.Menu} components).</p>
  21. * <p>Aside from supporting the config object interface, any component that needs to use Actions must also support
  22. * the following method list, as these will be called as needed by the Action class: setText(string), setIconCls(string),
  23. * setDisabled(boolean), setVisible(boolean) and setHandler(function).</p>
  24. * Example usage:<br>
  25. * <pre><code>
  26. // Define the shared action. Each component below will have the same
  27. // display text and icon, and will display the same message on click.
  28. var action = new Ext.Action({
  29. {@link #text}: 'Do something',
  30. {@link #handler}: function(){
  31. Ext.Msg.alert('Click', 'You did something.');
  32. },
  33. {@link #iconCls}: 'do-something',
  34. {@link #itemId}: 'myAction'
  35. });
  36. var panel = new Ext.Panel({
  37. title: 'Actions',
  38. width: 500,
  39. height: 300,
  40. tbar: [
  41. // Add the action directly to a toolbar as a menu button
  42. action,
  43. {
  44. text: 'Action Menu',
  45. // Add the action to a menu as a text item
  46. menu: [action]
  47. }
  48. ],
  49. items: [
  50. // Add the action to the panel body as a standard button
  51. new Ext.Button(action)
  52. ],
  53. renderTo: Ext.getBody()
  54. });
  55. // Change the text for all components using the action
  56. action.setText('Something else');
  57. // Reference an action through a container using the itemId
  58. var btn = panel.getComponent('myAction');
  59. var aRef = btn.baseAction;
  60. aRef.setText('New text');
  61. </code></pre>
  62. * @constructor
  63. * @param {Object} config The configuration options
  64. */
  65. Ext.Action = Ext.extend(Object, {
  66. <div id="cfg-Ext.Action-text"></div>/**
  67. * @cfg {String} text The text to set for all components using this action (defaults to '').
  68. */
  69. <div id="cfg-Ext.Action-iconCls"></div>/**
  70. * @cfg {String} iconCls
  71. * The CSS class selector that specifies a background image to be used as the header icon for
  72. * all components using this action (defaults to '').
  73. * <p>An example of specifying a custom icon class would be something like:
  74. * </p><pre><code>
  75. // specify the property in the config for the class:
  76. ...
  77. iconCls: 'do-something'
  78. // css class that specifies background image to be used as the icon image:
  79. .do-something { background-image: url(../images/my-icon.gif) 0 6px no-repeat !important; }
  80. </code></pre>
  81. */
  82. <div id="cfg-Ext.Action-disabled"></div>/**
  83. * @cfg {Boolean} disabled True to disable all components using this action, false to enable them (defaults to false).
  84. */
  85. <div id="cfg-Ext.Action-hidden"></div>/**
  86. * @cfg {Boolean} hidden True to hide all components using this action, false to show them (defaults to false).
  87. */
  88. <div id="cfg-Ext.Action-handler"></div>/**
  89. * @cfg {Function} handler The function that will be invoked by each component tied to this action
  90. * when the component's primary event is triggered (defaults to undefined).
  91. */
  92. <div id="cfg-Ext.Action-itemId"></div>/**
  93. * @cfg {String} itemId
  94. * See {@link Ext.Component}.{@link Ext.Component#itemId itemId}.
  95. */
  96. <div id="cfg-Ext.Action-scope"></div>/**
  97. * @cfg {Object} scope The scope (<tt><b>this</b></tt> reference) in which the
  98. * <code>{@link #handler}</code> is executed. Defaults to this Button.
  99. */
  100. constructor : function(config){
  101. this.initialConfig = config;
  102. this.itemId = config.itemId = (config.itemId || config.id || Ext.id());
  103. this.items = [];
  104. },
  105. // private
  106. isAction : true,
  107. <div id="method-Ext.Action-setText"></div>/**
  108. * Sets the text to be displayed by all components using this action.
  109. * @param {String} text The text to display
  110. */
  111. setText : function(text){
  112. this.initialConfig.text = text;
  113. this.callEach('setText', [text]);
  114. },
  115. <div id="method-Ext.Action-getText"></div>/**
  116. * Gets the text currently displayed by all components using this action.
  117. */
  118. getText : function(){
  119. return this.initialConfig.text;
  120. },
  121. <div id="method-Ext.Action-setIconClass"></div>/**
  122. * Sets the icon CSS class for all components using this action. The class should supply
  123. * a background image that will be used as the icon image.
  124. * @param {String} cls The CSS class supplying the icon image
  125. */
  126. setIconClass : function(cls){
  127. this.initialConfig.iconCls = cls;
  128. this.callEach('setIconClass', [cls]);
  129. },
  130. <div id="method-Ext.Action-getIconClass"></div>/**
  131. * Gets the icon CSS class currently used by all components using this action.
  132. */
  133. getIconClass : function(){
  134. return this.initialConfig.iconCls;
  135. },
  136. <div id="method-Ext.Action-setDisabled"></div>/**
  137. * Sets the disabled state of all components using this action. Shortcut method
  138. * for {@link #enable} and {@link #disable}.
  139. * @param {Boolean} disabled True to disable the component, false to enable it
  140. */
  141. setDisabled : function(v){
  142. this.initialConfig.disabled = v;
  143. this.callEach('setDisabled', [v]);
  144. },
  145. <div id="method-Ext.Action-enable"></div>/**
  146. * Enables all components using this action.
  147. */
  148. enable : function(){
  149. this.setDisabled(false);
  150. },
  151. <div id="method-Ext.Action-disable"></div>/**
  152. * Disables all components using this action.
  153. */
  154. disable : function(){
  155. this.setDisabled(true);
  156. },
  157. <div id="method-Ext.Action-isDisabled"></div>/**
  158. * Returns true if the components using this action are currently disabled, else returns false.
  159. */
  160. isDisabled : function(){
  161. return this.initialConfig.disabled;
  162. },
  163. <div id="method-Ext.Action-setHidden"></div>/**
  164. * Sets the hidden state of all components using this action. Shortcut method
  165. * for <code>{@link #hide}</code> and <code>{@link #show}</code>.
  166. * @param {Boolean} hidden True to hide the component, false to show it
  167. */
  168. setHidden : function(v){
  169. this.initialConfig.hidden = v;
  170. this.callEach('setVisible', [!v]);
  171. },
  172. <div id="method-Ext.Action-show"></div>/**
  173. * Shows all components using this action.
  174. */
  175. show : function(){
  176. this.setHidden(false);
  177. },
  178. <div id="method-Ext.Action-hide"></div>/**
  179. * Hides all components using this action.
  180. */
  181. hide : function(){
  182. this.setHidden(true);
  183. },
  184. <div id="method-Ext.Action-isHidden"></div>/**
  185. * Returns true if the components using this action are currently hidden, else returns false.
  186. */
  187. isHidden : function(){
  188. return this.initialConfig.hidden;
  189. },
  190. <div id="method-Ext.Action-setHandler"></div>/**
  191. * Sets the function that will be called by each Component using this action when its primary event is triggered.
  192. * @param {Function} fn The function that will be invoked by the action's components. The function
  193. * will be called with no arguments.
  194. * @param {Object} scope The scope (<code>this</code> reference) in which the function is executed. Defaults to the Component firing the event.
  195. */
  196. setHandler : function(fn, scope){
  197. this.initialConfig.handler = fn;
  198. this.initialConfig.scope = scope;
  199. this.callEach('setHandler', [fn, scope]);
  200. },
  201. <div id="method-Ext.Action-each"></div>/**
  202. * Executes the specified function once for each Component currently tied to this action. The function passed
  203. * in should accept a single argument that will be an object that supports the basic Action config/method interface.
  204. * @param {Function} fn The function to execute for each component
  205. * @param {Object} scope The scope (<code>this</code> reference) in which the function is executed. Defaults to the Component.
  206. */
  207. each : function(fn, scope){
  208. Ext.each(this.items, fn, scope);
  209. },
  210. // private
  211. callEach : function(fnName, args){
  212. var cs = this.items;
  213. for(var i = 0, len = cs.length; i < len; i++){
  214. cs[i][fnName].apply(cs[i], args);
  215. }
  216. },
  217. // private
  218. addComponent : function(comp){
  219. this.items.push(comp);
  220. comp.on('destroy', this.removeComponent, this);
  221. },
  222. // private
  223. removeComponent : function(comp){
  224. this.items.remove(comp);
  225. },
  226. <div id="method-Ext.Action-execute"></div>/**
  227. * Executes this action manually using the handler function specified in the original config object
  228. * or the handler function set with <code>{@link #setHandler}</code>. Any arguments passed to this
  229. * function will be passed on to the handler function.
  230. * @param {Mixed} arg1 (optional) Variable number of arguments passed to the handler function
  231. * @param {Mixed} arg2 (optional)
  232. * @param {Mixed} etc... (optional)
  233. */
  234. execute : function(){
  235. this.initialConfig.handler.apply(this.initialConfig.scope || window, arguments);
  236. }
  237. });
  238. </pre>
  239. </body>
  240. </html>