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.

277 lines
8.0 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. Ext.ns('Ext.ux');
  16. Ext.ux.Rating = Ext.extend(Ext.util.Observable, {
  17. // Configuration options
  18. starWidth: 16,
  19. split: 1,
  20. resetValue: '',
  21. defaultSelected: -1,
  22. selected: -1,
  23. showTitles: true,
  24. // Our class constructor
  25. constructor : function(element, config) {
  26. Ext.apply(this, config);
  27. Ext.ux.Rating.superclass.constructor.call(this);
  28. this.addEvents(
  29. 'change',
  30. 'reset'
  31. );
  32. this.el = Ext.get(element);
  33. this.init();
  34. },
  35. init : function() {
  36. var me = this;
  37. // Some arrays we are going to store data in
  38. this.values = [];
  39. this.titles = [];
  40. this.stars = [];
  41. // We create a container to put all our stars into
  42. this.container = this.el.createChild({
  43. cls: 'ux-rating-container ux-rating-clearfix'
  44. });
  45. if(this.canReset) {
  46. this.resetEl = this.container.createChild({
  47. cls: 'ux-rating-reset',
  48. cn: [{
  49. tag: 'a',
  50. title: this.showTitles ? (this.resetTitle || 'Reset your vote') : '',
  51. html: 'Reset'
  52. }]
  53. });
  54. this.resetEl.visibilityMode = Ext.Element.DISPLAY;
  55. this.resetEl.hover(function() {
  56. Ext.fly(this).addClass('ux-rating-reset-hover');
  57. }, function() {
  58. Ext.fly(this).removeClass('ux-rating-reset-hover');
  59. });
  60. this.resetEl.on('click', this.reset, this);
  61. }
  62. // We use DomQuery to select the radio buttons
  63. this.radioBoxes = this.el.select('input[type=radio]');
  64. // Then we can loop over the CompositeElement using each
  65. this.radioBoxes.each(this.initStar, this);
  66. // We use DomHelper to create our hidden input
  67. this.input = this.container.createChild({
  68. tag: 'input',
  69. type: 'hidden',
  70. name: this.name,
  71. value: this.values[this.defaultSelected] || this.resetValue
  72. });
  73. // Lets remove all the radio buttons from the DOM
  74. this.radioBoxes.remove();
  75. this.select(this.defaultSelected === undefined ? false : this.defaultSelected)
  76. if(this.disabled) {
  77. this.disable();
  78. } else {
  79. // Enable will set up our event listeners
  80. this.enable();
  81. }
  82. },
  83. initStar : function(item, all, i) {
  84. var sw = Math.floor(this.starWidth / this.split);
  85. // We use the name and disabled attributes of the first radio button
  86. if(i == 0) {
  87. this.name = item.dom.name;
  88. this.disabled = item.dom.disabled;
  89. }
  90. // Saving the value and title for this star
  91. this.values[i] = item.dom.value;
  92. this.titles[i] = item.dom.title;
  93. if(item.dom.checked) {
  94. this.defaultSelected = i;
  95. }
  96. // Now actually create the star!
  97. var star = this.container.createChild({
  98. cls: 'ux-rating-star'
  99. });
  100. var starLink = star.createChild({
  101. tag: 'a',
  102. html: this.values[i],
  103. title: this.showTitles ? this.titles[i] : ''
  104. });
  105. // Prepare division settings
  106. if(this.split) {
  107. var odd = (i % this.split);
  108. star.setWidth(sw);
  109. starLink.setStyle('margin-left', '-' + (odd * sw) + 'px');
  110. }
  111. // Save the reference to this star so we can easily access it later
  112. this.stars.push(star.dom);
  113. },
  114. onStarClick : function(ev, t) {
  115. if(!this.disabled) {
  116. this.select(this.stars.indexOf(t));
  117. }
  118. },
  119. onStarOver : function(ev, t) {
  120. if(!this.disabled) {
  121. this.fillTo(this.stars.indexOf(t), true);
  122. }
  123. },
  124. onStarOut : function(ev, t) {
  125. if(!this.disabled) {
  126. this.fillTo(this.selected, false);
  127. }
  128. },
  129. reset : function(ev, t) {
  130. this.select(-1);
  131. },
  132. select : function(index) {
  133. if(index === false || index === -1) {
  134. // remove current selection in el
  135. this.value = this.resetValue;
  136. this.title = "";
  137. this.input.dom.value = '';
  138. if(this.canReset) {
  139. this.resetEl.setOpacity(0.5);
  140. }
  141. this.fillNone();
  142. if(this.selected !== -1) {
  143. this.fireEvent('change', this, this.values[index], this.stars[index]);
  144. }
  145. this.selected = -1;
  146. }
  147. else if(index !== this.selected) {
  148. // Update some properties
  149. this.selected = index;
  150. this.value = this.values[index];
  151. this.title = this.titles[index];
  152. // Set the value of our hidden input so the rating can be submitted
  153. this.input.dom.value = this.value;
  154. if(this.canReset) {
  155. this.resetEl.setOpacity(0.99);
  156. }
  157. // the fillTo() method will fill the stars up until the selected one
  158. this.fillTo(index, false);
  159. // Lets also not forget to fire our custom event!
  160. this.fireEvent('change', this, this.values[index], this.stars[index]);
  161. }
  162. },
  163. fillTo : function(index, hover) {
  164. if (index != -1) {
  165. var addClass = hover ? 'ux-rating-star-hover' : 'ux-rating-star-on';
  166. var removeClass = hover ? 'ux-rating-star-on' : 'ux-rating-star-hover';
  167. // We add a css class to each star up until the selected one
  168. Ext.each(this.stars.slice(0, index+1), function() {
  169. Ext.fly(this).removeClass(removeClass).addClass(addClass);
  170. });
  171. // And then remove the same class from all the stars after this one
  172. Ext.each(this.stars.slice(index+1), function() {
  173. Ext.fly(this).removeClass([removeClass, addClass]);
  174. });
  175. }
  176. else {
  177. this.fillNone();
  178. }
  179. },
  180. fillNone : function() {
  181. this.container.select('.ux-rating-star').removeClass(['ux-rating-star-hover', 'ux-rating-star-on']);
  182. },
  183. enable : function() {
  184. if(this.canReset) {
  185. this.resetEl.show();
  186. }
  187. this.input.dom.disabled = null;
  188. this.disabled = false;
  189. this.container.removeClass('ux-rating-disabled');
  190. // We will be using the technique of event delegation by listening
  191. // for bubbled up events on the container
  192. this.container.on({
  193. click: this.onStarClick,
  194. mouseover: this.onStarOver,
  195. mouseout: this.onStarOut,
  196. scope: this,
  197. delegate: 'div.ux-rating-star'
  198. });
  199. },
  200. disable : function() {
  201. if(this.canReset) {
  202. this.resetEl.hide();
  203. }
  204. this.input.dom.disabled = true;
  205. this.disabled = true;
  206. this.container.addClass('ux-rating-disabled');
  207. this.container.un({
  208. click: this.onStarClick,
  209. mouseover: this.onStarOver,
  210. mouseout: this.onStarOut,
  211. scope: this,
  212. delegate: 'div.ux-rating-star'
  213. });
  214. },
  215. getValue : function() {
  216. return this.values[this.selected] || this.resetValue;
  217. },
  218. destroy : function() {
  219. this.disable();
  220. this.container.remove();
  221. this.radioBoxes.appendTo(this.el);
  222. if(this.selected !== -1) {
  223. this.radioBoxes.elements[this.selected].checked = true;
  224. }
  225. }
  226. });
  227. </pre>
  228. </body>
  229. </html>