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.

1145 lines
37 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * Ext JS Library 3.3.1
  3. * Copyright(c) 2006-2010 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. /**
  8. * @class Ext.Button
  9. * @extends Ext.BoxComponent
  10. * Simple Button class
  11. * @cfg {String} text The button text to be used as innerHTML (html tags are accepted)
  12. * @cfg {String} icon The path to an image to display in the button (the image will be set as the background-image
  13. * CSS property of the button by default, so if you want a mixed icon/text button, set cls:'x-btn-text-icon')
  14. * @cfg {Function} handler A function called when the button is clicked (can be used instead of click event).
  15. * The handler is passed the following parameters:<div class="mdetail-params"><ul>
  16. * <li><code>b</code> : Button<div class="sub-desc">This Button.</div></li>
  17. * <li><code>e</code> : EventObject<div class="sub-desc">The click event.</div></li>
  18. * </ul></div>
  19. * @cfg {Number} minWidth The minimum width for this button (used to give a set of buttons a common width).
  20. * See also {@link Ext.Panel}.<tt>{@link Ext.Panel#minButtonWidth minButtonWidth}</tt>.
  21. * @cfg {String/Object} tooltip The tooltip for the button - can be a string to be used as innerHTML (html tags are accepted) or QuickTips config object
  22. * @cfg {Boolean} hidden True to start hidden (defaults to false)
  23. * @cfg {Boolean} disabled True to start disabled (defaults to false)
  24. * @cfg {Boolean} pressed True to start pressed (only if enableToggle = true)
  25. * @cfg {String} toggleGroup The group this toggle button is a member of (only 1 per group can be pressed)
  26. * @cfg {Boolean/Object} repeat True to repeat fire the click event while the mouse is down. This can also be
  27. * a {@link Ext.util.ClickRepeater ClickRepeater} config object (defaults to false).
  28. * @constructor
  29. * Create a new button
  30. * @param {Object} config The config object
  31. * @xtype button
  32. */
  33. Ext.Button = Ext.extend(Ext.BoxComponent, {
  34. /**
  35. * Read-only. True if this button is hidden
  36. * @type Boolean
  37. */
  38. hidden : false,
  39. /**
  40. * Read-only. True if this button is disabled
  41. * @type Boolean
  42. */
  43. disabled : false,
  44. /**
  45. * Read-only. True if this button is pressed (only if enableToggle = true)
  46. * @type Boolean
  47. */
  48. pressed : false,
  49. /**
  50. * @cfg {Number} tabIndex Set a DOM tabIndex for this button (defaults to undefined)
  51. */
  52. /**
  53. * @cfg {Boolean} allowDepress
  54. * False to not allow a pressed Button to be depressed (defaults to undefined). Only valid when {@link #enableToggle} is true.
  55. */
  56. /**
  57. * @cfg {Boolean} enableToggle
  58. * True to enable pressed/not pressed toggling (defaults to false)
  59. */
  60. enableToggle : false,
  61. /**
  62. * @cfg {Function} toggleHandler
  63. * Function called when a Button with {@link #enableToggle} set to true is clicked. Two arguments are passed:<ul class="mdetail-params">
  64. * <li><b>button</b> : Ext.Button<div class="sub-desc">this Button object</div></li>
  65. * <li><b>state</b> : Boolean<div class="sub-desc">The next state of the Button, true means pressed.</div></li>
  66. * </ul>
  67. */
  68. /**
  69. * @cfg {Mixed} menu
  70. * Standard menu attribute consisting of a reference to a menu object, a menu id or a menu config blob (defaults to undefined).
  71. */
  72. /**
  73. * @cfg {String} menuAlign
  74. * The position to align the menu to (see {@link Ext.Element#alignTo} for more details, defaults to 'tl-bl?').
  75. */
  76. menuAlign : 'tl-bl?',
  77. /**
  78. * @cfg {String} overflowText If used in a {@link Ext.Toolbar Toolbar}, the
  79. * text to be used if this item is shown in the overflow menu. See also
  80. * {@link Ext.Toolbar.Item}.<code>{@link Ext.Toolbar.Item#overflowText overflowText}</code>.
  81. */
  82. /**
  83. * @cfg {String} iconCls
  84. * A css class which sets a background image to be used as the icon for this button
  85. */
  86. /**
  87. * @cfg {String} type
  88. * submit, reset or button - defaults to 'button'
  89. */
  90. type : 'button',
  91. // private
  92. menuClassTarget : 'tr:nth(2)',
  93. /**
  94. * @cfg {String} clickEvent
  95. * The DOM event that will fire the handler of the button. This can be any valid event name (dblclick, contextmenu).
  96. * Defaults to <tt>'click'</tt>.
  97. */
  98. clickEvent : 'click',
  99. /**
  100. * @cfg {Boolean} handleMouseEvents
  101. * False to disable visual cues on mouseover, mouseout and mousedown (defaults to true)
  102. */
  103. handleMouseEvents : true,
  104. /**
  105. * @cfg {String} tooltipType
  106. * The type of tooltip to use. Either 'qtip' (default) for QuickTips or 'title' for title attribute.
  107. */
  108. tooltipType : 'qtip',
  109. /**
  110. * @cfg {String} buttonSelector
  111. * <p>(Optional) A {@link Ext.DomQuery DomQuery} selector which is used to extract the active, clickable element from the
  112. * DOM structure created.</p>
  113. * <p>When a custom {@link #template} is used, you must ensure that this selector results in the selection of
  114. * a focussable element.</p>
  115. * <p>Defaults to <b><tt>'button:first-child'</tt></b>.</p>
  116. */
  117. buttonSelector : 'button:first-child',
  118. /**
  119. * @cfg {String} scale
  120. * <p>(Optional) The size of the Button. Three values are allowed:</p>
  121. * <ul class="mdetail-params">
  122. * <li>'small'<div class="sub-desc">Results in the button element being 16px high.</div></li>
  123. * <li>'medium'<div class="sub-desc">Results in the button element being 24px high.</div></li>
  124. * <li>'large'<div class="sub-desc">Results in the button element being 32px high.</div></li>
  125. * </ul>
  126. * <p>Defaults to <b><tt>'small'</tt></b>.</p>
  127. */
  128. scale : 'small',
  129. /**
  130. * @cfg {Object} scope The scope (<tt><b>this</b></tt> reference) in which the
  131. * <code>{@link #handler}</code> and <code>{@link #toggleHandler}</code> is
  132. * executed. Defaults to this Button.
  133. */
  134. /**
  135. * @cfg {String} iconAlign
  136. * <p>(Optional) The side of the Button box to render the icon. Four values are allowed:</p>
  137. * <ul class="mdetail-params">
  138. * <li>'top'<div class="sub-desc"></div></li>
  139. * <li>'right'<div class="sub-desc"></div></li>
  140. * <li>'bottom'<div class="sub-desc"></div></li>
  141. * <li>'left'<div class="sub-desc"></div></li>
  142. * </ul>
  143. * <p>Defaults to <b><tt>'left'</tt></b>.</p>
  144. */
  145. iconAlign : 'left',
  146. /**
  147. * @cfg {String} arrowAlign
  148. * <p>(Optional) The side of the Button box to render the arrow if the button has an associated {@link #menu}.
  149. * Two values are allowed:</p>
  150. * <ul class="mdetail-params">
  151. * <li>'right'<div class="sub-desc"></div></li>
  152. * <li>'bottom'<div class="sub-desc"></div></li>
  153. * </ul>
  154. * <p>Defaults to <b><tt>'right'</tt></b>.</p>
  155. */
  156. arrowAlign : 'right',
  157. /**
  158. * @cfg {Ext.Template} template (Optional)
  159. * <p>A {@link Ext.Template Template} used to create the Button's DOM structure.</p>
  160. * Instances, or subclasses which need a different DOM structure may provide a different
  161. * template layout in conjunction with an implementation of {@link #getTemplateArgs}.
  162. * @type Ext.Template
  163. * @property template
  164. */
  165. /**
  166. * @cfg {String} cls
  167. * A CSS class string to apply to the button's main element.
  168. */
  169. /**
  170. * @property menu
  171. * @type Menu
  172. * The {@link Ext.menu.Menu Menu} object associated with this Button when configured with the {@link #menu} config option.
  173. */
  174. /**
  175. * @cfg {Boolean} autoWidth
  176. * By default, if a width is not specified the button will attempt to stretch horizontally to fit its content.
  177. * If the button is being managed by a width sizing layout (hbox, fit, anchor), set this to false to prevent
  178. * the button from doing this automatic sizing.
  179. * Defaults to <tt>undefined</tt>.
  180. */
  181. initComponent : function(){
  182. if(this.menu){
  183. this.menu = Ext.menu.MenuMgr.get(this.menu);
  184. this.menu.ownerCt = this;
  185. }
  186. Ext.Button.superclass.initComponent.call(this);
  187. this.addEvents(
  188. /**
  189. * @event click
  190. * Fires when this button is clicked
  191. * @param {Button} this
  192. * @param {EventObject} e The click event
  193. */
  194. 'click',
  195. /**
  196. * @event toggle
  197. * Fires when the 'pressed' state of this button changes (only if enableToggle = true)
  198. * @param {Button} this
  199. * @param {Boolean} pressed
  200. */
  201. 'toggle',
  202. /**
  203. * @event mouseover
  204. * Fires when the mouse hovers over the button
  205. * @param {Button} this
  206. * @param {Event} e The event object
  207. */
  208. 'mouseover',
  209. /**
  210. * @event mouseout
  211. * Fires when the mouse exits the button
  212. * @param {Button} this
  213. * @param {Event} e The event object
  214. */
  215. 'mouseout',
  216. /**
  217. * @event menushow
  218. * If this button has a menu, this event fires when it is shown
  219. * @param {Button} this
  220. * @param {Menu} menu
  221. */
  222. 'menushow',
  223. /**
  224. * @event menuhide
  225. * If this button has a menu, this event fires when it is hidden
  226. * @param {Button} this
  227. * @param {Menu} menu
  228. */
  229. 'menuhide',
  230. /**
  231. * @event menutriggerover
  232. * If this button has a menu, this event fires when the mouse enters the menu triggering element
  233. * @param {Button} this
  234. * @param {Menu} menu
  235. * @param {EventObject} e
  236. */
  237. 'menutriggerover',
  238. /**
  239. * @event menutriggerout
  240. * If this button has a menu, this event fires when the mouse leaves the menu triggering element
  241. * @param {Button} this
  242. * @param {Menu} menu
  243. * @param {EventObject} e
  244. */
  245. 'menutriggerout'
  246. );
  247. if (this.menu){
  248. this.menu.ownerCt = undefined;
  249. }
  250. if(Ext.isString(this.toggleGroup)){
  251. this.enableToggle = true;
  252. }
  253. },
  254. /**
  255. * <p>This method returns an Array which provides substitution parameters for the {@link #template Template} used
  256. * to create this Button's DOM structure.</p>
  257. * <p>Instances or subclasses which use a different Template to create a different DOM structure may need to provide their
  258. * own implementation of this method.</p>
  259. * <p>The default implementation which provides data for the default {@link #template} returns an Array containing the
  260. * following items:</p><div class="mdetail-params"><ul>
  261. * <li>The &lt;button&gt;'s {@link #type}</li>
  262. * <li>A CSS class name applied to the Button's main &lt;tbody&gt; element which determines the button's scale and icon alignment.</li>
  263. * <li>A CSS class to determine the presence and position of an arrow icon. (<code>'x-btn-arrow'</code> or <code>'x-btn-arrow-bottom'</code> or <code>''</code>)</li>
  264. * <li>The {@link #cls} CSS class name applied to the button's wrapping &lt;table&gt; element.</li>
  265. * <li>The Component id which is applied to the button's wrapping &lt;table&gt; element.</li>
  266. * </ul></div>
  267. * @return {Array} Substitution data for a Template.
  268. */
  269. getTemplateArgs : function(){
  270. return [this.type, 'x-btn-' + this.scale + ' x-btn-icon-' + this.scale + '-' + this.iconAlign, this.getMenuClass(), this.cls, this.id];
  271. },
  272. // private
  273. setButtonClass : function(){
  274. if(this.useSetClass){
  275. if(!Ext.isEmpty(this.oldCls)){
  276. this.el.removeClass([this.oldCls, 'x-btn-pressed']);
  277. }
  278. this.oldCls = (this.iconCls || this.icon) ? (this.text ? 'x-btn-text-icon' : 'x-btn-icon') : 'x-btn-noicon';
  279. this.el.addClass([this.oldCls, this.pressed ? 'x-btn-pressed' : null]);
  280. }
  281. },
  282. // protected
  283. getMenuClass : function(){
  284. return this.menu ? (this.arrowAlign != 'bottom' ? 'x-btn-arrow' : 'x-btn-arrow-bottom') : '';
  285. },
  286. // private
  287. onRender : function(ct, position){
  288. if(!this.template){
  289. if(!Ext.Button.buttonTemplate){
  290. // hideous table template
  291. Ext.Button.buttonTemplate = new Ext.Template(
  292. '<table id="{4}" cellspacing="0" class="x-btn {3}"><tbody class="{1}">',
  293. '<tr><td class="x-btn-tl"><i>&#160;</i></td><td class="x-btn-tc"></td><td class="x-btn-tr"><i>&#160;</i></td></tr>',
  294. '<tr><td class="x-btn-ml"><i>&#160;</i></td><td class="x-btn-mc"><em class="{2}" unselectable="on"><button type="{0}"></button></em></td><td class="x-btn-mr"><i>&#160;</i></td></tr>',
  295. '<tr><td class="x-btn-bl"><i>&#160;</i></td><td class="x-btn-bc"></td><td class="x-btn-br"><i>&#160;</i></td></tr>',
  296. '</tbody></table>');
  297. Ext.Button.buttonTemplate.compile();
  298. }
  299. this.template = Ext.Button.buttonTemplate;
  300. }
  301. var btn, targs = this.getTemplateArgs();
  302. if(position){
  303. btn = this.template.insertBefore(position, targs, true);
  304. }else{
  305. btn = this.template.append(ct, targs, true);
  306. }
  307. /**
  308. * An {@link Ext.Element Element} encapsulating the Button's clickable element. By default,
  309. * this references a <tt>&lt;button&gt;</tt> element. Read only.
  310. * @type Ext.Element
  311. * @property btnEl
  312. */
  313. this.btnEl = btn.child(this.buttonSelector);
  314. this.mon(this.btnEl, {
  315. scope: this,
  316. focus: this.onFocus,
  317. blur: this.onBlur
  318. });
  319. this.initButtonEl(btn, this.btnEl);
  320. Ext.ButtonToggleMgr.register(this);
  321. },
  322. // private
  323. initButtonEl : function(btn, btnEl){
  324. this.el = btn;
  325. this.setIcon(this.icon);
  326. this.setText(this.text);
  327. this.setIconClass(this.iconCls);
  328. if(Ext.isDefined(this.tabIndex)){
  329. btnEl.dom.tabIndex = this.tabIndex;
  330. }
  331. if(this.tooltip){
  332. this.setTooltip(this.tooltip, true);
  333. }
  334. if(this.handleMouseEvents){
  335. this.mon(btn, {
  336. scope: this,
  337. mouseover: this.onMouseOver,
  338. mousedown: this.onMouseDown
  339. });
  340. // new functionality for monitoring on the document level
  341. //this.mon(btn, 'mouseout', this.onMouseOut, this);
  342. }
  343. if(this.menu){
  344. this.mon(this.menu, {
  345. scope: this,
  346. show: this.onMenuShow,
  347. hide: this.onMenuHide
  348. });
  349. }
  350. if(this.repeat){
  351. var repeater = new Ext.util.ClickRepeater(btn, Ext.isObject(this.repeat) ? this.repeat : {});
  352. this.mon(repeater, 'click', this.onRepeatClick, this);
  353. }else{
  354. this.mon(btn, this.clickEvent, this.onClick, this);
  355. }
  356. },
  357. // private
  358. afterRender : function(){
  359. Ext.Button.superclass.afterRender.call(this);
  360. this.useSetClass = true;
  361. this.setButtonClass();
  362. this.doc = Ext.getDoc();
  363. this.doAutoWidth();
  364. },
  365. /**
  366. * Sets the CSS class that provides a background image to use as the button's icon. This method also changes
  367. * the value of the {@link iconCls} config internally.
  368. * @param {String} cls The CSS class providing the icon image
  369. * @return {Ext.Button} this
  370. */
  371. setIconClass : function(cls){
  372. this.iconCls = cls;
  373. if(this.el){
  374. this.btnEl.dom.className = '';
  375. this.btnEl.addClass(['x-btn-text', cls || '']);
  376. this.setButtonClass();
  377. }
  378. return this;
  379. },
  380. /**
  381. * Sets the tooltip for this Button.
  382. * @param {String/Object} tooltip. This may be:<div class="mdesc-details"><ul>
  383. * <li><b>String</b> : A string to be used as innerHTML (html tags are accepted) to show in a tooltip</li>
  384. * <li><b>Object</b> : A configuration object for {@link Ext.QuickTips#register}.</li>
  385. * </ul></div>
  386. * @return {Ext.Button} this
  387. */
  388. setTooltip : function(tooltip, /* private */ initial){
  389. if(this.rendered){
  390. if(!initial){
  391. this.clearTip();
  392. }
  393. if(Ext.isObject(tooltip)){
  394. Ext.QuickTips.register(Ext.apply({
  395. target: this.btnEl.id
  396. }, tooltip));
  397. this.tooltip = tooltip;
  398. }else{
  399. this.btnEl.dom[this.tooltipType] = tooltip;
  400. }
  401. }else{
  402. this.tooltip = tooltip;
  403. }
  404. return this;
  405. },
  406. // private
  407. clearTip : function(){
  408. if(Ext.isObject(this.tooltip)){
  409. Ext.QuickTips.unregister(this.btnEl);
  410. }
  411. },
  412. // private
  413. beforeDestroy : function(){
  414. if(this.rendered){
  415. this.clearTip();
  416. }
  417. if(this.menu && this.destroyMenu !== false) {
  418. Ext.destroy(this.btnEl, this.menu);
  419. }
  420. Ext.destroy(this.repeater);
  421. },
  422. // private
  423. onDestroy : function(){
  424. if(this.rendered){
  425. this.doc.un('mouseover', this.monitorMouseOver, this);
  426. this.doc.un('mouseup', this.onMouseUp, this);
  427. delete this.doc;
  428. delete this.btnEl;
  429. Ext.ButtonToggleMgr.unregister(this);
  430. }
  431. Ext.Button.superclass.onDestroy.call(this);
  432. },
  433. // private
  434. doAutoWidth : function(){
  435. if(this.autoWidth !== false && this.el && this.text && this.width === undefined){
  436. this.el.setWidth('auto');
  437. if(Ext.isIE7 && Ext.isStrict){
  438. var ib = this.btnEl;
  439. if(ib && ib.getWidth() > 20){
  440. ib.clip();
  441. ib.setWidth(Ext.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr'));
  442. }
  443. }
  444. if(this.minWidth){
  445. if(this.el.getWidth() < this.minWidth){
  446. this.el.setWidth(this.minWidth);
  447. }
  448. }
  449. }
  450. },
  451. /**
  452. * Assigns this Button's click handler
  453. * @param {Function} handler The function to call when the button is clicked
  454. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the handler function is executed.
  455. * Defaults to this Button.
  456. * @return {Ext.Button} this
  457. */
  458. setHandler : function(handler, scope){
  459. this.handler = handler;
  460. this.scope = scope;
  461. return this;
  462. },
  463. /**
  464. * Sets this Button's text
  465. * @param {String} text The button text
  466. * @return {Ext.Button} this
  467. */
  468. setText : function(text){
  469. this.text = text;
  470. if(this.el){
  471. this.btnEl.update(text || '&#160;');
  472. this.setButtonClass();
  473. }
  474. this.doAutoWidth();
  475. return this;
  476. },
  477. /**
  478. * Sets the background image (inline style) of the button. This method also changes
  479. * the value of the {@link icon} config internally.
  480. * @param {String} icon The path to an image to display in the button
  481. * @return {Ext.Button} this
  482. */
  483. setIcon : function(icon){
  484. this.icon = icon;
  485. if(this.el){
  486. this.btnEl.setStyle('background-image', icon ? 'url(' + icon + ')' : '');
  487. this.setButtonClass();
  488. }
  489. return this;
  490. },
  491. /**
  492. * Gets the text for this Button
  493. * @return {String} The button text
  494. */
  495. getText : function(){
  496. return this.text;
  497. },
  498. /**
  499. * If a state it passed, it becomes the pressed state otherwise the current state is toggled.
  500. * @param {Boolean} state (optional) Force a particular state
  501. * @param {Boolean} supressEvent (optional) True to stop events being fired when calling this method.
  502. * @return {Ext.Button} this
  503. */
  504. toggle : function(state, suppressEvent){
  505. state = state === undefined ? !this.pressed : !!state;
  506. if(state != this.pressed){
  507. if(this.rendered){
  508. this.el[state ? 'addClass' : 'removeClass']('x-btn-pressed');
  509. }
  510. this.pressed = state;
  511. if(!suppressEvent){
  512. this.fireEvent('toggle', this, state);
  513. if(this.toggleHandler){
  514. this.toggleHandler.call(this.scope || this, this, state);
  515. }
  516. }
  517. }
  518. return this;
  519. },
  520. // private
  521. onDisable : function(){
  522. this.onDisableChange(true);
  523. },
  524. // private
  525. onEnable : function(){
  526. this.onDisableChange(false);
  527. },
  528. onDisableChange : function(disabled){
  529. if(this.el){
  530. if(!Ext.isIE6 || !this.text){
  531. this.el[disabled ? 'addClass' : 'removeClass'](this.disabledClass);
  532. }
  533. this.el.dom.disabled = disabled;
  534. }
  535. this.disabled = disabled;
  536. },
  537. /**
  538. * Show this button's menu (if it has one)
  539. */
  540. showMenu : function(){
  541. if(this.rendered && this.menu){
  542. if(this.tooltip){
  543. Ext.QuickTips.getQuickTip().cancelShow(this.btnEl);
  544. }
  545. if(this.menu.isVisible()){
  546. this.menu.hide();
  547. }
  548. this.menu.ownerCt = this;
  549. this.menu.show(this.el, this.menuAlign);
  550. }
  551. return this;
  552. },
  553. /**
  554. * Hide this button's menu (if it has one)
  555. */
  556. hideMenu : function(){
  557. if(this.hasVisibleMenu()){
  558. this.menu.hide();
  559. }
  560. return this;
  561. },
  562. /**
  563. * Returns true if the button has a menu and it is visible
  564. * @return {Boolean}
  565. */
  566. hasVisibleMenu : function(){
  567. return this.menu && this.menu.ownerCt == this && this.menu.isVisible();
  568. },
  569. // private
  570. onRepeatClick : function(repeat, e){
  571. this.onClick(e);
  572. },
  573. // private
  574. onClick : function(e){
  575. if(e){
  576. e.preventDefault();
  577. }
  578. if(e.button !== 0){
  579. return;
  580. }
  581. if(!this.disabled){
  582. this.doToggle();
  583. if(this.menu && !this.hasVisibleMenu() && !this.ignoreNextClick){
  584. this.showMenu();
  585. }
  586. this.fireEvent('click', this, e);
  587. if(this.handler){
  588. //this.el.removeClass('x-btn-over');
  589. this.handler.call(this.scope || this, this, e);
  590. }
  591. }
  592. },
  593. // private
  594. doToggle: function(){
  595. if (this.enableToggle && (this.allowDepress !== false || !this.pressed)) {
  596. this.toggle();
  597. }
  598. },
  599. // private
  600. isMenuTriggerOver : function(e, internal){
  601. return this.menu && !internal;
  602. },
  603. // private
  604. isMenuTriggerOut : function(e, internal){
  605. return this.menu && !internal;
  606. },
  607. // private
  608. onMouseOver : function(e){
  609. if(!this.disabled){
  610. var internal = e.within(this.el, true);
  611. if(!internal){
  612. this.el.addClass('x-btn-over');
  613. if(!this.monitoringMouseOver){
  614. this.doc.on('mouseover', this.monitorMouseOver, this);
  615. this.monitoringMouseOver = true;
  616. }
  617. this.fireEvent('mouseover', this, e);
  618. }
  619. if(this.isMenuTriggerOver(e, internal)){
  620. this.fireEvent('menutriggerover', this, this.menu, e);
  621. }
  622. }
  623. },
  624. // private
  625. monitorMouseOver : function(e){
  626. if(e.target != this.el.dom && !e.within(this.el)){
  627. if(this.monitoringMouseOver){
  628. this.doc.un('mouseover', this.monitorMouseOver, this);
  629. this.monitoringMouseOver = false;
  630. }
  631. this.onMouseOut(e);
  632. }
  633. },
  634. // private
  635. onMouseOut : function(e){
  636. var internal = e.within(this.el) && e.target != this.el.dom;
  637. this.el.removeClass('x-btn-over');
  638. this.fireEvent('mouseout', this, e);
  639. if(this.isMenuTriggerOut(e, internal)){
  640. this.fireEvent('menutriggerout', this, this.menu, e);
  641. }
  642. },
  643. focus : function() {
  644. this.btnEl.focus();
  645. },
  646. blur : function() {
  647. this.btnEl.blur();
  648. },
  649. // private
  650. onFocus : function(e){
  651. if(!this.disabled){
  652. this.el.addClass('x-btn-focus');
  653. }
  654. },
  655. // private
  656. onBlur : function(e){
  657. this.el.removeClass('x-btn-focus');
  658. },
  659. // private
  660. getClickEl : function(e, isUp){
  661. return this.el;
  662. },
  663. // private
  664. onMouseDown : function(e){
  665. if(!this.disabled && e.button === 0){
  666. this.getClickEl(e).addClass('x-btn-click');
  667. this.doc.on('mouseup', this.onMouseUp, this);
  668. }
  669. },
  670. // private
  671. onMouseUp : function(e){
  672. if(e.button === 0){
  673. this.getClickEl(e, true).removeClass('x-btn-click');
  674. this.doc.un('mouseup', this.onMouseUp, this);
  675. }
  676. },
  677. // private
  678. onMenuShow : function(e){
  679. if(this.menu.ownerCt == this){
  680. this.menu.ownerCt = this;
  681. this.ignoreNextClick = 0;
  682. this.el.addClass('x-btn-menu-active');
  683. this.fireEvent('menushow', this, this.menu);
  684. }
  685. },
  686. // private
  687. onMenuHide : function(e){
  688. if(this.menu.ownerCt == this){
  689. this.el.removeClass('x-btn-menu-active');
  690. this.ignoreNextClick = this.restoreClick.defer(250, this);
  691. this.fireEvent('menuhide', this, this.menu);
  692. delete this.menu.ownerCt;
  693. }
  694. },
  695. // private
  696. restoreClick : function(){
  697. this.ignoreNextClick = 0;
  698. }
  699. /**
  700. * @cfg {String} autoEl @hide
  701. */
  702. /**
  703. * @cfg {String/Object} html @hide
  704. */
  705. /**
  706. * @cfg {String} contentEl @hide
  707. */
  708. /**
  709. * @cfg {Mixed} data @hide
  710. */
  711. /**
  712. * @cfg {Mixed} tpl @hide
  713. */
  714. /**
  715. * @cfg {String} tplWriteMode @hide
  716. */
  717. });
  718. Ext.reg('button', Ext.Button);
  719. // Private utility class used by Button
  720. Ext.ButtonToggleMgr = function(){
  721. var groups = {};
  722. function toggleGroup(btn, state){
  723. if(state){
  724. var g = groups[btn.toggleGroup];
  725. for(var i = 0, l = g.length; i < l; i++){
  726. if(g[i] != btn){
  727. g[i].toggle(false);
  728. }
  729. }
  730. }
  731. }
  732. return {
  733. register : function(btn){
  734. if(!btn.toggleGroup){
  735. return;
  736. }
  737. var g = groups[btn.toggleGroup];
  738. if(!g){
  739. g = groups[btn.toggleGroup] = [];
  740. }
  741. g.push(btn);
  742. btn.on('toggle', toggleGroup);
  743. },
  744. unregister : function(btn){
  745. if(!btn.toggleGroup){
  746. return;
  747. }
  748. var g = groups[btn.toggleGroup];
  749. if(g){
  750. g.remove(btn);
  751. btn.un('toggle', toggleGroup);
  752. }
  753. },
  754. /**
  755. * Gets the pressed button in the passed group or null
  756. * @param {String} group
  757. * @return Button
  758. */
  759. getPressed : function(group){
  760. var g = groups[group];
  761. if(g){
  762. for(var i = 0, len = g.length; i < len; i++){
  763. if(g[i].pressed === true){
  764. return g[i];
  765. }
  766. }
  767. }
  768. return null;
  769. }
  770. };
  771. }();
  772. /**
  773. * @class Ext.SplitButton
  774. * @extends Ext.Button
  775. * A split button that provides a built-in dropdown arrow that can fire an event separately from the default
  776. * click event of the button. Typically this would be used to display a dropdown menu that provides additional
  777. * options to the primary button action, but any custom handler can provide the arrowclick implementation. Example usage:
  778. * <pre><code>
  779. // display a dropdown menu:
  780. new Ext.SplitButton({
  781. renderTo: 'button-ct', // the container id
  782. text: 'Options',
  783. handler: optionsHandler, // handle a click on the button itself
  784. menu: new Ext.menu.Menu({
  785. items: [
  786. // these items will render as dropdown menu items when the arrow is clicked:
  787. {text: 'Item 1', handler: item1Handler},
  788. {text: 'Item 2', handler: item2Handler}
  789. ]
  790. })
  791. });
  792. // Instead of showing a menu, you provide any type of custom
  793. // functionality you want when the dropdown arrow is clicked:
  794. new Ext.SplitButton({
  795. renderTo: 'button-ct',
  796. text: 'Options',
  797. handler: optionsHandler,
  798. arrowHandler: myCustomHandler
  799. });
  800. </code></pre>
  801. * @cfg {Function} arrowHandler A function called when the arrow button is clicked (can be used instead of click event)
  802. * @cfg {String} arrowTooltip The title attribute of the arrow
  803. * @constructor
  804. * Create a new menu button
  805. * @param {Object} config The config object
  806. * @xtype splitbutton
  807. */
  808. Ext.SplitButton = Ext.extend(Ext.Button, {
  809. // private
  810. arrowSelector : 'em',
  811. split: true,
  812. // private
  813. initComponent : function(){
  814. Ext.SplitButton.superclass.initComponent.call(this);
  815. /**
  816. * @event arrowclick
  817. * Fires when this button's arrow is clicked
  818. * @param {MenuButton} this
  819. * @param {EventObject} e The click event
  820. */
  821. this.addEvents("arrowclick");
  822. },
  823. // private
  824. onRender : function(){
  825. Ext.SplitButton.superclass.onRender.apply(this, arguments);
  826. if(this.arrowTooltip){
  827. this.el.child(this.arrowSelector).dom[this.tooltipType] = this.arrowTooltip;
  828. }
  829. },
  830. /**
  831. * Sets this button's arrow click handler.
  832. * @param {Function} handler The function to call when the arrow is clicked
  833. * @param {Object} scope (optional) Scope for the function passed above
  834. */
  835. setArrowHandler : function(handler, scope){
  836. this.arrowHandler = handler;
  837. this.scope = scope;
  838. },
  839. getMenuClass : function(){
  840. return 'x-btn-split' + (this.arrowAlign == 'bottom' ? '-bottom' : '');
  841. },
  842. isClickOnArrow : function(e){
  843. if (this.arrowAlign != 'bottom') {
  844. var visBtn = this.el.child('em.x-btn-split');
  845. var right = visBtn.getRegion().right - visBtn.getPadding('r');
  846. return e.getPageX() > right;
  847. } else {
  848. return e.getPageY() > this.btnEl.getRegion().bottom;
  849. }
  850. },
  851. // private
  852. onClick : function(e, t){
  853. e.preventDefault();
  854. if(!this.disabled){
  855. if(this.isClickOnArrow(e)){
  856. if(this.menu && !this.menu.isVisible() && !this.ignoreNextClick){
  857. this.showMenu();
  858. }
  859. this.fireEvent("arrowclick", this, e);
  860. if(this.arrowHandler){
  861. this.arrowHandler.call(this.scope || this, this, e);
  862. }
  863. }else{
  864. this.doToggle();
  865. this.fireEvent("click", this, e);
  866. if(this.handler){
  867. this.handler.call(this.scope || this, this, e);
  868. }
  869. }
  870. }
  871. },
  872. // private
  873. isMenuTriggerOver : function(e){
  874. return this.menu && e.target.tagName == this.arrowSelector;
  875. },
  876. // private
  877. isMenuTriggerOut : function(e, internal){
  878. return this.menu && e.target.tagName != this.arrowSelector;
  879. }
  880. });
  881. Ext.reg('splitbutton', Ext.SplitButton);/**
  882. * @class Ext.CycleButton
  883. * @extends Ext.SplitButton
  884. * A specialized SplitButton that contains a menu of {@link Ext.menu.CheckItem} elements. The button automatically
  885. * cycles through each menu item on click, raising the button's {@link #change} event (or calling the button's
  886. * {@link #changeHandler} function, if supplied) for the active menu item. Clicking on the arrow section of the
  887. * button displays the dropdown menu just like a normal SplitButton. Example usage:
  888. * <pre><code>
  889. var btn = new Ext.CycleButton({
  890. showText: true,
  891. prependText: 'View as ',
  892. items: [{
  893. text:'text only',
  894. iconCls:'view-text',
  895. checked:true
  896. },{
  897. text:'HTML',
  898. iconCls:'view-html'
  899. }],
  900. changeHandler:function(btn, item){
  901. Ext.Msg.alert('Change View', item.text);
  902. }
  903. });
  904. </code></pre>
  905. * @constructor
  906. * Create a new split button
  907. * @param {Object} config The config object
  908. * @xtype cycle
  909. */
  910. Ext.CycleButton = Ext.extend(Ext.SplitButton, {
  911. /**
  912. * @cfg {Array} items An array of {@link Ext.menu.CheckItem} <b>config</b> objects to be used when creating the
  913. * button's menu items (e.g., {text:'Foo', iconCls:'foo-icon'})
  914. */
  915. /**
  916. * @cfg {Boolean} showText True to display the active item's text as the button text (defaults to false)
  917. */
  918. /**
  919. * @cfg {String} prependText A static string to prepend before the active item's text when displayed as the
  920. * button's text (only applies when showText = true, defaults to '')
  921. */
  922. /**
  923. * @cfg {Function} changeHandler A callback function that will be invoked each time the active menu
  924. * item in the button's menu has changed. If this callback is not supplied, the SplitButton will instead
  925. * fire the {@link #change} event on active item change. The changeHandler function will be called with the
  926. * following argument list: (SplitButton this, Ext.menu.CheckItem item)
  927. */
  928. /**
  929. * @cfg {String} forceIcon A css class which sets an image to be used as the static icon for this button. This
  930. * icon will always be displayed regardless of which item is selected in the dropdown list. This overrides the
  931. * default behavior of changing the button's icon to match the selected item's icon on change.
  932. */
  933. /**
  934. * @property menu
  935. * @type Menu
  936. * The {@link Ext.menu.Menu Menu} object used to display the {@link Ext.menu.CheckItem CheckItems} representing the available choices.
  937. */
  938. // private
  939. getItemText : function(item){
  940. if(item && this.showText === true){
  941. var text = '';
  942. if(this.prependText){
  943. text += this.prependText;
  944. }
  945. text += item.text;
  946. return text;
  947. }
  948. return undefined;
  949. },
  950. /**
  951. * Sets the button's active menu item.
  952. * @param {Ext.menu.CheckItem} item The item to activate
  953. * @param {Boolean} suppressEvent True to prevent the button's change event from firing (defaults to false)
  954. */
  955. setActiveItem : function(item, suppressEvent){
  956. if(!Ext.isObject(item)){
  957. item = this.menu.getComponent(item);
  958. }
  959. if(item){
  960. if(!this.rendered){
  961. this.text = this.getItemText(item);
  962. this.iconCls = item.iconCls;
  963. }else{
  964. var t = this.getItemText(item);
  965. if(t){
  966. this.setText(t);
  967. }
  968. this.setIconClass(item.iconCls);
  969. }
  970. this.activeItem = item;
  971. if(!item.checked){
  972. item.setChecked(true, false);
  973. }
  974. if(this.forceIcon){
  975. this.setIconClass(this.forceIcon);
  976. }
  977. if(!suppressEvent){
  978. this.fireEvent('change', this, item);
  979. }
  980. }
  981. },
  982. /**
  983. * Gets the currently active menu item.
  984. * @return {Ext.menu.CheckItem} The active item
  985. */
  986. getActiveItem : function(){
  987. return this.activeItem;
  988. },
  989. // private
  990. initComponent : function(){
  991. this.addEvents(
  992. /**
  993. * @event change
  994. * Fires after the button's active menu item has changed. Note that if a {@link #changeHandler} function
  995. * is set on this CycleButton, it will be called instead on active item change and this change event will
  996. * not be fired.
  997. * @param {Ext.CycleButton} this
  998. * @param {Ext.menu.CheckItem} item The menu item that was selected
  999. */
  1000. "change"
  1001. );
  1002. if(this.changeHandler){
  1003. this.on('change', this.changeHandler, this.scope||this);
  1004. delete this.changeHandler;
  1005. }
  1006. this.itemCount = this.items.length;
  1007. this.menu = {cls:'x-cycle-menu', items:[]};
  1008. var checked = 0;
  1009. Ext.each(this.items, function(item, i){
  1010. Ext.apply(item, {
  1011. group: item.group || this.id,
  1012. itemIndex: i,
  1013. checkHandler: this.checkHandler,
  1014. scope: this,
  1015. checked: item.checked || false
  1016. });
  1017. this.menu.items.push(item);
  1018. if(item.checked){
  1019. checked = i;
  1020. }
  1021. }, this);
  1022. Ext.CycleButton.superclass.initComponent.call(this);
  1023. this.on('click', this.toggleSelected, this);
  1024. this.setActiveItem(checked, true);
  1025. },
  1026. // private
  1027. checkHandler : function(item, pressed){
  1028. if(pressed){
  1029. this.setActiveItem(item);
  1030. }
  1031. },
  1032. /**
  1033. * This is normally called internally on button click, but can be called externally to advance the button's
  1034. * active item programmatically to the next one in the menu. If the current item is the last one in the menu
  1035. * the active item will be set to the first item in the menu.
  1036. */
  1037. toggleSelected : function(){
  1038. var m = this.menu;
  1039. m.render();
  1040. // layout if we haven't before so the items are active
  1041. if(!m.hasLayout){
  1042. m.doLayout();
  1043. }
  1044. var nextIdx, checkItem;
  1045. for (var i = 1; i < this.itemCount; i++) {
  1046. nextIdx = (this.activeItem.itemIndex + i) % this.itemCount;
  1047. // check the potential item
  1048. checkItem = m.items.itemAt(nextIdx);
  1049. // if its not disabled then check it.
  1050. if (!checkItem.disabled) {
  1051. checkItem.setChecked(true);
  1052. break;
  1053. }
  1054. }
  1055. }
  1056. });
  1057. Ext.reg('cycle', Ext.CycleButton);