# HG changeset patch # User Raimund Renkert # Date 1429269340 -7200 # Node ID 7eb8ef8e68ca787ee1210060d5b60c00787257f3 # Parent aadb6e1f0a703f67950f156be05077e12078be06 Added window to display importer messages. diff -r aadb6e1f0a70 -r 7eb8ef8e68ca app/view/window/ImportResponse.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/view/window/ImportResponse.js Fri Apr 17 13:15:40 2015 +0200 @@ -0,0 +1,135 @@ +/** + * + */ +Ext.define('Lada.view.window.ImportResponse', { + extend: 'Ext.window.Window', + alias: 'widget.importresponse', + + data: null, + message: null, + fileName: '', + + layout: 'fit', + /** + * @private + * Initialize the view. + */ + initComponent: function() { + var me = this; + var html; + if (me.data && me.message) { + html = me.parseResponse(me.message, me.data); + } + this.bodyStyle = {background: '#fff'}; + me.items = [{ + xtype: 'panel', + html: html, + margin: 10, + border: false + }]; + + this.callParent(arguments); + }, + + parseResponse: function(msg, data) { + console.log(Ext.JSON.decode(data)); + data = Ext.JSON.decode(data); + var errors = data.data.errors; + var warnings = data.data.warnings; + var out = []; + // There is a entry for each imported proben in the errors dict (might be + // empty) + + var numErrors; + var numWarnings; + if (Ext.isEmpty(Object.keys(errors))) { + numErrors = 0; + } + else { + numErrors = Object.keys(errors).length; + } + if (Ext.isEmpty(Object.keys(warnings))) { + numWarnings = 0; + } + else { + numWarnings = Object.keys(warnings).length; + } + if (msg !== '200') { + out.push('Der Import der Datei ' + this.fileName + + ' war nicht erfolgreich. Der Importvorgang konnte ' + + 'aufgrund eines Fehlers im Server nicht beendet werden.'); + } + else { + if (numErrors > 0) { + out.push('Folgende Proben konnten nicht erfolgreich ' + + 'importiert werden:'); + out.push('
'); + out.push('
    '); + var msgs; + for (var key in errors) { + out.push('
  1. Probe: ' + key); + msgs = errors[key]; + out.push('
      '); + for (var i = msgs.length - 1; i >= 0; i--) { + if (msgs[i].key === 'validation') { + out.push('Validierungsfehler: '); + out.push('
        '); + for (var vKey in msgs[i].value) { + out.push(Lada.getApplication().bundle.getMsg(vKey) + ': '); + for (var j = 0; j < msgs[i].value[vKey].length; j++) { + console.log(msgs[i].value[vKey][j]); + out.push(Lada.getApplication().bundle.getMsg(msgs[i].value[vKey][j].toString())); + } + } + out.push('
      '); + } + else { + out.push(msgs[i].key + + ' (' + Lada.getApplication().bundle.getMsg( + msgs[i].code.toString()) + + '): ' + msgs[i].value); + } + } + out.push('
    '); + out.push('
  2. '); + } + out.push('
'); + out.push('
'); + } + if (numWarnings > 0) { + out.push('
'); + out.push('Bei folgenden Proben traten Warnungen auf:'); + out.push('
'); + out.push('
    '); + for (key in warnings) { + out.push('
  1. ' + key); + msgs = warnings[key]; + out.push('
      '); + for (var i = msgs.length - 1; i >= 0; i--) { + if (msgs[i].key === 'validation') { + out.push('Validierungswarnungen: '); + out.push('
        '); + for (var vKey in msgs[i].value) { + out.push(Lada.getApplication().bundle.getMsg(vKey) + ': '); + for (var j = 0; j < msgs[i].value[vKey].length; j++) { + console.log(msgs[i].value[vKey][j]); + out.push(Lada.getApplication().bundle.getMsg(msgs[i].value[vKey][j].toString())); + } + } + out.push('
      '); + } + else { + out.push('
    1. ' + msgs[i].key + ' (' + Lada.getApplication().bundle.getMsg(msgs[i].code.toString())+'): '+msgs[i].value+'
    2. ') + } + } + out.push('
    '); + out.push('
  2. '); + } + out.push('
'); + } + out.push('
'); + } + console.log(out.join('')); + return out.join(''); + } +});