ParamField.js 2.82 KB
Ext.define('amdaPlotComp.plotFunction.ParamField', {
    extend: 'Ext.form.Panel',
    label_number_field: "NUMBERFIELD",
    label_number_field1: "NUMBERFIELD1",

    initComponent: function () {
        const items_params = [];
        const minSampling = "Min Sampling (s)";
        const minValue = 0;
        const labelWitdh = 120;
        const width = 30;

        for (p in this.params) {
            const param = this.params[p];
            const fieldSet = {
                xtype: 'fieldset',
                name: 'FIELDSET' + param.id,
                title: param.id,
                collapsible: false,
                layout: {
                    type: 'vbox',
                    align: 'stretch',
                },
                items: [
                    {
                        xtype: 'numberfield',
                        name: this.label_number_field + param.id,
                        labelWidth: labelWitdh,
                        width: width,
                        value: param.MinSampling,
                        minValue: minValue,
                        disabled: true,
                        fieldLabel: minSampling
                    },
                    {
                        xtype: 'numberfield',
                        name: this.label_number_field1 + param.id,
                        labelWidth: labelWitdh,
                        width: width,
                        value: 0,
                        minValue: minValue,
                        fieldLabel: "Nb Points"
                    }
                ]
            };

            items_params.push(fieldSet);
        }

        const tabParams = Ext.create('Ext.tab.Panel', {
            layout: 'fit',
            plain: true,
            bodyStyle: 'background: none',
            items: items_params
        });

        const config =
        {
            title: 'Parameters Sampling',
            layout: 'fit',
            bodyStyle: { background: '#dfe8f6' },
            items: [tabParams]
        };

        Ext.apply(this, config);
        this.callParent(arguments);
    },

    getNbPoints: function (parentForm) {
        const list = [];
        for (p in this.params) {
            let param = this.params[p];
            const ui_item = parentForm.findField(this.label_number_field1 + param.id);
            if (ui_item !== undefined && ui_item !== null) {
                param["nb_points"] = ui_item.getValue();
                console.log(param);
            }
        }
    },

    setNbPoints: function (parentForm, startTime, stopTime) {
        for (p in this.params) {
            let param = this.params[p];
            const nb_points = (stopTime - startTime) / param.MinSampling;
            const ui_item = parentForm.findField(this.label_number_field1 + param.id);
            ui_item.setValue(parseInt(nb_points));
        }
    }
});