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
1cc40cdc
Commit
1cc40cdc
authored
Mar 17, 2014
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed unnecessary code, prepare to switch to async
parent
d9a502cb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
213 additions
and
319 deletions
+213
-319
js/erp5_loader.js
js/erp5_loader.js
+213
-319
No files found.
js/erp5_loader.js
View file @
1cc40cdc
...
...
@@ -3,9 +3,6 @@
jQuery, i18n, hello, Recaptcha, XMLHttpRequest, Modernizr */
// *************************************************************************
// WARNING:
// WARNING: HACKED TOGETHER SO IT WORKS - FOR DEMO PURPOSE ONLY!!!
...
...
@@ -14,8 +11,6 @@
(
function
(
window
,
document
,
$
)
{
"
use strict
"
;
...
...
@@ -547,106 +542,6 @@
}
};
/**
* HACKED handlers
**/
map
.
handlers
=
{
/**
* @method software_list
* @param {object} reply Object received from previous chain element
* @param {object} response Object object passed on to next element
**/
"
software_list
"
:
function
(
reply
)
{
var
config
,
property
,
query
,
props
,
store
,
pass
=
reply
.
pass
;
store
=
app
.
storage_dict
;
if
(
store
.
property_dict
.
storage
)
{
config
=
{
"
url
"
:
app
.
storage_dict
.
property_dict
.
items
.
storage_list
[
0
].
url
,
"
type
"
:
"
GET
"
,
"
xhrFields
"
:
{
"
withCredentials
"
:
true
}
};
// access storage
return
jIO
.
util
.
ajax
(
config
)
.
then
(
function
(
response
)
{
query
=
util
.
parse
(
response
.
target
.
responseText
).
_links
.
slapos_jump
.
_query
;
if
(
pass
.
config
.
initial_query
===
undefined
)
{
pass
.
config
.
initial_query
=
{};
}
pass
.
config
.
initial_query
.
query
=
query
;
pass
.
config
.
initial_query
.
skip_type
=
true
;
pass
.
preserve_lookup
=
reply
.
pass
.
value
;
// set a flag to now run allDocs
pass
.
force_allDocs
=
true
;
// pass hacked query back into chain
if
(
reply
.
response
)
{
return
{
"
response
"
:
util
.
parse
(
reply
.
response
),
"
pass
"
:
pass
};
}
return
{
"
pass
"
:
pass
}
})
.
fail
(
util
.
error
);
}
return
(
reply
);
},
/**
* @method subscription_details
* @param {object} reply Object received from previous chain element
* @param {object} response Object object passed on to next element
**/
"
subscription_details
"
:
function
(
reply
)
{
var
config
,
property
,
query
,
fetch
,
href
,
store
,
pass
=
reply
.
pass
;
store
=
app
.
storage_dict
;
if
(
store
.
property_dict
.
storage
)
{
// access storage
fetch
=
reply
.
pass
.
value
||
reply
.
pass
.
state
.
query
.
force
;
return
store
.
items
.
get
({
"
_id
"
:
window
.
decodeURIComponent
(
fetch
)})
.
then
(
function
(
answer
)
{
query
=
util
.
parse
(
answer
).
data
.
_links
.
slapos_jump
.
_query
;
if
(
pass
.
config
.
initial_query
===
undefined
)
{
pass
.
config
.
initial_query
=
{};
}
pass
.
config
.
initial_query
.
query
=
query
;
pass
.
config
.
initial_query
.
skip_type
=
true
;
pass
.
preserve_lookup
=
reply
.
pass
.
value
;
// set a flag to now run allDocs
pass
.
force_allDocs
=
true
;
// pass hacked query back into chain
if
(
reply
.
response
)
{
return
{
"
response
"
:
util
.
parse
(
reply
.
response
),
"
pass
"
:
pass
};
}
return
{
"
pass
"
:
pass
}
}).
fail
(
util
.
error
);
}
return
(
reply
);
}
};
/**
* Add connection to application standard actions or add own actions here
* @object map.actions
...
...
@@ -2999,25 +2894,28 @@
}
answer
=
app
.
setContent
(
element
);
if
(
answer
.
childElementCount
===
undefined
)
{
promise_list
[
i
]
=
answer
;
}
else
{
promise_list
[
i
]
=
RSVP
.
resolve
(
answer
);
}
content
.
appendChild
(
answer
);
// if (answer.childElementCount === undefined) {
// promise_list[i] = answer;
// } else {
// promise_list[i] = RSVP.resolve(answer);
// }
}
}
collapsible
.
appendChild
(
content
);
return
RSVP
.
all
(
promise_list
)
.
then
(
function
(
responses
)
{
for
(
k
=
0
,
m
=
responses
.
length
;
k
<
m
;
k
+=
1
)
{
content
.
appendChild
(
responses
[
k
]);
}
collapsible
.
appendChild
(
content
);
return
collapsible
;
});
return
collapsible
;
//return collapsible;
// return RSVP.all(promise_list)
// .then(function(responses) {
// for (k = 0, m = responses.length; k < m; k += 1) {
// content.appendChild(responses[k]);
// }
// collapsible.appendChild(content);
//
// return collapsible;
// });
}
};
...
...
@@ -6700,61 +6598,6 @@
return
obj
;
};
/**
* parse a link into query-able parameters
* @method parseLink
* @param {string} url Url to go to
* @return {object} pointer object
*/
app
.
generateLinkObject
=
function
(
url
)
{
var
i
,
query
,
path
,
clean_hash
,
config
,
backup
,
decode
;
path
=
$
.
mobile
.
path
.
parseUrl
(
url
.
replace
(
$
.
mobile
.
dialogHashKey
,
""
));
decode
=
util
.
testForString
(
"
%2
"
,
path
.
hash
,
true
)
&&
util
.
testForString
(
"
\
/
"
,
path
.
hash
,
true
)
===
false
;
clean_hash
=
decode
?
window
.
decodeURIComponent
(
path
.
hash
).
replace
(
"
#
"
,
""
)
:
path
.
hash
.
replace
(
"
#
"
,
""
);
backup
=
0
;
config
=
{};
if
(
clean_hash
===
""
)
{
config
.
data_url
=
config
.
layout_identifier
=
util
.
getPage
().
getAttribute
(
"
data-url
"
);
}
else
{
// NOTE: as the hash will be set as page id by JQM, we cannot pass
// complex structures or query parameters to not produce invalid HTML
// check for mode(s)
query
=
clean_hash
.
split
(
"
/
"
);
// TODO: this should be generic and without a backup....
// TODO: the whole view handling is not flexible, refactor!
for
(
i
=
0
;
i
<
query
.
length
;
i
+=
1
)
{
switch
(
query
[
i
])
{
case
"
new
"
:
config
.
mode
=
"
new
"
;
backup
=
1
;
break
;
case
"
add
"
:
case
"
config
"
:
case
"
scope
"
:
case
"
ssl_on
"
:
case
"
ssl_off
"
:
case
"
ssl
"
:
case
"
request
"
:
case
"
installation
"
:
config
.
mode
=
query
[
i
];
break
;
}
}
config
.
fragment_list
=
clean_hash
.
split
(
"
/
"
);
config
.
data_url
=
clean_hash
;
config
.
layout_level
=
config
.
fragment_list
.
length
-
1
-
backup
;
config
.
deeplink
=
true
;
config
.
layout_identifier
=
clean_hash
.
split
(
"
/
"
)[
0
];
}
return
config
;
};
/**
* Generate an action object (vs duplicate in every action call)
* @method generateActionObject
...
...
@@ -6817,59 +6660,6 @@
document
.
title
=
value
;
};
/**
* cross-browser wrapper for DOMContentLoaded
* Thx Diego Perini http://javascript.nwbox.com/ContentLoaded/
* @method contentLoaded
* @param {object} win Window
* @param {method} fn Callback to run
*/
app
.
contentLoaded
=
function
(
win
,
fn
)
{
var
done
=
false
,
top
=
true
,
doc
=
win
.
document
,
root
=
doc
.
documentElement
,
add
=
doc
.
addEventListener
?
'
addEventListener
'
:
'
attachEvent
'
,
rem
=
doc
.
addEventListener
?
'
removeEventListener
'
:
'
detachEvent
'
,
pre
=
doc
.
addEventListener
?
''
:
'
on
'
,
init
=
function
(
e
)
{
if
(
e
.
type
===
'
readystatechange
'
&&
doc
.
readyState
!==
'
complete
'
)
{
return
;
}
(
e
.
type
===
'
load
'
?
win
:
doc
)[
rem
](
pre
+
e
.
type
,
init
,
false
);
if
(
!
done
)
{
done
=
true
;
fn
.
call
(
win
,
e
.
type
||
e
);
}
},
poll
=
function
()
{
try
{
root
.
doScroll
(
'
left
'
);
}
catch
(
e
)
{
window
.
setTimeout
(
poll
,
50
);
return
;
}
init
(
'
poll
'
);
};
if
(
doc
.
readyState
===
'
complete
'
)
{
fn
.
call
(
win
,
'
lazy
'
);
}
else
{
if
(
doc
.
createEventObject
&&
root
.
doScroll
)
{
try
{
top
=
!
win
.
frameElement
;
}
catch
(
ignore
)
{}
if
(
top
)
{
poll
();
}
}
doc
[
add
](
pre
+
'
DOMContentLoaded
'
,
init
,
false
);
doc
[
add
](
pre
+
'
readystatechange
'
,
init
,
false
);
win
[
add
](
pre
+
'
load
'
,
init
,
false
);
}
};
/**
* Generate gadget content based on query data and passed config
* @method makeContent
...
...
@@ -7394,7 +7184,6 @@
})
.
then
(
app
.
checkAuth
)
.
then
(
app
.
fetchFields
)
.
then
(
app
.
store
)
.
then
(
storage
.
fetchTotal
)
.
then
(
storage
.
fetchQuery
)
.
then
(
app
.
makeContent
)
...
...
@@ -7544,6 +7333,124 @@
.
fail
(
util
.
error
);
};
/**
* parse a link into query-able parameters
* @method parseLink
* @param {string} url Url to go to
* @return {object} pointer object
*/
app
.
parseLink
=
function
(
url
)
{
var
i
,
query
,
path
,
clean_hash
,
config
,
backup
,
decode
;
path
=
$
.
mobile
.
path
.
parseUrl
(
url
.
replace
(
$
.
mobile
.
dialogHashKey
,
""
));
decode
=
util
.
testForString
(
"
%2
"
,
path
.
hash
,
true
)
&&
util
.
testForString
(
"
\
/
"
,
path
.
hash
,
true
)
===
false
;
clean_hash
=
decode
?
window
.
decodeURIComponent
(
path
.
hash
).
replace
(
"
#
"
,
""
)
:
path
.
hash
.
replace
(
"
#
"
,
""
);
backup
=
0
;
config
=
{};
if
(
clean_hash
===
""
)
{
config
.
data_url
=
config
.
layout_identifier
=
util
.
getPage
().
getAttribute
(
"
data-url
"
);
}
else
{
// NOTE: as the hash will be set as page id by JQM, we cannot pass
// complex structures or query parameters to not produce invalid HTML
// check for mode(s)
query
=
clean_hash
.
split
(
"
/
"
);
// TODO: this should be generic and without a backup....
// TODO: the whole view handling is not flexible, refactor!
for
(
i
=
0
;
i
<
query
.
length
;
i
+=
1
)
{
switch
(
query
[
i
])
{
case
"
new
"
:
config
.
mode
=
"
new
"
;
backup
=
1
;
break
;
case
"
add
"
:
case
"
config
"
:
case
"
scope
"
:
case
"
ssl_on
"
:
case
"
ssl_off
"
:
case
"
ssl
"
:
case
"
request
"
:
case
"
installation
"
:
config
.
mode
=
query
[
i
];
break
;
}
}
config
.
fragment_list
=
clean_hash
.
split
(
"
/
"
);
config
.
data_url
=
clean_hash
;
config
.
layout_level
=
config
.
fragment_list
.
length
-
1
-
backup
;
config
.
deeplink
=
true
;
config
.
layout_identifier
=
clean_hash
.
split
(
"
/
"
)[
0
];
}
return
config
;
};
/**
* Parse a clicked link to determine which page to load
* @method parseLink
* @param {string} url Url being navigated to
* @return {object} navigation object
**/
app
.
parseLink
=
function
(
url
)
{
var
i
,
hash
,
path
,
clean_hash
,
backup
,
decode
,
mode
,
root
;
hash
=
$
.
mobile
.
path
.
parseUrl
(
url
.
replace
(
$
.
mobile
.
dialogHashKey
,
""
)
).
hash
.
replace
(
"
#
"
,
""
);
decode
=
/^
[^\/]
*%2
[^\/]
*$/
.
test
(
hash
);
backup
=
0
;
// decode (allowing URI encoded identifiers)
if
(
decode
)
{
clean_hash
=
window
.
decodeURIComponent
(
hash
);
}
else
{
clean_hash
=
hash
;
}
if
(
clean_hash
===
""
)
{
root
=
util
.
getPage
().
getAttribute
(
"
data-url
"
);
return
{
"
data_url
"
:
root
,
"
root
"
:
root
};
}
// check for mode
path
=
clean_hash
.
split
(
"
/
"
);
// TODO: this should be generic and without a backup....
// TODO: REFACTOR!!!
for
(
i
=
0
;
i
<
path
.
length
;
i
+=
1
)
{
switch
(
path
[
i
])
{
case
"
new
"
:
config
.
mode
=
"
new
"
;
backup
=
1
;
break
;
case
"
add
"
:
case
"
config
"
:
case
"
scope
"
:
case
"
ssl_on
"
:
case
"
ssl_off
"
:
case
"
ssl
"
:
case
"
request
"
:
case
"
installation
"
:
config
.
mode
=
path
[
i
];
break
;
}
}
return
{
"
mode
"
:
mode
,
"
fragment_list
"
:
path
,
"
data_url
"
:
clean_hash
,
"
layout_level
"
:
path
.
length
-
1
-
backup
,
"
deeplink
"
:
true
,
"
root
"
:
path
[
0
]
};
};
/**
* Parse a page for gadgets and run page setup
* @method parsePage
...
...
@@ -7580,7 +7487,7 @@
if
(
data
&&
data
.
options
.
reverse
)
{
raw_url
=
window
.
decodeURIComponent
(
raw_url
);
}
config
=
app
.
generateLinkObject
(
raw_url
);
config
=
app
.
parseLink
(
raw_url
);
if
(
e
)
{
page
=
util
.
getPage
(
raw_url
.
split
(
"
#
"
).
pop
());
...
...
@@ -7624,25 +7531,21 @@
}
}
// fetch pageIndex and trigger loading of page and gadgets of a view
if
(
e
===
undefined
||
handle
)
{
if
(
config
.
deeplink
)
{
create
=
true
;
}
// prevent browser loading hash?query.json
if
(
config
.
layout_identifier
.
split
(
"
?
"
).
length
>
1
)
{
destination
=
config
.
layout_identifier
.
split
(
"
?
"
)[
0
];
}
else
{
destination
=
config
.
layout_identifier
;
}
return
app
.
fetchConfig
({
"
storage
"
:
app
.
storage_dict
.
settings
,
"
file
"
:
"
pages
"
,
"
attachment
"
:
destination
,
"
attachment
"
:
config
.
root
.
split
(
"
?
"
)[
0
]
,
"
pass
"
:
undefined
})
.
then
(
function
(
reply
)
{
return
app
.
setContent
(
reply
,
config
,
create
);
// pick the page to display
return
app
.
setContent
(
reply
.
children
[
config
.
layout_level
||
0
],
config
,
util
.
getPage
(
config
.
data_url
)
?
undefined
:
true
);
})
.
then
(
app
.
setPageBindings
)
.
fail
(
util
.
error
);
...
...
@@ -7727,17 +7630,6 @@
};
/**
* Prevent filterable from triggering
* @method preventFilterableTrigger
* @params {object} element Filterable element
*/
app
.
preventFilterableTrigger
=
function
(
element
)
{
$
(
element
).
on
(
"
filterablebeforefilter
"
,
function
(
e
)
{
e
.
preventDefault
();
});
};
/**
* Set bindings on page specific elements after content has been appended
* @method setPageBindings
...
...
@@ -7750,13 +7642,14 @@
filter_list
=
document
.
querySelectorAll
(
"
[data-filter]
"
);
// disable default filtering of JQM filterable
// TODO: does not work! JQM still runs
for
(
i
=
0
;
i
<
filter_list
.
length
;
i
+=
1
)
{
filterable
=
filter_list
[
i
];
if
(
filterable
.
getAttribute
(
"
data-bound
"
)
===
null
)
{
filterable
.
setAttribute
(
"
data-bound
"
,
true
);
app
.
preventFilterableTrigger
(
filterable
);
$
(
filterable
).
on
(
"
filterablebeforefilter
"
,
function
(
e
)
{
e
.
preventDefault
();
});
}
}
...
...
@@ -7812,11 +7705,6 @@
*/
util
=
{};
/**
* Storage container
*/
util
.
storage_dict
=
{};
/**
* Fetch a value from an object based on an array path
* @method fetchByArray
...
...
@@ -8160,49 +8048,21 @@
};
/**
* Test a list of features requested by a gadget
* @param testBrowserSupport
* @method {array} property_list Features to be tested
*/
util
.
testSupport
=
function
(
property_list
)
{
var
j
,
supported
,
fail
,
message
,
container
;
if
(
Modernizr
)
{
fail
=
""
;
for
(
j
=
0
;
j
<
property_list
.
length
;
j
+=
1
)
{
if
(
Modernizr
[
property_list
[
j
]]
===
false
)
{
supported
=
false
;
fail
+=
property_list
[
j
]
+
"
|
"
;
}
}
if
(
supported
===
false
)
{
message
=
fail
.
splice
(
0
,
-
1
);
util
.
error
(
"
browser:
"
+
message
+
"
not supported
"
);
* Merge object 1 and object 2
* @method merge
* @param {object} Object 1 to merge into object 2 (including overwrites)
* @param {objcet} Object 2
* @return {object} merged object
**/
util
.
mergeObject
=
function
(
a
,
b
)
{
var
attribute
;
container
=
factory
.
element
(
"
p
"
,
{
"
class
"
:
"
responsive ui-content-element
"
}
);
container
.
appendChild
(
factory
.
element
(
"
span
"
,
{
"
class
"
:
"
translate
"
},
{
"
data-i18n
"
:
"
validation.fail.browser_support
"
},
{
"
text
"
:
"
Your browser does not support:
"
}
));
container
.
appendChild
(
factory
.
element
(
"
span
"
,
{},
{},
{
"
text
"
:
message
}
));
document
.
documentElement
.
appendChild
(
container
);
return
false
;
for
(
attribute
in
a
)
{
if
(
a
.
hasOwnProperty
(
attribute
))
{
b
[
attribute
]
=
a
[
attribute
];
}
return
true
;
}
util
.
error
(
"
testBrowserSupport: Modernizr undefined
"
);
return
false
;
return
b
;
};
/* ====================================================================== */
...
...
@@ -8222,24 +8082,6 @@
}
};
/**
* Merge object 1 and object 2
* @method merge
* @param {object} Object 1 to merge into object 2 (including overwrites)
* @param {objcet} Object 2
* @return {object} merged object
**/
util
.
mergeObject
=
function
(
a
,
b
)
{
var
attribute
;
for
(
attribute
in
a
)
{
if
(
a
.
hasOwnProperty
(
attribute
))
{
b
[
attribute
]
=
a
[
attribute
];
}
}
return
b
;
};
/* ====================================================================== */
/* APP INIT */
/* ====================================================================== */
...
...
@@ -8410,6 +8252,58 @@
return
result
;
};
/**
* cross-browser wrapper for DOMContentLoaded
* Thx Diego Perini http://javascript.nwbox.com/ContentLoaded/
* @method contentLoaded
* @param {object} win Window
* @param {method} fn Callback to run
*/
app
.
init
.
contentLoaded
=
function
(
win
,
fn
)
{
var
done
=
false
,
top
=
true
,
doc
=
win
.
document
,
root
=
doc
.
documentElement
,
add
=
doc
.
addEventListener
?
'
addEventListener
'
:
'
attachEvent
'
,
rem
=
doc
.
addEventListener
?
'
removeEventListener
'
:
'
detachEvent
'
,
pre
=
doc
.
addEventListener
?
''
:
'
on
'
,
init
=
function
(
e
)
{
if
(
e
.
type
===
'
readystatechange
'
&&
doc
.
readyState
!==
'
complete
'
)
{
return
;
}
(
e
.
type
===
'
load
'
?
win
:
doc
)[
rem
](
pre
+
e
.
type
,
init
,
false
);
if
(
!
done
)
{
done
=
true
;
fn
.
call
(
win
,
e
.
type
||
e
);
}
},
poll
=
function
()
{
try
{
root
.
doScroll
(
'
left
'
);
}
catch
(
e
)
{
window
.
setTimeout
(
poll
,
50
);
return
;
}
init
(
'
poll
'
);
};
if
(
doc
.
readyState
===
'
complete
'
)
{
fn
.
call
(
win
,
'
lazy
'
);
}
else
{
if
(
doc
.
createEventObject
&&
root
.
doScroll
)
{
try
{
top
=
!
win
.
frameElement
;
}
catch
(
ignore
)
{}
if
(
top
)
{
poll
();
}
}
doc
[
add
](
pre
+
'
DOMContentLoaded
'
,
init
,
false
);
doc
[
add
](
pre
+
'
readystatechange
'
,
init
,
false
);
win
[
add
](
pre
+
'
load
'
,
init
,
false
);
}
};
/* ====================================================================== */
/* ENTRY POINT */
/* ====================================================================== */
...
...
@@ -8418,7 +8312,7 @@
* Initializer fetching configuration file to setup application
* @method ContentLoaded
*/
app
.
contentLoaded
(
window
,
function
()
{
app
.
init
.
contentLoaded
(
window
,
function
()
{
// TODO: Don't wipe. Wait for sync...!
// NOTE: Don't clear if page is opened in popup (like when using oauth)
...
...
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