GitHub PullRequestReviewCommentEvent at 2014-05-09 16:07:33
Repository: MapStore
Actor: mbarto
Payload: {"comment":{"url":"https://api.github.com/repos/geosolutions-it/MapStore/pulls/comments/12482750","id":12482750,"diff_hunk":"@@ -112,70 +424,481 @@ gxp.form.FilterField = Ext.extend(Ext.form.CompositeField, {\n              *\n              * Listener arguments:\n              * filter - {OpenLayers.Filter} This filter.\n+             * this - {gxp.form.FilterField} (TODO change sequence of event parameters)\n              */\n             \"change\"\n         ); \n \n         gxp.form.FilterField.superclass.initComponent.call(this);\n     },\n+\n+    /**\n+     * Method: validateValue\n+     * Performs validation checks on the filter field.\n+     *\n+     * Returns:\n+     * {Boolean} True if value is valid. \n+     */\n+    validateValue: function(value, preventMark) {\n+        if (this.filter.type === OpenLayers.Filter.Comparison.BETWEEN) {\n+            return (this.filter.property !== null && this.filter.upperBoundary !== null &&\n+                this.filter.lowerBoundary !== null);\n+        } else {\n+            return (this.filter.property !== null &&\n+                this.filter.value !== null && this.filter.type !== null);\n+        }\n+    },\n     \n     /**\n      * Method: createDefaultFilter\n      * May be overridden to change the default filter.\n      *\n      * Returns:\n-     * {OpenLayers.Filter} By default, returns a comarison filter.\n+     * {OpenLayers.Filter} By default, returns a comparison filter.\n      */\n     createDefaultFilter: function() {\n-        return new OpenLayers.Filter.Comparison();\n+        return new OpenLayers.Filter.Comparison({matchCase: !this.caseInsensitiveMatch});\n     },\n     \n     /**\n      * Method: createFilterItems\n      * Creates a panel config containing filter parts.\n      */\n-    createFilterItems: function() {\n+    createFilterItems: function(type) {\n+        var me = this;\n+        \n+        //controllare il tipo booleano, con l'operatore LIKE e ILIKE da errore\n+        var types = {\n+            \"xsd:boolean\": \"boolean\",\n+            \"xsd:int\": \"int\",\n+            \"xsd:integer\": \"int\",\n+            \"xsd:short\": \"int\",\n+            \"xsd:long\": \"int\",\n+            \"xsd:date\": \"date\",\n+            \"xsd:string\": \"string\",\n+            \"xsd:float\": \"float\",\n+            \"xsd:double\": \"float\"\n+        };     \n+        \n+        this.fieldType = type.split(\":\").pop();    \n+    \n+        var isBetween = this.filter.type === OpenLayers.Filter.Comparison.BETWEEN;\n+\n+        var defaultItemsProp = {\n+            validateOnBlur: false,\n+            disabled: this.filter.type == null,\n+            hidden: true,\n+            ref: \"value\",\n+            value: this.filter.value,\n+            width: 50,\n+            grow: true,\n+            growMin: 50,\n+            anchor: \"100%\",\n+            allowBlank: this.allowBlank,\n+            listeners: {\n+                \"change\": function(field, value) {\n+                    this.filter.value = value;\n+                    this.fireEvent(\"change\", this.filter, this);\n+                },\n+                \"blur\": function(field){\n+                \n+                },\n+                scope: this\n+            }   \n+        };\n         \n+        var lowerBoundaryDefaultItemsProp = {\n+            disabled: this.filter.type == null,\n+            hidden: !isBetween,\n+            value: this.filter.lowerBoundary,\n+            //tooltip: this.lowerBoundaryTip,\n+            grow: true,\n+            growMin: 30,\n+            ref: \"lowerBoundary\",\n+            anchor: \"100%\",\n+            allowBlank: this.allowBlank,\n+            listeners: {\n+                \"change\": function(field, value) {\n+                    this.filter.lowerBoundary = value;\n+                    this.fireEvent(\"change\", this.filter, this);\n+                },\n+                /*\"render\": function(c) {\n+                    Ext.QuickTips.register({\n+                        target: c.getEl(),\n+                        text: this.lowerBoundaryTip\n+                    });\n+                },*/\n+                \"autosize\": function(field, width) {\n+                    field.setWidth(width);\n+                    field.ownerCt.doLayout();\n+                },\n+                scope: this\n+            }\n+        };\n+        \n+        var upperBoundaryDefaultItemsProp = {\n+            disabled: this.filter.type == null,\n+            hidden: !isBetween,\n+            grow: true,\n+            growMin: 30,\n+            ref: \"upperBoundary\",\n+            value: this.filter.upperBoundary,\n+            allowBlank: this.allowBlank,\n+            listeners: {\n+                \"change\": function(field, value) {\n+                    this.filter.upperBoundary = value;\n+                    this.fireEvent(\"change\", this.filter, this);\n+                },\n+                /*\"render\": function(c) {\n+                    Ext.QuickTips.register({\n+                        target: c.getEl(),\n+                        text: this.upperBoundaryTip\n+                    });\n+                },*/\n+                scope: this\n+            }\n+        };\n+                \n+        var itemsTextFieldDefault = Ext.applyIf({\n+            xtype: \"textfield\"\n+        },defaultItemsProp);\n+            \n+        var itemsNumberDoubleFieldDefault = Ext.applyIf({\n+            xtype: \"numberfield\",\n+            allowDecimals:true,\n+            decimalPrecision: 10\n+        },defaultItemsProp);\n+        \n+        var itemsNumberIntFieldDefault = Ext.applyIf({\n+            xtype: \"numberfield\",\n+            allowDecimals:false\n+        },defaultItemsProp);        \n+\n+        var itemsDateFieldDefault = Ext.applyIf({\n+            xtype: \"datefield\",\n+            width: 70,\n+            allowBlank: false,\n+            format: this.dateFormat\n+        },defaultItemsProp);\n+        \n+        var itemsDateTimeFieldDefault = Ext.applyIf({\n+            xtype: \"datefield\",\n+            width: 70,\n+            allowBlank: false,\n+            format: 'c'\n+        },defaultItemsProp);        \n+        \n+        /*var itemsBooleanFieldDefault = Ext.applyIf({\n+            xtype: 'combo',\n+            width: 60,\n+            typeAhead: true,\n+            triggerAction: 'all',\n+            lazyRender:false,\n+            mode: 'local',\n+            autoLoad:true,\n+            displayField: 'text',\n+            valueField:'value',\n+            value:'false',\n+            readOnly:false,\n+            editable: false,\n+            store: new Ext.data.ArrayStore({\n+                fields: [\n+                    'value',\n+                    'text'\n+                ],\n+                data: [\n+                    ['false', 'FALSE'],\n+                    ['true', 'TRUE']\n+                ]\n+            })\n+        },defaultItemsProp);*/\n+            \n+        var itemsTextFieldLowerBoundary = Ext.apply({\n+                    xtype: \"textfield\",\n+                    //id: \"items_string_lowerBoundary\"\n+                },lowerBoundaryDefaultItemsProp);\n+\n+        var itemsTextFieldUpperBoundary = Ext.apply({\n+                    xtype: \"textfield\",\n+                    //id: \"items_string_upperBoundary\"\n+                },upperBoundaryDefaultItemsProp);\n+\n+        var itemsNumberDoubleFieldLowerBoundary = Ext.apply({\n+                    xtype: \"numberfield\",\n+                    //id: \"items_number_lowerBoundary\",\n+                    allowDecimals:true,\n+                    decimalPrecision: 10\n+                },lowerBoundaryDefaultItemsProp);\n+\n+        var itemsNumberDoubleFieldUpperBoundary = Ext.apply({\n+                    xtype: \"numberfield\",\n+                    //id: \"items_number_upperBoundary\",\n+                    allowDecimals:true,\n+                    decimalPrecision: 10\n+                },upperBoundaryDefaultItemsProp);\n+                \n+        var itemsNumberIntFieldLowerBoundary = Ext.apply({\n+                    xtype: \"numberfield\",\n+                    //id: \"items_number_lowerBoundary\",\n+                    allowDecimals:false\n+                },lowerBoundaryDefaultItemsProp);\n+\n+        var itemsNumberIntFieldUpperBoundary = Ext.apply({\n+                    xtype: \"numberfield\",\n+                    //id: \"items_number_upperBoundary\",\n+                    allowDecimals:false\n+                },upperBoundaryDefaultItemsProp);                \n+\n+        var itemsDateFieldLowerBoundary = Ext.apply({\n+                    xtype: \"datefield\",\n+                    width: 70,\n+                    allowBlank: false,\n+                    format: this.dateFormat\n+                },lowerBoundaryDefaultItemsProp);\n+\n+        var itemsDateFieldUpperBoundary = Ext.apply({\n+                    xtype: \"datefield\",\n+                    width: 70,\n+                    allowBlank: false,\n+                    format: this.dateFormat\n+                },upperBoundaryDefaultItemsProp);\n+                \n+        var itemsDateTimeFieldLowerBoundary = Ext.apply({\n+                    xtype: \"datefield\",\n+                    width: 70,\n+                    allowBlank: false,\n+                    format: 'c'\n+                },lowerBoundaryDefaultItemsProp);\n+\n+        var itemsDateTimeFieldUpperBoundary = Ext.apply({\n+                    xtype: \"datefield\",\n+                    width: 70,\n+                    allowBlank: false,\n+                    format: 'c'\n+                },upperBoundaryDefaultItemsProp);\n+                \n         return [\n-            this.attributesComboConfig, {\n+            this.attributesComboConfig, Ext.applyIf({\n                 xtype: \"gxp_comparisoncombo\",\n-                disabled: true,\n+                ref: \"type\",\n+                disabled: this.filter.property == null,\n                 allowBlank: this.allowBlank,\n                 value: this.filter.type,\n                 listeners: {\n                     select: function(combo, record) {\n-                        this.items.get(2).enable();\n-                        this.filter.type = record.get(\"value\");\n-                        // Ilike (ignore case)\n-                        if(this.filter.type == \"ilike\"){\n-                            this.filter.type = OpenLayers.Filter.Comparison.LIKE;\n-                            this.filter.matchCase = false;\n-                        }else{\n-                            // default matches case. See OpenLayers.Filter.Comparison#matchCase\n-                            this.filter.matchCase = true;\n-                        }\n-                        this.fireEvent(\"change\", this.filter);\n+                    \n+                        this.items.get(2).enable();                        \n+                        this.items.get(3).enable();\n+                        this.items.get(4).enable();                        \n+                        this.items.get(5).enable();\n+                        this.items.get(6).enable();                        \n+                        this.items.get(7).enable();\n+                        this.items.get(8).enable();                        \n+                        this.items.get(9).enable();\n+                        this.items.get(10).enable();\n+                        this.items.get(11).enable();\n+                        this.items.get(12).enable();                        \n+                        this.items.get(13).enable();                        \n+                        this.items.get(14).enable();\n+                        this.items.get(15).enable();\n+                        this.items.get(16).enable();\n+                        \n+                        this.setFilterType(record.get(\"value\"),this.fieldType);\n+                        this.fireEvent(\"change\", this.filter, this);\n                     },\n-                    scope: this\n-                }\n-            }, {\n-                xtype: \"textfield\",\n-                disabled: true,\n-                value: this.filter.value,\n-                width: 50,\n-                grow: true,\n-                growMin: 50,\n-                anchor: \"100%\",\n-                allowBlank: this.allowBlank,\n-                listeners: {\n-                    change: function(el, value) {\n-                        this.filter.value = value;\n-                        this.fireEvent(\"change\", this.filter);\n+                    expand: function(combo) {\n+                        var store = combo.getStore();\n+                        store.clearFilter();\n+                        if(this.fieldType === \"date\" || this.fieldType === \"dateTime\" || this.fieldType === \"time\" || this.fieldType === \"int\" || this.fieldType === \"double\" || this.fieldType === \"decimal\" || this.fieldType === \"integer\" || this.fieldType === \"long\" || this.fieldType === \"float\" || this.fieldType === \"short\"){\n+                            store.filter([\n+                              {\n+                                fn   : function(record) {\n+                                    return (record.get('name') === \"=\") || (record.get('name') === \"<>\") || (record.get('name') === \"<\") || (record.get('name') === \">\") || (record.get('name') === \"<=\") || (record.get('name') === \">=\") || (record.get('name') === \"between\");\n+                                },\n+                                scope: this\n+                              }                      \n+                            ]);\n+                        }/*else if(this.fieldType === \"boolean\"){\n+                            store.filter([\n+                              {\n+                                fn   : function(record) {\n+                                    return (record.get('name') === \"=\");\n+                                },\n+                                scope: this\n+                              }                      \n+                            ]);\n+                        }*/ \n                     },\n                     scope: this\n                 }\n-            }\n+            }, this.comparisonComboConfig),\n+            \n+                itemsTextFieldDefault, //(2)\n+                itemsDateFieldDefault, //(3)\n+                itemsDateTimeFieldDefault, //(4)\n+                //itemsBooleanFieldDefault, //()\n+                itemsNumberDoubleFieldDefault, //(5)\n+                itemsNumberIntFieldDefault, //(6)\n+                \n+                itemsTextFieldLowerBoundary, //(7)\n+                itemsDateFieldLowerBoundary, //(8)\n+                itemsDateTimeFieldLowerBoundary, //(9)                \n+                itemsNumberDoubleFieldLowerBoundary, //(10)\n+                itemsNumberIntFieldLowerBoundary, //(11)\n+                \n+                itemsTextFieldUpperBoundary, //(12)\n+                itemsDateFieldUpperBoundary, //(13)                \n+                itemsDateTimeFieldUpperBoundary, //(14)\n+                itemsNumberDoubleFieldUpperBoundary, //(15)\n+                itemsNumberIntFieldUpperBoundary //(16)\n         ];\n+    },\n+    \n+    setFilterType: function(type,fieldType) {\n+        this.filter.type = type;\n+        \n+        // Ilike (ignore case)\n+        if(this.filter.type == \"ilike\"){\n+            this.filter.type = OpenLayers.Filter.Comparison.LIKE;\n+            this.filter.matchCase = false;\n+        }else{\n+            // default matches case. See OpenLayers.Filter.Comparison#matchCase\n+            this.filter.matchCase = true;\n+        }\n+\n+        if (type === OpenLayers.Filter.Comparison.BETWEEN) {\n+            \n+            if(this.fieldType === \"string\"){\n+                this.items.get(2).hide();\n+                this.items.get(3).hide();\n+                this.items.get(4).hide();\n+                this.items.get(5).hide();\n+                this.items.get(6).hide();\n+                this.items.get(7).show();\n+                this.items.get(12).show();\n+            }else if(this.fieldType === \"date\"){\n+                this.items.get(2).hide();\n+                this.items.get(3).hide();\n+                this.items.get(4).hide();\n+                this.items.get(5).hide();\n+                this.items.get(6).hide(); \n+                this.items.get(8).show();\n+                this.items.get(13).show();            \n+            }else if(this.fieldType === \"dateTime\"){\n+                this.items.get(2).hide();\n+                this.items.get(3).hide();\n+                this.items.get(4).hide();\n+                this.items.get(5).hide();\n+                this.items.get(6).hide();\n+                this.items.get(9).show();\n+                this.items.get(14).show();               \n+            }else if(this.fieldType === \"double\" || this.fieldType === \"decimal\" || this.fieldType === \"float\"){\n+                this.items.get(2).hide();\n+                this.items.get(3).hide();\n+                this.items.get(4).hide();\n+                this.items.get(5).hide();\n+                this.items.get(6).hide();\n+                this.items.get(10).show();\n+                this.items.get(15).show();               \n+            }else if(this.fieldType === \"int\" || this.fieldType === \"integer\" || this.fieldType === \"long\" || this.fieldType === \"short\"){\n+                this.items.get(2).hide();\n+                this.items.get(3).hide();\n+                this.items.get(4).hide();\n+                this.items.get(5).hide();\n+                this.items.get(6).hide();\n+                this.items.get(11).show();\n+                this.items.get(16).show();                        \n+            }else{\n+                this.items.get(2).hide();\n+                this.items.get(3).hide();\n+                this.items.get(4).hide();\n+                this.items.get(5).hide();\n+                this.items.get(6).hide();\n+                this.items.get(7).show();\n+                this.items.get(12).show();            \n+            }            \n+            \n+        } else {\n+\n+            if(this.fieldType === \"string\"){\n+                this.items.get(2).show();\n+                this.items.get(3).hide();\n+                this.items.get(4).hide();\n+                this.items.get(5).hide();\n+                this.items.get(6).hide();\n+                \n+                this.items.get(7).hide();\n+                this.items.get(12).hide();\n+            }else if(this.fieldType === \"date\"){\n+                this.items.get(2).hide();\n+                this.items.get(3).show();\n+                this.items.get(4).hide();\n+                this.items.get(5).hide();\n+                this.items.get(6).hide();\n+                \n+                this.items.get(8).hide();\n+                this.items.get(13).hide();            \n+            }else if(this.fieldType === \"dateTime\"){\n+                this.items.get(2).hide();\n+                this.items.get(3).hide();\n+                this.items.get(4).show();\n+                this.items.get(5).hide();\n+                this.items.get(6).hide();\n+                \n+                this.items.get(9).hide();\n+                this.items.get(14).hide();        \n+            }else if(this.fieldType === \"double\" || this.fieldType === \"decimal\" || this.fieldType === \"float\"){\n+                this.items.get(2).hide();\n+                this.items.get(3).hide();\n+                this.items.get(4).hide();\n+                this.items.get(5).show();\n+                this.items.get(6).hide();                    \n+                \n+                this.items.get(10).hide();\n+                this.items.get(15).hide();              \n+            }else if(this.fieldType === \"int\" || this.fieldType === \"integer\" || this.fieldType === \"long\" || this.fieldType === \"short\"){\n+                this.items.get(2).hide();\n+                this.items.get(3).hide();\n+                this.items.get(4).hide();\n+                this.items.get(5).hide();\n+                this.items.get(6).show();\n+                \n+                this.items.get(11).hide();\n+                this.items.get(16).hide();\n+            }else{\n+                this.items.get(2).show();\n+                this.items.get(3).hide();\n+                this.items.get(4).hide();\n+                this.items.get(5).hide();\n+                this.items.get(6).hide();\n+                \n+                this.items.get(7).hide();\n+                this.items.get(12).hide();         \n+            }          \n+ ","path":"mapcomposer/app/static/externals/gxp/src/script/widgets/form/FilterField.js","position":870,"original_position":870,"commit_id":"64d3732b258ba1e9d24e195731ec68fb5117ca84","original_commit_id":"64d3732b258ba1e9d24e195731ec68fb5117ca84","user":{"login":"mbarto","id":2770528,"avatar_url":"https://avatars.githubusercontent.com/u/2770528?","gravatar_id":"b4b895b7f0da532766178eed8dd7cd6d","url":"https://api.github.com/users/mbarto","html_url":"https://github.com/mbarto","followers_url":"https://api.github.com/users/mbarto/followers","following_url":"https://api.github.com/users/mbarto/following{/other_user}","gists_url":"https://api.github.com/users/mbarto/gists{/gist_id}","starred_url":"https://api.github.com/users/mbarto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbarto/subscriptions","organizations_url":"https://api.github.com/users/mbarto/orgs","repos_url":"https://api.github.com/users/mbarto/repos","events_url":"https://api.github.com/users/mbarto/events{/privacy}","received_events_url":"https://api.github.com/users/mbarto/received_events","type":"User","site_admin":false},"body":"here too","created_at":"2014-05-09T16:07:33Z","updated_at":"2014-05-09T16:07:33Z","html_url":"https://github.com/geosolutions-it/MapStore/pull/384#discussion_r12482750","pull_request_url":"https://api.github.com/repos/geosolutions-it/MapStore/pulls/384","_links":{"self":{"href":"https://api.github.com/repos/geosolutions-it/MapStore/pulls/comments/12482750"},"html":{"href":"https://github.com/geosolutions-it/MapStore/pull/384#discussion_r12482750"},"pull_request":{"href":"https://api.github.com/repos/geosolutions-it/MapStore/pulls/384"}}}}