raimund@548: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
raimund@548:  * Software engineering by Intevation GmbH
raimund@548:  *
raimund@548:  * This file is Free Software under the GNU GPL (v>=3)
raimund@548:  * and comes with ABSOLUTELY NO WARRANTY! Check out
raimund@548:  * the documentation coming with IMIS-Labordaten-Application for details.
raimund@548:  */
raimund@548: 
dustin@894: /**
dustin@894:  * Form to edit a Probe
raimund@548:  */
raimund@548: Ext.define('Lada.view.form.Probe', {
raimund@548:     extend: 'Ext.form.Panel',
raimund@548:     alias: 'widget.probeform',
raimund@548:     requires: [
raimund@548:         'Lada.view.widget.Datenbasis',
raimund@555:         'Lada.view.widget.Messstelle',
raimund@548:         'Lada.view.widget.Netzbetreiber',
raimund@548:         'Lada.view.widget.Betriebsart',
raimund@548:         'Lada.view.widget.Testdatensatz',
raimund@548:         'Lada.view.widget.Probenart',
raimund@548:         'Lada.view.widget.Umwelt',
raimund@771:         'Lada.view.widget.Deskriptor',
raimund@548:         'Lada.view.widget.base.TextField',
raimund@548:         'Lada.view.widget.base.Datetime',
raimund@548:         'Lada.view.widget.base.FieldSet',
dustin@646:         'Lada.view.widget.base.DateField',
raimund@771:         'Lada.model.Probe'
raimund@548:     ],
raimund@548: 
raimund@548:     model: 'Lada.model.Probe',
raimund@548:     minWidth: 650,
raimund@548:     margin: 5,
raimund@548:     border: 0,
raimund@548: 
raimund@548:     recordId: null,
raimund@548: 
raimund@548:     trackResetOnLoad: true,
raimund@548: 
raimund@548:     initComponent: function() {
raimund@548:         var me = this;
raimund@548:         this.items = [{
raimund@548:             xtype: 'fieldset',
raimund@548:             title: 'Allgemein',
raimund@548:             items: [{
raimund@548:                 border: 0,
raimund@548:                 margin: '0, 0, 10, 0',
raimund@548:                 dockedItems: [{
raimund@548:                     xtype: 'toolbar',
raimund@548:                     dock: 'bottom',
raimund@548:                     border: '0, 1, 1, 1',
raimund@548:                     style: {
raimund@548:                         borderBottom: '1px solid #b5b8c8 !important',
raimund@548:                         borderLeft: '1px solid #b5b8c8 !important',
raimund@548:                         borderRight: '1px solid #b5b8c8 !important'
raimund@548:                     },
raimund@548:                     items: ['->', {
raimund@548:                         text: 'Speichern',
raimund@548:                         qtip: 'Daten speichern',
raimund@548:                         icon: 'resources/img/dialog-ok-apply.png',
raimund@548:                         action: 'save',
raimund@548:                         disabled: true
raimund@548:                     }, {
raimund@548:                         text: 'Verwerfen',
raimund@548:                         qtip: 'Änderungen verwerfen',
raimund@548:                         icon: 'resources/img/dialog-cancel.png',
raimund@548:                         action: 'discard',
raimund@548:                         disabled: true
raimund@548:                     }]
raimund@548:                 }],
raimund@548:                 items: [{
raimund@548:                     layout: 'hbox',
raimund@548:                     border: 0,
raimund@548:                     items: [{
raimund@548:                         border: 0,
raimund@548:                         width: '50%',
raimund@548:                         minWidth: 290,
raimund@548:                         layout: {
raimund@548:                             type: 'vbox',
raimund@548:                             align: 'stretch'
raimund@548:                         },
raimund@548:                         margin: '0, 10, 0, 0',
raimund@548:                         items: [{
raimund@555:                             xtype: 'messstelle',
raimund@548:                             name: 'mstId',
raimund@548:                             fieldLabel: 'Messstelle',
raimund@548:                             labelWidth: 135,
dustin@740:                             allowBlank: false,
dustin@740:                             editable: true
raimund@548:                         }, {
raimund@548:                             xtype: 'tfield',
raimund@548:                             name: 'hauptprobenNr',
raimund@548:                             maxLength: 20,
raimund@548:                             fieldLabel: 'Hauptprobennr.',
raimund@548:                             labelWidth: 135
raimund@548:                         }]
raimund@548:                     }, {
raimund@548:                         border: 0,
raimund@548:                         width: '50%',
raimund@548:                         minWidth: 300,
dustin@623:                         margin: '0, 1, 0, 0',
raimund@548:                         items: [{
raimund@548:                             xtype: 'fset',
raimund@548:                             title: 'Erweiterte Angaben',
dustin@720:                             name: 'erwAngaben',
raimund@548:                             collapsible: true,
raimund@548:                             collapsed: true,
raimund@548:                             items: [{
raimund@548:                                 xtype: 'datenbasis',
raimund@548:                                 editable: false,
raimund@548:                                 name: 'datenbasisId',
raimund@548:                                 fieldLabel: 'Datenbasis',
dustin@623:                                 anchor: '100%',
dustin@718:                                 labelWidth: 105
raimund@548:                             }, {
raimund@548:                                 xtype: 'betriebsart',
raimund@548:                                 name: 'baId',
raimund@548:                                 fieldLabel: 'Betriebsart',
dustin@623:                                 anchor: '100%',
dustin@718:                                 labelWidth: 105
raimund@548:                             }, {
raimund@548:                                 xtype: 'testdatensatz',
raimund@548:                                 name: 'test',
raimund@548:                                 fieldLabel: 'Testdatensatz',
dustin@623:                                 anchor: '100%',
dustin@623:                                 labelWidth: 105,
dustin@718:                                 allowBlank: false
raimund@548:                             }, {
raimund@548:                                 xtype: 'probenart',
raimund@548:                                 editable: false,
raimund@548:                                 name: 'probenartId',
raimund@548:                                 fieldLabel: 'Probenart',
dustin@623:                                 anchor: '100%',
dustin@623:                                 labelWidth: 105,
dustin@718:                                 allowBlank: false
raimund@548:                             }, {
raimund@548:                                 xtype: 'numberfield',
raimund@548:                                 allowDecimals: false,
raimund@548:                                 name: 'probeNehmerId',
raimund@548:                                 fieldLabel: 'Probennehmer',
dustin@817:                                 minValue: 0,
dustin@623:                                 anchor: '100%',
dustin@718:                                 labelWidth: 105
raimund@548:                             }, {
raimund@548:                                 xtype: 'netzbetreiber',
raimund@548:                                 name: 'netzbetreiberId',
raimund@548:                                 editable: false,
dustin@847:                                 readOnly: true,
raimund@548:                                 fieldLabel: 'Netzbetreiber',
dustin@623:                                 anchor: '100%',
dustin@623:                                 labelWidth: 105,
dustin@718:                                 allowBlank: false
raimund@548:                             }, {
raimund@548:                                 xtype: 'tfield',
raimund@548:                                 name: 'x11',
raimund@548:                                 fieldLabel: 'Datensatzerzeuger',
dustin@623:                                 anchor: '100%',
dustin@718:                                 labelWidth: 105
raimund@548:                             }]
raimund@548:                         }]
raimund@548:                     }]
raimund@548:                 }, {
raimund@548:                     // Zeit
raimund@548:                     xtype: 'fieldset',
raimund@548:                     title: 'Zeit',
raimund@548:                     layout: {
dustin@646:                         type: 'hbox',
dustin@646:                         pack: 'center',
dustin@646:                         align: 'stretch'
raimund@548:                     },
raimund@548:                     items: [{
dustin@717:                         xtype: 'fset',
dustin@646:                         title: 'Probenentnahme',
dustin@717:                         name: 'entnahmePeriod',
dustin@646:                         anchor: '100%',
dustin@646:                         width: '50%',
dustin@646:                         margin: '0, 5, 5, 5',
raimund@548:                         layout: {
raimund@548:                             type: 'vbox',
raimund@548:                             align: 'stretch'
raimund@548:                         },
raimund@548:                         items: [{
raimund@650:                             xtype: 'datetime',
dustin@646:                             fieldLabel: 'Beginn',
dustin@646:                             labelWidth: 90,
dustin@646:                             anchor: '100%',
raimund@548:                             name: 'probeentnahmeBeginn',
dustin@717:                             format: 'd.m.Y H:i',
dustin@717:                             period: 'start'
raimund@548:                         }, {
raimund@650:                             xtype: 'datetime',
dustin@646:                             fieldLabel: 'Ende',
dustin@646:                             labelWidth: 90,
dustin@646:                             anchor: '100%',
raimund@548:                             name: 'probeentnahmeEnde',
dustin@717:                             format: 'd.m.Y H:i',
dustin@717:                             period: 'end'
raimund@548:                         }]
raimund@548:                     }, {
dustin@717:                         xtype: 'fset',
dustin@646:                         title: 'Sollzeitraum',
dustin@717:                         name: 'sollzeitPeriod',
dustin@646:                         anchor: '100%',
dustin@646:                         width: '50%',
dustin@646:                         margin: '0, 5, 5, 5',
dustin@646:                         layout: {
dustin@646:                             type: 'vbox',
raimund@650:                             align: 'stretch'
dustin@646:                         },
raimund@548:                         items: [{
raimund@650:                             xtype: 'datetime',
dustin@646:                             fieldLabel: 'Von',
raimund@548:                             labelWidth: 90,
dustin@646:                             anchor: '100%',
raimund@548:                             name: 'solldatumBeginn',
dustin@717:                             format: 'd.m.Y H:i',
dustin@717:                             period: 'start'
raimund@650:                         }, {
raimund@650:                             xtype: 'datetime',
dustin@646:                             fieldLabel: 'Bis',
raimund@548:                             labelWidth: 90,
dustin@646:                             anchor: '100%',
raimund@548:                             name: 'solldatumEnde',
dustin@717:                             format: 'd.m.Y H:i',
dustin@717:                             period: 'end'
raimund@548:                         }]
raimund@548:                     }]
dustin@838:                 }, {
dustin@838:                     // Medium
dustin@838:                     xtype: 'fieldset',
dustin@838:                     title: 'Medium',
dustin@838:                     items: [{
dustin@838:                         border: 0,
dustin@838:                         layout: {
dustin@838:                             type: 'vbox',
dustin@838:                             align: 'stretch'
dustin@838:                         },
dustin@838:                         width: '100%',
dustin@838:                         items: [{
dustin@838:                             xtype: 'textfield',
dustin@838:                             name: 'media',
dustin@838:                             labelWidth: 125,
dustin@838:                             fieldLabel: 'Medienbezeichnung',
dustin@838:                             listeners: {
dustin@838:                                 dirtychange: {
dustin@838:                                     fn: this.updateOnChange,
dustin@838:                                     scope: me
dustin@838:                                 }
dustin@838:                             }
dustin@838:                         }, {
dustin@838:                             xtype: 'tfield',
dustin@838:                             maxLength: 38,
dustin@838:                             enforceMaxLength: true,
dustin@838:                             name: 'mediaDesk',
dustin@838:                             labelWidth: 125,
dustin@838:                             fieldLabel: 'Deskriptoren',
dustin@838:                             regex: new RegExp('(?:D: ){1}(?:[0-9]{2} ){11}[0-9]{2}'),
dustin@838:                             regexText: 'Die Deskriptoren haben das falsche Format.<br />'+
dustin@838:                             'Richtig wäre: D: 99 99 99 99 99 99 99 99 99 99 99 99',
dustin@838:                             listeners: {
dustin@838:                                 dirtychange: {
dustin@838:                                     fn: this.updateOnChange,
dustin@838:                                     scope: me
dustin@838:                                 }
dustin@838:                             }
dustin@838:                         }, {
dustin@838:                             xtype: 'umwelt',
dustin@838:                             name: 'umwId',
dustin@838:                             fieldLabel: 'Umweltbereich',
dustin@838:                             labelWidth: 125,
dustin@838:                             allowBlank: false,
dustin@838:                             editable: true,
dustin@838:                             listeners: {
dustin@838:                                 dirtychange: {
dustin@838:                                     fn: this.updateOnChange,
dustin@838:                                     scope: me
dustin@838:                                 }
dustin@838:                             }
dustin@838:                         }, {
dustin@838:                             xtype: 'fieldset',
dustin@838:                             title: 'Details Deskriptoren',
dustin@838:                             collapsible: true,
dustin@838:                             collapsed: true,
dustin@838:                             layout: {
dustin@838:                                 type: 'table',
dustin@838:                                 columns: 3
dustin@838:                             },
dustin@838:                             items: this.buildDescriptors()
dustin@838:                         }]
dustin@838:                     }]
raimund@548:                 }]
raimund@548:             }]
raimund@548:         }];
dustin@681:         this.callParent(arguments);
dustin@816:         this.clearMessages();
raimund@548:     },
raimund@548: 
raimund@548:     setRecord: function(record) {
dustin@717:         this.clearMessages();
raimund@548:         this.getForm().loadRecord(record);
raimund@548:     },
raimund@548: 
raimund@771:     setMediaDesk: function(record) {
raimund@771:         var media = record.get('mediaDesk').split(' ');
raimund@771:         this.setMediaSN(0, media);
raimund@771:     },
raimund@771: 
raimund@771:     setMediaSN: function(ndx, media) {
raimund@771:         if (ndx >= 12) {
raimund@771:             return;
raimund@771:         }
raimund@771:         var me = this;
raimund@771:         var current = this.down('deskriptor[layer=' + ndx + ']');
raimund@771:         var cbox = current.down('combobox');
raimund@771:         if (ndx === 0) {
raimund@771:             cbox.store.proxy.extraParams = {
raimund@771:                 'layer': ndx
raimund@771:             };
raimund@771:         }
raimund@771:         else {
raimund@771:             var parents = current.getParents(current.down('combobox'));
raimund@771:             if (parents.length === 0) {
raimund@771:                 return;
raimund@771:             }
raimund@771:             cbox.store.proxy.extraParams = {
raimund@771:                 'layer': ndx,
raimund@771:                 'parents': parents
raimund@771:             };
raimund@771:         }
raimund@771:         cbox.store.load(function(records, op, success) {
raimund@771:             if (!success) {
raimund@771:                 return;
raimund@771:             }
raimund@771:             cbox.select(cbox.store.findRecord('sn', parseInt(media[ndx + 1], 10)));
raimund@771:             me.setMediaSN(++ndx, media);
raimund@771:         });
raimund@771:     },
raimund@771: 
raimund@548:     setMessages: function(errors, warnings) {
raimund@548:         var key;
raimund@548:         var element;
raimund@548:         var content;
raimund@548:         var i18n = Lada.getApplication().bundle;
raimund@548:         if (warnings) {
raimund@548:             for (key in warnings) {
raimund@548:                 element = this.down('component[name=' + key + ']');
raimund@548:                 if (!element) {
raimund@548:                     continue;
raimund@548:                 }
raimund@548:                 content = warnings[key];
raimund@548:                 var warnText = '';
raimund@548:                 for (var i = 0; i < content.length; i++) {
raimund@548:                     warnText += i18n.getMsg(content[i].toString()) + '\n';
raimund@548:                 }
raimund@548:                 element.showWarnings(warnText);
raimund@548:             }
raimund@548:         }
raimund@548:         if (errors) {
raimund@548:             for (key in errors) {
raimund@548:                 element = this.down('component[name=' + key + ']');
raimund@548:                 if (!element) {
raimund@548:                     continue;
raimund@548:                 }
raimund@548:                 content = errors[key];
raimund@548:                 var errorText = '';
raimund@548:                 for (var i = 0; i < content.length; i++) {
raimund@548:                     errorText += i18n.getMsg(content[i].toString()) + '\n';
raimund@548:                 }
raimund@548:                 element.showErrors(errorText);
raimund@548:             }
raimund@548:         }
raimund@548:     },
raimund@548: 
raimund@548:     clearMessages: function() {
raimund@548:         this.down('cbox[name=mstId]').clearWarningOrError();
raimund@548:         this.down('tfield[name=hauptprobenNr]').clearWarningOrError();
raimund@548:         this.down('cbox[name=datenbasisId]').clearWarningOrError();
raimund@548:         this.down('cbox[name=baId]').clearWarningOrError();
raimund@548:         this.down('cbox[name=test]').clearWarningOrError();
raimund@548:         this.down('cbox[name=probenartId]').clearWarningOrError();
raimund@548:         this.down('cbox[name=netzbetreiberId]').clearWarningOrError();
raimund@548:         this.down('tfield[name=x11]').clearWarningOrError();
raimund@548:         this.down('cbox[name=umwId]').clearWarningOrError();
raimund@652:         this.down('datetime[name=probeentnahmeBeginn]').clearWarningOrError();
raimund@652:         this.down('datetime[name=probeentnahmeEnde]').clearWarningOrError();
raimund@652:         this.down('datetime[name=solldatumBeginn]').clearWarningOrError();
raimund@652:         this.down('datetime[name=solldatumEnde]').clearWarningOrError();
dustin@681:         //this.down('numberfield[name=probeNehmerId]').clearWarningOrError();
dustin@720:         this.down('fset[name=erwAngaben]').clearMessages();
dustin@717:         this.down('fset[name=entnahmePeriod]').clearMessages();
dustin@717:         this.down('fset[name=sollzeitPeriod]').clearMessages();
raimund@548:     },
raimund@548: 
raimund@548:     setReadOnly: function(value) {
raimund@548:         this.down('cbox[name=mstId]').setReadOnly(value);
raimund@548:         this.down('tfield[name=hauptprobenNr]').setReadOnly(value);
raimund@548:         this.down('cbox[name=datenbasisId]').setReadOnly(value);
raimund@548:         this.down('cbox[name=baId]').setReadOnly(value);
raimund@548:         this.down('cbox[name=test]').setReadOnly(value);
raimund@548:         this.down('cbox[name=probenartId]').setReadOnly(value);
dustin@847:         //this.down('cbox[name=netzbetreiberId]').setReadOnly(value);
raimund@548:         this.down('tfield[name=x11]').setReadOnly(value);
raimund@548:         this.down('textfield[name=media]').setReadOnly(value);
raimund@783:         this.down('tfield[name=mediaDesk]').setReadOnly(value);
raimund@548:         this.down('cbox[name=umwId]').setReadOnly(value);
raimund@652:         this.down('datetime[name=probeentnahmeBeginn]').setReadOnly(value);
raimund@652:         this.down('datetime[name=probeentnahmeEnde]').setReadOnly(value);
raimund@652:         this.down('datetime[name=solldatumBeginn]').setReadOnly(value);
raimund@652:         this.down('datetime[name=solldatumEnde]').setReadOnly(value);
dustin@681:         this.down('numberfield[name=probeNehmerId]').setReadOnly(value);
dustin@685: 
dustin@685:         //Deskriptoren
dustin@685:         for (var i = 0; i < 12; i++) {
raimund@783:             this.down('deskriptor[layer='+i+']').setReadOnly(value);
dustin@685:         }
raimund@548:     },
raimund@548: 
raimund@548:     buildDescriptors: function() {
raimund@548:         var fields = [];
raimund@548:         for (var i = 0; i < 12; i++) {
raimund@548:             fields[i] = {
raimund@771:                 xtype: 'deskriptor',
raimund@548:                 fieldLabel: 'S' + i,
raimund@783:                 //name: 's' + i,
raimund@548:                 labelWidth: 25,
raimund@771:                 width: 190,
raimund@771:                 layer: i,
dustin@718:                 margin: '0, 10, 5, 0'
raimund@548:             };
raimund@548:         }
raimund@548:         return fields;
raimund@548:     }
raimund@548: });