dustin@760: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz dustin@760: * Software engineering by Intevation GmbH dustin@760: * dustin@760: * This file is Free Software under the GNU GPL (v>=3) dustin@760: * and comes with ABSOLUTELY NO WARRANTY! Check out dustin@760: * the documentation coming with IMIS-Labordaten-Application for details. dustin@760: */ dustin@760: dustin@891: /** dustin@760: * Window to generate Proben from a Messprogramm dustin@760: */ dustin@760: Ext.define('Lada.view.window.GenProbenFromMessprogramm', { dustin@760: extend: 'Ext.window.Window', dustin@760: alias: 'widget.genpfm', dustin@760: tom@1195: requires: [ tom@1195: 'Lada.store.Proben' tom@1195: ], tom@1195: dustin@760: collapsible: true, dustin@760: maximizable: true, dustin@760: autoShow: true, dustin@760: autoScroll: true, dustin@760: layout: 'fit', dustin@760: constrain: true, dustin@760: dustin@760: record: null, dustin@818: parentWindow: null, dustin@760: dustin@890: /** dustin@890: * This function initialises the Window dustin@890: */ dustin@760: initComponent: function() { dustin@760: var i18n = Lada.getApplication().bundle; dustin@760: dustin@818: // add listeners to change the window appearence when it becomes inactive dustin@818: this.on({ dustin@818: activate: function(){ dustin@818: this.getEl().removeCls('window-inactive'); dustin@818: }, dustin@818: deactivate: function(){ dustin@818: this.getEl().addCls('window-inactive'); dustin@818: } dustin@818: }); dustin@818: dustin@760: this.title = i18n.getMsg('gpfm.window.title'); dustin@760: var me = this; dustin@760: this.buttons = [{ dustin@760: text: i18n.getMsg('cancel'), dustin@760: scope: this, dustin@760: handler: this.close dustin@760: }, { dustin@760: text: i18n.getMsg('generateproben'), dustin@760: handler: function() { tom@1208: me.setLoading(true); raimund@1191: var startDate = new Date(me.down('datefield[name=start]').getValue()); raimund@1191: var startUTC = Date.UTC( raimund@1191: startDate.getFullYear(), startDate.getMonth(), startDate.getDate()); raimund@1191: var endDate = new Date(me.down('datefield[name=end]').getValue()); raimund@1191: var endUTC = Date.UTC( raimund@1191: endDate.getFullYear(), endDate.getMonth(), endDate.getDate()); dustin@760: var jsondata = { dustin@760: id: me.record.id, raimund@1191: start: startUTC, raimund@1191: end: endUTC dustin@760: }; dustin@760: dustin@760: Ext.Ajax.request({ dustin@999: url: 'lada-server/rest/probe/messprogramm', dustin@760: method: 'POST', raimund@1245: timeout: 2 * 60 * 1000, dustin@760: jsonData: jsondata, tom@1204: success: me.onSuccess, tom@1204: failure: me.onFailure, dustin@760: }); dustin@760: } dustin@760: }]; dustin@834: this.width = 350; dustin@834: this.height = 250; dustin@760: dustin@760: // add listeners to change the window appearence when it becomes inactive dustin@760: this.on({ dustin@760: activate: function(){ dustin@760: this.getEl().removeCls('window-inactive'); dustin@760: }, dustin@760: deactivate: function(){ dustin@760: this.getEl().addCls('window-inactive'); dustin@818: }, dustin@818: close: function () { dustin@860: if (this.parentWindow) { dustin@860: this.parentWindow.probenWindow = null; dustin@860: } dustin@760: } dustin@760: }); dustin@760: dustin@760: // InitialConfig is the config object passed to the constructor on dustin@760: // creation of this window. We need to pass it throuh to the form as dustin@760: // we need the "Id" param to load the correct item. dustin@760: this.items = [{ dustin@760: border: 0, dustin@760: autoScroll: true, dustin@760: items: [{ dustin@807: xtype: 'panel', dustin@807: border: 0, dustin@807: margin: 5, dustin@807: layout: 'fit', dustin@807: html: '
'
dustin@807: + i18n.getMsg('nameofmessprogramm')
dustin@807: + '
'
dustin@807: + this.record.get('name')
dustin@807: + '
' + i18n.getMsg('messprogtimeperiod') + '
' dustin@760: }, { mstanko@1105: xtype: 'datefield', dustin@760: fieldLabel: i18n.getMsg('from'), dustin@760: labelWidth: 90, dustin@807: margin: 5, mstanko@1105: width: 200, dustin@760: name: 'start', mstanko@1105: format: 'd.m.Y', dustin@760: period: 'start' dustin@760: }, { mstanko@1105: xtype: 'datefield', dustin@760: fieldLabel: i18n.getMsg('to'), dustin@760: labelWidth: 90, dustin@807: margin: 5, mstanko@1105: width: 200, dustin@760: name: 'end', mstanko@1105: format: 'd.m.Y', dustin@760: period: 'end' dustin@760: }] dustin@760: }]; dustin@760: this.callParent(arguments); dustin@760: }, dustin@760: dustin@760: /** tom@1204: * Callback on success of request (HTTP status 200) tom@1204: */ tom@1204: onSuccess: function(response) { tom@1204: var i18n = Lada.getApplication().bundle; tom@1204: tom@1204: var json = Ext.JSON.decode(response.responseText); tom@1204: tom@1205: if (json.message != '200') { tom@1205: // handle LADA server errors tom@1205: Ext.Msg.alert(i18n.getMsg('err.msg.generic.title'), tom@1205: i18n.getMsg(json.message)); tom@1209: me.setLoading(false); tom@1205: } else { tom@1205: var radio = Ext.ComponentQuery.query('modeswitcher')[0] tom@1205: .down('radiofield[inputValue=proben]'); tom@1205: radio.setValue(true); tom@1205: tom@1205: var contentPanel = Ext.ComponentQuery.query('panel[name=main]')[0] tom@1205: .down('panel[name=contentpanel]'); tom@1205: contentPanel.removeAll(); //clear panel: make space for new grids tom@1205: var gridstore = Ext.create('Lada.store.Proben'); tom@1205: var frgrid = Ext.create('Lada.view.grid.ProbeList', { tom@1205: plugins: [{ tom@1205: ptype: 'gridrowexpander', tom@1205: gridType: 'Lada.view.grid.Messung', tom@1205: expandOnDblClick: false, tom@1205: gridConfig: { tom@1205: bottomBar: false tom@1205: } tom@1205: }] tom@1205: }); tom@1205: tom@1205: var columns = [{ tom@1205: header: i18n.getMsg('prnId'), tom@1233: dataIndex: 'idAlt' tom@1205: }, { tom@1205: header: i18n.getMsg('mstId'), tom@1205: dataIndex: 'mstId', tom@1205: renderer: function(value) { tom@1205: var r = ''; tom@1205: if (!value || value === '') { tom@1205: r = 'Error'; tom@1205: } tom@1205: var store = Ext.data.StoreManager.get('messstellen'); tom@1205: var record = store.getById(value); tom@1205: if (record) { tom@1205: r = record.get('messStelle'); tom@1205: } tom@1205: return r; tom@1204: } tom@1205: }, { tom@1205: header: i18n.getMsg('datenbasisId'), tom@1205: dataIndex: 'datenbasisId', tom@1205: renderer: function(value) { tom@1205: var r = ''; tom@1205: if (!value || value === '') { tom@1205: r = value; tom@1205: } tom@1205: var store = Ext.data.StoreManager.get('datenbasis'); tom@1205: var record = store.getById(value); tom@1205: if (record) { tom@1205: r = record.get('datenbasis'); tom@1205: } tom@1205: return r; tom@1204: } tom@1205: }, { tom@1205: header: i18n.getMsg('baId'), tom@1205: dataIndex: 'baId', tom@1205: renderer: function(value) { tom@1205: var r = ''; tom@1205: var store = Ext.create('Ext.data.Store', { tom@1232: fields: ['id', 'betriebsart'], tom@1205: data: [{ tom@1232: 'id': 1, tom@1205: 'betriebsart': 'Normal-/Routinebetrieb' tom@1205: }, { tom@1232: 'id': 2, tom@1205: 'betriebsart': 'Störfall/Intensivbetrieb' tom@1205: }] tom@1205: }); tom@1205: var record = store.getById(value); tom@1205: if (record) { tom@1205: r = record.get('betriebsart'); tom@1205: } tom@1205: return r; tom@1204: } tom@1205: }, { tom@1205: header: i18n.getMsg('probenartId'), tom@1205: dataIndex: 'probenartId', tom@1205: renderer: function(value) { tom@1205: var r = ''; tom@1205: if (!value || value === '') { tom@1205: r = value; tom@1205: } tom@1205: var store = Ext.data.StoreManager.get('probenarten'); tom@1205: var record = store.getById(value); tom@1205: if (record) { tom@1205: r = record.get('probenart'); tom@1205: } tom@1205: return r; tom@1205: } tom@1205: }, { tom@1205: header: i18n.getMsg('sollVon'), tom@1205: dataIndex: 'solldatumBeginn', tom@1205: renderer: function(value) { tom@1205: if (!value) { tom@1205: return ''; tom@1205: } tom@1205: return Ext.Date.format(value, 'd.m.Y'); tom@1205: } tom@1205: }, { tom@1205: header: i18n.getMsg('sollBis'), tom@1205: dataIndex: 'solldatumEnde', tom@1205: renderer: function(value) { tom@1205: if (!value) { tom@1205: return ''; tom@1205: } tom@1205: return Ext.Date.format(value, 'd.m.Y'); tom@1205: } tom@1205: }]; tom@1205: frgrid.reconfigure(gridstore, columns); tom@1204: tom@1205: gridstore.loadData(json.data); tom@1205: contentPanel.add(frgrid); tom@1205: Ext.Msg.show({ tom@1205: title: i18n.getMsg('success'), tom@1205: autoScroll: true, tom@1205: msg: me.evalResponse(json), tom@1205: buttons: Ext.Msg.OK tom@1205: }); tom@1205: me.close(); tom@1205: } tom@1204: }, tom@1204: tom@1204: /** tom@1204: * Callback on failure of request (HTTP status != 200) tom@1204: */ tom@1204: onFailure: function(response) { tom@1208: me.setLoading(false); tom@1208: tom@1204: var i18n = Lada.getApplication().bundle; tom@1204: tom@1204: var json = null; tom@1204: try { tom@1204: json = Ext.JSON.decode(response.responseText); tom@1204: } tom@1204: catch(err){ tom@1204: Ext.Msg.alert(i18n.getMsg('err.msg.generic.title'), tom@1204: i18n.getMsg('err.msg.response.body')); tom@1204: } tom@1204: if (json) { tom@1204: if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){ tom@1204: formPanel.setMessages(json.errors, json.warnings); tom@1204: } tom@1204: /* tom@1204: SSO will send a 302 if the Client is not authenticated tom@1204: unfortunately this seems to be filtered by the browser. tom@1204: We assume that a 302 was send when the follwing statement tom@1204: is true. tom@1204: */ tom@1204: if (response.status == 0 && response.responseText === "") { tom@1204: Ext.MessageBox.confirm( tom@1204: 'Erneutes Login erforderlich', tom@1204: 'Ihre Session ist abgelaufen.