raimund@548: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz raimund@548: * Software engineering by Intevation GmbH raimund@548: * raimund@548: * This file is Free Software under the GNU GPL (v>=3) raimund@548: * and comes with ABSOLUTELY NO WARRANTY! Check out raimund@548: * the documentation coming with IMIS-Labordaten-Application for details. raimund@548: */ raimund@548: dustin@893: /** dustin@1004: * Grid to list Ortszuordnungen raimund@548: */ dustin@1004: Ext.define('Lada.view.grid.Ortszuordnung', { raimund@548: extend: 'Ext.grid.Panel', dustin@1012: alias: 'widget.ortszuordnunggrid', raimund@548: raimund@548: maxHeight: 350, raimund@548: emptyText: 'Keine Orte gefunden.', raimund@548: // minHeight and deferEmptyText are needed to be able to show the raimund@548: // emptyText message. raimund@548: minHeight: 110, raimund@548: viewConfig: { raimund@548: deferEmptyText: false raimund@548: }, raimund@548: margin: '0, 5, 5, 5', raimund@548: raimund@548: recordId: null, raimund@548: raimund@548: warnings: null, raimund@548: errors: null, dustin@823: readOnly: true, dustin@823: allowDeselect: true, raimund@548: raimund@548: initComponent: function() { raimund@548: this.dockedItems = [{ raimund@548: xtype: 'toolbar', raimund@548: dock: 'bottom', raimund@548: items: ['->', { raimund@548: text: 'Hinzufügen', raimund@548: icon: 'resources/img/list-add.png', raimund@548: action: 'add', raimund@548: probeId: this.probeId raimund@548: }, { raimund@548: text: 'Löschen', raimund@548: icon: 'resources/img/list-remove.png', raimund@548: action: 'delete' raimund@548: }] raimund@548: }]; raimund@548: this.columns = [{ mstanko@1257: xtype: 'actioncolumn', mstanko@1257: text: '', mstanko@1257: dataIndex: 'readonly', mstanko@1257: sortable: false, mstanko@1257: width: 30, mstanko@1257: getClass: function (val, meta, rec) { mstanko@1257: if (rec.get('readonly') === false) { mstanko@1257: return 'edit'; mstanko@1257: } mstanko@1257: return 'noedit'; mstanko@1257: }, mstanko@1257: handler: function(grid, rowIndex, colIndex) { mstanko@1257: var rec = grid.getStore().getAt(rowIndex); mstanko@1257: grid.fireEvent('itemdblclick', grid, rec); mstanko@1257: } mstanko@1257: }, { raimund@548: header: 'Typ', dustin@1012: dataIndex: 'ortszuordnungTyp', dustin@1021: flex: 1, raimund@548: editor: { raimund@548: allowBlank: false raimund@548: } raimund@548: }, { mstanko@1257: header: 'Ort-ID', mstanko@1257: dataIndex: 'ortId', mstanko@1257: flex: 2, mstanko@1257: renderer: function(value) { mstanko@1257: var store = Ext.data.StoreManager.get('orte'); mstanko@1257: var record = store.getById(value); mstanko@1257: return record.get('ortId'); mstanko@1257: } mstanko@1257: }, { raimund@548: header: 'Staat', dustin@1012: dataIndex: 'ortId', dustin@1021: flex: 1, raimund@548: renderer: function(value) { dustin@1004: var store = Ext.data.StoreManager.get('orte'); raimund@548: var staaten = Ext.data.StoreManager.get('staaten'); raimund@548: var record = raimund@548: staaten.getById(store.getById(value).get('staatId')); raimund@548: return record.get('staatIso'); raimund@548: } raimund@548: }, { dustin@1012: header: 'Gemeindeschlüssel', dustin@1012: dataIndex: 'ortId', dustin@1021: flex: 3, raimund@548: renderer: function(value) { dustin@1004: var store = Ext.data.StoreManager.get('orte'); raimund@548: var record = store.getById(value); dustin@1004: return record.get('gemId'); raimund@548: } raimund@548: }, { raimund@548: header: 'Gemeindename', dustin@1012: dataIndex: 'ortId', dustin@1021: flex: 4, raimund@548: renderer: function(value) { dustin@1004: var store = Ext.data.StoreManager.get('orte'); raimund@548: var gemeinden = raimund@548: Ext.data.StoreManager.get('verwaltungseinheiten'); raimund@548: var record = store.getById(value); dustin@1004: var gemid = record.get('gemId'); raimund@548: var record2 = gemeinden.getById(gemid); raimund@548: return record2.get('bezeichnung'); raimund@548: } raimund@548: }, { mstanko@1257: header: 'Anlage', mstanko@1257: dataIndex: 'ortId', mstanko@1257: flex: 3, mstanko@1257: renderer: function(value) { mstanko@1257: var store = Ext.data.StoreManager.get('orte'); mstanko@1257: var record = store.getById(value); mstanko@1257: return record.get('anlageId'); mstanko@1257: } raimund@548: }]; dustin@823: this.listeners = { dustin@823: select: { dustin@823: fn: this.activateRemoveButton, dustin@823: scope: this dustin@823: }, dustin@823: deselect: { dustin@823: fn: this.deactivateRemoveButton, dustin@823: scope: this dustin@823: } dustin@823: }; raimund@548: this.initData(); raimund@548: this.callParent(arguments); dustin@823: this.setReadOnly(true); //Grid is always initialised as RO raimund@548: }, raimund@548: raimund@548: initData: function() { dustin@1004: this.store = Ext.create('Lada.store.Ortszuordnung'); raimund@548: this.store.load({ raimund@548: params: { raimund@548: probeId: this.recordId raimund@548: } raimund@548: }); raimund@548: Ext.ClassManager.get('Lada.model.Probe').load(this.recordId, { raimund@548: failure: function(record, action) { raimund@548: // TODO raimund@548: }, raimund@548: success: function(record, response) { raimund@548: var json = Ext.decode(response.response.responseText); raimund@548: if (json) { raimund@548: this.warnings = json.warnings; raimund@548: this.errors = json.errors; raimund@548: } raimund@548: }, raimund@548: scope: this raimund@548: }); raimund@548: }, raimund@548: dustin@684: setReadOnly: function(b) { raimund@1034: this.readOnly = b; raimund@1034: if (b) { dustin@684: //Readonly raimund@1035: if (this.getPlugin('rowedit')) { dustin@684: this.getPlugin('rowedit').disable(); dustin@684: } dustin@684: this.down('button[action=delete]').disable(); dustin@684: this.down('button[action=add]').disable(); raimund@1035: } raimund@1035: else { dustin@684: //Writable raimund@1035: if (this.getPlugin('rowedit')) { dustin@684: this.getPlugin('rowedit').enable(); dustin@684: } dustin@824: //this.down('button[action=delete]').enable(); dustin@684: this.down('button[action=add]').enable(); dustin@684: } dustin@823: }, dustin@823: /** dustin@823: * Activate the Remove Button dustin@823: */ dustin@823: activateRemoveButton: function(selection, record) { dustin@823: var grid = this; dustin@823: //only enable the remove buttone, when the grid is editable. dustin@823: if (! grid.readOnly) { dustin@823: grid.down('button[action=delete]').enable(); dustin@823: } dustin@823: }, dustin@823: /** dustin@823: * Activate the Remove Button dustin@823: */ dustin@823: deactivateRemoveButton: function(selection, record) { dustin@823: var grid = this; dustin@823: //only enable the remove buttone, when the grid is editable. dustin@823: if (! grid.readOnly) { dustin@823: grid.down('button[action=delete]').disable(); dustin@823: } raimund@548: } raimund@548: });