Web UI for ARGUS server
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.

452 lines
12 KiB

6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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.ux.Spinner"></div>/**
  16. * @class Ext.ux.Spinner
  17. * @extends Ext.util.Observable
  18. * Creates a Spinner control utilized by Ext.ux.form.SpinnerField
  19. */
  20. Ext.ux.Spinner = Ext.extend(Ext.util.Observable, {
  21. incrementValue: 1,
  22. alternateIncrementValue: 5,
  23. triggerClass: 'x-form-spinner-trigger',
  24. splitterClass: 'x-form-spinner-splitter',
  25. alternateKey: Ext.EventObject.shiftKey,
  26. defaultValue: 0,
  27. accelerate: false,
  28. constructor: function(config){
  29. Ext.ux.Spinner.superclass.constructor.call(this, config);
  30. Ext.apply(this, config);
  31. this.mimicing = false;
  32. },
  33. init: function(field){
  34. this.field = field;
  35. field.afterMethod('onRender', this.doRender, this);
  36. field.afterMethod('onEnable', this.doEnable, this);
  37. field.afterMethod('onDisable', this.doDisable, this);
  38. field.afterMethod('afterRender', this.doAfterRender, this);
  39. field.afterMethod('onResize', this.doResize, this);
  40. field.afterMethod('onFocus', this.doFocus, this);
  41. field.beforeMethod('onDestroy', this.doDestroy, this);
  42. },
  43. doRender: function(ct, position){
  44. var el = this.el = this.field.getEl();
  45. var f = this.field;
  46. if (!f.wrap) {
  47. f.wrap = this.wrap = el.wrap({
  48. cls: "x-form-field-wrap"
  49. });
  50. }
  51. else {
  52. this.wrap = f.wrap.addClass('x-form-field-wrap');
  53. }
  54. this.trigger = this.wrap.createChild({
  55. tag: "img",
  56. src: Ext.BLANK_IMAGE_URL,
  57. cls: "x-form-trigger " + this.triggerClass
  58. });
  59. if (!f.width) {
  60. this.wrap.setWidth(el.getWidth() + this.trigger.getWidth());
  61. }
  62. this.splitter = this.wrap.createChild({
  63. tag: 'div',
  64. cls: this.splitterClass,
  65. style: 'width:13px; height:2px;'
  66. });
  67. this.splitter.setRight((Ext.isIE) ? 1 : 2).setTop(10).show();
  68. this.proxy = this.trigger.createProxy('', this.splitter, true);
  69. this.proxy.addClass("x-form-spinner-proxy");
  70. this.proxy.setStyle('left', '0px');
  71. this.proxy.setSize(14, 1);
  72. this.proxy.hide();
  73. this.dd = new Ext.dd.DDProxy(this.splitter.dom.id, "SpinnerDrag", {
  74. dragElId: this.proxy.id
  75. });
  76. this.initTrigger();
  77. this.initSpinner();
  78. },
  79. doAfterRender: function(){
  80. var y;
  81. if (Ext.isIE && this.el.getY() != (y = this.trigger.getY())) {
  82. this.el.position();
  83. this.el.setY(y);
  84. }
  85. },
  86. doEnable: function(){
  87. if (this.wrap) {
  88. this.disabled = false;
  89. this.wrap.removeClass(this.field.disabledClass);
  90. }
  91. },
  92. doDisable: function(){
  93. if (this.wrap) {
  94. this.disabled = true;
  95. this.wrap.addClass(this.field.disabledClass);
  96. this.el.removeClass(this.field.disabledClass);
  97. }
  98. },
  99. doResize: function(w, h){
  100. if (typeof w == 'number') {
  101. this.el.setWidth(w - this.trigger.getWidth());
  102. }
  103. this.wrap.setWidth(this.el.getWidth() + this.trigger.getWidth());
  104. },
  105. doFocus: function(){
  106. if (!this.mimicing) {
  107. this.wrap.addClass('x-trigger-wrap-focus');
  108. this.mimicing = true;
  109. Ext.get(Ext.isIE ? document.body : document).on("mousedown", this.mimicBlur, this, {
  110. delay: 10
  111. });
  112. this.el.on('keydown', this.checkTab, this);
  113. }
  114. },
  115. // private
  116. checkTab: function(e){
  117. if (e.getKey() == e.TAB) {
  118. this.triggerBlur();
  119. }
  120. },
  121. // private
  122. mimicBlur: function(e){
  123. if (!this.wrap.contains(e.target) && this.field.validateBlur(e)) {
  124. this.triggerBlur();
  125. }
  126. },
  127. // private
  128. triggerBlur: function(){
  129. this.mimicing = false;
  130. Ext.get(Ext.isIE ? document.body : document).un("mousedown", this.mimicBlur, this);
  131. this.el.un("keydown", this.checkTab, this);
  132. this.field.beforeBlur();
  133. this.wrap.removeClass('x-trigger-wrap-focus');
  134. this.field.onBlur.call(this.field);
  135. },
  136. initTrigger: function(){
  137. this.trigger.addClassOnOver('x-form-trigger-over');
  138. this.trigger.addClassOnClick('x-form-trigger-click');
  139. },
  140. initSpinner: function(){
  141. this.field.addEvents({
  142. 'spin': true,
  143. 'spinup': true,
  144. 'spindown': true
  145. });
  146. this.keyNav = new Ext.KeyNav(this.el, {
  147. "up": function(e){
  148. e.preventDefault();
  149. this.onSpinUp();
  150. },
  151. "down": function(e){
  152. e.preventDefault();
  153. this.onSpinDown();
  154. },
  155. "pageUp": function(e){
  156. e.preventDefault();
  157. this.onSpinUpAlternate();
  158. },
  159. "pageDown": function(e){
  160. e.preventDefault();
  161. this.onSpinDownAlternate();
  162. },
  163. scope: this
  164. });
  165. this.repeater = new Ext.util.ClickRepeater(this.trigger, {
  166. accelerate: this.accelerate
  167. });
  168. this.field.mon(this.repeater, "click", this.onTriggerClick, this, {
  169. preventDefault: true
  170. });
  171. this.field.mon(this.trigger, {
  172. mouseover: this.onMouseOver,
  173. mouseout: this.onMouseOut,
  174. mousemove: this.onMouseMove,
  175. mousedown: this.onMouseDown,
  176. mouseup: this.onMouseUp,
  177. scope: this,
  178. preventDefault: true
  179. });
  180. this.field.mon(this.wrap, "mousewheel", this.handleMouseWheel, this);
  181. this.dd.setXConstraint(0, 0, 10)
  182. this.dd.setYConstraint(1500, 1500, 10);
  183. this.dd.endDrag = this.endDrag.createDelegate(this);
  184. this.dd.startDrag = this.startDrag.createDelegate(this);
  185. this.dd.onDrag = this.onDrag.createDelegate(this);
  186. },
  187. onMouseOver: function(){
  188. if (this.disabled) {
  189. return;
  190. }
  191. var middle = this.getMiddle();
  192. this.tmpHoverClass = (Ext.EventObject.getPageY() < middle) ? 'x-form-spinner-overup' : 'x-form-spinner-overdown';
  193. this.trigger.addClass(this.tmpHoverClass);
  194. },
  195. //private
  196. onMouseOut: function(){
  197. this.trigger.removeClass(this.tmpHoverClass);
  198. },
  199. //private
  200. onMouseMove: function(){
  201. if (this.disabled) {
  202. return;
  203. }
  204. var middle = this.getMiddle();
  205. if (((Ext.EventObject.getPageY() > middle) && this.tmpHoverClass == "x-form-spinner-overup") ||
  206. ((Ext.EventObject.getPageY() < middle) && this.tmpHoverClass == "x-form-spinner-overdown")) {
  207. }
  208. },
  209. //private
  210. onMouseDown: function(){
  211. if (this.disabled) {
  212. return;
  213. }
  214. var middle = this.getMiddle();
  215. this.tmpClickClass = (Ext.EventObject.getPageY() < middle) ? 'x-form-spinner-clickup' : 'x-form-spinner-clickdown';
  216. this.trigger.addClass(this.tmpClickClass);
  217. },
  218. //private
  219. onMouseUp: function(){
  220. this.trigger.removeClass(this.tmpClickClass);
  221. },
  222. //private
  223. onTriggerClick: function(){
  224. if (this.disabled || this.el.dom.readOnly) {
  225. return;
  226. }
  227. var middle = this.getMiddle();
  228. var ud = (Ext.EventObject.getPageY() < middle) ? 'Up' : 'Down';
  229. this['onSpin' + ud]();
  230. },
  231. //private
  232. getMiddle: function(){
  233. var t = this.trigger.getTop();
  234. var h = this.trigger.getHeight();
  235. var middle = t + (h / 2);
  236. return middle;
  237. },
  238. //private
  239. //checks if control is allowed to spin
  240. isSpinnable: function(){
  241. if (this.disabled || this.el.dom.readOnly) {
  242. Ext.EventObject.preventDefault(); //prevent scrolling when disabled/readonly
  243. return false;
  244. }
  245. return true;
  246. },
  247. handleMouseWheel: function(e){
  248. //disable scrolling when not focused
  249. if (this.wrap.hasClass('x-trigger-wrap-focus') == false) {
  250. return;
  251. }
  252. var delta = e.getWheelDelta();
  253. if (delta > 0) {
  254. this.onSpinUp();
  255. e.stopEvent();
  256. }
  257. else
  258. if (delta < 0) {
  259. this.onSpinDown();
  260. e.stopEvent();
  261. }
  262. },
  263. //private
  264. startDrag: function(){
  265. this.proxy.show();
  266. this._previousY = Ext.fly(this.dd.getDragEl()).getTop();
  267. },
  268. //private
  269. endDrag: function(){
  270. this.proxy.hide();
  271. },
  272. //private
  273. onDrag: function(){
  274. if (this.disabled) {
  275. return;
  276. }
  277. var y = Ext.fly(this.dd.getDragEl()).getTop();
  278. var ud = '';
  279. if (this._previousY > y) {
  280. ud = 'Up';
  281. } //up
  282. if (this._previousY < y) {
  283. ud = 'Down';
  284. } //down
  285. if (ud != '') {
  286. this['onSpin' + ud]();
  287. }
  288. this._previousY = y;
  289. },
  290. //private
  291. onSpinUp: function(){
  292. if (this.isSpinnable() == false) {
  293. return;
  294. }
  295. if (Ext.EventObject.shiftKey == true) {
  296. this.onSpinUpAlternate();
  297. return;
  298. }
  299. else {
  300. this.spin(false, false);
  301. }
  302. this.field.fireEvent("spin", this);
  303. this.field.fireEvent("spinup", this);
  304. },
  305. //private
  306. onSpinDown: function(){
  307. if (this.isSpinnable() == false) {
  308. return;
  309. }
  310. if (Ext.EventObject.shiftKey == true) {
  311. this.onSpinDownAlternate();
  312. return;
  313. }
  314. else {
  315. this.spin(true, false);
  316. }
  317. this.field.fireEvent("spin", this);
  318. this.field.fireEvent("spindown", this);
  319. },
  320. //private
  321. onSpinUpAlternate: function(){
  322. if (this.isSpinnable() == false) {
  323. return;
  324. }
  325. this.spin(false, true);
  326. this.field.fireEvent("spin", this);
  327. this.field.fireEvent("spinup", this);
  328. },
  329. //private
  330. onSpinDownAlternate: function(){
  331. if (this.isSpinnable() == false) {
  332. return;
  333. }
  334. this.spin(true, true);
  335. this.field.fireEvent("spin", this);
  336. this.field.fireEvent("spindown", this);
  337. },
  338. spin: function(down, alternate){
  339. var v = parseFloat(this.field.getValue());
  340. var incr = (alternate == true) ? this.alternateIncrementValue : this.incrementValue;
  341. (down == true) ? v -= incr : v += incr;
  342. v = (isNaN(v)) ? this.defaultValue : v;
  343. v = this.fixBoundries(v);
  344. this.field.setRawValue(v);
  345. },
  346. fixBoundries: function(value){
  347. var v = value;
  348. if (this.field.minValue != undefined && v < this.field.minValue) {
  349. v = this.field.minValue;
  350. }
  351. if (this.field.maxValue != undefined && v > this.field.maxValue) {
  352. v = this.field.maxValue;
  353. }
  354. return this.fixPrecision(v);
  355. },
  356. // private
  357. fixPrecision: function(value){
  358. var nan = isNaN(value);
  359. if (!this.field.allowDecimals || this.field.decimalPrecision == -1 || nan || !value) {
  360. return nan ? '' : value;
  361. }
  362. return parseFloat(parseFloat(value).toFixed(this.field.decimalPrecision));
  363. },
  364. doDestroy: function(){
  365. if (this.trigger) {
  366. this.trigger.remove();
  367. }
  368. if (this.wrap) {
  369. this.wrap.remove();
  370. delete this.field.wrap;
  371. }
  372. if (this.splitter) {
  373. this.splitter.remove();
  374. }
  375. if (this.dd) {
  376. this.dd.unreg();
  377. this.dd = null;
  378. }
  379. if (this.proxy) {
  380. this.proxy.remove();
  381. }
  382. if (this.repeater) {
  383. this.repeater.purgeListeners();
  384. }
  385. if (this.mimicing){
  386. Ext.get(Ext.isIE ? document.body : document).un("mousedown", this.mimicBlur, this);
  387. }
  388. }
  389. });
  390. //backwards compat
  391. Ext.form.Spinner = Ext.ux.Spinner;</pre>
  392. </body>
  393. </html>