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: raimund@548: /* raimund@548: * Window to edit a Probe raimund@548: */ raimund@548: Ext.define('Lada.view.window.ProbeEdit', { raimund@548: extend: 'Ext.window.Window', raimund@548: alias: 'widget.probenedit', raimund@548: raimund@548: requires: [ raimund@548: 'Lada.view.form.Probe', raimund@548: 'Lada.view.grid.Ort', raimund@548: 'Lada.view.grid.Probenzusatzwert', dustin@561: 'Lada.view.grid.PKommentar', dustin@561: 'Lada.view.grid.Messungen' raimund@548: ], raimund@548: raimund@548: collapsible: true, raimund@548: maximizable: true, raimund@548: autoShow: true, raimund@548: autoScroll: true, raimund@548: layout: 'fit', raimund@548: raimund@548: record: null, raimund@548: raimund@548: initComponent: function() { raimund@548: if (this.record === null) { raimund@548: Ext.Msg.alert('Keine valide Probe ausgewählt!'); raimund@548: this.callParent(arguments); raimund@548: return; raimund@548: } raimund@548: this.title = '§3-Probe ' + this.record.get('probeId'); raimund@548: this.buttons = [{ raimund@548: text: 'Schließen', raimund@548: scope: this, raimund@548: handler: this.close raimund@548: }]; raimund@548: this.width = 700; raimund@548: this.height = Ext.getBody().getViewSize().height - 30; raimund@548: // InitialConfig is the config object passed to the constructor on raimund@548: // creation of this window. We need to pass it throuh to the form as raimund@548: // we need the "modelId" param to load the correct item. raimund@548: raimund@548: this.items = [{ raimund@548: border: 0, raimund@548: autoScroll: true, raimund@548: items: [{ raimund@548: xtype: 'probeform', raimund@548: recordId: this.record.get('id') raimund@548: }, { raimund@548: xtype: 'fset', raimund@548: name: 'orte', raimund@548: title: 'Ortsangaben', raimund@548: padding: '5, 5', raimund@548: margin: 5, raimund@548: items: [{ raimund@548: xtype: 'ortgrid', raimund@548: recordId: this.record.get('id') raimund@548: }] raimund@548: }, { raimund@548: xtype: 'fset', raimund@548: name: 'probenzusaetzwerte', raimund@548: title: 'Zusatzwerte', raimund@548: padding: '5, 5', raimund@548: margin: 5, raimund@548: collapsible: true, raimund@548: collapsed: true, raimund@548: items: [{ raimund@548: xtype: 'probenzusatzwertgrid', raimund@548: recordId: this.record.get('id') raimund@548: }] raimund@548: }, { raimund@548: xtype: 'fset', raimund@548: name: 'pkommentare', raimund@548: title: 'Kommentare', raimund@548: padding: '5, 5', raimund@548: margin: 5, raimund@548: collapsible: true, raimund@548: collapsed: true, raimund@548: items: [{ raimund@548: xtype: 'pkommentargrid', raimund@548: recordId: this.record.get('id') raimund@548: }] dustin@561: }, { dustin@561: xtype: 'fset', dustin@561: name: 'messungen', dustin@561: title: 'Messungen', dustin@561: padding: '5, 5', dustin@561: margin: 5, dustin@561: collapsible: false, dustin@561: collapsed: false, dustin@561: items: [{ dustin@561: xtype: 'messungengrid', dustin@561: recordId: this.record.get('id') dustin@561: }] raimund@548: }] raimund@548: }]; raimund@548: this.callParent(arguments); raimund@548: }, raimund@548: raimund@548: initData: function() { raimund@548: this.clearMessages(); raimund@548: Ext.ClassManager.get('Lada.model.Probe').load(this.record.get('id'), { raimund@548: failure: function(record, action) { raimund@548: // TODO raimund@548: }, raimund@548: success: function(record, response) { raimund@548: this.down('probeform').setRecord(record); raimund@548: var json = Ext.decode(response.response.responseText); raimund@548: if (json) { raimund@548: this.setMessages(json.errors, json.warnings); raimund@548: } raimund@548: }, raimund@548: scope: this raimund@548: }); raimund@548: }, raimund@548: raimund@548: setMessages: function(errors, warnings) { raimund@548: this.down('probeform').setMessages(errors, warnings); raimund@548: var errorOrtText = ''; raimund@548: var errorOrt = false; raimund@548: var warningOrtText = ''; raimund@548: var warningOrt = false; raimund@548: var key; raimund@548: var content; raimund@548: var i; raimund@548: var keyText; raimund@548: var i18n = Lada.getApplication().bundle; raimund@548: for (key in errors) { raimund@582: if (key && key.indexOf('Ort') > -1) { raimund@548: errorOrt = true; raimund@548: content = errors[key]; raimund@557: keyText = i18n.getMsg(key); raimund@548: for (i = 0; i < content.length; i++) { raimund@548: errorOrtText += keyText + ': ' + raimund@548: i18n.getMsg(content[i].toString()) + '\n'; raimund@548: } raimund@548: } raimund@548: } raimund@548: for (key in warnings) { raimund@582: if (key && key.indexOf('Ort') > -1) { raimund@548: warningOrt = true; raimund@548: content = warnings[key]; raimund@557: keyText = i18n.getMsg(key); raimund@548: for (i = 0; i < content.length; i++) { raimund@548: warningOrtText += keyText + ': ' + raimund@548: i18n.getMsg(content[i].toString()) + '\n'; raimund@548: } raimund@548: } raimund@548: } raimund@548: this.down('fset[name=orte]').showWarningOrError( raimund@548: warningOrt, raimund@548: warningOrtText === '' ? null : warningOrtText, raimund@548: errorOrt, raimund@548: errorOrtText === '' ? null : errorOrtText); raimund@548: }, raimund@548: raimund@548: clearMessages: function() { raimund@548: this.down('probeform').clearMessages(); raimund@548: this.down('fset[name=orte]').clearMessages(); raimund@548: } raimund@548: });