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@757: /* dustin@757: * Formular 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', dustin@757: 'Lada.view.widget.Messstelle', dustin@757: 'Lada.view.widget.Netzbetreiber', dustin@757: 'Lada.view.widget.Betriebsart', dustin@757: 'Lada.view.widget.Testdatensatz', dustin@757: 'Lada.view.widget.Probenart', dustin@757: 'Lada.view.widget.Umwelt', dustin@757: 'Lada.view.widget.base.TextField', dustin@757: 'Lada.view.widget.base.FieldSet', dustin@757: 'Lada.model.Messprogramm', dustin@757: 'Lada.model.MmtMessprogramm', dustin@757: 'Lada.view.widget.Probenintervall', dustin@757: 'Lada.view.widget.ProbenintervallSlider', dustin@757: 'Lada.view.widget.base.Datetime', dustin@757: 'Lada.view.widget.base.DateField' 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: layout: 'hbox', dustin@757: border: 0, dustin@757: items: [{ dustin@757: border: 0, dustin@757: width: '50%', 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: [{ dustin@757: xtype: 'messstelle', dustin@757: name: 'mstId', dustin@757: fieldLabel: i18n.getMsg('mstId'), dustin@757: labelWidth: 135, dustin@757: allowBlank: false, dustin@757: editable: true dustin@757: }, { dustin@757: xtype: 'textfield', dustin@757: name: 'name', dustin@757: fieldLabel: i18n.getMsg('name'), dustin@757: labelWidth: 135, dustin@757: allowBlank: false, dustin@757: editable: true dustin@757: }, { dustin@757: xtype: 'textarea', //todo: we need a widget which is capable of handling errormsg. dustin@757: name: 'probeKommentar', dustin@757: labelAlign: 'top', dustin@757: fieldLabel: i18n.getMsg('probeKommentar'), dustin@757: labelwidth: 135, dustin@757: anchor: '100%' dustin@757: }] dustin@757: }, { dustin@757: border: 0, dustin@757: width: '50%', dustin@757: minWidth: 300, dustin@757: margin: '0, 1, 0, 0', dustin@757: items: [{ dustin@757: xtype: 'fset', dustin@757: title: i18n.getMsg('erwAngaben'), dustin@757: name: 'erwAngaben', dustin@757: collapsible: false, dustin@757: collapsed: false, dustin@757: items: [{ dustin@757: xtype: 'datenbasis', dustin@757: editable: false, dustin@757: name: 'datenbasisId', dustin@757: fieldLabel: i18n.getMsg('datenbasisId'), dustin@757: anchor: '100%', dustin@757: labelWidth: 105 dustin@757: }, { dustin@757: xtype: 'betriebsart', dustin@757: name: 'baId', dustin@757: fieldLabel: i18n.getMsg('baId'), dustin@757: anchor: '100%', dustin@757: labelWidth: 105 dustin@757: }, { dustin@757: xtype: 'testdatensatz', dustin@757: name: 'test', dustin@757: fieldLabel: i18n.getMsg('test'), dustin@757: anchor: '100%', dustin@757: labelWidth: 105, dustin@757: allowBlank: false dustin@757: }, { dustin@757: xtype: 'probenart', dustin@757: editable: false, dustin@757: name: 'probenartId', dustin@757: fieldLabel: i18n.getMsg('probenartId'), dustin@757: anchor: '100%', dustin@757: labelWidth: 105, dustin@757: allowBlank: false dustin@757: }, { dustin@757: xtype: 'numberfield', dustin@757: allowDecimals: false, dustin@757: name: 'probeNehmerId', dustin@757: fieldLabel: i18n.getMsg('probeNehmerId'), dustin@757: anchor: '100%', dustin@757: labelWidth: 105 dustin@757: }, { dustin@757: xtype: 'netzbetreiber', dustin@757: name: 'netzbetreiberId', dustin@757: editable: false, dustin@757: fieldLabel: i18n.getMsg('netzbetreiberId'), dustin@757: anchor: '100%', dustin@757: labelWidth: 105, dustin@757: allowBlank: false dustin@757: }] dustin@757: }] dustin@757: }] dustin@757: }, { dustin@757: // Medium dustin@757: xtype: 'fieldset', dustin@757: title: i18n.getMsg('medium'), 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: 'textfield', dustin@757: maxLength: 38, dustin@757: enforceMaxLength: true, dustin@757: name: 'mediaDesk', dustin@757: labelWidth: 125, dustin@757: fieldLabel: i18n.getMsg('mediaDesk'), dustin@757: regex: new RegExp('(?:D: ){1}(?:[0-9]{2} ){11}[0-9]{2}'), dustin@757: regexText: i18n.getMsg('err.msg.deskriptorvalidation'), dustin@757: listeners: { dustin@757: dirtychange: { dustin@757: fn: this.updateOnChange, dustin@757: scope: me dustin@757: } dustin@757: } dustin@757: }, { dustin@757: xtype: 'umwelt', dustin@757: name: 'umwId', dustin@757: fieldLabel: i18n.getMsg('umwId'), dustin@757: labelWidth: 125, dustin@757: allowBlank: false, 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: }, { 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: { dustin@757: type: 'table', dustin@757: columns: 3 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: }, { dustin@757: // Zeit dustin@757: xtype: 'fieldset', dustin@757: title: i18n.getMsg('time'), dustin@757: layout: { dustin@757: type: 'hbox', dustin@757: pack: 'center', dustin@757: align: 'stretch' dustin@757: }, dustin@757: items: [{ dustin@757: xtype: 'fset', dustin@757: title: i18n.getMsg('validity'), dustin@757: name: 'gueltigPeriod', dustin@757: anchor: '100%', dustin@757: width: '50%', dustin@757: margin: '0, 5, 5, 5', dustin@757: layout: { dustin@757: type: 'vbox', dustin@757: align: 'stretch' dustin@757: }, dustin@757: items: [{ dustin@757: xtype: 'datetime', dustin@757: fieldLabel: i18n.getMsg('gueltigVon'), dustin@757: labelWidth: 90, dustin@757: anchor: '100%', dustin@757: name: 'gueltigVon', dustin@757: format: 'd.m.Y H:i', dustin@757: period: 'start' dustin@757: }, { dustin@757: xtype: 'datetime', dustin@757: fieldLabel: i18n.getMsg('gueltigBis'), dustin@757: labelWidth: 90, dustin@757: anchor: '100%', dustin@757: name: 'gueltigBis', dustin@757: format: 'd.m.Y H:i', dustin@757: period: 'end' dustin@757: }] dustin@757: }, { dustin@757: xtype: 'fset', dustin@757: title: i18n.getMsg('probenintervall'), dustin@757: name: 'probenintervall', dustin@757: anchor: '100%', dustin@757: width: '50%', dustin@757: margin: '0, 5, 5, 5', dustin@757: layout: { dustin@757: type: 'vbox', dustin@757: align: 'stretch' dustin@757: }, dustin@757: items: [{ dustin@757: xtype: 'probenintervall', dustin@757: fieldLabel: i18n.getMsg('probenintervall'), dustin@757: labelWidth: 90, dustin@757: anchor: '100%', dustin@757: name: 'probenintervall' dustin@757: }, { dustin@757: xtype: 'numberfield', dustin@757: fieldLabel: i18n.getMsg('teilintervallVon'), dustin@757: labelWidth: 90, dustin@757: anchor: '100%', dustin@757: name: 'teilintervallVon', dustin@757: period: 'start' dustin@757: }, { dustin@757: xtype: 'numberfield', dustin@757: fieldLabel: i18n.getMsg('teilintervallBis'), dustin@757: labelWidth: 90, dustin@757: anchor: '100%', dustin@757: name: 'teilintervallBis', dustin@757: period: 'end' dustin@757: }, { dustin@757: xtype: 'probenintervallslider', dustin@757: fieldLabel: i18n.getMsg('intervall'), dustin@757: labelWidth: 90, dustin@757: anchor: '100%', dustin@757: values: [0, 0], dustin@757: //this will be overridden dustin@757: // by setRecord dustin@757: }] dustin@757: }] dustin@757: }] dustin@757: }] dustin@757: }]; dustin@757: this.callParent(arguments); dustin@757: }, dustin@757: dustin@757: populateIntervall: function(record, intervall) { dustin@757: console.log('Populate Start'); 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@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@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@757: if (!intervall) { 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: dustin@757: dustin@757: var intrec = intervallstore dustin@757: .findRecord('probenintervall', dustin@757: intervall, 0, false, false, true); dustin@757: dustin@757: var min = intrec.get('periodstart'); dustin@757: var max = intrec.get('periodend'); 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@757: console.log('Populate End'); dustin@757: }, dustin@757: dustin@757: setRecord: function(record) { dustin@757: this.clearMessages(); dustin@757: this.getForm().loadRecord(record); dustin@757: //Set the intervall numberfields and the slider. dustin@757: this.down('probenintervallslider').setValue([ dustin@757: record.get('teilintervallVon'), dustin@757: record.get('teilintervallBis') dustin@757: ]); dustin@757: dustin@757: //TODO Set Sliders MinMaxValue 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: ); dustin@757: 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 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] = { dustin@757: fieldLabel: 'S' + i, dustin@757: name: 's' + i, dustin@757: labelWidth: 25, dustin@757: margin: '0, 10, 5, 0' dustin@757: }; dustin@757: } dustin@757: return fields; dustin@757: } dustin@757: });