Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
plugin_dbui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
w2pext
plugin_dbui
Commits
090cd149
Commit
090cd149
authored
8 years ago
by
LE GAC Renaud
Browse files
Options
Downloads
Patches
Plain Diff
Update Filter.js to work with Dict field.
parent
7fb044af
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!30
Release 0.9.3
,
!29
28 grid filter with dict list
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
static/plugin_dbui/src/grid/Filter.js
+81
-9
81 additions, 9 deletions
static/plugin_dbui/src/grid/Filter.js
with
81 additions
and
9 deletions
static/plugin_dbui/src/grid/Filter.js
+
81
−
9
View file @
090cd149
...
...
@@ -64,6 +64,14 @@ Ext.define('Dbui.grid.Filter', {
scope
:
me
});
}
else
if
(
itemType
===
'
xdictfield
'
)
{
item
.
on
({
change
:
me
.
onChange
,
keychange
:
me
.
onChange
,
scope
:
me
});
}
else
{
item
.
on
(
'
keyup
'
,
me
.
onChange
,
me
,
{
...
...
@@ -106,6 +114,14 @@ Ext.define('Dbui.grid.Filter', {
scope
:
me
});
}
else
if
(
itemType
===
'
xdictfield
'
)
{
item
.
un
({
change
:
me
.
onChange
,
keychange
:
me
.
onChange
,
scope
:
me
});
}
else
{
item
.
un
(
'
keyup
'
,
me
.
onChange
,
me
,
{
...
...
@@ -184,6 +200,69 @@ Ext.define('Dbui.grid.Filter', {
return
filter
;
},
/**
* Build the value to be used by the filter.
*
* Convert properly, Date, list and Dict.
* For List and Dict the filter operator has to be LIKE.
*
* @param {Ext.form.Field} field
*/
getFilterValue
:
function
(
field
)
{
"
use strict
"
;
var
value
=
field
.
getValue
(),
vdict
;
switch
(
field
.
xtype
)
{
case
'
datefield
'
:
if
(
value
instanceof
Date
)
{
value
=
Ext
.
util
.
Format
.
date
(
value
,
field
.
format
);
}
break
;
case
'
xdictfield
'
:
//
// A dict is a collection of (key, value) pairs
// In the database the dict is encoded as a JSON string
// The filter value is therefore encoded as:
//
// "%"key1": "value"%"key2": "value2"%
//
// The compararison operator has to be LIKE since it
// understand % as the jocker.
//
// The string "", "true" and "false" are handled properly
//
vdict
=
""
;
Ext
.
Object
.
each
(
value
,
function
(
prop
,
val
)
{
var
s
=
'
"
'
+
prop
+
'
":
'
;
if
(
val
instanceof
Number
)
{
s
+=
val
;
}
else
if
(
val
===
"
false
"
||
val
===
"
true
"
||
val
===
"
%
"
)
{
s
+=
val
;
}
else
if
(
!
val
)
{
s
+=
"
%
"
;
}
else
{
s
+=
'
"
'
+
val
+
'
"
'
;
}
vdict
+=
(
vdict
.
length
>
0
?
'
%
'
+
s
:
s
);
});
value
=
"
%
"
+
vdict
+
"
%
"
;
break
;
}
return
value
;
},
/**
* Setup filter conditions for non buffered store
*
...
...
@@ -266,15 +345,8 @@ Ext.define('Dbui.grid.Filter', {
store
=
me
.
grid
.
getStore
(),
i
,
k
,
value
,
where
;
// get the field value
value
=
field
.
getValue
();
// handle date using the proper format
if
(
field
.
xtype
===
'
datefield
'
)
{
if
(
value
instanceof
Date
)
{
value
=
Ext
.
util
.
Format
.
date
(
value
,
field
.
format
);
}
}
// get the value to be used by the filter
value
=
me
.
getFilterValue
(
field
);
// update the condition dictionary
if
(
Ext
.
isEmpty
(
value
))
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment