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.

506 lines
17 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.form.CheckboxGroup"></div>/**
  16. * @class Ext.form.CheckboxGroup
  17. * @extends Ext.form.Field
  18. * <p>A grouping container for {@link Ext.form.Checkbox} controls.</p>
  19. * <p>Sample usage:</p>
  20. * <pre><code>
  21. var myCheckboxGroup = new Ext.form.CheckboxGroup({
  22. id:'myGroup',
  23. xtype: 'checkboxgroup',
  24. fieldLabel: 'Single Column',
  25. itemCls: 'x-check-group-alt',
  26. // Put all controls in a single column with width 100%
  27. columns: 1,
  28. items: [
  29. {boxLabel: 'Item 1', name: 'cb-col-1'},
  30. {boxLabel: 'Item 2', name: 'cb-col-2', checked: true},
  31. {boxLabel: 'Item 3', name: 'cb-col-3'}
  32. ]
  33. });
  34. * </code></pre>
  35. * @constructor
  36. * Creates a new CheckboxGroup
  37. * @param {Object} config Configuration options
  38. * @xtype checkboxgroup
  39. */
  40. Ext.form.CheckboxGroup = Ext.extend(Ext.form.Field, {
  41. <div id="cfg-Ext.form.CheckboxGroup-items"></div>/**
  42. * @cfg {Array} items An Array of {@link Ext.form.Checkbox Checkbox}es or Checkbox config objects
  43. * to arrange in the group.
  44. */
  45. <div id="cfg-Ext.form.CheckboxGroup-columns"></div>/**
  46. * @cfg {String/Number/Array} columns Specifies the number of columns to use when displaying grouped
  47. * checkbox/radio controls using automatic layout. This config can take several types of values:
  48. * <ul><li><b>'auto'</b> : <p class="sub-desc">The controls will be rendered one per column on one row and the width
  49. * of each column will be evenly distributed based on the width of the overall field container. This is the default.</p></li>
  50. * <li><b>Number</b> : <p class="sub-desc">If you specific a number (e.g., 3) that number of columns will be
  51. * created and the contained controls will be automatically distributed based on the value of {@link #vertical}.</p></li>
  52. * <li><b>Array</b> : Object<p class="sub-desc">You can also specify an array of column widths, mixing integer
  53. * (fixed width) and float (percentage width) values as needed (e.g., [100, .25, .75]). Any integer values will
  54. * be rendered first, then any float values will be calculated as a percentage of the remaining space. Float
  55. * values do not have to add up to 1 (100%) although if you want the controls to take up the entire field
  56. * container you should do so.</p></li></ul>
  57. */
  58. columns : 'auto',
  59. <div id="cfg-Ext.form.CheckboxGroup-vertical"></div>/**
  60. * @cfg {Boolean} vertical True to distribute contained controls across columns, completely filling each column
  61. * top to bottom before starting on the next column. The number of controls in each column will be automatically
  62. * calculated to keep columns as even as possible. The default value is false, so that controls will be added
  63. * to columns one at a time, completely filling each row left to right before starting on the next row.
  64. */
  65. vertical : false,
  66. <div id="cfg-Ext.form.CheckboxGroup-allowBlank"></div>/**
  67. * @cfg {Boolean} allowBlank False to validate that at least one item in the group is checked (defaults to true).
  68. * If no items are selected at validation time, {@link @blankText} will be used as the error text.
  69. */
  70. allowBlank : true,
  71. <div id="cfg-Ext.form.CheckboxGroup-blankText"></div>/**
  72. * @cfg {String} blankText Error text to display if the {@link #allowBlank} validation fails (defaults to "You must
  73. * select at least one item in this group")
  74. */
  75. blankText : "You must select at least one item in this group",
  76. // private
  77. defaultType : 'checkbox',
  78. // private
  79. groupCls : 'x-form-check-group',
  80. // private
  81. initComponent: function(){
  82. this.addEvents(
  83. <div id="event-Ext.form.CheckboxGroup-change"></div>/**
  84. * @event change
  85. * Fires when the state of a child checkbox changes.
  86. * @param {Ext.form.CheckboxGroup} this
  87. * @param {Array} checked An array containing the checked boxes.
  88. */
  89. 'change'
  90. );
  91. this.on('change', this.validate, this);
  92. Ext.form.CheckboxGroup.superclass.initComponent.call(this);
  93. },
  94. // private
  95. onRender : function(ct, position){
  96. if(!this.el){
  97. var panelCfg = {
  98. autoEl: {
  99. id: this.id
  100. },
  101. cls: this.groupCls,
  102. layout: 'column',
  103. renderTo: ct,
  104. bufferResize: false // Default this to false, since it doesn't really have a proper ownerCt.
  105. };
  106. var colCfg = {
  107. xtype: 'container',
  108. defaultType: this.defaultType,
  109. layout: 'form',
  110. defaults: {
  111. hideLabel: true,
  112. anchor: '100%'
  113. }
  114. };
  115. if(this.items[0].items){
  116. // The container has standard ColumnLayout configs, so pass them in directly
  117. Ext.apply(panelCfg, {
  118. layoutConfig: {columns: this.items.length},
  119. defaults: this.defaults,
  120. items: this.items
  121. });
  122. for(var i=0, len=this.items.length; i<len; i++){
  123. Ext.applyIf(this.items[i], colCfg);
  124. }
  125. }else{
  126. // The container has field item configs, so we have to generate the column
  127. // panels first then move the items into the columns as needed.
  128. var numCols, cols = [];
  129. if(typeof this.columns == 'string'){ // 'auto' so create a col per item
  130. this.columns = this.items.length;
  131. }
  132. if(!Ext.isArray(this.columns)){
  133. var cs = [];
  134. for(var i=0; i<this.columns; i++){
  135. cs.push((100/this.columns)*.01); // distribute by even %
  136. }
  137. this.columns = cs;
  138. }
  139. numCols = this.columns.length;
  140. // Generate the column configs with the correct width setting
  141. for(var i=0; i<numCols; i++){
  142. var cc = Ext.apply({items:[]}, colCfg);
  143. cc[this.columns[i] <= 1 ? 'columnWidth' : 'width'] = this.columns[i];
  144. if(this.defaults){
  145. cc.defaults = Ext.apply(cc.defaults || {}, this.defaults);
  146. }
  147. cols.push(cc);
  148. };
  149. // Distribute the original items into the columns
  150. if(this.vertical){
  151. var rows = Math.ceil(this.items.length / numCols), ri = 0;
  152. for(var i=0, len=this.items.length; i<len; i++){
  153. if(i>0 && i%rows==0){
  154. ri++;
  155. }
  156. if(this.items[i].fieldLabel){
  157. this.items[i].hideLabel = false;
  158. }
  159. cols[ri].items.push(this.items[i]);
  160. };
  161. }else{
  162. for(var i=0, len=this.items.length; i<len; i++){
  163. var ci = i % numCols;
  164. if(this.items[i].fieldLabel){
  165. this.items[i].hideLabel = false;
  166. }
  167. cols[ci].items.push(this.items[i]);
  168. };
  169. }
  170. Ext.apply(panelCfg, {
  171. layoutConfig: {columns: numCols},
  172. items: cols
  173. });
  174. }
  175. this.panel = new Ext.Container(panelCfg);
  176. this.panel.ownerCt = this;
  177. this.el = this.panel.getEl();
  178. if(this.forId && this.itemCls){
  179. var l = this.el.up(this.itemCls).child('label', true);
  180. if(l){
  181. l.setAttribute('htmlFor', this.forId);
  182. }
  183. }
  184. var fields = this.panel.findBy(function(c){
  185. return c.isFormField;
  186. }, this);
  187. this.items = new Ext.util.MixedCollection();
  188. this.items.addAll(fields);
  189. }
  190. Ext.form.CheckboxGroup.superclass.onRender.call(this, ct, position);
  191. },
  192. initValue : function(){
  193. if(this.value){
  194. this.setValue.apply(this, this.buffered ? this.value : [this.value]);
  195. delete this.buffered;
  196. delete this.value;
  197. }
  198. },
  199. afterRender : function(){
  200. Ext.form.CheckboxGroup.superclass.afterRender.call(this);
  201. this.eachItem(function(item){
  202. item.on('check', this.fireChecked, this);
  203. item.inGroup = true;
  204. });
  205. },
  206. // private
  207. doLayout: function(){
  208. //ugly method required to layout hidden items
  209. if(this.rendered){
  210. this.panel.forceLayout = this.ownerCt.forceLayout;
  211. this.panel.doLayout();
  212. }
  213. },
  214. // private
  215. fireChecked: function(){
  216. var arr = [];
  217. this.eachItem(function(item){
  218. if(item.checked){
  219. arr.push(item);
  220. }
  221. });
  222. this.fireEvent('change', this, arr);
  223. },
  224. <div id="method-Ext.form.CheckboxGroup-getErrors"></div>/**
  225. * Runs CheckboxGroup's validations and returns an array of any errors. The only error by default
  226. * is if allowBlank is set to true and no items are checked.
  227. * @return {Array} Array of all validation errors
  228. */
  229. getErrors: function() {
  230. var errors = Ext.form.CheckboxGroup.superclass.getErrors.apply(this, arguments);
  231. if (!this.allowBlank) {
  232. var blank = true;
  233. this.eachItem(function(f){
  234. if (f.checked) {
  235. return (blank = false);
  236. }
  237. });
  238. if (blank) errors.push(this.blankText);
  239. }
  240. return errors;
  241. },
  242. // private
  243. isDirty: function(){
  244. //override the behaviour to check sub items.
  245. if (this.disabled || !this.rendered) {
  246. return false;
  247. }
  248. var dirty = false;
  249. this.eachItem(function(item){
  250. if(item.isDirty()){
  251. dirty = true;
  252. return false;
  253. }
  254. });
  255. return dirty;
  256. },
  257. // private
  258. setReadOnly : function(readOnly){
  259. if(this.rendered){
  260. this.eachItem(function(item){
  261. item.setReadOnly(readOnly);
  262. });
  263. }
  264. this.readOnly = readOnly;
  265. },
  266. // private
  267. onDisable : function(){
  268. this.eachItem(function(item){
  269. item.disable();
  270. });
  271. },
  272. // private
  273. onEnable : function(){
  274. this.eachItem(function(item){
  275. item.enable();
  276. });
  277. },
  278. // private
  279. onResize : function(w, h){
  280. this.panel.setSize(w, h);
  281. this.panel.doLayout();
  282. },
  283. // inherit docs from Field
  284. reset : function(){
  285. if (this.originalValue) {
  286. // Clear all items
  287. this.eachItem(function(c){
  288. if(c.setValue){
  289. c.setValue(false);
  290. c.originalValue = c.getValue();
  291. }
  292. });
  293. // Set items stored in originalValue, ugly - set a flag to reset the originalValue
  294. // during the horrible onSetValue. This will allow trackResetOnLoad to function.
  295. this.resetOriginal = true;
  296. this.setValue(this.originalValue);
  297. delete this.resetOriginal;
  298. } else {
  299. this.eachItem(function(c){
  300. if(c.reset){
  301. c.reset();
  302. }
  303. });
  304. }
  305. // Defer the clearInvalid so if BaseForm's collection is being iterated it will be called AFTER it is complete.
  306. // Important because reset is being called on both the group and the individual items.
  307. (function() {
  308. this.clearInvalid();
  309. }).defer(50, this);
  310. },
  311. <div id="method-Ext.form.CheckboxGroup-setValue"></div>/**
  312. * {@link Ext.form.Checkbox#setValue Set the value(s)} of an item or items
  313. * in the group. Examples illustrating how this method may be called:
  314. * <pre><code>
  315. // call with name and value
  316. myCheckboxGroup.setValue('cb-col-1', true);
  317. // call with an array of boolean values
  318. myCheckboxGroup.setValue([true, false, false]);
  319. // call with an object literal specifying item:value pairs
  320. myCheckboxGroup.setValue({
  321. 'cb-col-2': false,
  322. 'cb-col-3': true
  323. });
  324. // use comma separated string to set items with name to true (checked)
  325. myCheckboxGroup.setValue('cb-col-1,cb-col-3');
  326. * </code></pre>
  327. * See {@link Ext.form.Checkbox#setValue} for additional information.
  328. * @param {Mixed} id The checkbox to check, or as described by example shown.
  329. * @param {Boolean} value (optional) The value to set the item.
  330. * @return {Ext.form.CheckboxGroup} this
  331. */
  332. setValue: function(){
  333. if(this.rendered){
  334. this.onSetValue.apply(this, arguments);
  335. }else{
  336. this.buffered = true;
  337. this.value = arguments;
  338. }
  339. return this;
  340. },
  341. /**
  342. * @private
  343. * Sets the values of one or more of the items within the CheckboxGroup
  344. * @param {String|Array|Object} id Can take multiple forms. Can be optionally:
  345. * <ul>
  346. * <li>An ID string to be used with a second argument</li>
  347. * <li>An array of the form ['some', 'list', 'of', 'ids', 'to', 'mark', 'checked']</li>
  348. * <li>An array in the form [true, true, false, true, false] etc, where each item relates to the check status of
  349. * the checkbox at the same index</li>
  350. * <li>An object containing ids of the checkboxes as keys and check values as properties</li>
  351. * </ul>
  352. * @param {String} value The value to set the field to if the first argument was a string
  353. */
  354. onSetValue: function(id, value){
  355. if(arguments.length == 1){
  356. if(Ext.isArray(id)){
  357. Ext.each(id, function(val, idx){
  358. if (Ext.isObject(val) && val.setValue){ // array of checkbox components to be checked
  359. val.setValue(true);
  360. if (this.resetOriginal === true) {
  361. val.originalValue = val.getValue();
  362. }
  363. } else { // an array of boolean values
  364. var item = this.items.itemAt(idx);
  365. if(item){
  366. item.setValue(val);
  367. }
  368. }
  369. }, this);
  370. }else if(Ext.isObject(id)){
  371. // set of name/value pairs
  372. for(var i in id){
  373. var f = this.getBox(i);
  374. if(f){
  375. f.setValue(id[i]);
  376. }
  377. }
  378. }else{
  379. this.setValueForItem(id);
  380. }
  381. }else{
  382. var f = this.getBox(id);
  383. if(f){
  384. f.setValue(value);
  385. }
  386. }
  387. },
  388. // private
  389. beforeDestroy: function(){
  390. Ext.destroy(this.panel);
  391. if (!this.rendered) {
  392. Ext.destroy(this.items);
  393. }
  394. Ext.form.CheckboxGroup.superclass.beforeDestroy.call(this);
  395. },
  396. setValueForItem : function(val){
  397. val = String(val).split(',');
  398. this.eachItem(function(item){
  399. if(val.indexOf(item.inputValue)> -1){
  400. item.setValue(true);
  401. }
  402. });
  403. },
  404. // private
  405. getBox : function(id){
  406. var box = null;
  407. this.eachItem(function(f){
  408. if(id == f || f.dataIndex == id || f.id == id || f.getName() == id){
  409. box = f;
  410. return false;
  411. }
  412. });
  413. return box;
  414. },
  415. <div id="method-Ext.form.CheckboxGroup-getValue"></div>/**
  416. * Gets an array of the selected {@link Ext.form.Checkbox} in the group.
  417. * @return {Array} An array of the selected checkboxes.
  418. */
  419. getValue : function(){
  420. var out = [];
  421. this.eachItem(function(item){
  422. if(item.checked){
  423. out.push(item);
  424. }
  425. });
  426. return out;
  427. },
  428. /**
  429. * @private
  430. * Convenience function which passes the given function to every item in the composite
  431. * @param {Function} fn The function to call
  432. * @param {Object} scope Optional scope object
  433. */
  434. eachItem: function(fn, scope) {
  435. if(this.items && this.items.each){
  436. this.items.each(fn, scope || this);
  437. }
  438. },
  439. <div id="cfg-Ext.form.CheckboxGroup-name"></div>/**
  440. * @cfg {String} name
  441. * @hide
  442. */
  443. <div id="method-Ext.form.CheckboxGroup-getRawValue"></div>/**
  444. * @method getRawValue
  445. * @hide
  446. */
  447. getRawValue : Ext.emptyFn,
  448. <div id="method-Ext.form.CheckboxGroup-setRawValue"></div>/**
  449. * @method setRawValue
  450. * @hide
  451. */
  452. setRawValue : Ext.emptyFn
  453. });
  454. Ext.reg('checkboxgroup', Ext.form.CheckboxGroup);
  455. </pre>
  456. </body>
  457. </html>