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
934722cb
Commit
934722cb
authored
Oct 24, 2013
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor parse-link to enable deeplinking
parent
e1060f36
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
42 deletions
+32
-42
js/erp5_loader.js
js/erp5_loader.js
+32
-42
No files found.
js/erp5_loader.js
View file @
934722cb
...
...
@@ -323,7 +323,6 @@
/* ********************************************************************** */
factory
.
map_buttons
=
erp5
.
map_buttons
;
factory
.
map_info
=
erp5
.
map_info
;
factory
.
map_types
=
erp5
.
map_portal_types
;
factory
.
map_actions
=
erp5
.
map_actions
;
factory
.
map_gadgets
=
erp5
.
map_gadgets
;
factory
.
map_references
=
erp5
.
map_references
;
...
...
@@ -2456,7 +2455,7 @@
"
_mimetype
"
:
"
application/json
"
});
};
url
=
"
data/
"
+
factory
.
map_types
[
attachment
]
+
"
.json
"
;
url
=
"
data/
"
+
attachment
+
"
.json
"
;
return
jIO
.
util
.
ajax
({
"
url
"
:
url
,
"
dataType
"
:
'
json
'
})
...
...
@@ -2502,6 +2501,7 @@
}
return
url
;
};
/**
* parse a link into query-able parameters
* @method parseLink
...
...
@@ -2509,47 +2509,37 @@
* @param {object} location object
* @return {object} pointer object
*/
// TODO: map this to URL router!
refactor...
util
.
parseLink
=
function
(
url
,
location
)
{
var
i
,
href
,
pointers
,
url_fragments
,
fragment
,
identifier
;
// TODO: map this to URL router!
And... this is crap!
util
.
parseLink
=
function
(
url
)
{
var
fragments
,
config
;
if
(
url
===
undefined
)
{
// deeplink
if
(
location
!==
undefined
)
{
href
=
location
.
href
;
pointers
=
{
"
url
"
:
href
config
=
{
"
url
"
:
url
||
location
.
href
};
// don't show index.html > /
// WARNING: requires IE8- requires shim
// TODO: not sure that id can be used globally!!!
if
(
href
.
substr
(
href
.
lastIndexOf
(
'
/
'
)
+
1
)
===
""
)
{
pointers
[
"
id
"
]
=
util
.
getActivePageModule
();
return
pointers
;
}
if
(
url
===
undefined
)
{
if
(
location
.
hash
)
{
// TODO: break this down further e.g. #invoices/1234-56767/1 (map?)
config
[
"
id
"
]
=
location
.
hash
.
replace
(
"
#
"
,
""
);
// flag to generate a deeplinked page dynamically!
config
[
"
deeplink
"
]
=
true
;
}
else
{
util
.
errorHandler
({
"
Error
"
:
"
parseLink: Missing location object
"
});
// all we can do
config
[
"
id
"
]
=
util
.
getActivePageModule
();
}
}
else
{
// clicked link
url_fragments
=
util
.
removeTrailingSlash
(
url
).
split
(
"
/
"
);
pointers
=
{
"
url
"
:
url
};
fragments
=
util
.
removeTrailingSlash
(
url
).
split
(
"
/
"
);
for
(
i
=
0
;
i
<
url_
fragments
.
length
;
i
+=
1
)
{
fragment
=
url_
fragments
[
i
];
for
(
i
=
0
;
i
<
fragments
.
length
;
i
+=
1
)
{
fragment
=
fragments
[
i
];
identifier
=
fragment
.
split
(
"
;
"
);
if
(
identifier
[
1
]
!==
undefined
)
{
pointers
[
identifier
[
0
]]
=
identifier
[
1
].
split
(
"
=
"
)[
1
];
config
[
identifier
[
0
]]
=
identifier
[
1
].
split
(
"
=
"
)[
1
];
}
}
return
pointers
;
}
return
undefined
;
return
config
;
};
...
...
@@ -2576,9 +2566,13 @@
* @param {object} pointer Parsed link containing info on page to generate
* @param {boolean} create Create a page or not
*/
// TODO: either page id or data-module define what happens. Improve.
init
.
parsePage
=
function
(
pointers
,
create
)
{
var
page
,
config
=
pointers
||
util
.
parseLink
(
undefined
,
location
);
// NOTE: parseLink is called here in case pointers is undefined!
init
.
parsePage
=
function
(
url
,
create
)
{
var
config
=
util
.
parseLink
(
url
);
if
(
config
.
deeplink
)
{
create
=
true
;
}
init
.
fetchPageLayouts
(
"
settings
"
,
config
.
id
)
.
then
(
function
(
layouts
)
{
...
...
@@ -2661,7 +2655,7 @@
// no need to fetch field definitions if we are updating?
if
(
create
!==
false
)
{
return
util
.
fetchConfiguration
(
"
settings
"
,
"
portal_types
"
,
portal_type
"
settings
"
,
"
portal_types
"
,
gadget_config
.
portal_type_fields
);
}
return
undefined
;
...
...
@@ -3002,18 +2996,14 @@
// generate dynamic pages
.
on
(
"
pagebeforechange
"
,
function
(
e
,
data
)
{
var
page
;
// TODO: mercy...not merci...
if
(
typeof
data
.
toPage
===
"
string
"
)
{
page
=
document
.
getElementById
(
data
.
toPage
.
replace
(
"
#
"
,
""
));
if
(
page
||
// stay calm if...
if
(
document
.
getElementById
(
data
.
toPage
.
replace
(
"
#
"
,
""
))
||
data
.
toPage
===
$
.
mobile
.
getDocumentUrl
()
||
data
.
options
.
role
===
"
popup
"
)
{
return
;
}
init
.
parsePage
(
util
.
parseLink
(
data
.
toPage
)
,
true
);
init
.
parsePage
(
data
.
toPage
,
true
);
e
.
preventDefault
();
}
})
...
...
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