# HG changeset patch # User Raimund Renkert # Date 1477493366 -7200 # Node ID 746915a63a1103903e3841dc86473fc552ac47c1 # Parent 4270da0f7d3b4fc573649f39b6a9b67380566627 Updated import response window. * Show only a summary of errors and warnings * Prepare response for html fiel download diff -r 4270da0f7d3b -r 746915a63a11 app/view/window/ImportResponse.js --- a/app/view/window/ImportResponse.js Fri Oct 14 18:34:19 2016 +0200 +++ b/app/view/window/ImportResponse.js Wed Oct 26 16:49:26 2016 +0200 @@ -17,8 +17,10 @@ initComponent: function() { var me = this; var html; + var download; + var i18n = Lada.getApplication().bundle; if (me.data && me.message) { - html = me.parseResponse(me.message, me.data); + html = me.parseShortResponse(me.message, me.data); } this.bodyStyle = {background: '#fff'}; me.items = [{ @@ -28,7 +30,78 @@ border: false }]; + me.buttons = [{ + text: i18n.getMsg('close'), + scope: this, + name: 'close', + handler: this.close + }, { + text: i18n.getMsg('download'), + name: 'download', + disabled: true, + handler: function() { + var blob = new Blob([download],{type: 'text/html'}); + saveAs(blob, 'report.html'); + } + }]; this.callParent(arguments); + download = me.parseResponse(me.message, me.data); + }, + + /** + * Parse the response and create a summary of the result + * @param msg + * @param data + */ + parseShortResponse: function(msg, 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.isObject(errors)) { + numErrors = 0; + } + else { + numErrors = Object.keys(errors).length; + } + if (!Ext.isObject(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(numErrors + ' Probe(n) konnten nicht erfolgreich ' + + 'importiert werden.'); + out.push('
'); + out.push('
'); + } + if (numWarnings > 0) { + out.push('Bei ' + numWarnings + ' Probe(n) traten Warnungen auf. '); + out.push('
'); + out.push('
'); + } + if (numErrors > 0 || numWarnings > 0) { + out.push('Der ausführliche Bericht steht als Download bereit.'); + out.push('
'); + } + else { + out.push('Die Proben wurden importiert.'); + out.push('
'); + } + } + return out.join(''); }, /** @@ -47,13 +120,13 @@ var numErrors; var numWarnings; - if (Ext.isEmpty(Object.keys(errors))) { + if (!Ext.isObject(errors)) { numErrors = 0; } else { numErrors = Object.keys(errors).length; } - if (Ext.isEmpty(Object.keys(warnings))) { + if (!Ext.isObject(warnings)) { numWarnings = 0; } else { @@ -75,26 +148,23 @@ out.push('
  • Probe: ' + key); msgs = errors[key]; out.push('
      '); + validation = [] + validation.push('Validierungsfehler: '); 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('
      '); + validation.push('
        '); + validation.push(Lada.getApplication().bundle.getMsg(msgs[i].value) + ' (' + Lada.getApplication().bundle.getMsg(msgs[i].code.toString()) + ')'); + validation.push('
      '); } else { - out.push(msgs[i].key + - ' (' + Lada.getApplication().bundle.getMsg( - msgs[i].code.toString()) + - '): ' + msgs[i].value); + out.push('
    1. ' + msgs[i].key + ' (' + Lada.getApplication().bundle.getMsg(msgs[i].code.toString())+'): '+msgs[i].value+'
    2. ') } } + if (validation.length > 1) { + out.push('
    3. ') + out.push(validation.join('')); + out.push('
    4. ') + } out.push('
    '); out.push('
  • '); } @@ -110,29 +180,32 @@ out.push('
  • ' + key); msgs = warnings[key]; out.push('
      '); + validation = [] + validation.push('Validierungswarnungen: '); 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('
      '); + validation.push('
        '); + validation.push(Lada.getApplication().bundle.getMsg(msgs[i].value) + ' (' + Lada.getApplication().bundle.getMsg(msgs[i].code.toString()) + ')'); + validation.push('
      '); } else { out.push('
    1. ' + msgs[i].key + ' (' + Lada.getApplication().bundle.getMsg(msgs[i].code.toString())+'): '+msgs[i].value+'
    2. ') } } + if (validation.length > 1) { + out.push('
    3. ') + out.push(validation.join('')); + out.push('
    4. ') + } out.push('
    '); out.push('
  • '); } out.push(''); } out.push('
    '); + if (numWarnings > 0 || numErrors > 0) { + this.down('button[name=download]').enable(); + } } console.log(out.join('')); return out.join('');