dustin@759: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz dustin@759: * Software engineering by Intevation GmbH dustin@759: * dustin@759: * This file is Free Software under the GNU GPL (v>=3) dustin@759: * and comes with ABSOLUTELY NO WARRANTY! Check out dustin@759: * the documentation coming with IMIS-Labordaten-Application for details. dustin@759: */ dustin@759: dustin@891: /** dustin@759: * Window to edit a Messprogramm dustin@759: */ dustin@759: Ext.define('Lada.view.window.Messprogramm', { dustin@759: extend: 'Ext.window.Window', dustin@759: alias: 'widget.messprogramm', dustin@759: dustin@759: requires: [ dustin@759: 'Lada.view.form.Messprogramm', dustin@759: 'Lada.view.grid.Messmethoden', dustin@764: 'Lada.view.grid.Nuklide' dustin@759: ], dustin@759: dustin@759: collapsible: true, dustin@759: maximizable: true, dustin@759: autoShow: true, dustin@759: autoScroll: true, dustin@759: layout: 'fit', dustin@759: constrain: true, dustin@818: probenWindow: null, dustin@759: dustin@759: record: null, dustin@759: dustin@890: /** dustin@890: * This function initialises the Window dustin@890: */ dustin@759: initComponent: function() { dustin@759: var i18n = Lada.getApplication().bundle; raimund@859: var me = this; dustin@759: dustin@759: if (this.record == null) { dustin@759: this.title = i18n.getMsg('messprogramm.window.create.title'); dustin@759: } dustin@759: else { dustin@759: this.title = i18n.getMsg('messprogramm.window.edit.title'); dustin@759: } dustin@759: this.buttons = [{ dustin@760: text: i18n.getMsg('generateproben'), dustin@760: scope: this, dustin@760: disabled: this.record? false : true, //disable button if no record is set. dustin@760: handler: function() { dustin@818: //Make the Window a "singleton" dustin@818: if (! this.probenWindow) { dustin@818: var winname = 'Lada.view.window.GenProbenFromMessprogramm'; dustin@818: var win = Ext.create(winname, { dustin@818: record: this.record, dustin@818: parentWindow: this dustin@818: }); dustin@818: win.show(); dustin@818: win.initData(); dustin@818: this.probenWindow = win; dustin@818: } dustin@818: else { dustin@818: this.probenWindow.focus(); dustin@818: this.probenWindow.setActive(true); dustin@818: } raimund@859: me.close(); dustin@760: } dustin@760: }, dustin@760: '->', dustin@760: { dustin@759: text: i18n.getMsg('close'), dustin@759: scope: this, dustin@759: handler: this.close dustin@759: }]; dustin@759: this.width = 700; dustin@759: dustin@759: // add listeners to change the window appearence when it becomes inactive dustin@759: this.on({ dustin@759: activate: function(){ dustin@759: this.getEl().removeCls('window-inactive'); dustin@759: }, dustin@759: deactivate: function(){ dustin@759: this.getEl().addCls('window-inactive'); dustin@759: } dustin@759: }); dustin@759: dustin@759: this.height = Ext.getBody().getViewSize().height - 30; dustin@759: // InitialConfig is the config object passed to the constructor on dustin@759: // creation of this window. We need to pass it throuh to the form as dustin@759: // we need the "Id" param to load the correct item. dustin@759: this.items = [{ dustin@759: border: 0, dustin@759: autoScroll: true, dustin@759: items: [{ dustin@759: xtype: 'messprogrammform', raimund@773: recordId: this.record ? this.record.get('id') : null dustin@759: }, { mkrambach@1289: xtype: 'fset', mkrambach@1289: name: 'orte', mkrambach@1289: title: 'Ortsangaben', mkrambach@1289: padding: '5, 5', mkrambach@1289: margin: 5, mkrambach@1289: items: [{ mkrambach@1289: xtype: 'ortszuordnunggrid', mkrambach@1339: recordId: me.record ? me.record.get('id') : null, mkrambach@1339: isMessprogramm: true mkrambach@1289: }] mkrambach@1289: }, { dustin@759: //Messmethoden dustin@759: xtype: 'fieldset', raimund@772: padding: '5, 5', dustin@759: title: i18n.getMsg('mmtmessprogramm.form.fieldset.title'), dustin@759: margin: 5, dustin@759: layout: { raimund@772: type: 'column' dustin@759: }, dustin@759: items: [{ dustin@759: xtype: 'messmethodengrid', raimund@772: columnWidth: 0.5, raimund@773: recordId: this.record ? this.record.get('id') : null, dustin@759: flex: 1 dustin@764: }, { dustin@764: xtype: 'nuklidegrid', raimund@772: columnWidth: 0.5, raimund@773: recordId: this.record ? this.record.get('id') : null, dustin@764: flex: 1 dustin@759: }] dustin@759: }] dustin@759: }]; dustin@759: this.callParent(arguments); dustin@759: }, dustin@759: dustin@759: /** dustin@759: * Init Data is longer than in other windows. dustin@759: * If the Window was used to CREATE a Messprogramm, dustin@759: * it will load an empty record dustin@759: * if it was used to EDIT an existing Messprogramm, dustin@759: * it will load this record AND create a grid to dustin@759: * enable the editing of Messmethoden dustin@759: * which are associated to the Messprogramm dustin@759: */ dustin@759: initData: function() { dustin@759: var i18n = Lada.getApplication().bundle; dustin@759: this.clearMessages(); dustin@759: me = this; dustin@759: dustin@759: // If a record was passed to this window, dustin@759: // create a Edit window dustin@759: if (this.record) { dustin@759: this.setLoading(true); dustin@762: this.down('messmethodengrid').setReadOnly(false); dustin@759: Ext.ClassManager.get('Lada.model.Messprogramm').load(this.record.get('id'), { dustin@759: failure: function(record, action) { dustin@759: me.setLoading(false); dustin@759: // TODO dustin@759: console.log('An unhandled Failure occured. See following Response and Record'); dustin@759: console.log(action); dustin@759: console.log(record); dustin@759: }, dustin@759: success: function(record, response) { dustin@759: this.down('messprogrammform').setRecord(record); dustin@759: this.record = record; dustin@759: dustin@759: var json = Ext.decode(response.response.responseText); dustin@759: if (json) { dustin@759: this.setMessages(json.errors, json.warnings); raimund@784: if (!json.warnings.mediaDesk) { raimund@784: this.down('messprogrammform').setMediaDesk(record); raimund@784: } dustin@759: } dustin@759: // If the Messprogramm is ReadOnly, disable Inputfields and grids dustin@759: if (this.record.get('readonly') === true) { dustin@759: this.down('messprogrammform').setReadOnly(true); mkrambach@1289: this.disableChildren(); dustin@759: } dustin@759: else { dustin@759: this.down('messprogrammform').setReadOnly(false); mkrambach@1289: this.enableChildren(); dustin@759: } dustin@759: me.setLoading(false); dustin@759: }, dustin@759: scope: this dustin@759: }); dustin@759: } dustin@759: // Create a Create Window dustin@759: else { dustin@759: var record = Ext.create('Lada.model.Messprogramm'); dustin@762: this.down('messmethodengrid').setReadOnly(true); dustin@759: this.down('messprogrammform').setRecord(record); ehuber@1255: this.down('dayofyear[name=gueltigBis]').setValue(365); ehuber@1255: this.down('dayofyear[name=gueltigVon]').setValue(1); dustin@759: } tom@1212: this.down('messprogrammform').isValid(); dustin@759: }, dustin@759: dustin@759: //This was used in a Probewindow, I left it here for reference... dustin@759: /* dustin@759: enableAddMessungen: function() { dustin@759: this.down('fset[name=messungen]').down('messunggrid').setReadOnly(false); dustin@759: }, dustin@759: */ dustin@759: dustin@759: disableChildren: function() { mkrambach@1289: this.down('fset[name=orte]').down('ortszuordnunggrid').setReadOnly(true); dustin@759: }, dustin@759: dustin@759: enableChildren: function() { mkrambach@1289: this.down('fset[name=orte]').down('ortszuordnunggrid').setReadOnly(false); dustin@759: }, dustin@759: dustin@890: /** dustin@890: * Instructs the fields / forms listed in this method to set a message. dustin@890: * @param errors These Errors shall be shown dustin@890: * @param warnings These Warning shall be shown dustin@890: */ dustin@759: setMessages: function(errors, warnings) { dustin@759: this.down('messprogrammform').setMessages(errors, warnings); dustin@759: }, dustin@759: dustin@890: /** dustin@890: * Instructs the fields / forms listed in this method to clear their messages. dustin@890: */ dustin@759: clearMessages: function() { dustin@759: this.down('messprogrammform').clearMessages(); dustin@759: } dustin@759: });