partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

SiUnitField.js (1521B)


      1 /**
      2  * This class represents a field which can handle a number (value) bound to a specific SI prefix.
      3  *
      4  * Internally, we use an object as value. Example:
      5  *
      6  * {
      7  *     value: 10 		// The base value, in our case 10
      8  *     symbol: "n" 		// The symbol for display
      9  *     power: -9    	// The power
     10  *     siprefix_id: 5	// The ID of the siprefix record  
     11  * }
     12  *
     13  */
     14 Ext.define("PartKeepr.SiUnitField", {
     15     extend: "Ext.form.FieldContainer",
     16     alias: 'widget.SiUnitField',
     17 
     18     xtype: 'SiUnitField',
     19 
     20     layout: {
     21         type: 'hbox'
     22     },
     23     initComponent: function ()
     24     {
     25         this.numberField = Ext.create({
     26                 xtype: 'numberfield',
     27                 hideTrigger: true,
     28                 emptyText: i18n("Value"),
     29                 decimalPrecision: 20,
     30                 name: this.name,
     31                 flex: 1
     32             });
     33 
     34         this.items = [
     35             this.numberField, {
     36                 xtype: 'SiUnitCombo',
     37                 itemId: this.siUnitItemId,
     38                 returnObject: true,
     39                 caseSensitive: true,
     40                 name: this.siFieldName,
     41                 width: 40
     42             }
     43         ];
     44 
     45         this.callParent(arguments);
     46         this.down("#"+this.siUnitItemId).setStore(Ext.create("Ext.data.Store",
     47             {
     48                 model: 'PartKeepr.SiPrefixBundle.Entity.SiPrefix',
     49                 pageSize: 99999999,
     50                 autoLoad: true
     51             }));
     52     },
     53     getValue: function () {
     54         return this.numberField.getValue();
     55     }
     56 });