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: [ 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: raimund@589: initComponent: function() { dustin@611: var me = this; 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: ['->', { 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', dustin@611: fieldLabel: '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', 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: isFormField: false, dustin@945: preventMark: true, //Do not display error msg. dustin@945: validateValue: function() { dustin@945: return true; //this field is always valid dustin@945: }, dustin@611: }] dustin@611: }] dustin@581: }]; dustin@581: this.callParent(arguments); dustin@581: }, dustin@581: raimund@589: setRecord: function(record) { dustin@581: this.getForm().loadRecord(record); dustin@945: this.retrieveStatus(record.id, record.get('status')); dustin@945: }, dustin@945: 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@945: dustin@945: textfield.setRawValue(msg); dustin@945: dustin@945: var sStore = Ext.StoreManager.lookup('Status'); dustin@945: if (!sStore) { dustin@945: sStore = Ext.create('Lada.store.Status'); dustin@945: } dustin@945: sStore.on('load', dustin@945: function(records, operation, success) { dustin@945: var ret; dustin@945: var i18n = Lada.getApplication().bundle; dustin@950: if (sStore.getTotalCount() === 0 || !statusId) { dustin@945: ret = 0; dustin@945: } dustin@945: else { dustin@945: ret = sStore.getById(statusId).get('statusWert'); dustin@945: } dustin@945: this.setStatusWert(ret); dustin@945: }, dustin@945: this); dustin@945: sStore.load({ dustin@945: params: { dustin@945: messungsId: messungsId dustin@945: } dustin@945: }); dustin@945: }, dustin@945: dustin@945: setStatusWert: function(value){ dustin@945: var swStore = Ext.StoreManager.lookup('StatusWerte'); dustin@945: if (!swStore) { dustin@945: var swStore = Ext.create('Lada.store.StatusWerte'); dustin@945: } dustin@955: swStore.load({ dustin@955: scope: this, dustin@955: callback: function(records, operation, success) { dustin@945: var i18n = Lada.getApplication().bundle; dustin@945: var msg = i18n.getMsg('load.statuswert.error'); dustin@945: var textfield = this.down('[name=status]'); dustin@945: if (success) { dustin@945: msg = swStore.getById(value).get('wert'); dustin@945: } dustin@945: textfield.setRawValue(msg); dustin@945: }, dustin@955: }); 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@715: if (!this.getForm().getRecord().get('owner')) { dustin@715: //Only set this Field to Readonly when the User is NOT the Owner of the Record. dustin@715: this.down('chkbox[name=fertig]').setReadOnly(value); dustin@715: } dustin@581: } dustin@581: });