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() {
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',
dustin@760: jsonData: jsondata,
dustin@809: success: function(response) {
dustin@809: var json = Ext.JSON.decode(response.responseText);
raimund@1162: var radio = Ext.ComponentQuery.query('modeswitcher')[0].down('radiofield[inputValue=proben]');
raimund@1162: radio.setValue(true);
raimund@1162:
raimund@1162: var contentPanel = Ext.ComponentQuery.query('panel[name=main]')[0].down('panel[name=contentpanel]');
raimund@1162: contentPanel.removeAll(); //clear the panel: make space for new grids
raimund@1162: var gridstore = Ext.create('Lada.store.Proben');
raimund@1162: var frgrid = Ext.create('Lada.view.grid.ProbeList', {
raimund@1162: plugins: [{
raimund@1162: ptype: 'gridrowexpander',
raimund@1162: gridType: 'Lada.view.grid.Messung',
raimund@1162: expandOnDblClick: false,
raimund@1162: gridConfig: {
raimund@1162: bottomBar: false
raimund@1162: }
raimund@1162: }]
raimund@1162: });
raimund@1162:
raimund@1162: var columns = [{
raimund@1162: header: i18n.getMsg('prnId'),
raimund@1162: dataIndex: 'probeIdAlt'
raimund@1162: }, {
raimund@1162: header: i18n.getMsg('netzbetreiberId'),
raimund@1162: dataIndex: 'netzbetreiberId',
raimund@1162: renderer: function(value) {
raimund@1162: var r = '';
raimund@1162: if (!value || value === '') {
raimund@1162: r = 'Error';
raimund@1162: }
raimund@1162: var store = Ext.data.StoreManager.get('netzbetreiber');
raimund@1162: var record = store.getById(value);
raimund@1162: if (record) {
raimund@1162: r = record.get('netzbetreiber');
raimund@1162: }
raimund@1162: return r;
raimund@1162: }
raimund@1162: }, {
raimund@1162: header: i18n.getMsg('mstId'),
raimund@1162: dataIndex: 'mstId',
raimund@1162: renderer: function(value) {
raimund@1162: var r = '';
raimund@1162: if (!value || value === '') {
raimund@1162: r = 'Error';
raimund@1162: }
raimund@1162: var store = Ext.data.StoreManager.get('messstellen');
raimund@1162: var record = store.getById(value);
raimund@1162: if (record) {
raimund@1162: r = record.get('messStelle');
raimund@1162: }
raimund@1162: return r;
raimund@1162: }
raimund@1162: }, {
raimund@1162: header: i18n.getMsg('datenbasisId'),
raimund@1162: dataIndex: 'datenbasisId',
raimund@1162: renderer: function(value) {
raimund@1162: var r = '';
raimund@1162: if (!value || value === '') {
raimund@1162: r = value;
raimund@1162: }
raimund@1162: var store = Ext.data.StoreManager.get('datenbasis');
raimund@1162: var record = store.getById(value);
raimund@1162: if (record) {
raimund@1162: r = record.get('datenbasis');
raimund@1162: }
raimund@1162: return r;
raimund@1162: }
raimund@1162: }, {
raimund@1162: header: i18n.getMsg('baId'),
raimund@1162: dataIndex: 'baId',
raimund@1162: renderer: function(value) {
raimund@1162: var r = '';
raimund@1162: if (!value || value === '') {
raimund@1162: r = '';
raimund@1162: }
raimund@1162: var store = Ext.create('Ext.data.Store', {
raimund@1162: fields: ['betriebsartId', 'betriebsart'],
raimund@1162: data: [{
raimund@1162: 'betriebsartId': '1',
raimund@1162: 'betriebsart': 'Normal-/Routinebetrieb'
raimund@1162: }, {
raimund@1162: 'betriebsartId': '2',
raimund@1162: 'betriebsart': 'Störfall/Intensivbetrieb'
raimund@1162: }]
raimund@1162: });
raimund@1162: var record = store.getById(value);
raimund@1162: if (record) {
raimund@1162: r = record.get('betriebsart');
raimund@1162: }
raimund@1162: return r;
raimund@1162: }
raimund@1162: }, {
raimund@1162: header: i18n.getMsg('probenartId'),
raimund@1162: dataIndex: 'probenartId',
raimund@1162: renderer: function(value) {
raimund@1162: var r = '';
raimund@1162: if (!value || value === '') {
raimund@1162: r = value;
raimund@1162: }
raimund@1162: var store = Ext.data.StoreManager.get('probenarten');
raimund@1162: var record = store.getById(value);
raimund@1162: if (record) {
raimund@1162: r = record.get('probenart');
raimund@1162: }
raimund@1162: return r;
raimund@1162: }
raimund@1162: }, {
raimund@1162: header: i18n.getMsg('sollVon'),
raimund@1162: dataIndex: 'solldatumBeginn',
raimund@1162: renderer: function(value) {
raimund@1162: console.log(value);
raimund@1162: if (!value) {
raimund@1162: return '';
raimund@1162: }
raimund@1162: return Ext.Date.format(value, 'd.m.Y');
raimund@1162: }
raimund@1162: }, {
raimund@1162: header: i18n.getMsg('sollBis'),
raimund@1162: dataIndex: 'solldatumEnde',
raimund@1162: renderer: function(value) {
raimund@1162: if (!value) {
raimund@1162: return '';
raimund@1162: }
raimund@1162: return Ext.Date.format(value, 'd.m.Y');
raimund@1162: }
raimund@1162: }];
raimund@1162: frgrid.reconfigure(gridstore, columns);
raimund@1162:
raimund@1162: gridstore.loadData(json.data);
raimund@1162: contentPanel.add(frgrid);
dustin@809: Ext.Msg.show({
dustin@809: title: i18n.getMsg('success'),
dustin@809: autoScroll: true,
dustin@809: msg: me.evalResponse(json),
dustin@882: buttons: Ext.Msg.OK
dustin@809: });
raimund@859: me.close();
dustin@760: },
dustin@809: failure: function(response) {
dustin@855: var json = null;
dustin@855: try {
dustin@855: json = Ext.JSON.decode(response.responseText);
dustin@855: }
dustin@855: catch(err){
dustin@855: Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title'),
dustin@855: Lada.getApplication().bundle.getMsg('err.msg.response.body'));
dustin@855: }
dustin@809: if (json) {
dustin@809: if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){
dustin@809: formPanel.setMessages(json.errors, json.warnings);
dustin@809: }
dustin@920: /*
dustin@920: SSO will send a 302 if the Client is not authenticated
dustin@920: unfortunately this seems to be filtered by the browser.
dustin@920: We assume that a 302 was send when the follwing statement
dustin@920: is true.
dustin@920: */
dustin@920: if (response.status == 0 && response.responseText === "") {
dustin@812: Ext.MessageBox.confirm('Erneutes Login erforderlich',
dustin@920: 'Ihre Session ist abgelaufen.
'+
dustin@812: 'Für ein erneutes Login muss die Anwendung neu geladen werden.
' +
dustin@812: 'Alle ungesicherten Daten gehen dabei verloren.
' +
dustin@920: 'Soll die Anwendung jetzt neu geladen werden?', this.reload);
dustin@812: }
dustin@920: // further error handling
dustin@920: if(json.message){
dustin@812: Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title')
dustin@809: +' #'+json.message,
dustin@809: Lada.getApplication().bundle.getMsg(json.message));
dustin@809: } else {
dustin@812: Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title'),
dustin@809: Lada.getApplication().bundle.getMsg('err.msg.generic.body'));
dustin@809: }
dustin@809: } else {
dustin@812: Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title'),
dustin@809: Lada.getApplication().bundle.getMsg('err.msg.response.body'));
dustin@809: }
dustin@760: }
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: /** dustin@890: * Initiatlise the Data dustin@760: */ dustin@760: initData: function() { dustin@760: var i18n = Lada.getApplication().bundle; dustin@760: me = this; dustin@760: }, dustin@809: dustin@809: /** dustin@809: * Parse ServerResponse when Proben have been generated dustin@809: */ dustin@809: evalResponse: function(response) { dustin@809: var i18n = Lada.getApplication().bundle; dustin@809: var r = ''; dustin@812: r += response.data.length; dustin@809: r += ' ' + i18n.getMsg('probecreated'); dustin@809: r += '