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.

202 lines
7.5 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.CycleButton"></div>/**
  16. * @class Ext.CycleButton
  17. * @extends Ext.SplitButton
  18. * A specialized SplitButton that contains a menu of {@link Ext.menu.CheckItem} elements. The button automatically
  19. * cycles through each menu item on click, raising the button's {@link #change} event (or calling the button's
  20. * {@link #changeHandler} function, if supplied) for the active menu item. Clicking on the arrow section of the
  21. * button displays the dropdown menu just like a normal SplitButton. Example usage:
  22. * <pre><code>
  23. var btn = new Ext.CycleButton({
  24. showText: true,
  25. prependText: 'View as ',
  26. items: [{
  27. text:'text only',
  28. iconCls:'view-text',
  29. checked:true
  30. },{
  31. text:'HTML',
  32. iconCls:'view-html'
  33. }],
  34. changeHandler:function(btn, item){
  35. Ext.Msg.alert('Change View', item.text);
  36. }
  37. });
  38. </code></pre>
  39. * @constructor
  40. * Create a new split button
  41. * @param {Object} config The config object
  42. * @xtype cycle
  43. */
  44. Ext.CycleButton = Ext.extend(Ext.SplitButton, {
  45. <div id="cfg-Ext.CycleButton-items"></div>/**
  46. * @cfg {Array} items An array of {@link Ext.menu.CheckItem} <b>config</b> objects to be used when creating the
  47. * button's menu items (e.g., {text:'Foo', iconCls:'foo-icon'})
  48. */
  49. <div id="cfg-Ext.CycleButton-showText"></div>/**
  50. * @cfg {Boolean} showText True to display the active item's text as the button text (defaults to false)
  51. */
  52. <div id="cfg-Ext.CycleButton-prependText"></div>/**
  53. * @cfg {String} prependText A static string to prepend before the active item's text when displayed as the
  54. * button's text (only applies when showText = true, defaults to '')
  55. */
  56. <div id="cfg-Ext.CycleButton-changeHandler"></div>/**
  57. * @cfg {Function} changeHandler A callback function that will be invoked each time the active menu
  58. * item in the button's menu has changed. If this callback is not supplied, the SplitButton will instead
  59. * fire the {@link #change} event on active item change. The changeHandler function will be called with the
  60. * following argument list: (SplitButton this, Ext.menu.CheckItem item)
  61. */
  62. <div id="cfg-Ext.CycleButton-forceIcon"></div>/**
  63. * @cfg {String} forceIcon A css class which sets an image to be used as the static icon for this button. This
  64. * icon will always be displayed regardless of which item is selected in the dropdown list. This overrides the
  65. * default behavior of changing the button's icon to match the selected item's icon on change.
  66. */
  67. <div id="prop-Ext.CycleButton-menu"></div>/**
  68. * @property menu
  69. * @type Menu
  70. * The {@link Ext.menu.Menu Menu} object used to display the {@link Ext.menu.CheckItem CheckItems} representing the available choices.
  71. */
  72. // private
  73. getItemText : function(item){
  74. if(item && this.showText === true){
  75. var text = '';
  76. if(this.prependText){
  77. text += this.prependText;
  78. }
  79. text += item.text;
  80. return text;
  81. }
  82. return undefined;
  83. },
  84. <div id="method-Ext.CycleButton-setActiveItem"></div>/**
  85. * Sets the button's active menu item.
  86. * @param {Ext.menu.CheckItem} item The item to activate
  87. * @param {Boolean} suppressEvent True to prevent the button's change event from firing (defaults to false)
  88. */
  89. setActiveItem : function(item, suppressEvent){
  90. if(!Ext.isObject(item)){
  91. item = this.menu.getComponent(item);
  92. }
  93. if(item){
  94. if(!this.rendered){
  95. this.text = this.getItemText(item);
  96. this.iconCls = item.iconCls;
  97. }else{
  98. var t = this.getItemText(item);
  99. if(t){
  100. this.setText(t);
  101. }
  102. this.setIconClass(item.iconCls);
  103. }
  104. this.activeItem = item;
  105. if(!item.checked){
  106. item.setChecked(true, false);
  107. }
  108. if(this.forceIcon){
  109. this.setIconClass(this.forceIcon);
  110. }
  111. if(!suppressEvent){
  112. this.fireEvent('change', this, item);
  113. }
  114. }
  115. },
  116. <div id="method-Ext.CycleButton-getActiveItem"></div>/**
  117. * Gets the currently active menu item.
  118. * @return {Ext.menu.CheckItem} The active item
  119. */
  120. getActiveItem : function(){
  121. return this.activeItem;
  122. },
  123. // private
  124. initComponent : function(){
  125. this.addEvents(
  126. <div id="event-Ext.CycleButton-change"></div>/**
  127. * @event change
  128. * Fires after the button's active menu item has changed. Note that if a {@link #changeHandler} function
  129. * is set on this CycleButton, it will be called instead on active item change and this change event will
  130. * not be fired.
  131. * @param {Ext.CycleButton} this
  132. * @param {Ext.menu.CheckItem} item The menu item that was selected
  133. */
  134. "change"
  135. );
  136. if(this.changeHandler){
  137. this.on('change', this.changeHandler, this.scope||this);
  138. delete this.changeHandler;
  139. }
  140. this.itemCount = this.items.length;
  141. this.menu = {cls:'x-cycle-menu', items:[]};
  142. var checked = 0;
  143. Ext.each(this.items, function(item, i){
  144. Ext.apply(item, {
  145. group: item.group || this.id,
  146. itemIndex: i,
  147. checkHandler: this.checkHandler,
  148. scope: this,
  149. checked: item.checked || false
  150. });
  151. this.menu.items.push(item);
  152. if(item.checked){
  153. checked = i;
  154. }
  155. }, this);
  156. Ext.CycleButton.superclass.initComponent.call(this);
  157. this.on('click', this.toggleSelected, this);
  158. this.setActiveItem(checked, true);
  159. },
  160. // private
  161. checkHandler : function(item, pressed){
  162. if(pressed){
  163. this.setActiveItem(item);
  164. }
  165. },
  166. <div id="method-Ext.CycleButton-toggleSelected"></div>/**
  167. * This is normally called internally on button click, but can be called externally to advance the button's
  168. * active item programmatically to the next one in the menu. If the current item is the last one in the menu
  169. * the active item will be set to the first item in the menu.
  170. */
  171. toggleSelected : function(){
  172. var m = this.menu;
  173. m.render();
  174. // layout if we haven't before so the items are active
  175. if(!m.hasLayout){
  176. m.doLayout();
  177. }
  178. var nextIdx, checkItem;
  179. for (var i = 1; i < this.itemCount; i++) {
  180. nextIdx = (this.activeItem.itemIndex + i) % this.itemCount;
  181. // check the potential item
  182. checkItem = m.items.itemAt(nextIdx);
  183. // if its not disabled then check it.
  184. if (!checkItem.disabled) {
  185. checkItem.setChecked(true);
  186. break;
  187. }
  188. }
  189. }
  190. });
  191. Ext.reg('cycle', Ext.CycleButton);</pre>
  192. </body>
  193. </html>