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@870: /**
dustin@747:  * Panel to show available search queries
raimund@548:  */
raimund@548: Ext.define('Lada.view.FilterPanel', {
raimund@548:     extend: 'Ext.form.FieldSet',
raimund@548:     alias: 'widget.filterpanel',
raimund@548: 
raimund@548:     require: [
raimund@548:         'Ext.layout.container.Column'
raimund@548:     ],
raimund@548: 
raimund@1015:     title: 'Filter',
raimund@548:     initComponent: function() {
raimund@548:         this.layout = {
raimund@548:             type: 'vbox',
raimund@548:             align: 'stretch'
raimund@548:         };
dustin@795:         var me = this;
raimund@548:         this.items = [{
raimund@1015:             layout: 'hbox',
raimund@1015:             border: false,
raimund@1015:             items: [{
raimund@1015:                 xtype: 'combobox',
raimund@1015:                 name: 'filter',
raimund@1015:                 editable: false,
raimund@1015:                 flex: 1,
raimund@1015:                 displayField: 'name',
raimund@1015:                 valueField: 'id',
raimund@1015:                 queryMode: 'local',
raimund@1015:                 emptyText: 'Wählen Sie eine Abfrage'
raimund@1015:             }, {
raimund@1015:                 xtype: 'button',
raimund@1015:                 action: 'details',
raimund@1015:                 enableToggle: true,
raimund@1015:                 text: 'Details',
raimund@1015:                 margin: '0 0 0 10'
raimund@1015:             }]
raimund@1015:         }, {
mstanko@1104:             layout: {
mstanko@1104:                 type: 'hbox',
mstanko@1104:             },
mstanko@1104:             border: false,
mstanko@1104:             items: [{
mstanko@1104:                 xtype: 'checkbox',
mstanko@1104:                 name: 'favorites',
mstanko@1104:                 boxLabel: 'nur Favoriten',
mstanko@1104:                 checked: true
mstanko@1104:             }, {
mstanko@1104:                 xtype: 'button',
mstanko@1104:                 action: 'manage',
mstanko@1104:                 text: 'Filterauswahl bearbeiten',
mstanko@1104:                 margin: '0 0 0 20'
mstanko@1104:             }]
raimund@1015:         }, {
raimund@1015:             xtype: 'displayfield',
raimund@1015:             name: 'description',
raimund@1015:             shrinkWrap: 3,
raimund@1015:             margin: '0, 0, 0 ,5',
raimund@1015:             value: '-/-'
raimund@548:         }, {
raimund@548:             xtype: 'panel',
raimund@548:             border: false,
mstanko@1104:             margin: '10 0 10 0',
mstanko@1104:             items: [{
mstanko@1104:                 xtype: 'button',
mstanko@1104:                 action: 'search',
mstanko@1104:                 text: 'Suchen',
mstanko@1104:                 margin: '0 10 0 0'
mstanko@1104:             }, {
mstanko@1104:                 xtype: 'button',
mstanko@1104:                 action: 'reset',
mstanko@1104:                 text: 'Zurücksetzen',
mstanko@1104:                 margin: '0 10 0 0'
mstanko@1104:             }],
mstanko@1104:             hidden: false
mstanko@1104:         }, {
mstanko@1104:             xtype: 'panel',
mstanko@1104:             border: false,
raimund@1016:             name: 'filtervariables',
raimund@1016:             hidden: true,
raimund@1016:             margin: '10, 0, 10, 0',
raimund@1016:             items: [{
raimund@1016:                 xtype: 'panel',
raimund@1016:                 border: false,
raimund@1016:                 name: 'filtervalues',
raimund@1016:                 items: []
raimund@1016:             }, {
raimund@1016:                 layout: {
raimund@1016:                     type: 'hbox',
raimund@1016:                     pack: 'end'
raimund@1016:                 },
raimund@1016:                 border: false,
raimund@1016:                 items: [{
raimund@1016:                     xtype: 'button',
raimund@1016:                     action: 'savedefault',
raimund@1016:                     text: 'Vorbelegung speichern',
raimund@1016:                     margin: '0, 10, 0, 0'
raimund@1016:                 }, {
raimund@1016:                     xtype: 'button',
raimund@1016:                     action: 'resetdefault',
raimund@1064:                     text: 'Vorbelegung zurücksetzen'
raimund@1016:                 }]
raimund@1016:             }]
raimund@548:         }];
raimund@548:         this.callParent(arguments);
raimund@1015:         var combo = me.down('combobox[name=filter]');
raimund@1015:         combo.store = Ext.create('Ext.data.Store', {
raimund@1015:             model: 'Lada.model.Query'
raimund@1015:         });
raimund@1015:         var store = Ext.StoreManager.get('probequeries');
raimund@1015:         store.on('load', function storeLoad () {
raimund@1015:             var entries = store.queryBy(function(record) {
raimund@1015:                 if (record.get('favorite')) {
raimund@1015:                     return true;
raimund@1015:                 }
raimund@1015:             });
raimund@1029:             if (entries.getCount() === 0) {
raimund@1029:                 var cb = me.down('checkbox[name=favorites]');
raimund@1029:                 cb.setValue(false);
raimund@1029:             }
raimund@1015:             combo.store.add(entries.items);
raimund@1015:             combo.select(combo.store.getAt(0));
raimund@1015:             combo.fireEvent('select', combo, [combo.store.getAt(0)]);
raimund@1015:             store.un('load', storeLoad);
raimund@1015:         });
raimund@548:     }
raimund@548: });