`

extjs4 自定义类

 
阅读更多
Ext.define('FX.Table.Filter.Condition', {
               
    extend: 'Ext.data.Model',

    fields: [
        {type: 'string', name: 'name'},
        {type: 'string', name: 'value'}
    ]
   
});
                  
Ext.define('FX.Table.Filter',{
    extend: 'Ext.panel.Panel',
   
    conditionNumber: 2,
    height: 200,
    border: false,
   
    filterConditionStore: '',
    filterColumnTitleStore: '',
    filterOperatorStore: '',
    filterAllConditionLabel: 'Match All Conditions',
    filterAnyConditionLabel: 'Match Any Condition',
   
    layout: {
        type: 'vbox',
  //      padding: '4',
  //      marginTop: '10px'
    },
    defaults: {
        margins: '3,0,0,0'
    },
   
    /**
     * Initialize component method
     */
    initComponent: function() {
   
        Ext.tip.QuickTipManager.init();
       
        this.getDefaultStore();
       
        this.items = [{
                 xtype: 'panel',
                 width: 694,
                 height: 35,
                 layout: {
                     type: 'hbox',
                     padding: '4',
                     pack: 'end'
                 },
                 defaults: {
                     margins: '2,5,2,2'
                 },
                 items: [{
                     xtype: 'textfield',
                     id: 'filtercondition',
                     name: 'filtercondition',
                     fieldLabel: ''
                 }, {
                     xtype: 'button',
                     id: 'filter',
                     text: 'Filter',
                     width: 45,
                     listeners: {
                         'click': Ext.bind(this.filter,this)
                     }
                 }, {
                     xtype: 'button',
                     id: 'remove',
                     text: 'Remove Filter',
                disabled: true,
                listeners: {
                         'click': Ext.bind(this.removeFilter, this)
                     }
                 }, {
                     xtype: 'button',
                id: 'detail',
                text: 'Detailed Conditions>>',
                listeners: {
                         'click': Ext.bind(this.togglePanel, this)
                     }
                 }]
             }, {
                 xtype: 'panel',
                 id : 'displayPanel',
                 name: 'displayPanel',
                 hidden: true,
                 width:  694,
                 height: 85,
                 layout: 'border',
                
                  
                items:[{
                    region: 'north',
                    xtype: 'panel',
                    border: false,
                    layout: 'absolute',
                   
                    items:[{
                        xtype: 'combobox',
                        displayField: 'name',
                        valueField: 'value',
                        id:'filterConditionName',
                        value : this.filterConditionStore.getAt(0).get('value'),
                        width: 180,
                        store: this.filterConditionStore,
                        queryMode: 'local',
                        x: 355,
                        y: 5                     
                    }, {
                        xtype: 'button',
                        id: 'save',
                        text: 'Save Filter',
                        x: 540,
                        y: 5,
                        listeners: {
                            'click': Ext.bind(this.saveFilter, this)
                        }                       
                    }, {
                        xtype: 'button',
                        id: 'delete',
                        text: 'Delete Filter',
                        disabled: true,
                        x: 610,
                        y: 5,
                        listeners: {
                            'click': Ext.bind(this.deleteFilter,this)
                        }
                    }, {
                        xtype: 'fieldcontainer',
                        defaultType: 'radiofield',
                        id:'radiocontainer',
                        layout: 'hbox',
                        items: [
                            {boxLabel: this.filterAllConditionLabel, name: 'filterRadio', id:'filterAllCondition', inputValue: '1'},
                            {boxLabel: this.filterAnyConditionLabel, name: 'filterRadio', inputValue: '2', checked: true}
                        ],
                        x: 15,
                        y: 20
                    }],
                    height: 50
                }, {
               
                    region: 'center',
                    xtype: 'panel',
                    id:'centerpanel',
                    border: false,
                   
                    layout: {
                        type: 'table',
                        columns: 5
                    },
                   
                    items:[{
                        xtype: 'combobox',
                        id: 'devicegroup1',
                        displayField: 'name',
                        valueField: 'value',
                        value : this.filterColumnTitleStore.getAt(0).get('value'),
                        width: 220,
                        store: this.filterColumnTitleStore,
                        queryMode: 'local',
                        style: {
                            marginLeft: '10px',
                            marginTop: '5px'
                        }                  
                    }, {
                        xtype: 'combobox',
                        id: 'condition1',
                        displayField: 'name',
                        valueField: 'value',
                        value : this.filterOperatorStore.getAt(0).get('value'),
                        width: 220,
                        store: this.filterOperatorStore,
                        queryMode: 'local',
                        style: {
                            marginLeft: '10px',
                            marginTop: '5px'
                        }
                    }, {
                        xtype: 'textfield',
                        id: 'result1',
                        name: 'result1',
                        fieldLabel: '',
                        style:{
                            marginLeft: '10px',
                            marginTop: '5px'
                        }
                    }, {
                        xtype: 'button',
                        id: 'add1',
                        text: '+',
                        width: 23,
                        style:{
                            marginLeft: '10px'
                        },
                        listeners: {
                            'click': Ext.bind(this.addRules, this)
                        }
                    }, {
                        xtype: 'button',
                        id: 'delete1',
                        text: '-',
                        width: 23,
                        disabled: true,
                        style:{
                            marginLeft: '10px'
                        },
                        listeners: {
                            'click': Ext.bind(this.removeComponent,this)
                        }
                   }]
               }]
                
        }];
       
        this.callParent(arguments);
    },

    // private method
    addRules: function(addBtn){
        var popupbox = addBtn.findParentByType("panel");
        var count = this.componentCount(popupbox);
        if (count < 5) {            
            this.createAndAddFilterComponent(addBtn);
            var displayPanel = Ext.getCmp("displayPanel");
            var height = displayPanel.getHeight();
            displayPanel.setHeight(height+32);
            var countagain = this.componentCount(popupbox);
            if (count == 1) {
                var array = popupbox.query('button[text="-"]');
                array[0].setDisabled(false);
            }
            if (countagain >= 5) {
                var array = popupbox.query('button[text="+"]');
                Ext.Array.each(array, function(btn) {
                    btn.setDisabled(true);
                });  
            }  
       }                        
    },
   
    // private method
    createAndAddFilterComponent: function(newcmp){
        var popupbox = newcmp.findParentByType("panel");
        var deviceGroup = new Ext.form.ComboBox({
            id: 'devicegroup'+this.conditionNumber,
            displayField: 'name',
            valueField: 'value',
            value: this.filterColumnTitleStore.getAt(0).get('value'),
            width: 220,
            store: this.filterColumnTitleStore,
            queryMode: 'local',
            style: {
                marginLeft: '10px',
                marginTop: '5px'
            }
        });
                       
        var condition = new Ext.form.ComboBox({
            id: 'condition'+this.conditionNumber,
            displayField: 'name',
            valueField: 'value',
            value: this.filterOperatorStore.getAt(0).get('value'),
            width: 220,
            store: this.filterOperatorStore,
            queryMode: 'local',
            style: {
                marginLeft: '10px',
                marginTop: '5px'
            }
        });
                       
        var result = new Ext.form.Text({
            id: 'result'+this.conditionNumber,
            name: 'result'+this.conditionNumber,
            fieldLabel: '',
            style:{
                marginLeft: '10px',
                marginTop: '5px'
            }                    
        });
                       
        var add = new Ext.Button({
            id: 'add'+this.conditionNumber,
            text: '+',
            width: 23,
            style:{
                marginLeft: '10px'
            },
            listeners: {
                'click': Ext.bind(this.addRules, this)                 
            }         
        });
                       
        var del = new Ext.Button({
            id: 'delete'+this.conditionNumber,
            text: '-',
            width: 23,
            style:{
                marginLeft: '10px'
            },
            listeners: {                        
                'click': Ext.bind(this.removeComponent,this)
            }          
        });
                       
        this.conditionNumber++;
       
        popupbox.add(deviceGroup);
        popupbox.add(condition);
        popupbox.add(result);
        popupbox.add(add);
        popupbox.add(del);
    },
   
    // private method
    removeComponent: function(removeBtn){
   
        var delid = removeBtn.getId();
        var no = delid.substring(6,delid.length);
        var popupbox = removeBtn.findParentByType("panel");
       
        popupbox.remove("devicegroup"+no);
        popupbox.remove("condition"+no);
        popupbox.remove("result"+no);
        popupbox.remove("add"+no);
        popupbox.remove("delete"+no);
       
        var displaypanel = Ext.getCmp("displayPanel");
        displaypanel.setHeight(displaypanel.getHeight() - 32);
       
        var count = this.componentCount(popupbox);
        if (count == 1) {       
            var array = popupbox.query('button[text="-"]');
            array[0].setDisabled(true);
           
        }else if(count == 4) {       
            var array = popupbox.query('button[text="+"]');
            Ext.Array.each(array, function(btn) {
                btn.setDisabled(false);
            });  
        }                                     
    },
   
    // private method
    componentCount: function(popupbox){
        var array = popupbox.query('button[text="+"]');
        return array.length;
    },
   
    // private method
    setRemoveFilterButtonDisabled: function(disabled){
        Ext.getCmp("remove").setDisabled(disabled);
    },
   
    // private method
    setDeleteFilterButtonDisabled: function(disabled){
        Ext.getCmp("delete").setDisabled(disabled);
    },
   
    /**
     * Detailbutton's click event handling method
     *
     */
    togglePanel: function(detailBtn){
        if (Ext.getCmp("filtercondition").hidden) {
            Ext.getCmp("filtercondition").setVisible(true);
        } else {
            Ext.getCmp("filtercondition").setVisible(false);
        }
       
        if (Ext.getCmp("displayPanel").hidden) {
            Ext.getCmp("displayPanel").setVisible(true);
            detailBtn.setText("Detailed Conditions<<");
        } else {
            Ext.getCmp("displayPanel").setVisible(false);
            detailBtn.setText("Detailed Conditions>>");
        }
    },
   
    // private method
    getDefaultStore: function(){
        if (this.filterConditionStore == '') {
            var filterConditionCombo = [
                {"name":"Enter New Conditions","value":"Enter New Conditions"},
            ];
                       
            this.filterConditionStore = Ext.create('Ext.data.Store', {
                model: 'FX.Table.Filter.Condition',
                data: filterConditionCombo
            });
        }
                                                           
        if (this.filterColumnTitleStore == '') {
            var mgmtDeviceDisplayTablefilterColumnTitleCombo = [
                {"name":"Device/Group ID","value":"Device/Group ID"},
                {"name":"Device/Group Name","value":"Device/Group Name"},
                {"name":"Remarks","value":"Remarks"}
            ];
               
            this.filterColumnTitleStore = Ext.create('Ext.data.Store', {
                model: 'FX.Table.Filter.Condition',
                data: mgmtDeviceDisplayTablefilterColumnTitleCombo
            });
        }
                         
        if (this.filterOperatorStore == '') {
            var mgmtDeviceDisplayTablefilterOperatorCombo = [
                {"name":"Is equal to test","value":"equal"},
                {"name":"Is not equal to test","value":"not equal"},
                {"name":"Contains test","value":"contains"},
                {"name":"Does not contain test","value":"not contain"}
            ];

            this.filterOperatorStore = Ext.create('Ext.data.Store', {
                model: 'FX.Table.Filter.Condition',
                data: mgmtDeviceDisplayTablefilterOperatorCombo
            });
        }
    },
   
    /**
     * Savefilterbutton's click event handling method
     */
    saveFilter: function(){
     
    },
   
    /**
     * Deletefilterbutton's click event handling method
     */
    deleteFilter: function(){
                       
    },
   
    /**
     * Removefilterbutton's click event handling method
     */
    removeFilter: function(){
     
    },
   
    /**
     * Filterbutton's click event handling method
     */
    filter: function(){
     
    },
                   
    /**
     * Get Filter Conditions
     * 
     */
    getConditions: function(){                                                   
        var popupbox = Ext.getCmp("centerpanel");
        var array = popupbox.query('button[text="+"]');
        var conditionArrayIndex = 0;
        var conditionArray = new Array();
        for(i = 0;i < array.length;i++){
            conditionArray[i] = new Array();
        }
        Ext.Array.each(array, function(btn) {
            var addId = btn.getId();
            var componentNumber = addId.substring(3,addId.length);
            var deviceGroupVal = Ext.getCmp("devicegroup"+componentNumber).getValue();
            var conditionVal = Ext.getCmp("condition"+componentNumber).getValue();
            var result = Ext.getCmp("result"+componentNumber).getValue();
                            
            conditionArray[conditionArrayIndex][0] = deviceGroupVal;
            conditionArray[conditionArrayIndex][1] = conditionVal;
            conditionArray[conditionArrayIndex][2] = result;
                         
            conditionArrayIndex++;
        });                         
        return conditionArray;  
    },
   
    /**
     * 
     */
    getConditionName: function(){
        var conditionName = Ext.getCmp("filterConditionName").getValue();
        return conditionName;
    },
   
    /**
     * Get  all Or Any . all : 1 Any : 2
     */
    getAllOrAny: function(){                  
        var allOrAny = Ext.getCmp('filterAllCondition').getGroupValue();
        return allOrAny;
    },
   
    /**
     * 
     */
    getCondition: function(){
        var condition = Ext.getCmp("filtercondition").getValue();
        return condition;
    }             
                   
});
分享到:
评论

相关推荐

    extjs4自定义深蓝色主题

    "extjs4自定义深蓝色主题"是针对ExtJS4框架的一个特定主题设计,旨在为应用程序提供一种专业且深沉的视觉体验。 这个主题继承自ExtJS4的经典(Classic)主题,这意味着它在保持原有组件结构的基础上,对颜色、字体...

    Extjs4.2自定义ComboTree

    Extjs4.2自定义ComboTree

    ExtJS如何自定义图片按钮组件

    1.ExtJS自定义组件,图片按钮为例. 2.此图片按钮背景完全为图片,没有边框,需要使用者提供2张图片,一张初始化用,一张点击后用,可在'imgPaths:'属性里填写,格式为'01.jpg~02.jpg' 3.解压后请将所有附件放置您extjs...

    ExtJs自定义消息框

    ### ExtJs自定义消息框详解 #### 一、引言 在Web开发中,与用户的交互体验至关重要。作为一款优秀的JavaScript框架,ExtJs提供了多种工具和组件帮助开发者快速构建高质量的用户界面。其中,消息框作为一种常见的...

    EXTJS 自定义combo控件

    xtype : 'jxcombo' //配置项 jxValueField:要获取值得字段名称,默认null //公共方法 getJXValue():返回自定义字段的值,如果没有自定义字段,则等价Ext.form.Combo类的getValue()方法

    extjs 自定义验证

    extjs验证 extjs验证 extjs验证 extjs验证extjs验证 extjs验证 extjs验证 extjs验证

    Extjs自定义组件-下拉树

    ### Extjs自定义组件——下拉树:深入解析与实现 在现代Web开发中,Extjs作为一款功能强大且灵活的框架,深受开发者喜爱。它提供了丰富的UI组件库,能够帮助开发者快速构建复杂的用户界面。其中,自定义组件是Extjs...

    extjs用户自定义换肤并保存

    在EXTJS这个强大的JavaScript框架中,用户自定义换肤功能是一项非常吸引人的特性。EXTJS允许用户根据个人喜好调整界面的色彩和样式,为应用程序提供更个性化的用户体验。这一功能的实现基于EXTJS的皮肤机制,它使得...

    包含各种类型的extjs小图标,Extjs4小图标

    - ExtJS 4允许开发者自定义图标,可以通过编写CSS来设置新的背景图片,或者使用Icon类并传入自定义的SVG代码或数据URL。 6. **响应式设计**: - 在移动设备上,图标可能需要调整大小或样式以适应不同的屏幕尺寸。...

    ExtJs自定义分页控件----PM3PagingToolbar.js

    在 ExtJS3.3基础上开发的. 低一点的版本应该也能用. 没有去测试. 参考: Ext.PagingToolbar.js 因为我开发测试完这个分页工具后, 电脑上显示刚好是15:00, 所以取名: PM3PagingToolbar 如有BUG还请各位提出或留言. ...

    ExtJs6.2中包含文本及时间选择框的自定义查询控件的解决方案

    ### ExtJs 6.2 中包含文本及时间选择框的自定义查询控件解决方案 在ExtJs 6.2框架中实现一个具有文本输入与时间选择功能的自定义查询控件是一个常见但实用的需求。本篇文章将详细介绍如何设计并实现这样一个控件,...

    EXTJS主题自定义

    EXTJS主题自定义是关于如何根据EXTJS框架创建和应用个性化视觉主题的过程。EXTJS是一个JavaScript库,用于构建富客户端应用程序,它提供了丰富的组件和强大的数据管理能力。主题是EXTJS应用程序的重要组成部分,它们...

    自定义高级查询Extjs

    在这个场景中,"自定义高级查询Extjs"指的是利用Ext JS框架来构建这样的功能。Ext JS是一个流行的JavaScript库,用于创建富客户端应用程序,特别是与数据展示和操作相关的Web应用。 1. **Ext JS简介** - Ext JS...

    Extjs 自定义树结构实现以及动态表头实现

    在本文中,我们将深入探讨如何使用ExtJS框架来实现自定义树结构以及动态表头的功能。ExtJS是一款强大的JavaScript库,常用于构建富客户端应用程序,它提供了丰富的UI组件和强大的数据绑定机制。VS2015是Visual ...

    extjs自定义控件

    下面将详细介绍ExtJS自定义控件的相关知识点。 1. **自定义控件基础** - **组件模型**:ExtJS基于MVC(Model-View-Controller)模式,其中控件(Component)是View层的核心。每个控件都有自己的配置选项、方法和...

    extjs4中文文档

    8. **主题定制**:EXTJS4允许开发者自定义主题,改变组件的颜色、字体等样式,满足不同项目的需求。 9. **工具栏和菜单**:EXTJS4提供各种工具栏和菜单组件,方便构建应用程序的交互界面。 10. **拖放功能**:...

    ExtJS4多文件上传,带进度条及管理

    在ExtJS4中,可以使用自定义组件或者第三方插件来实现文件上传功能。uploadPanel是一个常见的组件,它提供了一个用户友好的界面,包括文件选择、上传按钮、取消和暂停选项,以及关键的进度条展示。 **四、swfupload...

    ExtJs4.rar

    在本文中,我们将深入探讨ExtJS4这一版本的重要特性、改进以及它如何扩展了先前版本的功能。 首先,ExtJS4在组件化方面有了显著提升。在之前的版本中,组件系统就已经是其核心优势,而ExtJS4进一步优化了这一系统,...

Global site tag (gtag.js) - Google Analytics