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: mkrambach@1289: isMessprogramm: false, mkrambach@1289: raimund@548: warnings: null, raimund@548: errors: null, dustin@823: readOnly: true, dustin@823: allowDeselect: true, raimund@548: raimund@548: initComponent: function() { raimund@1264: var me = this; tom@1299: var i18n = Lada.getApplication().bundle; tom@1299: 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: }, { tom@1299: header: i18n.getMsg('orte.ortId'), mstanko@1257: dataIndex: 'ortId', mstanko@1257: flex: 2, raimund@1274: renderer: function(value, meta, zuordnung) { mstanko@1257: var store = Ext.data.StoreManager.get('orte'); mstanko@1257: var record = store.getById(value); raimund@1264: if (!record) { raimund@1264: record = Ext.create('Lada.model.Ort'); raimund@1264: record.set('id', value); raimund@1264: store.add(record); raimund@1264: Lada.model.Ort.load(value, { raimund@1264: success: function(rec) { raimund@1264: record.beginEdit(); raimund@1264: for (key in rec.getData()) { raimund@1264: record.set(key, rec.getData()[key]); raimund@1264: } raimund@1264: record.endEdit(); raimund@1264: me.getView().refresh(); raimund@1264: } raimund@1264: }); raimund@1264: } mstanko@1257: return record.get('ortId'); mstanko@1257: } mstanko@1257: }, { tom@1299: header: i18n.getMsg('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@1264: var ortRecord = store.getById(value); tom@1351: if (!ortRecord) { raimund@1264: return ''; raimund@1264: } tom@1351: var stId = ortRecord.get('staatId'); tom@1351: if (stId == undefined || stId == null || stId === '') { tom@1351: return ''; tom@1351: } tom@1351: var record = staaten.getById(stId); raimund@548: return record.get('staatIso'); raimund@548: } raimund@548: }, { tom@1299: header: i18n.getMsg('orte.gemId'), 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); raimund@1264: if (!record || record.get('gemId') === '') { raimund@1264: return ''; raimund@1264: } dustin@1004: return record.get('gemId'); raimund@548: } raimund@548: }, { tom@1299: header: i18n.getMsg('orte.verwaltungseinheit'), 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); tom@1351: if (!record) { raimund@1264: return ''; raimund@1264: } dustin@1004: var gemid = record.get('gemId'); tom@1351: if (gemid == undefined || gemid == null || gemid === '') { tom@1351: return ''; tom@1351: } raimund@548: var record2 = gemeinden.getById(gemid); raimund@548: return record2.get('bezeichnung'); raimund@548: } raimund@548: }, { tom@1299: header: i18n.getMsg('orte.anlageId'), 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); tom@1351: if (!record) { tom@1351: return ''; tom@1351: } tom@1351: var ktaId = record.get('anlageId'); tom@1351: if (ktaId == undefined || ktaId == null || ktaId === '') { raimund@1264: return ''; raimund@1264: } raimund@1346: var ktas = Ext.data.StoreManager.get('ktas'); raimund@1346: var kta = ktas.getById(record.get('anlageId')); raimund@1346: return kta.get('code'); 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() { mkrambach@1339: var modelname; mkrambach@1289: if (this.isMessprogramm) { mkrambach@1339: this.store = Ext.create('Lada.store.OrtszuordnungMp'); raimund@1394: if (this.recordId) { raimund@1394: this.store.load({ raimund@1394: params: { raimund@1394: messprogrammId: this.recordId raimund@1394: }}); raimund@1394: modelname = 'Lada.model.Messprogramm'; raimund@1394: } raimund@1394: else { raimund@1394: return; raimund@1394: } raimund@1394: } raimund@1394: else { mkrambach@1339: modelname = 'Lada.model.Probe'; mkrambach@1289: this.store = Ext.create('Lada.store.Ortszuordnung'); mkrambach@1289: this.store.load({ mkrambach@1289: params: { mkrambach@1289: probeId: this.recordId mkrambach@1339: }}); mkrambach@1339: } mkrambach@1339: Ext.ClassManager.get(modelname).load(this.recordId, { mkrambach@1339: failure: function(record, action) { mkrambach@1339: // TODO mkrambach@1339: }, mkrambach@1339: success: function(record, response) { mkrambach@1339: var json = Ext.decode(response.response.responseText); mkrambach@1339: if (json) { mkrambach@1339: this.warnings = json.warnings; mkrambach@1339: this.errors = json.errors; raimund@548: } mkrambach@1339: }, mkrambach@1339: scope: this mkrambach@1339: }); 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: });