raimund@594: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
raimund@594:  * Software engineering by Intevation GmbH
raimund@594:  *
raimund@594:  * This file is Free Software under the GNU GPL (v>=3)
raimund@594:  * and comes with ABSOLUTELY NO WARRANTY! Check out
raimund@594:  * the documentation coming with IMIS-Labordaten-Application for details.
raimund@594:  */
raimund@594: 
dustin@893: /**
raimund@594:  * Grid to list Status
raimund@594:  */
raimund@594: Ext.define('Lada.view.grid.Status', {
raimund@594:     extend: 'Ext.grid.Panel',
raimund@594:     alias: 'widget.statusgrid',
raimund@594: 
raimund@594:     maxHeight: 350,
raimund@594:     emptyText: 'Keine Statusangaben gefunden.',
raimund@594:     minHeight: 110,
raimund@594:     viewConfig: {
raimund@594:         deferEmptyText: false
raimund@594:     },
raimund@594: 
raimund@594:     recordId: null,
dustin@824:     readOnly: true,
dustin@824:     allowDeselect: true,
raimund@594: 
raimund@594:     initComponent: function() {
raimund@594:         this.rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
raimund@594:             clicksToMoveEditor: 1,
dustin@683:             autoCancel: false,
dustin@703:             disabled: false,
dustin@684:             pluginId: 'rowedit',
dustin@683:             listeners:{
dustin@683:                 // Make row ineditable when readonly is set to true
dustin@683:                 // Normally this would belong into a controller an not the view.
dustin@703:                 // But the RowEditPlugin is not handled there.
dustin@683:                 beforeedit: function(e, o) {
dustin@703:                     var readonlywin = o.grid.up('window').record.get('readonly');
dustin@703:                     var readonlygrid = o.record.get('readonly');
dustin@703:                     if (readonlywin == true || readonlygrid == true || this.disabled)  {
dustin@683:                         return false;
dustin@683:                     }
dustin@683:                     return true;
dustin@683:                 }
dustin@683:             }
dustin@683:          });
raimund@594:         this.plugins = [this.rowEditing];
raimund@594: 
dustin@799:         var statusStore = Ext.create('Lada.store.StatusWerte');
raimund@594:         this.dockedItems = [{
raimund@594:             xtype: 'toolbar',
raimund@594:             dock: 'bottom',
raimund@594:             items: ['->', {
raimund@594:                 text: 'Hinzufügen',
raimund@594:                 icon: 'resources/img/list-add.png',
raimund@594:                 action: 'add',
raimund@594:                 probeId: this.probeId,
raimund@594:                 parentId: this.parentId
raimund@594:             }, {
raimund@594:                 text: 'Löschen',
raimund@594:                 icon: 'resources/img/list-remove.png',
raimund@594:                 action: 'delete'
raimund@594:             }]
raimund@594:         }];
raimund@594:         this.columns = [{
raimund@594:             header: 'Erzeuger',
raimund@594:             dataIndex: 'erzeuger',
raimund@594:             renderer: function(value) {
raimund@594:                 if (!value || value === '') {
raimund@594:                     return '';
raimund@594:                 }
raimund@594:                 var mstore = Ext.data.StoreManager.get('messstellen');
raimund@594:                 return mstore.getById(value).get('messStelle');
raimund@594:             },
raimund@594:             editor: {
raimund@594:                 xtype: 'combobox',
raimund@594:                 store: Ext.data.StoreManager.get('messstellen'),
raimund@594:                 displayField: 'messStelle',
raimund@594:                 valueField: 'id',
dustin@663:                 allowBlank: false,
dustin@663:                 editable: false
raimund@594:             }
raimund@594:         }, {
raimund@594:             header: 'Status',
raimund@594:             dataIndex: 'status',
raimund@594:             renderer: function(value) {
raimund@594:                 if (!value || value === '') {
raimund@594:                     return '';
raimund@594:                 }
raimund@594:                 return statusStore.getById(value).get('display');
raimund@594:             },
raimund@594:             editor: {
raimund@594:                 xtype: 'combobox',
raimund@594:                 store: statusStore,
raimund@594:                 displayField: 'display',
raimund@594:                 valueField: 'id',
dustin@663:                 allowBlank: false,
dustin@663:                 editable: false
raimund@594:             }
raimund@594:         }, {
raimund@594:             header: 'Datum',
raimund@594:             dataIndex: 'sdatum',
dustin@630:             xtype: 'datecolumn',
dustin@663:             format: 'd.m.Y',
raimund@594:             editor: {
raimund@594:                 xtype: 'datefield',
raimund@594:                 allowBlank: false,
dustin@663:                 format: 'd.m.Y',
raimund@594:                 maxValue: Ext.Date.format(new Date(), 'd.m.Y')
raimund@594:             }
raimund@594:         }, {
raimund@594:             header: 'Text',
raimund@594:             dataIndex: 'skommentar',
raimund@594:             flex: 1,
raimund@594:             editor: {
dustin@663:                 allowBlank: true,
dustin@663:                 maxLength: 1000,
dustin@663:                 enforceMaxLength: true
raimund@594:             }
raimund@594:         }];
dustin@824:         this.listeners = {
dustin@824:            select: {
dustin@824:                fn: this.activateRemoveButton,
dustin@824:                scope: this
dustin@824:             },
dustin@824:             deselect: {
dustin@824:                 fn: this.deactivateRemoveButton,
dustin@824:                 scope: this
dustin@824:             }
dustin@824:         };
raimund@594:         this.initData();
raimund@594:         this.callParent(arguments);
dustin@824:         this.setReadOnly(true); //Grid is always initialised as RO
raimund@594:     },
raimund@594: 
raimund@594:     initData: function() {
raimund@594:         if (this.store) {
raimund@594:             this.store.removeAll();
raimund@594:         }
raimund@594:         else {
raimund@594:             this.store = Ext.create('Lada.store.Status');
raimund@594:         }
raimund@594:         this.store.load({
raimund@594:             params: {
raimund@594:                 messungsId: this.recordId
raimund@594:             }
raimund@594:         });
dustin@684:     },
dustin@684: 
dustin@684:     setReadOnly: function(b) {
dustin@684:         if (b == true){
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@824:     },
dustin@824:     /**
dustin@824:      * Activate the Remove Button
dustin@824:      */
dustin@824:     activateRemoveButton: function(selection, record) {
dustin@824:         var grid = this;
dustin@824:         //only enable the remove buttone, when the grid is editable.
dustin@824:         if (! grid.readOnly) {
dustin@824:             grid.down('button[action=delete]').enable();
dustin@824:         }
dustin@824:     },
dustin@824:     /**
dustin@824:      * Activate the Remove Button
dustin@824:      */
dustin@824:     deactivateRemoveButton: function(selection, record) {
dustin@824:         var grid = this;
dustin@824:         //only enable the remove buttone, when the grid is editable.
dustin@824:         if (! grid.readOnly) {
dustin@824:             grid.down('button[action=delete]').disable();
dustin@824:         }
raimund@594:     }
raimund@594: });