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.

265 lines
10 KiB

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