torsten@202: Ext.define('Lada.controller.Status', { torsten@202: extend: 'Ext.app.Controller', torsten@202: views: [ torsten@202: 'status.Create' torsten@202: ], torsten@202: stores: [ torsten@202: 'Status' torsten@202: ], torsten@202: init: function() { torsten@202: console.log('Initialising the Status controller'); torsten@202: this.control({ torsten@202: // CSS like selector to select element in the viewpzusatzwert. See torsten@202: // ComponentQuery documentation for more details. torsten@202: 'statuslist': { torsten@202: itemdblclick: this.editStatus torsten@202: }, torsten@202: 'statuslist toolbar button[action=add]': { torsten@202: click: this.addStatus torsten@202: }, torsten@202: 'statuslist toolbar button[action=delete]': { torsten@202: click: this.deleteStatus torsten@202: }, torsten@202: 'statuscreate form': { torsten@202: savesuccess: this.createSuccess, torsten@202: savefailure: this.createFailure torsten@202: }, torsten@202: 'statuscreate button[action=save]': { torsten@202: click: this.saveStatus torsten@202: }, torsten@202: 'statusedit form': { torsten@202: savesuccess: this.editSuccess, torsten@202: savefailure: this.editFailure torsten@202: } torsten@202: }); torsten@202: }, torsten@202: saveStatus: function(button) { torsten@202: console.log('Saving Status'); torsten@202: var form = button.up('window').down('form'); torsten@202: form.commit(); torsten@202: }, torsten@202: addStatus: function(button) { torsten@202: console.log('Adding new Status for Messung ' + button.parentId + ' in Probe ' + button.probeId); torsten@202: var zusatzwert = Ext.create('Lada.model.Status'); torsten@202: zusatzwert.set('probeId', button.probeId); torsten@202: zusatzwert.set('messungsId', button.parentId); torsten@202: var view = Ext.widget('statuscreate', {model: zusatzwert}); torsten@202: }, torsten@202: editStatus: function(grid, record) { torsten@202: console.log('Editing Status'); torsten@202: var view = Ext.widget('statuscreate', {model: record}); torsten@202: console.log("Loaded Status with ID " + record.getId()); //outputs ID torsten@202: }, torsten@202: deleteStatus: function(button) { torsten@202: // Get selected item in grid torsten@202: var grid = button.up('grid'); torsten@202: var selection = grid.getView().getSelectionModel().getSelection()[0]; torsten@202: Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn){ torsten@202: if(btn === 'yes'){ torsten@202: var store = grid.getStore(); torsten@202: var deleteUrl = selection.getProxy().url + selection.getEidi(); torsten@202: Ext.Ajax.request({ torsten@202: url: deleteUrl, torsten@202: method: 'DELETE', torsten@202: success: function(response, opts) { torsten@202: store.reload(); torsten@202: } torsten@202: }); torsten@202: console.log('Deleting Kommentar'); torsten@202: } else { torsten@202: console.log('Cancel Deleting Kommentar'); torsten@202: } torsten@202: }); torsten@202: }, torsten@202: createSuccess: function(form, record, operation) { torsten@202: // Reload store torsten@202: var store = this.getStatusStore(); torsten@202: store.reload(); torsten@202: var win = form.up('window'); torsten@202: win.close(); torsten@202: }, torsten@202: createFailure: function(form, record, operation) { torsten@202: Ext.MessageBox.show({ torsten@202: title: 'Fehler beim Speichern', torsten@202: msg: form.message, torsten@202: icon: Ext.MessageBox.ERROR, torsten@202: buttons: Ext.Msg.OK torsten@202: }); torsten@202: }, torsten@202: editSuccess: function(form, record, operation) { torsten@202: // Reload store torsten@202: var store = this.getStatusStore(); torsten@202: store.reload(); torsten@202: var win = form.up('window'); torsten@202: win.close(); torsten@202: }, torsten@202: editFailure: function(form, record, operation) { torsten@202: Ext.MessageBox.show({ torsten@202: title: 'Fehler beim Speichern', torsten@202: msg: form.message, torsten@202: icon: Ext.MessageBox.ERROR, torsten@202: buttons: Ext.Msg.OK torsten@202: }); torsten@202: } torsten@202: });