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', raimund@548: alias: 'widget.ortgrid', 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 = [{ raimund@548: header: 'Typ', raimund@548: dataIndex: 'ortsTyp', raimund@548: width: 50, raimund@548: editor: { raimund@548: allowBlank: false raimund@548: } raimund@548: }, { raimund@548: header: 'Staat', raimund@548: dataIndex: 'ort', raimund@548: width: 70, 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: }, { raimund@548: header: 'Gemeineschlüssel', raimund@548: dataIndex: 'ort', raimund@548: width: 120, 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', raimund@548: dataIndex: 'ort', raimund@548: flex: 1, 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: }, { raimund@548: header: 'Messpunkt', raimund@548: dataIndex: 'ort', raimund@548: renderer: function(value) { dustin@1004: var store = Ext.getStore('orte'); raimund@548: var record = store.getById(value); raimund@548: return record.get('bezeichnung'); raimund@548: } 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 dustin@684: 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(); dustin@684: }else{ dustin@684: //Writable dustin@684: 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: });