Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
ecommerce-ui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
ecommerce-ui
Commits
6190e95f
Commit
6190e95f
authored
Apr 24, 2014
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
app: add query params matched to JIO api and lookup in setParam and setSubordinate
parent
52fea96c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
98 additions
and
15 deletions
+98
-15
js/erp5_loader.js
js/erp5_loader.js
+98
-15
No files found.
js/erp5_loader.js
View file @
6190e95f
...
...
@@ -6011,6 +6011,14 @@
// test for auth based access
pass
.
grant
=
true
;
// update initial query with urlQuery if one was passed
if
(
pass
.
url_dict
.
url_query
)
{
pass
.
config_dict
.
initial_query
=
util
.
mergeObject
(
pass
.
url_dict
.
url_query
,
pass
.
config_dict
.
initial_query
||
{}
);
}
// fetch field definitions - why make a query without fieldlist?
if
(
pass
.
grant
||
pass
.
mode
===
"
new
"
)
{
app
.
util
.
loader
(
""
,
"
status_dict.loading_config
"
);
...
...
@@ -6853,22 +6861,25 @@
* @param {object} wrapper Wrapping document
* @returns {object} kid
*/
// TODO: clean up, no exceptions (location), clear key + val!
// TODO: make lookup parsing robust!
app
.
util
.
setParam
=
function
(
kid
,
wrapper
)
{
var
i
,
len
,
param_list
,
param
,
href
,
loc
,
splitter
,
val
;
var
i
,
len
,
param_list
,
param
,
href
,
loc
,
splitter
,
key
,
val
,
lookup
,
new_
val
;
param_list
=
kid
.
logic
.
setParam
;
for
(
i
=
0
,
len
=
param_list
.
length
;
i
<
len
;
i
+=
1
)
{
param
=
param_list
[
i
];
switch
(
param
[
1
])
{
val
=
param
[
1
];
key
=
param
[
0
];
switch
(
val
)
{
// NOTE: hacked for oauth redirect url
// TODO: remove, not generic!
// TODO: find way to include encoding when setting a href
case
"
location
"
:
href
=
kid
.
direct
.
href
;
splitter
=
href
.
indexOf
(
"
?
"
)
>
0
?
"
&
"
:
"
?
"
;
loc
=
window
.
location
;
kid
.
direct
.
href
+=
splitter
+
window
.
encodeURIComponent
(
param
[
0
]
)
+
kid
.
direct
.
href
+=
splitter
+
window
.
encodeURIComponent
(
key
)
+
"
=
"
+
window
.
encodeURIComponent
(
loc
.
origin
+
loc
.
pathname
+
loc
.
hash
.
split
(
"
?
"
)[
0
]
);
...
...
@@ -6876,15 +6887,27 @@
// set values or flag for subordination inside map.element
default
:
if
(
param
[
1
].
split
(
"
subordinate_
"
).
length
>
1
)
{
kid
.
needs_subordination
=
true
;
}
else
{
val
=
param
[
0
];
kid
.
logic
[
val
]
=
kid
.
logic
[
val
]
||
""
;
kid
.
logic
[
val
]
+=
wrapper
.
property_dict
.
data
.
doc
[
param
[
1
]];
if
(
val
===
"
href
"
)
{
kid
.
logic
[
val
]
=
window
.
encodeURIComponent
(
kid
.
logic
[
val
]);
kid
.
logic
[
key
]
=
kid
.
logic
[
key
]
||
""
;
if
(
val
.
split
(
"
subordinate_
"
).
length
>
1
)
{
// NOTE: try to get value from state/URL before flagging
// NOTE: must check for equality, otherwise id foo > foofoo
lookup
=
wrapper
.
property_dict
.
state
.
query
.
query
;
if
(
lookup
&&
lookup
.
indexOf
(
val
)
>
-
1
)
{
new_val
=
lookup
.
split
(
val
)[
1
].
split
(
"
+
"
)[
0
]
.
replace
(
"
:=
"
,
""
).
replace
(
"
)
"
,
""
);
if
(
kid
.
logic
[
key
]
!==
new_val
)
{
kid
.
logic
[
key
]
+=
new_val
;
}
}
else
{
kid
.
needs_subordination
=
true
;
}
}
else
{
kid
.
logic
[
key
]
+=
wrapper
.
property_dict
.
data
.
doc
[
val
];
// if (key === "href") {
// kid.logic[key] = window.encodeURIComponent(kid.logic[key]);
// }
delete
kid
.
logic
.
setParam
[
i
];
}
}
...
...
@@ -6892,6 +6915,56 @@
return
kid
;
};
/**
* Parse url query parameter into storage query object
* Expects the following URL format:
*
* #foo&
* query:id=bar+foo=baz&
* limit:start=0+items=5&
* sort:id=ascending+foo=descending&
* select:id+foo+baz+cous
*
* @method parseUrlQuery
* @param {string} str String to parse
* @returns {object} Query to run based on parameters
*/
app
.
util
.
parseQueryParameter
=
function
(
str
)
{
var
i
,
param_list
,
param_len
,
param
,
initial_query
,
indicator
,
value_list
;
param_list
=
str
.
split
(
"
&
"
);
initial_query
=
{};
for
(
i
=
0
,
param_len
=
param_list
.
length
;
i
<
param_len
;
i
+=
1
)
{
param
=
param_list
[
i
].
split
(
"
:
"
);
indicator
=
param
[
0
];
value_list
=
param
[
1
];
switch
(
indicator
)
{
case
"
query
"
:
initial_query
.
query
=
param
[
1
].
replace
(
"
=
"
,
"
:=
"
,
"
g
"
)
.
replace
(
"
+
"
,
"
AND
"
,
"
g
"
);
break
;
case
"
limit
"
:
// NOTE: Thanks Tristan!
initial_query
.
limit
=
param
[
1
].
split
(
"
+
"
)
.
map
(
function
(
part
)
{
return
part
.
split
(
"
=
"
)[
1
];
});
break
;
case
"
sort
"
:
initial_query
.
sort_on
=
param
[
1
].
split
(
"
+
"
).
map
(
function
(
part
)
{
var
s
=
part
.
split
(
"
=
"
);
return
[
s
[
0
],
s
[
1
]];
});
break
;
case
"
select
"
:
initial_query
.
select_list
=
param
[
1
].
replace
(
"
+
"
,
"
,
"
,
"
g
"
);
break
;
}
}
return
initial_query
;
};
/**
* Parse a clicked link to determine which page to load
* @method parseLink
...
...
@@ -6899,7 +6972,8 @@
* @return {object} navigation object
**/
app
.
util
.
parseLink
=
function
(
url
)
{
var
i
,
hash
,
path
,
clean_hash
,
decode
,
root
,
last
;
var
i
,
hash
,
path
,
clean_hash
,
decode
,
root
,
last
,
stripped
,
url_query
,
strip
;
hash
=
$
.
mobile
.
path
.
parseUrl
(
url
.
replace
(
$
.
mobile
.
dialogHashKey
,
""
)
...
...
@@ -6914,7 +6988,15 @@
clean_hash
=
hash
;
}
if
(
clean_hash
===
""
)
{
// query parameters
strip
=
clean_hash
.
split
(
"
&
"
);
stripped
=
strip
[
0
];
if
(
strip
.
length
>
1
)
{
url_query
=
app
.
util
.
parseQueryParameter
(
strip
[
1
]);
}
if
(
stripped
===
""
)
{
root
=
util
.
getPage
().
getAttribute
(
"
data-url
"
);
return
{
"
data_url
"
:
root
,
...
...
@@ -6922,12 +7004,13 @@
};
}
// check for mode
path
=
clean_hash
.
split
(
"
/
"
);
path
=
stripped
.
split
(
"
/
"
);
last
=
path
.
length
-
1
;
return
{
"
mode
"
:
path
[
last
],
"
fragment_list
"
:
path
,
"
url_query
"
:
url_query
,
"
data_url
"
:
clean_hash
,
"
layout_level
"
:
last
,
"
deeplink
"
:
true
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment