partkeepr

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

PartParameterValueEditor.js (5885B)


      1 Ext.define("PartKeepr.PartParameterValueEditor", {
      2     extend: "Ext.form.Panel",
      3 
      4     layout: {
      5         type: 'vbox',
      6         pack: 'start',
      7         align: 'stretch'
      8 
      9     },
     10     items: [
     11         {
     12             fieldLabel: i18n("Parameter Name"),
     13             name: 'name',
     14             itemId: 'partParameter',
     15             xtype: 'PartParameterComboBox'
     16         },
     17         {
     18             fieldLabel: i18n("Description"),
     19             name: 'description',
     20             itemId: 'description',
     21             xtype: 'textarea'
     22         },
     23         {
     24             xtype: 'UnitComboBox',
     25             fieldLabel: i18n("Unit"),
     26             name: 'unit',
     27             itemId: "unit",
     28             returnObject: true
     29         },
     30         {
     31             fieldLabel: i18n("Value Type"),
     32             xtype: 'radiogroup',
     33             name: 'valueType',
     34             itemId: 'valueType',
     35             items: [
     36                 {
     37                     boxLabel: i18n("Numeric"),
     38                     inputValue: "numeric"
     39                 }, {
     40                     boxLabel: i18n("Text"),
     41                     inputValue: "string"
     42                 }
     43             ]
     44         },
     45         {
     46             xtype: 'container',
     47             layout: 'card',
     48             itemId: 'typeFields',
     49             items: [
     50                 {
     51                     xtype: 'fieldcontainer',
     52                     itemId: "numeric",
     53                     layout: 'vbox',
     54                     items: [
     55                         {
     56                             fieldLabel: i18n("Min Value"),
     57                             name: 'minValue',
     58                             siFieldName: 'minSiPrefix',
     59                             siUnitItemId: 'minSiPrefix',
     60                             xtype: 'SiUnitField',
     61                             width: 200
     62                         },
     63                         {
     64                             xtype: 'SiUnitField',
     65                             itemId: "singleValue",
     66                             fieldLabel: i18n("Nominal Value"),
     67                             siUnitItemId: 'siPrefix',
     68                             name: 'value',
     69                             siFieldName: 'siPrefix',
     70                             width: 200
     71                         },
     72                         {
     73                             fieldLabel: i18n("Max Value"),
     74                             name: 'maxValue',
     75                             siFieldName: 'maxSiPrefix',
     76                             siUnitItemId: 'maxSiPrefix',
     77                             xtype: 'SiUnitField',
     78                             width: 200
     79                         }
     80                     ]
     81                 },
     82                 {
     83                     fieldLabel: i18n("Value"),
     84                     itemId: 'text',
     85                     name: 'stringValue',
     86                     xtype: 'textfield'
     87                 }
     88             ]
     89         },
     90     ],
     91 
     92     bbar: [
     93         {
     94             xtype: 'button',
     95             itemId: "save",
     96             text: i18n("Save")
     97         }
     98     ],
     99     initComponent: function ()
    100     {
    101         this.callParent(arguments);
    102 
    103         this.unitFilter = Ext.create("PartKeepr.util.Filter", {
    104            property: "@id",
    105             operator: "in",
    106             value: []
    107         });
    108         this.down("#valueType").on("change", this.onTypeChange, this);
    109         this.down("#partParameter").on("select", this.onPartParameterSelect, this);
    110         this.down("#save").on("click", this.onSave, this);
    111         this.down("#unit").on("change", this.onUnitChange, this);
    112     },
    113     onPartParameterSelect: function (combo, record) {
    114 
    115         var description = record.get("description");
    116         if (description !== null) {
    117             this.down("#description").setRawValue(description);
    118         }
    119 
    120         if (record.get("unitName") !== null) {
    121             var unit = this.down("#unit").getStore().findRecord("name", record.get("unitName"), 0, false, true, true);
    122 
    123             if (unit instanceof PartKeepr.UnitBundle.Entity.Unit) {
    124                 this.down("#unit").select(unit);
    125                 this.down("#valueType").setValue({valueType: "numeric"});
    126             }
    127 
    128         } else {
    129             this.down("#unit").select(null);
    130         }
    131 
    132         var valueType = record.get("valueType");
    133         if (valueType == "numeric") {
    134             this.down("#valueType").setValue({valueType: "numeric"});
    135 
    136         } else if (valueType == "string") {
    137             this.down("#valueType").setValue({valueType: "string"});
    138         }
    139 
    140     },
    141     onUnitChange: function (combo, newValue) {
    142         var prefixes,j, unitFilter = [];
    143 
    144         this.down("#siPrefix").getStore().removeFilter(this.unitFilter);
    145         this.down("#minSiPrefix").getStore().removeFilter(this.unitFilter);
    146         this.down("#maxSiPrefix").getStore().removeFilter(this.unitFilter);
    147 
    148         if (newValue instanceof PartKeepr.UnitBundle.Entity.Unit) {
    149             prefixes = newValue.prefixes().getData();
    150 
    151             for (j=0;j<prefixes.getCount();j++) {
    152                 unitFilter.push(prefixes.getAt(j).get("@id"));
    153             }
    154         }
    155 
    156         this.unitFilter.setValue(unitFilter);
    157         this.down("#siPrefix").getStore().addFilter(this.unitFilter);
    158         this.down("#minSiPrefix").getStore().addFilter(this.unitFilter);
    159         this.down("#maxSiPrefix").getStore().addFilter(this.unitFilter);
    160     },
    161     loadRecord: function (record) {
    162         this.callParent(arguments);
    163 
    164         this.down("#valueType").setValue({ valueType: record.get("valueType")});
    165     },
    166     onSave: function () {
    167         this.updateRecord();
    168         this.fireEvent("save");
    169     },
    170     onTypeChange: function (field, newValue)
    171     {
    172         switch (newValue.valueType) {
    173             case "string":
    174                 this.down("#typeFields").setActiveItem(this.down("#text"));
    175                 break;
    176             case "numeric":
    177                 this.down("#typeFields").setActiveItem(this.down("#numeric"));
    178                 break;
    179 
    180         }
    181     }
    182 });