dustin@581: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz dustin@581: * Software engineering by Intevation GmbH dustin@581: * dustin@581: * This file is Free Software under the GNU GPL (v>=3) dustin@581: * and comes with ABSOLUTELY NO WARRANTY! Check out dustin@581: * the documentation coming with IMIS-Labordaten-Application for details. dustin@581: */ dustin@581: dustin@894: /** dustin@894: * Form to edit a Messung dustin@581: */ dustin@581: Ext.define('Lada.view.form.Messung', { dustin@581: extend: 'Ext.form.Panel', dustin@581: alias: 'widget.messungform', dustin@581: requires: [ raimund@1156: 'Ext.layout.container.Table', dustin@581: 'Lada.view.widget.Datenbasis', dustin@611: 'Lada.view.widget.base.CheckBox', dustin@611: 'Lada.view.widget.Messmethode', dustin@581: 'Lada.view.widget.base.TextField', dustin@882: 'Lada.view.widget.base.Datetime' dustin@581: ], dustin@581: dustin@581: model: 'Lada.model.Messung', dustin@581: minWidth: 650, dustin@581: margin: 5, dustin@581: border: 0, dustin@581: dustin@581: recordId: null, dustin@581: dustin@581: trackResetOnLoad: true, dustin@581: tom@1217: currentStatus: null, tom@1217: raimund@589: initComponent: function() { dustin@611: var me = this; tom@1155: var i18n = Lada.getApplication().bundle; dustin@581: this.items = [{ dustin@581: xtype: 'fieldset', dustin@611: title: 'Allgemein', dustin@611: items: [{ dustin@611: border: 0, dustin@611: margin: '0, 0, 10, 0', dustin@611: layout: { dustin@611: type: 'table', dustin@611: columns: 2 dustin@611: }, dustin@611: dockedItems: [{ dustin@611: xtype: 'toolbar', dustin@611: dock: 'bottom', dustin@611: border: '0, 1, 1, 1', dustin@611: style: { dustin@611: borderBottom: '1px solid #b5b8c8 !important', dustin@611: borderLeft: '1px solid #b5b8c8 !important', dustin@611: borderRight: '1px solid #b5b8c8 !important' dustin@611: }, dustin@611: items: ['->', { raimund@1386: text: i18n.getMsg('audittrail'), raimund@1386: qtip: i18n.getMsg('qtip.audit'), raimund@1386: icon: 'resources/img/distribute-vertical-center.png', raimund@1386: action: 'audit', raimund@1386: disabled: this.recordId === null raimund@1386: }, { dustin@611: text: 'Speichern', dustin@611: qtip: 'Daten speichern', dustin@611: icon: 'resources/img/dialog-ok-apply.png', dustin@611: action: 'save', dustin@611: disabled: true dustin@611: }, { dustin@611: text: 'Verwerfen', dustin@611: qtip: 'Ă„nderungen verwerfen', dustin@611: icon: 'resources/img/dialog-cancel.png', dustin@611: action: 'discard', dustin@611: disabled: true dustin@611: }] dustin@611: }], dustin@611: items: [{ dustin@708: xtype: 'tfield', dustin@611: name: 'nebenprobenNr', dustin@611: maxLength: 10, dustin@611: margin: '0, 10, 5, 0', tom@1155: fieldLabel: i18n.getMsg('nebenprobenNr'), dustin@611: width: 300, dustin@718: labelWidth: 100 dustin@611: }, { dustin@611: xtype: 'messmethode', dustin@611: name: 'mmtId', dustin@611: margin: '0, 10, 5, 0', dustin@611: fieldLabel: 'Messmethode', tom@1217: allowBlank: false, dustin@611: width: 300, dustin@718: labelWidth: 100 dustin@611: }, { dustin@611: xtype: 'datetime', dustin@611: name: 'messzeitpunkt', dustin@611: margin: '0, 10, 5, 0', dustin@611: fieldLabel: 'Messzeitpunkt', dustin@611: width: 300, dustin@718: labelWidth: 100 dustin@611: }, { dustin@611: xtype: 'numberfield', dustin@611: allowDecimals: false, dustin@661: allowExponential: false, dustin@661: enforceMaxLength: true, dustin@661: maxLength: 10, dustin@611: minValue: 0, dustin@611: name: 'messdauer', dustin@611: margin: '0, 10, 5, 0', dustin@611: fieldLabel: 'Messdauer', dustin@611: width: 300, dustin@718: labelWidth: 100 dustin@611: }, { dustin@611: xtype: 'chkbox', dustin@611: name: 'fertig', dustin@611: margin: '0, 10, 5, 0', dustin@611: fieldLabel: 'Fertig', dustin@611: width: 300, dustin@718: labelWidth: 100 dustin@611: }, { dustin@611: xtype: 'chkbox', dustin@611: name: 'geplant', dustin@854: readOnly: true, dustin@611: margin: '0, 10, 5, 0', dustin@611: fieldLabel: 'Geplant', dustin@611: width: 300, dustin@718: labelWidth: 100 dustin@945: }, { dustin@945: xtype: 'textfield', dustin@945: name: 'status', dustin@945: readOnly: true, dustin@945: isFormField: false, dustin@945: maxLength: 10, dustin@945: margin: '0, 10, 5, 0', dustin@945: fieldLabel: 'Status', dustin@945: width: 300, dustin@945: labelWidth: 100, dustin@945: submitValue: false, dustin@945: preventMark: true, //Do not display error msg. dustin@945: validateValue: function() { dustin@945: return true; //this field is always valid dustin@965: } dustin@957: }, { dustin@957: xtype: 'textfield', dustin@957: name: 'stufe', dustin@957: readOnly: true, dustin@957: isFormField: false, dustin@957: maxLength: 10, dustin@957: margin: '0, 10, 5, 0', dustin@957: fieldLabel: 'Stufe', dustin@957: width: 300, dustin@957: labelWidth: 100, dustin@957: submitValue: false, dustin@957: isFormField: false, dustin@957: preventMark: true, //Do not display error msg. dustin@957: validateValue: function() { dustin@957: return true; //this field is always valid dustin@965: } dustin@611: }] dustin@611: }] dustin@581: }]; dustin@581: this.callParent(arguments); dustin@581: }, dustin@581: raimund@589: setRecord: function(record) { dustin@960: var form = this.getForm(); dustin@960: form.loadRecord(record); dustin@960: if (record.getId()){ dustin@961: this.retrieveStatus(record.getId(), record.get('status')); dustin@960: } dustin@960: else { dustin@960: //remove the StatusWert and StatusStufe field from the form dustin@960: var sw = this.down('[name=status]'); dustin@960: var ss = this.down('[name=stufe]'); dustin@960: ss.hide(); dustin@960: sw.hide(); dustin@960: } dustin@945: }, dustin@945: tom@1217: getCurrentStatus: function() { tom@1217: return this.currentStatus; tom@1217: }, tom@1217: dustin@945: retrieveStatus: function(messungsId, statusId) { dustin@945: var i18n = Lada.getApplication().bundle; dustin@945: var msg = i18n.getMsg('load.statuswert'); dustin@945: var textfield = this.down('[name=status]'); dustin@997: var messwin = this.up('window'); dustin@945: dustin@961: if(textfield) { dustin@961: textfield.setRawValue(msg); dustin@961: } dustin@945: tom@1217: var me = this; dustin@961: var sStore = Ext.create('Lada.store.Status'); dustin@961: sStore.load({ dustin@961: params: { dustin@961: messungsId: messungsId dustin@961: }, dustin@961: callback: function(records, operation, success) { dustin@1017: var sw, ss, se; dustin@945: var i18n = Lada.getApplication().bundle; dustin@950: if (sStore.getTotalCount() === 0 || !statusId) { dustin@957: sw = 0; dustin@945: } dustin@945: else { tom@1217: me.currentStatus = sStore.getById(statusId); tom@1217: sk = sStore.getById(statusId).get('statusKombi'); tom@1217: se = sStore.getById(statusId).get('mstId'); tom@1217: var kombis = Ext.data.StoreManager.get('statuskombi'); tom@1217: var rec = kombis.getById(sk); tom@1217: sw = rec.raw.statusWert.id; tom@1217: ss = rec.raw.statusStufe.id; dustin@945: } dustin@957: this.setStatusWert(sw); dustin@957: this.setStatusStufe(ss); dustin@997: dustin@1017: // Enable / Disable the statusreset button of the statusgrid of the messungwindow dustin@997: if (messwin.record.get('statusEdit') === true && dustin@997: sw != 0 && dustin@1017: sw != 4 && dustin@1017: Ext.Array.contains(Lada.mst, se)) { dustin@1017: dustin@997: messwin.enableStatusReset(); dustin@997: } dustin@997: else { dustin@997: messwin.disableStatusReset(); dustin@997: } dustin@997: dustin@945: }, dustin@961: scope: this dustin@945: }); dustin@945: }, dustin@945: dustin@957: /** dustin@957: * Updates the Messungform and fills the Statuswert dustin@957: */ dustin@945: setStatusWert: function(value){ dustin@963: var swStore = Ext.data.StoreManager.get('statuswerte'); dustin@963: var i18n = Lada.getApplication().bundle; dustin@963: var msg = i18n.getMsg('load.statuswert.error'); dustin@963: var textfield = this.down('[name=status]'); dustin@963: dustin@963: if (!swStore) { dustin@963: //Set the textfield asynchronously dustin@963: swStore = Ext.create('Lada.store.StatusWerte'); dustin@963: swStore.load({ dustin@963: scope: this, dustin@963: callback: function(records, operation, success) { dustin@963: if (success) { dustin@963: var item = swStore.getById(value); dustin@963: if (item) { dustin@963: msg = item.get('wert'); dustin@963: } dustin@957: } dustin@963: if (textfield) { dustin@963: textfield.setRawValue(msg); dustin@963: } dustin@965: } dustin@963: }); dustin@963: } dustin@963: else { dustin@963: //Set the textfield dustin@963: var item = swStore.getById(value); dustin@963: if (item) { dustin@963: msg = item.get('wert'); dustin@963: } dustin@963: if (textfield) { dustin@963: textfield.setRawValue(msg); dustin@963: } dustin@963: } dustin@963: dustin@957: }, dustin@957: dustin@957: /** dustin@957: * Updates the Messungform and fills the StatusStufe dustin@957: */ dustin@957: setStatusStufe: function(value){ dustin@963: var ssStore = Ext.data.StoreManager.get('statusstufe') dustin@963: var i18n = Lada.getApplication().bundle; dustin@963: var msg = i18n.getMsg('load.statusstufe.error'); dustin@963: var textfield = this.down('[name=stufe]'); dustin@963: if (!ssStore) { dustin@963: //set the value asynchronously dustin@963: Ext.create('Lada.store.StatusStufe'); dustin@963: ssStore.load({ dustin@963: scope: this, dustin@963: callback: function(records, operation, success) { dustin@963: if (success) { dustin@963: var item = ssStore.getById(value); dustin@963: if (item) { dustin@963: msg = item.get('stufe'); dustin@963: } dustin@957: } dustin@963: if (textfield) { dustin@963: textfield.setRawValue(msg); dustin@963: } dustin@965: } dustin@963: }); dustin@963: } dustin@963: else { dustin@963: //Set the value. dustin@963: var item = ssStore.getById(value); dustin@963: if (item) { dustin@963: msg = item.get('stufe'); dustin@963: } dustin@963: if (textfield) { dustin@963: textfield.setRawValue(msg); dustin@963: } dustin@963: } dustin@581: }, dustin@581: dustin@708: setMessages: function(errors, warnings) { dustin@708: var key; dustin@708: var element; dustin@708: var content; dustin@708: var i18n = Lada.getApplication().bundle; dustin@708: if (warnings) { dustin@708: for (key in warnings) { dustin@708: element = this.down('component[name=' + key + ']'); dustin@708: if (!element) { dustin@708: continue; dustin@708: } dustin@708: content = warnings[key]; dustin@708: var warnText = ''; dustin@708: for (var i = 0; i < content.length; i++) { dustin@708: warnText += i18n.getMsg(content[i].toString()) + '\n'; dustin@708: } dustin@708: element.showWarnings(warnText); dustin@708: } dustin@708: } dustin@708: if (errors) { dustin@708: for (key in errors) { dustin@708: element = this.down('component[name=' + key + ']'); dustin@708: if (!element) { dustin@708: continue; dustin@708: } dustin@708: content = errors[key]; dustin@708: var errorText = ''; dustin@708: for (var i = 0; i < content.length; i++) { dustin@708: errorText += i18n.getMsg(content[i].toString()) + '\n'; dustin@708: } dustin@708: element.showErrors(errorText); dustin@708: } dustin@708: } dustin@581: }, dustin@581: dustin@581: clearMessages: function() { dustin@708: this.down('tfield[name=nebenprobenNr]').clearWarningOrError(); dustin@708: //this.down('messmethode[name=mmtId]').clearWarningOrError(); dustin@708: this.down('datetime[name=messzeitpunkt]').clearWarningOrError(); dustin@708: //this.down('numberfield[name=messdauer]').clearWarningOrError(); dustin@708: this.down('chkbox[name=fertig]').clearWarningOrError(); dustin@708: this.down('chkbox[name=geplant]').clearWarningOrError(); dustin@581: }, dustin@581: dustin@694: setReadOnly: function(value) { dustin@708: this.down('tfield[name=nebenprobenNr]').setReadOnly(value); raimund@710: this.down('messmethode[name=mmtId]').setReadOnly(value); dustin@694: this.down('datetime[name=messzeitpunkt]').setReadOnly(value); dustin@694: this.down('numberfield[name=messdauer]').setReadOnly(value); dustin@985: this.down('chkbox[name=fertig]').setReadOnly(value); dustin@581: } dustin@581: });