torsten@293: /** torsten@293: * Controller for Proben torsten@293: */ torsten@379: torsten@379: function buildImportReport(filename, msg, errors, warnings) { torsten@379: var out = Array(); torsten@379: if (msg != 200) { torsten@379: out.push("Der Import der Datei " + filename + " war nicht erfolgreich."); torsten@379: } else { torsten@379: out.push("Der Import der Datei " + filename + " war erfolgreich."); torsten@379: } torsten@397: out.push("Bei dem Import sind folgende Fehler und Warnungen aufgetreten"); torsten@397: out.push("
"); torsten@397: out.push("Fehler:"); torsten@397: out.push("
"); torsten@397: if (errors) { torsten@397: out.push("
    "); torsten@397: for (var key in errors) { torsten@397: out.push("
  1. "+key) torsten@397: var msgs = errors[key]; torsten@397: out.push("
      "); torsten@397: for (var i = msgs.length - 1; i >= 0; i--){ torsten@397: out.push("
    1. "+msgs[i].key+" ("+msgs[i].code+"): "+msgs[i].value+"
    2. ") torsten@397: }; torsten@397: out.push("
    "); torsten@397: out.push("
  2. "); torsten@397: } torsten@397: out.push("
"); torsten@397: } else { torsten@397: out.push("Keine Fehler"); torsten@397: out.push("
"); torsten@397: } torsten@397: out.push("Warnungen:"); torsten@397: out.push("
"); torsten@397: if (warnings) { torsten@397: out.push("
    "); torsten@397: for (var key in warnings) { torsten@397: out.push("
  1. "+key) torsten@397: var msgs = warnings[key]; torsten@397: out.push("
      "); torsten@397: for (var i = msgs.length - 1; i >= 0; i--){ torsten@397: out.push("
    1. "+msgs[i].key+" ("+msgs[i].code+"): "+msgs[i].value+"
    2. ") torsten@397: }; torsten@397: out.push("
    "); torsten@397: out.push("
  2. "); torsten@397: } torsten@397: out.push("
"); torsten@397: } else { torsten@397: out.push("Keine Warnungen"); torsten@397: out.push("
"); torsten@397: } torsten@379: return out.join(""); torsten@379: } torsten@379: torsten@1: Ext.define('Lada.controller.Proben', { torsten@293: extend: 'Lada.controller.Base', torsten@4: views: [ torsten@65: 'proben.Edit', torsten@357: 'proben.Create', torsten@357: 'proben.Import' torsten@4: ], torsten@13: stores: [ torsten@122: 'Proben', torsten@135: 'Zusatzwerte', torsten@144: 'Probenzusatzwerte', torsten@149: 'Kommentare', torsten@157: 'Orte', torsten@157: 'Messungen' torsten@13: ], torsten@1: init: function() { torsten@1: console.log('Initialising the Proben controller'); torsten@293: this.callParent(); torsten@293: }, torsten@293: addListeners: function() { torsten@1: this.control({ torsten@18: 'probenlist': { torsten@293: itemdblclick: this.editItem torsten@18: }, torsten@64: 'probenlist toolbar button[action=add]': { torsten@293: click: this.addItem torsten@64: }, torsten@357: 'probenlist toolbar button[action=import]': { torsten@357: click: this.selectUploadFile torsten@357: }, torsten@381: 'probenlist toolbar button[action=export]': { torsten@381: click: this.downloadFile torsten@381: }, torsten@270: 'probencreate button[action=save]': { torsten@293: click: this.saveItem torsten@270: }, torsten@270: 'probenedit button[action=save]': { torsten@293: click: this.saveItem torsten@270: }, torsten@357: 'probenimport button[action=save]': { torsten@357: click: this.uploadItem torsten@357: }, torsten@70: 'probencreate form': { torsten@70: savesuccess: this.createSuccess, torsten@70: savefailure: this.createFailure torsten@70: }, torsten@70: 'probenedit form': { torsten@70: savesuccess: this.editSuccess, torsten@70: savefailure: this.editFailure torsten@1: } torsten@1: }); torsten@1: }, torsten@293: addItem: function(button) { torsten@71: console.log('Adding new Probe'); torsten@65: var view = Ext.widget('probencreate'); torsten@64: }, torsten@357: /** torsten@357: * Opens a window with a file chooser to select the file to upload torsten@357: * @private torsten@357: */ torsten@357: selectUploadFile: function(button) { torsten@357: console.log('Importing'); torsten@357: var view = Ext.widget('probenimport'); torsten@357: }, torsten@357: /** Uploads the selected file the the server torsten@357: * @private torsten@357: */ torsten@357: uploadItem: function(button) { torsten@357: var win = button.up('window'); torsten@357: var form = win.down('form'); torsten@357: if(form.isValid()){ torsten@357: form.submit({ rrenkert@376: url: 'server/rest/import/laf', torsten@357: waitMsg: 'Importiere...', torsten@357: // TODO: Handle the response correct. o must must contain the torsten@357: // filename (None) <2013-08-13 16:17> torsten@357: success: function(fp, resp) { torsten@397: var errors = resp.result.data.errors; torsten@397: var warnings = resp.result.data.warnings; torsten@397: var filename = resp.result.data.filename; torsten@397: var message = resp.result.message; torsten@397: var dialogbody = buildImportReport(filename, message, errors, warnings) torsten@397: var filename = resp.result.data.filename; torsten@397: Ext.Msg.alert('Erfolg', dialogbody); torsten@357: win.close(); torsten@357: }, torsten@357: failure: function(fp, resp) { torsten@382: var errors = resp.result.data.errors; torsten@382: var warnings = resp.result.data.warnings; torsten@382: var filename = resp.result.data.filename; torsten@382: var message = resp.result.message; torsten@382: var dialogbody = buildImportReport(filename, message, errors, warnings) torsten@379: Ext.Msg.alert('Fehler', dialogbody); torsten@357: win.close(); torsten@357: } torsten@357: }); torsten@357: } torsten@357: }, torsten@381: /** torsten@381: * Will download the selected Probe in LAF format in a new window (tab). torsten@381: */ torsten@381: downloadFile: function(button) { torsten@381: var grid = button.up('grid'); torsten@381: var selection = grid.getView().getSelectionModel().getSelection()[0]; torsten@381: var url = "server/rest/export/laf/" + selection.get('probeId'); torsten@381: window.open(url, "_blank"); torsten@381: }, torsten@293: editItem: function(grid, record) { torsten@71: console.log('Editing Probe'); torsten@71: var id = record.get('probeId'); torsten@122: // Load Zusatzwerte torsten@135: var pstore = this.getProbenzusatzwerteStore(); torsten@135: pstore.load(); torsten@122: var zstore = this.getZusatzwerteStore(); torsten@122: zstore.load({ torsten@122: params: { torsten@139: probeId: id torsten@122: } torsten@122: }); torsten@149: // Load Kommentare torsten@144: var kstore = this.getKommentareStore(); torsten@144: kstore.load({ torsten@144: params: { torsten@144: probeId: id torsten@144: } torsten@144: }); torsten@149: // Load Orte torsten@149: var ostore = this.getOrteStore(); torsten@149: ostore.load({ torsten@149: params: { torsten@149: probeId: id torsten@149: } torsten@149: }); torsten@157: // Load Orte torsten@157: var mstore = this.getMessungenStore(); torsten@157: mstore.load({ torsten@157: params: { torsten@157: probeId: id torsten@157: } torsten@157: }); torsten@362: var view = Ext.widget('probenedit', {modelId: id}); torsten@71: console.log("Loaded Probe with ID " + record.getId()); //outputs ID torsten@18: }, torsten@255: createSuccess: function(form, record, response) { torsten@256: // Close Createdialog torsten@69: var win = form.up('window'); torsten@18: win.close(); torsten@256: // Reload store torsten@256: var store = this.getProbenStore(); torsten@256: store.reload({ torsten@256: scope: this, torsten@256: callback: function(records, operation, success) { torsten@256: console.log('Reloaded store'); torsten@256: // Open Editdialog torsten@256: var json = Ext.decode(response.responseText); torsten@256: if (json) { torsten@256: var probeId = json.data.probeId; torsten@256: var probe = store.findRecord("probeId", probeId); torsten@293: this.editItem(null, probe); torsten@256: } torsten@256: } torsten@256: }); torsten@70: }, torsten@255: editSuccess: function(form, record, response) { torsten@86: // Reload store torsten@86: var store = this.getProbenStore(); torsten@86: store.reload(); torsten@70: var win = form.up('window'); torsten@70: win.close(); torsten@1: } torsten@1: });