Installer/Updater
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.

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