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:
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() {
dustin@760: var jsondata = {
dustin@760: id: me.record.id,
dustin@761: start: new Date(me.down('datetime [name=start]').getValue()).valueOf(),
dustin@761: end: new Date(me.down('datetime [name=end]').getValue()).valueOf()
dustin@760: };
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);
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: }, { dustin@760: xtype: 'datetime', dustin@760: fieldLabel: i18n.getMsg('from'), dustin@760: labelWidth: 90, dustin@807: margin: 5, dustin@834: width: 300, dustin@760: name: 'start', dustin@760: format: 'd.m.Y H:i', dustin@760: period: 'start' dustin@760: }, { dustin@760: xtype: 'datetime', dustin@760: fieldLabel: i18n.getMsg('to'), dustin@760: labelWidth: 90, dustin@807: margin: 5, dustin@834: width: 300, dustin@760: name: 'end', dustin@760: format: 'd.m.Y H:i', 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 += '