dustin@757: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
dustin@757:  * Software engineering by Intevation GmbH
dustin@757:  *
dustin@757:  * This file is Free Software under the GNU GPL (v>=3)
dustin@757:  * and comes with ABSOLUTELY NO WARRANTY! Check out
dustin@757:  * the documentation coming with IMIS-Labordaten-Application for details.
dustin@757:  */
dustin@757: 
dustin@894: /**
dustin@894:  * Form to edit a Messprogramm
dustin@757:  */
dustin@757: Ext.define('Lada.view.form.Messprogramm', {
dustin@757:     extend: 'Ext.form.Panel',
dustin@757:     alias: 'widget.messprogrammform',
dustin@757:     requires: [
dustin@757:         'Lada.view.widget.Datenbasis',
mstanko@1086:         'Lada.view.widget.base.CheckBox',
dustin@757:         'Lada.view.widget.Messstelle',
dustin@757:         'Lada.view.widget.Netzbetreiber',
dustin@757:         'Lada.view.widget.Betriebsart',
dustin@757:         'Lada.view.widget.Probenart',
ehuber@1258:         'Lada.view.widget.MessprogrammLand',
dustin@757:         'Lada.view.widget.Umwelt',
dustin@757:         'Lada.view.widget.base.TextField',
tom@1168:         'Lada.view.widget.base.NumberField',
dustin@757:         'Lada.view.widget.base.FieldSet',
dustin@757:         'Lada.model.Messprogramm',
dustin@757:         'Lada.model.MmtMessprogramm',
dustin@757:         'Lada.view.widget.Probenintervall',
dustin@797:         'Lada.view.widget.Location',
dustin@757:         'Lada.view.widget.ProbenintervallSlider',
tom@1199:         'Lada.view.widget.DayOfYear'
dustin@757:     ],
dustin@757: 
dustin@757:     model: 'Lada.model.Messprogramm',
dustin@757:     minWidth: 650,
dustin@757:     margin: 5,
dustin@757:     border: 0,
dustin@757: 
dustin@757:     recordId: null,
dustin@757: 
dustin@757:     trackResetOnLoad: true,
dustin@757: 
dustin@757:     initComponent: function() {
dustin@757:         var me = this;
dustin@757:         var i18n = Lada.getApplication().bundle;
dustin@757:         this.items = [{
dustin@757:             xtype: 'fieldset',
dustin@757:             title: i18n.getMsg('messprogramm.form.fieldset.title'),
dustin@757:             items: [{
dustin@757:                 border: 0,
dustin@757:                 margin: '0, 0, 10, 0',
dustin@757:                 dockedItems: [{
dustin@757:                     xtype: 'toolbar',
dustin@757:                     dock: 'bottom',
dustin@757:                     border: '0, 1, 1, 1',
dustin@757:                     style: {
dustin@757:                         borderBottom: '1px solid #b5b8c8 !important',
dustin@757:                         borderLeft: '1px solid #b5b8c8 !important',
dustin@757:                         borderRight: '1px solid #b5b8c8 !important'
dustin@757:                     },
dustin@757:                     items: ['->', {
dustin@757:                         text: i18n.getMsg('save'),
dustin@757:                         qtip: i18n.getMsg('save.qtip'),
dustin@757:                         icon: 'resources/img/dialog-ok-apply.png',
dustin@757:                         action: 'save',
dustin@757:                         disabled: true
dustin@757:                     }, {
dustin@757:                         text: i18n.getMsg('discard'),
dustin@757:                         qtip: i18n.getMsg('discard.qtip'),
dustin@757:                         icon: 'resources/img/dialog-cancel.png',
dustin@757:                         action: 'discard',
dustin@757:                         disabled: true
dustin@757:                     }]
dustin@757:                 }],
dustin@757:                 items: [{
dustin@757:                         border: 0,
dustin@757:                         minWidth: 290,
dustin@757:                         layout: {
dustin@757:                             type: 'vbox',
dustin@757:                             align: 'stretch'
dustin@757:                         },
dustin@757:                         margin: '0, 10, 0, 0',
dustin@757:                         items: [{
mstanko@1086:                             layout: {
mstanko@1086:                                 type: 'hbox',
mstanko@1086:                                 align: 'stretch'
mstanko@1086:                             },
mstanko@1086:                             border: 0,
mstanko@1086:                             items: [{
mstanko@1086:                                 xtype: 'messstellelabor',
mstanko@1086:                                 name: 'mstlabor',
mstanko@1086:                                 fieldLabel: 'Messstelle/Labor',
mstanko@1086:                                 margin: '0, 5, 5, 5',
mstanko@1086:                                 width: '35%',
mstanko@1086:                                 labelWidth: 95,
mstanko@1086:                                 allowBlank: false,
mstanko@1086:                                 editable: true,
mstanko@1086:                                 listeners: {
mstanko@1086:                                     select: {
mstanko@1086:                                         fn: function(combo, newValue) {
mstanko@1086:                                             var mst = newValue[0].get('messStelle');
mstanko@1086:                                             var labor = newValue[0].get('laborMst');
mstanko@1086:                                             combo.up('fieldset').down('messstelle[name=mstId]').setValue(mst);
mstanko@1086:                                             combo.up('fieldset').down('messstelle[name=laborMstId]').setValue(labor);
mstanko@1086:                                         }
raimund@1067:                                     }
raimund@1067:                                 }
mstanko@1086:                             }, {
mstanko@1086:                                 xtype: 'messstelle',
mstanko@1086:                                 name: 'mstId',
mstanko@1086:                                 fieldLabel: 'Messstelle/Labor',
mstanko@1086:                                 margin: '0, 5, 5, 5',
mstanko@1086:                                 width: '35%',
mstanko@1086:                                 labelWidth: 95,
mstanko@1086:                                 allowBlank: false,
mstanko@1086:                                 editable: true,
tom@1212:                                 hidden: true,
tom@1212:                                 listeners: {
tom@1212:                                     validitychange: me.mstLaborValidity
tom@1212:                                 }
mstanko@1086:                             }, {
mstanko@1086:                                 xtype: 'messstelle',
mstanko@1086:                                 name: 'laborMstId',
mstanko@1086:                                 fieldLabel: 'Messstelle/Labor',
mstanko@1086:                                 margin: '0, 5, 5, 5',
mstanko@1086:                                 width: '35%',
mstanko@1086:                                 labelWidth: 95,
mstanko@1086:                                 allowBlank: false,
mstanko@1086:                                 editable: true,
tom@1212:                                 hidden: true,
tom@1212:                                 listeners: {
tom@1212:                                     validitychange: me.mstLaborValidity
tom@1212:                                 }
mstanko@1086:                             }, {
mstanko@1086:                                 xtype: 'netzbetreiber',
mstanko@1086:                                 editable: false,
mstanko@1086:                                 readOnly: true,
tom@1235:                                 isFormField: false,
tom@1235:                                 submitValue: false,
mstanko@1086:                                 fieldLabel: i18n.getMsg('netzbetreiberId'),
mstanko@1086:                                 margin : '0, 5, 5, 5',
raimund@1248:                                 width : '45%',
tom@1235:                                 labelWidth: 80
dustin@797:                             }, {
dustin@757:                                 xtype: 'datenbasis',
dustin@757:                                 editable: false,
tom@1180:                                 allowBlank: false,
dustin@757:                                 name: 'datenbasisId',
dustin@757:                                 fieldLabel: i18n.getMsg('datenbasisId'),
mstanko@1086:                                 margin : '0, 5, 5, 5',
mstanko@1086:                                 width : '20%',
mstanko@1086:                                 labelWidth: 65
mstanko@1086:                             }]
mstanko@1086:                         }, {
mstanko@1086:                             layout: {
mstanko@1086:                                 type: 'hbox',
mstanko@1086:                                 align: 'stretch'
mstanko@1086:                             },
mstanko@1086:                             border: 0,
mstanko@1086:                             items: [{
raimund@1248:                                 xtype: 'probenart',
raimund@1248:                                 editable: false,
raimund@1248:                                 name: 'probenartId',
raimund@1248:                                 fieldLabel: i18n.getMsg('probenartId'),
mstanko@1086:                                 margin: '0, 5, 5, 5',
mstanko@1086:                                 width: '35%',
mstanko@1086:                                 labelWidth: 95,
raimund@1248:                                 allowBlank: false
dustin@757:                             }, {
dustin@757:                                 xtype: 'betriebsart',
dustin@757:                                 name: 'baId',
ehuber@1108:                                 margin: '0, 5, 5, 5',
dustin@757:                                 fieldLabel: i18n.getMsg('baId'),
ehuber@1108:                                 //anchor: '100%',
raimund@1248:                                 width: '45%',
ehuber@1108:                                 labelWidth: 80
dustin@757:                             }, {
raimund@1248:                                 xtype: 'chkbox',
raimund@1248:                                 name: 'test',
raimund@1248:                                 fieldLabel: i18n.getMsg('test'),
raimund@1248:                                 anchor: '100%',
raimund@1248:                                 margin : '0, 5, 5, 5',
raimund@1248:                                 width : '20%',
raimund@1248:                                 labelWidth: 30,
dustin@757:                                 allowBlank: false
mstanko@1086:                             }]
raimund@1252:                         }, {
raimund@1252:                             xtype: 'tfield',
raimund@1252:                             name: 'kommentar',
raimund@1252:                             fieldLabel: i18n.getMsg('kommentar'),
raimund@1252:                             width: '100%',
raimund@1252:                             margin: '0, 5, 5, 5',
raimund@1252:                             labelWidth: 95
mstanko@1086:                         }]
mstanko@1086:                 }, {
mstanko@1086:                     // Zeit
mstanko@1086:                     xtype: 'fieldset',
mstanko@1086:                     title: i18n.getMsg('probenintervall'),
mstanko@1086:                     layout: {
mstanko@1086:                         type: 'vbox',
mstanko@1086:                         align: 'stretch'
mstanko@1086:                     },
mstanko@1086:                     items: [{
mstanko@1086:                         xtype: 'fset',
mstanko@1086:                         name: 'probenIntervallFieldset',
mstanko@1086:                         layout: {
mstanko@1086:                             type: 'hbox',
mstanko@1086:                             align: 'stretch'
mstanko@1086:                         },
mstanko@1086:                         border: 0,
mstanko@1086:                         margin: '0, 0, 0, 0',
mstanko@1086:                         items: [{
mstanko@1086:                             xtype: 'probenintervall',
tom@1180:                             allowBlank: false,
mstanko@1086:                             fieldLabel: i18n.getMsg('probenintervall'),
mstanko@1086:                             margin: '0, 10, 5, 5',
mstanko@1086:                             labelWidth: 50,
mstanko@1086:                             width: '40%',
mstanko@1086:                             name: 'probenintervall'
mstanko@1086:                         }, {
tom@1168:                             xtype: 'numfield',
tom@1169:                             allowDecimals: false,
tom@1180:                             allowBlank: false,
mstanko@1086:                             fieldLabel: i18n.getMsg('teilintervallVon'),
mstanko@1086:                             margin: '0, 10, 5, 10',
mstanko@1086:                             labelWidth: 90,
mstanko@1086:                             width: '28%',
mstanko@1086:                             name: 'teilintervallVon',
mstanko@1086:                             period: 'start'
mstanko@1086:                         }, {
tom@1168:                             xtype: 'numfield',
tom@1169:                             allowDecimals: false,
tom@1180:                             allowBlank: false,
mstanko@1086:                             fieldLabel: i18n.getMsg('teilintervallBis'),
mstanko@1086:                             margin: '0, 15, 5, 5',
mstanko@1086:                             labelWidth: 18,
ehuber@1108:                             width: '15%',
mstanko@1086:                             name: 'teilintervallBis',
mstanko@1086:                             period: 'end'
mstanko@1086:                         }, {
tom@1168:                             xtype: 'numfield',
tom@1169:                             allowDecimals: false,
mstanko@1086:                             margin: '0, 10, 5, 5',
mstanko@1086:                             fieldLabel: i18n.getMsg('offset'),
mstanko@1086:                             labelWidth: 45,
ehuber@1108:                             width: '17%',
mstanko@1086:                             name: 'intervallOffset'
mstanko@1086:                         }]
mstanko@1086:                     }, {
mstanko@1086:                         xtype: 'probenintervallslider',
mstanko@1086: //                        fieldLabel: i18n.getMsg('intervall'),
mstanko@1086: //                        labelWidth: 70,
mstanko@1086:                         pack: 'center',
mstanko@1086:                         width: '70%',
mstanko@1086:                         margin: '0, 40, 10, 40',
mstanko@1086:                         values: [0, 0]
mstanko@1086:                         //this will be overridden
mstanko@1086:                         // by setRecord
mstanko@1086:                     }, {
mstanko@1086:                         xtype: 'fset',
mstanko@1086:                         name: 'gueltigPeriodFieldset',
mstanko@1086:                         layout: {
mstanko@1086:                             type: 'hbox',
mstanko@1086:                             align: 'stretch'
mstanko@1086:                         },
mstanko@1086:                         border: 0,
mstanko@1086:                         items: [{
tom@1199:                             xtype: 'dayofyear',
tom@1180:                             allowBlank: false,
mstanko@1086:                             fieldLabel: i18n.getMsg('gueltigVon'),
tom@1199:                             width: '50%',
mstanko@1086:                             labelWidth: 90,
mstanko@1086:                             name: 'gueltigVon',
tom@1199:                             border: false
mstanko@1086:                         }, {
tom@1199:                             xtype: 'dayofyear',
tom@1180:                             allowBlank: false,
mstanko@1086:                             fieldLabel: i18n.getMsg('gueltigBis'),
tom@1199:                             width: '50%',
mstanko@1086:                             labelWidth: 40,
mstanko@1086:                             name: 'gueltigBis',
tom@1199:                             border: false
dustin@757:                         }]
dustin@757:                     }]
dustin@757:                 }, {
dustin@757:                     // Medium
dustin@757:                     xtype: 'fieldset',
dustin@757:                     title: i18n.getMsg('medium'),
mstanko@1086:                     width: '100%',
dustin@757:                     items: [{
dustin@757:                         border: 0,
dustin@757:                         layout: {
dustin@757:                             type: 'vbox',
dustin@757:                             align: 'stretch'
dustin@757:                         },
dustin@757:                         width: '100%',
dustin@757:                         items: [{
dustin@757:                             xtype: 'umwelt',
dustin@757:                             name: 'umwId',
dustin@757:                             fieldLabel: i18n.getMsg('umwId'),
dustin@757:                             labelWidth: 125,
dustin@757:                             editable: true,
dustin@757:                             listeners: {
dustin@757:                                 dirtychange: {
dustin@757:                                     fn: this.updateOnChange,
dustin@757:                                     scope: me
dustin@757:                                 }
dustin@757:                             }
dustin@757:                         }, {
mstanko@1086:                             border: 0,
mstanko@1086:                             layout: {
mstanko@1086:                                 type: 'hbox',
mstanko@1086:                                 align: 'stretch'
mstanko@1086:                             },
mstanko@1086:                             width: '100%',
mstanko@1086:                             items: [{
mstanko@1086:                                 xtype: 'textfield',
mstanko@1086:                                 maxLength: 38,
mstanko@1086:                                 enforceMaxLength: true,
mstanko@1086:                                 name: 'mediaDesk',
mstanko@1086:                                 width: '60%',
mstanko@1086:                                 labelWidth: 125,
mstanko@1086:                                 fieldLabel: i18n.getMsg('mediaDesk'),
mstanko@1086:                                 editable: false,
mstanko@1086:                                 readOnly: true,
mstanko@1086:                                 listeners: {
mstanko@1086:                                     dirtychange: {
mstanko@1086:                                         fn: this.updateOnChange,
mstanko@1086:                                         scope: me
mstanko@1086:                                     }
mstanko@1086:                                 }
mstanko@1086:                             }, {
mstanko@1086:                                 xtype: 'textfield',
mstanko@1086:                                 name: 'media',
mstanko@1086:                                 margin: '0, 10, 5, 10',
mstanko@1086:                                 width: '40%',
mstanko@1086:                                 enforceMaxLength: true,
mstanko@1086:                                 editable: false,
mstanko@1086:                                 readOnly: true
mstanko@1086:                             }]
mstanko@1086:                         }, {
dustin@757:                             xtype: 'fieldset',
dustin@757:                             title: i18n.getMsg('deskDetails'),
dustin@757:                             collapsible: true,
dustin@757:                             collapsed: true,
dustin@757:                             defaultType: 'textfield',
dustin@757:                             layout: {
mstanko@1086:                                 type: 'vbox',
mstanko@1086:                                 align: 'stretch'
dustin@757:                             },
dustin@757:                             items: this.buildDescriptors(),
dustin@757:                             listeners: {
dustin@757:                                 dirtychange: {
dustin@757:                                     fn: this.updateOnChange,
dustin@757:                                     scope: me
dustin@757:                                 }
dustin@757:                             }
dustin@757:                         }]
dustin@757:                     }]
dustin@757:                 }, {
mstanko@1116:                     xtype: 'probenehmer',
mstanko@1086:                     name: 'probeNehmerId',
mstanko@1086:                     fieldLabel: i18n.getMsg('probeNehmerId'),
mstanko@1116:                     margin: '0, 5, 5, 5',
ehuber@1258:                     //width: '100%',
mstanko@1116:                     minValue: 0,
mstanko@1086:                     anchor: '100%',
mstanko@1116:                     labelWidth: 95
mstanko@1086:                 }, {
ehuber@1258:                     xtype: 'messprogrammland',
ehuber@1258:                     name: 'mplId',
ehuber@1258:                     fieldLabel: 'Messprogramm-Land',
ehuber@1258:                     margin: '0, 5, 5, 5',
ehuber@1258:                     //width: '100%',
ehuber@1258:                     anchor: '100%',
ehuber@1258:                     labelWidth: 115
ehuber@1258:                 }, {
mstanko@1086:                     xtype: 'textarea',
mstanko@1086:                     name: 'probeKommentar',
mstanko@1086:                     labelAlign: 'top',
mstanko@1086:                     fieldLabel: i18n.getMsg('probeKommentar'),
mstanko@1086:                     width: '100%',
mstanko@1086:                     labelwidth: 135,
mstanko@1086:                     anchor: '100%'
dustin@757:                 }]
dustin@757:             }]
dustin@757:         }];
dustin@757:         this.callParent(arguments);
dustin@757:     },
dustin@757: 
dustin@757:     populateIntervall: function(record, intervall) {
dustin@757:         //intervall is an identifier of a intervall
dustin@757:         // for instance H, M, J, ...
dustin@757:         // Initialize the probenintervallslider
dustin@757:         var s = this.down('probenintervallslider');
dustin@774:         var i = this.getForm().findField('intervallOffset');
dustin@757:         var v = this.getForm().findField('teilintervallVon');
dustin@757:         var b = this.getForm().findField('teilintervallBis');
dustin@757:         var intervallstore = Ext.data.StoreManager.get('Probenintervall');
dustin@757: 
dustin@757:         var svalUpper = null
dustin@757:         var svalLower = null
dustin@759:         var min = null
dustin@759:         var max = null
dustin@757: 
dustin@757:         if (!intervallstore) {
dustin@757:             intervallstore = Ext.create('Lada.store.Probenintervall');
dustin@757:         }
dustin@757: 
dustin@757:         //It is likely that this method was not
dustin@757:         // called from the controller,
dustin@757:         //and the probenintervall was not changed.
dustin@757:         // Load the records in this case
dustin@759:         if (!intervall && record) {
dustin@757:             intervall = record.get('probenintervall',
dustin@757:                     0, false, false, true);
dustin@757: 
dustin@757:             svalUpper = record.get('teilintervallBis');
dustin@757:             svalLower = record.get('teilintervallVon');
dustin@757:         }
dustin@757: 
tom@1210:         // subintervall is redundant to validity for yearly samples
tom@1210:         if (intervall == 'J') {
tom@1210:             svalUpper = this.getForm().findField('gueltigBis').getValue();
tom@1210:             svalLower = this.getForm().findField('gueltigVon').getValue();
tom@1210:             b.setReadOnly(true);
tom@1210:             v.setReadOnly(true);
tom@1210:             s.setDisabled(true);
tom@1210:         } else {
tom@1210:             b.setReadOnly(false);
tom@1210:             v.setReadOnly(false);
tom@1210:             s.setDisabled(false);
tom@1210:         }
dustin@757: 
dustin@757:         var intrec = intervallstore
dustin@757:             .findRecord('probenintervall',
dustin@757:                 intervall, 0, false, false, true);
dustin@757: 
dustin@759:         if (intrec) { // in cases when a new messprogramm is
mkrambach@1289:         // created and the discard function is used, intrec will be null && edit is allowed
dustin@759:         // consequently the assertion below will fail.
dustin@759:             min = intrec.get('periodstart');
dustin@759:             max = intrec.get('periodend');
dustin@759:         }
dustin@757: 
dustin@757:         if (!svalUpper) {
dustin@757:             svalUpper = max;
dustin@757:         }
dustin@757:         if (!svalLower) {
dustin@757:             svalLower = min;
dustin@757:         }
dustin@757: 
dustin@757:         //Set Teilintervalle
dustin@757:         v.setMinValue(min);
dustin@757:         v.setMaxValue(max);
dustin@757:         b.setMinValue(min);
dustin@757:         b.setMaxValue(max);
dustin@757: 
dustin@757:         //Set Slider
dustin@757:         s.setMinValue(min);
dustin@757:         s.setMaxValue(max);
dustin@757: 
dustin@757:         v.setValue(svalLower);
dustin@757:         b.setValue(svalUpper);
dustin@757: 
dustin@774:         //Set IntervallOffset
dustin@774:         i.setMinValue(0);
dustin@774:         i.setMaxValue(max-1);
dustin@757:     },
dustin@757: 
tom@1212:     /*
tom@1212:      * Set validity of messstellelabor field (not part of the form) based
tom@1212:      * on validitychange event of hidden mstId and laborMstId
tom@1212:      */
tom@1212:     mstLaborValidity: function(field, isValid) {
tom@1212:         if (!isValid) {
tom@1212:             field.up('fieldset').down('messstellelabor')
tom@1212:                 .down('combobox').markInvalid('');
tom@1212:         }
tom@1212:     },
tom@1212: 
raimund@1067:     setRecord: function(messRecord) {
dustin@757:         this.clearMessages();
raimund@1067:         this.getForm().loadRecord(messRecord);
dustin@757:         //Set the intervall numberfields and the slider.
dustin@757:         this.down('probenintervallslider').setValue([
raimund@1067:             messRecord.get('teilintervallVon'),
raimund@1067:             messRecord.get('teilintervallBis')
dustin@757:         ]);
dustin@757: 
dustin@757:         //TODO Set Sliders MinMaxValue
raimund@1067:         this.populateIntervall(messRecord);
dustin@757: 
dustin@757:         this.down('probenintervallslider').on(
dustin@757:             'change',
dustin@757:             Lada.app.getController('Lada.controller.form.Messprogramm')
dustin@757:                 .synchronizeFields
dustin@757:         );
raimund@1067:         var mstStore = Ext.data.StoreManager.get('messstellen');
tom@1235:         var mstId = mstStore.getById(messRecord.get('mstId'));
raimund@1067:         if (!messRecord.get('owner')) {
raimund@1071:             if (!mstId) {
raimund@1071:                 return;
raimund@1071:             }
raimund@1067:             var laborMstId = mstStore.getById(messRecord.get('laborMstId'));
raimund@1067:             if (laborMstId) {
raimund@1067:                 laborMstId = laborMstId.get('messStelle');
raimund@1067:             }
raimund@1067:             else {
raimund@1067:                 laborMstId = '';
raimund@1067:             }
raimund@1067:             var id = this.down('messstellelabor').store.count() + 1;
mstanko@1276:             if ( messRecord.get('mstId') === messRecord.get('laborMstId') ) {
mstanko@1276:                 displayCombi = mstId.get('messStelle');
mstanko@1276:             } else {
mstanko@1276:                 displayCombi = mstId.get('messStelle') + '/' + laborMstId
mstanko@1276: 
mstanko@1276:             }
mstanko@1276:             var newStore = Ext.create('Ext.data.Store', {
mstanko@1276:                 model: 'Lada.model.MessstelleLabor',
mstanko@1276:                 data: [{
mstanko@1276:                     id: id,
mstanko@1276:                     laborMst: messRecord.get('laborMstId'),
mstanko@1276:                     messStelle: messRecord.get('mstId'),
mstanko@1276:                     displayCombi: displayCombi
mstanko@1276:                 }]
mstanko@1276:             });
raimund@1067:             this.down('messstellelabor').down('combobox').store = newStore;
raimund@1067:             this.down('messstellelabor').setValue(id);
raimund@1067:         }
raimund@1067:         else {
raimund@1067:             var mstLaborStore = Ext.data.StoreManager.get('messstellelabor');
raimund@1067:             var items = mstLaborStore.queryBy(function(record) {
raimund@1067:                 if (record.get('messStelle') === messRecord.get('mstId') &&
raimund@1067:                     record.get('laborMst') === messRecord.get('laborMstId')) {
raimund@1067:                     return true;
raimund@1067:                 }
raimund@1067:             });
raimund@1067:             this.down('messstellelabor').setValue(items.getAt(0));
raimund@1067:         }
tom@1235:         this.down('netzbetreiber').setValue(mstId.get('netzbetreiberId'));
raimund@784:     },
dustin@757: 
raimund@784:     setMediaDesk: function(record) {
tom@1234:         var media = record.get('mediaDesk');
tom@1234:         if (media) {
tom@1234:             var mediaParts = media.split(' ');
tom@1234:             this.setMediaSN(0, mediaParts);
tom@1234:         }
raimund@784:     },
raimund@784: 
ehuber@1108:     setMediaSN: function(ndx, media, beschreibung) {
ehuber@1108:         var mediabeschreibung = this.getForm().findField('media');
raimund@784:         if (ndx >= 12) {
mstanko@1276:             mediabeschreibung.setValue(beschreibung);
raimund@784:             return;
raimund@784:         }
raimund@784:         var me = this;
raimund@784:         var current = this.down('deskriptor[layer=' + ndx + ']');
raimund@784:         var cbox = current.down('combobox');
raimund@784:         if (ndx === 0) {
raimund@784:             cbox.store.proxy.extraParams = {
raimund@784:                 'layer': ndx
raimund@784:             };
raimund@784:         }
raimund@784:         else {
raimund@784:             var parents = current.getParents(current.down('combobox'));
raimund@784:             if (parents.length === 0) {
raimund@784:                 return;
raimund@784:             }
raimund@784:             cbox.store.proxy.extraParams = {
raimund@784:                 'layer': ndx,
raimund@784:                 'parents': parents
raimund@784:             };
raimund@784:         }
raimund@784:         cbox.store.load(function(records, op, success) {
raimund@784:             if (!success) {
raimund@784:                 return;
raimund@784:             }
raimund@784:             cbox.select(cbox.store.findRecord('sn', parseInt(media[ndx + 1], 10)));
mstanko@1276:             var mediatext = cbox.store.findRecord('sn', parseInt(media[ndx + 1], 10));
mstanko@1276:             if (mediatext !== null) {
mstanko@1276:                 if ( (ndx <= 3) && (media[1] === '01') && (mediatext.data.beschreibung !== "leer") ) {
mstanko@1276:                     beschreibung = mediatext.data.beschreibung;
mstanko@1276:                 } else if ( (media[1] !== '01') && (mediatext.data.beschreibung !== "leer") && (ndx <= 1) ) {
mstanko@1276:                     beschreibung = mediatext.data.beschreibung;
mstanko@1276:                 }
mstanko@1276:             }
ehuber@1108:             me.setMediaSN(++ndx, media, beschreibung);
raimund@784:         });
dustin@757:     },
dustin@757: 
dustin@757:     setMessages: function(errors, warnings) {
dustin@757:         var key;
dustin@757:         var element;
dustin@757:         var content;
dustin@757:         var i18n = Lada.getApplication().bundle;
dustin@757:         if (warnings) {
dustin@757:             for (key in warnings) {
dustin@757:                 element = this.down('component[name=' + key + ']');
dustin@757:                 if (!element) {
dustin@757:                     continue;
dustin@757:                 }
dustin@757:                 content = warnings[key];
dustin@757:                 var warnText = '';
dustin@757:                 for (var i = 0; i < content.length; i++) {
dustin@757:                     warnText += i18n.getMsg(content[i].toString()) + '\n';
dustin@757:                 }
dustin@757:                 element.showWarnings(warnText);
dustin@757:             }
dustin@757:         }
dustin@757:         if (errors) {
dustin@757:             for (key in errors) {
dustin@757:                 element = this.down('component[name=' + key + ']');
dustin@757:                 if (!element) {
dustin@757:                     continue;
dustin@757:                 }
dustin@757:                 content = errors[key];
dustin@757:                 var errorText = '';
dustin@757:                 for (var i = 0; i < content.length; i++) {
dustin@757:                     errorText += i18n.getMsg(content[i].toString()) + '\n';
dustin@757:                 }
dustin@757:                 element.showErrors(errorText);
dustin@757:             }
dustin@757:         }
dustin@757:     },
dustin@757: 
dustin@757:     clearMessages: function() {
dustin@757:         // TODO
raimund@1068:         this.down('cbox[name=mstlabor]').clearWarningOrError();
dustin@777:         //no clearmsg for probeKommentar
dustin@777:         this.down('cbox[name=datenbasisId]').clearWarningOrError();
dustin@777:         this.down('cbox[name=baId]').clearWarningOrError();
mstanko@1086:         this.down('chkbox[name=test]').clearWarningOrError();
dustin@777:         this.down('cbox[name=probenartId]').clearWarningOrError();
tom@1235:         this.down('netzbetreiber').clearWarningOrError();
tom@1167:         // clear messages in intervall definition
tom@1167:         this.down('fset[name=probenIntervallFieldset]').clearMessages();
tom@1167:         this.down('cbox[name=probenintervall]').clearWarningOrError();
tom@1168:         this.down('numfield[name=teilintervallVon]').clearWarningOrError();
tom@1168:         this.down('numfield[name=teilintervallBis]').clearWarningOrError();
tom@1199:         this.down('dayofyear[name=gueltigVon]').clearWarningOrError();
tom@1199:         this.down('dayofyear[name=gueltigBis]').clearWarningOrError();
dustin@777:         //no clear for probeNehmerId
dustin@777:         // Deskriptoren are missing
dustin@777:         this.down('cbox[name=umwId]').clearWarningOrError();
dustin@757:     },
dustin@757: 
dustin@757:     setReadOnly: function(value) {
dustin@757:         // TODO
dustin@757:     },
dustin@757: 
dustin@757:     buildDescriptors: function() {
dustin@757:         var fields = [];
dustin@757:         for (var i = 0; i < 12; i++) {
dustin@757:             fields[i] = {
raimund@784:                 xtype: 'deskriptor',
dustin@757:                 fieldLabel: 'S' + i,
dustin@757:                 labelWidth: 25,
raimund@784:                 width: 190,
raimund@784:                 layer: i,
dustin@757:                 margin: '0, 10, 5, 0'
dustin@757:             };
dustin@757:         }
dustin@757:         return fields;
dustin@757:     }
dustin@757: });