dustin@757: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz dustin@757: * Software engineering by Intevation GmbH dustin@757: * dustin@757: * This file is Free Software under the GNU GPL (v>=3) dustin@757: * and comes with ABSOLUTELY NO WARRANTY! Check out dustin@757: * the documentation coming with IMIS-Labordaten-Application for details. dustin@757: */ dustin@757: dustin@757: /* dustin@757: * Grid to list Messmethoden dustin@757: */ dustin@757: Ext.define('Lada.view.grid.Messmethoden', { dustin@757: extend: 'Ext.grid.Panel', dustin@757: alias: 'widget.messmethodengrid', dustin@757: dustin@757: requires: [ dustin@757: 'Lada.view.widget.Messmethode' dustin@757: ], dustin@757: dustin@757: maxHeight: 350, dustin@757: minHeight: 110, dustin@757: viewConfig: { dustin@757: deferEmptyText: false dustin@757: }, dustin@757: margin: '0, 5, 5, 5', dustin@757: dustin@757: recordId: null, dustin@757: dustin@757: initComponent: function() { dustin@757: var i18n = Lada.getApplication().bundle; dustin@757: this.emptyText = i18n.getMsg('emptytext.mmtgrid'); dustin@757: dustin@757: this.rowEditing = Ext.create('Ext.grid.plugin.RowEditing', { dustin@757: clicksToMoveEditor: 1, dustin@757: autoCancel: false, dustin@757: disabled: false, dustin@757: pluginId: 'rowedit', dustin@757: listeners:{ dustin@757: // Make row ineditable when readonly is set to true dustin@757: // Normally this would belong into a controller an not the view. dustin@757: // But the RowEditPlugin is not handled there. dustin@757: beforeedit: function(e, o) { dustin@757: var readonlywin = o.grid.up('window').record.get('readonly'); dustin@757: var readonlygrid = o.record.get('readonly'); dustin@757: if (readonlywin == true || readonlygrid == true || this.disabled) { dustin@757: return false; dustin@757: } dustin@757: return true; dustin@757: } dustin@757: } dustin@757: }); dustin@757: dustin@757: this.plugins = [this.rowEditing]; dustin@757: dustin@758: dustin@758: dustin@757: this.dockedItems = [{ dustin@757: xtype: 'toolbar', dustin@757: dock: 'bottom', dustin@757: items: ['->', { dustin@757: text: i18n.getMsg('add'), dustin@757: icon: 'resources/img/list-add.png', dustin@757: action: 'add', dustin@758: recordId: this.recordId, dustin@757: }, { dustin@757: text: i18n.getMsg('delete'), dustin@757: icon: 'resources/img/list-remove.png', dustin@757: action: 'delete' dustin@757: }] dustin@757: }]; dustin@757: this.columns = [{ dustin@757: header: 'Messmethode', dustin@758: dataIndex: 'mmtId', dustin@757: flex: 1, dustin@757: renderer: function(value) { dustin@757: if (!value || value === '') { dustin@757: return ''; dustin@757: } dustin@758: var store = Ext.data.StoreManager.get('messmethoden'); dustin@758: if (!store) { dustin@758: store = Ext.create('Lada.store.Messmethoden'); dustin@758: } dustin@759: store.load(); dustin@759: console.log(store); dustin@759: return value + " - " + store.findRecord('id', value, 0, false, false, true).get('messmethode'); dustin@757: }, dustin@757: editor: { dustin@757: xtype: 'combobox', dustin@758: store: Ext.data.StoreManager.get('messmethoden'), dustin@758: //displayField: 'mmtId', dustin@757: valueField: 'id', dustin@757: allowBlank: false, dustin@757: editable: true, dustin@757: forceSelection: true, dustin@757: autoSelect: true, dustin@757: queryMode: 'local', dustin@757: minChars: 0, dustin@757: typeAhead: false, dustin@758: triggerAction: 'all', dustin@758: tpl: Ext.create("Ext.XTemplate", dustin@758: '' + dustin@758: '{id} - {messmethode}'), dustin@758: displayTpl: Ext.create('Ext.XTemplate', dustin@758: '{id} - {messmethode}'), dustin@757: } dustin@757: }]; dustin@757: this.initData(); dustin@757: this.callParent(arguments); dustin@757: }, dustin@757: initData: function() { dustin@757: if (this.store) { dustin@757: this.store.removeAll(); dustin@757: } dustin@757: else { dustin@757: this.store = Ext.create('Lada.store.MmtMessprogramm'); dustin@757: } dustin@759: // Only load the Store when a Record ID is Present dustin@759: if (this.recordId) { dustin@759: this.store.load({ dustin@759: params: { dustin@759: messprogrammId: this.recordId dustin@759: } dustin@759: }); dustin@759: } dustin@757: }, dustin@757: setReadOnly: function(b) { dustin@757: if (b == true){ dustin@757: //Readonly dustin@757: if (this.getPlugin('rowedit')){ dustin@757: this.getPlugin('rowedit').disable(); dustin@757: } dustin@757: this.down('button[action=delete]').disable(); dustin@757: this.down('button[action=add]').disable(); dustin@757: }else{ dustin@757: //Writable dustin@757: if (this.getPlugin('rowedit')){ dustin@757: this.getPlugin('rowedit').enable(); dustin@757: } dustin@757: this.down('button[action=delete]').enable(); dustin@757: this.down('button[action=add]').enable(); dustin@757: } dustin@757: } dustin@757: });