raimund@588: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz raimund@588: * Software engineering by Intevation GmbH raimund@588: * raimund@588: * This file is Free Software under the GNU GPL (v>=3) raimund@588: * and comes with ABSOLUTELY NO WARRANTY! Check out raimund@588: * the documentation coming with IMIS-Labordaten-Application for details. raimund@588: */ raimund@588: raimund@588: /* raimund@588: * Controller for a Messungengrid raimund@588: */ raimund@588: Ext.define('Lada.controller.grid.Messung', { raimund@588: extend: 'Ext.app.Controller', raimund@588: raimund@588: requires: [ raimund@588: 'Lada.view.window.MessungEdit' raimund@588: ], raimund@588: dustin@742: /** dustin@742: * Inhitialize the controller dustin@742: * It has 3 listeners dustin@742: */ raimund@588: init: function() { raimund@588: this.control({ raimund@592: 'messunggrid': { raimund@588: itemdblclick: this.editItem raimund@588: }, raimund@592: 'messunggrid button[action=add]': { raimund@588: click: this.add raimund@588: }, raimund@592: 'messunggrid button[action=delete]': { raimund@588: click: this.remove raimund@588: } raimund@588: }); raimund@588: }, raimund@588: dustin@742: /** dustin@742: * This function opens a new {@link Lada.view.window.MessungEdit} dustin@742: * Window. dustin@742: */ raimund@588: editItem: function(grid, record) { raimund@1111: // we have a window with a probe record! raimund@1111: if (grid.up('window')) { raimund@1111: var probe = grid.up('window').record; raimund@1111: /* Only open a new Window when: raimund@1111: statusEdit = True raimund@1111: -or- raimund@1111: the value of status is not 0 raimund@1111: -or- raimund@1111: the owner = True dustin@963: raimund@1111: the statusWert attribute is not present in the original data. raimund@1111: it is appended, when the value and name of the status were raimund@1111: determined. raimund@1111: */ raimund@1111: if (record.get('statusEdit') raimund@1111: || record.get('statusWert') > 0 raimund@1111: || record.get('owner')) { raimund@1111: var win = Ext.create('Lada.view.window.MessungEdit', { raimund@1111: parentWindow: grid.up('window'), raimund@1111: probe: probe, raimund@1111: record: record, raimund@1111: grid: grid raimund@1111: }); raimund@1111: win.show(); raimund@1111: win.initData(); raimund@1111: } raimund@1111: return; dustin@962: } raimund@1111: var probeRecord = Ext.create('Lada.model.ProbeList'); raimund@1111: probeRecord.setId(record.get('probeId')); raimund@1111: probeRecord.set('owner', record.get('owner')); raimund@1111: probeRecord.set('readonly', record.get('readonly')); raimund@1111: raimund@1111: var probeWin = Ext.create('Lada.view.window.ProbeEdit', { raimund@1111: record: probeRecord, raimund@1111: style: 'z-index: -1;' //Fixes an Issue where windows could not be created in IE8 raimund@1111: }); raimund@1111: raimund@1111: probeWin.setPosition(30); raimund@1111: probeWin.show(); raimund@1111: probeWin.initData(); raimund@1111: raimund@1111: Ext.ClassManager.get('Lada.model.Probe').load(record.get('probeId'), { raimund@1111: failure: function(record, action) { raimund@1111: me.setLoading(false); raimund@1111: // TODO raimund@1111: console.log('An unhandled Failure occured. See following Response and Record'); raimund@1111: console.log(action); raimund@1111: console.log(record); raimund@1111: }, raimund@1111: success: function(precord, response) { raimund@1111: var messungWin = Ext.create('Lada.view.window.MessungEdit', { raimund@1120: parentWindow: probeWin, raimund@1111: probe: precord, raimund@1111: record: record, raimund@1111: grid: grid raimund@1111: }); raimund@1111: messungWin.show(); raimund@1111: messungWin.setPosition(window.innerWidth - 30 - messungWin.width); raimund@1111: messungWin.initData(); raimund@1111: } raimund@1111: }); raimund@588: }, raimund@588: dustin@742: /** dustin@742: * This function opens a window add a Messung dustin@742: */ raimund@622: add: function(button) { raimund@622: var probe = button.up('window').record; raimund@622: var win = Ext.create('Lada.view.window.MessungCreate', { raimund@644: record: probe, raimund@1182: grid: button.up('messunggrid'), raimund@1182: parentWindow: button.up('window') raimund@622: }); raimund@622: win.show(); raimund@622: win.initData(); raimund@588: }, raimund@588: dustin@742: /** dustin@742: * This function removes a Messung dustin@742: * It displays a Confirmation-Popup. dustin@742: * When the Removal was confirmed and the operation was successful, dustin@742: * the Messung-row is removed from the grid. dustin@742: * On failure an Errormessage is shown dustin@742: */ raimund@588: remove: function(button) { raimund@588: var grid = button.up('grid'); raimund@588: var selection = grid.getView().getSelectionModel().getSelection()[0]; raimund@588: Ext.MessageBox.confirm( raimund@588: 'Messung löschen', raimund@588: 'Sind Sie sicher?', raimund@588: function(btn) { raimund@588: if (btn === 'yes') { raimund@588: selection.destroy({ raimund@588: success: function() { raimund@588: button.up('window').initData(); raimund@588: }, dustin@705: failure: function(request, response) { dustin@704: var json = response.request.scope.reader.jsonData; dustin@704: if (json) { dustin@704: if (json.message){ dustin@704: Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title') dustin@704: +' #'+json.message, dustin@704: Lada.getApplication().bundle.getMsg(json.message)); dustin@704: } else { dustin@704: Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title'), dustin@704: Lada.getApplication().bundle.getMsg('err.msg.generic.body')); dustin@704: } dustin@704: } else { dustin@704: Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title'), dustin@704: Lada.getApplication().bundle.getMsg('err.msg.response.body')); dustin@704: } raimund@588: } raimund@588: }); raimund@588: } raimund@622: } raimund@622: ); dustin@826: grid.down('button[action=delete]').disable(); raimund@588: } raimund@588: });