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
15e86bb5
Commit
15e86bb5
authored
Jan 16, 2014
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hack: add custom handlers in promise chain, fetch live data
parent
e15b1500
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
131 additions
and
36 deletions
+131
-36
js/erp5_loader.js
js/erp5_loader.js
+131
-36
No files found.
js/erp5_loader.js
View file @
15e86bb5
...
...
@@ -25,6 +25,88 @@
// TODO: remove!
map
.
handlers
=
{
/**
* @method subscriptions
* @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
,
href
,
pass
=
reply
.
pass
;
if
(
storage
)
{
// access storage
return
storage
.
items
.
get
({
"
_id
"
:
reply
.
pass
.
value
})
.
then
(
function
(
answer
)
{
console
.
log
(
util
.
parse
(
answer
).
data
)
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
;
// 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 subscriptions
* @param {object} reply Object received from previous chain element
* @param {object} response Object object passed on to next element
**/
"
subscriptions
"
:
function
(
reply
)
{
var
config
,
property
,
query
,
href
,
pass
=
reply
.
pass
;
if
(
storage
)
{
config
=
{
"
url
"
:
storage
.
items
.
dict
.
url
,
"
type
"
:
"
GET
"
,
"
data
"
:
JSON
.
stringify
({
"
_id
"
:
""
})
};
// access storage
return
jIO
.
util
.
ajax
(
config
)
.
then
(
function
(
response
)
{
return
jIO
.
util
.
ajax
({
"
url
"
:
util
.
parse
(
response
.
target
.
responseText
).
_links
.
me
.
href
});
}).
then
(
function
(
answer
)
{
query
=
util
.
parse
(
answer
.
target
.
responseText
).
_links
.
slapos_jump
.
_query
;
if
(
pass
.
config
.
initial_query
===
undefined
)
{
pass
.
config
.
initial_query
=
{};
}
pass
.
config
.
initial_query
.
query
=
query
;
// 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 person
* @param {object} reply Object received from previous chain element
...
...
@@ -47,26 +129,27 @@
"
url
"
:
util
.
parse
(
response
.
target
.
responseText
).
_links
.
me
.
href
})
.
then
(
function
(
answer
){
if
(
pass
.
config
.
initial_query
)
{
for
(
property
in
pass
.
config
.
initial_query
)
{
if
(
pass
.
config
.
initial_query
.
hasOwnProperty
(
property
))
{
delete
pass
.
config
.
initial_query
[
property
];
}
if
(
pass
.
config
.
initial_query
===
undefined
)
{
pass
.
config
.
initial_query
=
{};
}
for
(
property
in
pass
.
config
.
initial_query
)
{
if
(
pass
.
config
.
initial_query
.
hasOwnProperty
(
property
))
{
delete
pass
.
config
.
initial_query
[
property
];
}
pass
.
config
.
initial_query
.
query
=
{
"
_id
"
:
util
.
parse
(
answer
.
target
.
responseText
).
_relative_url
};
}
pass
.
config
.
initial_query
.
query
=
{
"
_id
"
:
util
.
parse
(
answer
.
target
.
responseText
).
_relative_url
};
// pass hacked query back into chain
if
(
reply
.
response
)
{
return
{
"
response
"
:
util
.
parse
(
reply
.
response
),
"
pass
"
:
pass
};
}
// pass hacked query back into chain
if
(
reply
.
response
)
{
return
{
"
response
"
:
util
.
parse
(
reply
.
response
),
"
pass
"
:
pass
}
};
}
return
{
"
pass
"
:
pass
}
}).
fail
(
util
.
error
);
...
...
@@ -849,22 +932,16 @@
"
0
"
:
prevail
.
widget
.
default_value
)
||
spec
.
widget
.
default_value
||
undefined
;
// TODO: not nice, find better way
if
(
prevail
.
setValue
)
{
field_value
=
prevail
.
setValue
+
util
.
uuid
();
}
// easy way out if not enabled
// span
// TODO: should a span still have full structure (label/container)?
if
(
prevail
.
properties
.
enabled
===
false
||
spec
.
properties
.
enabled
===
false
)
{
config
=
{
return
{
"
type
"
:
"
span
"
,
"
direct
"
:
{
"
className
"
:
"
static
"
},
"
attributes
"
:
{},
"
logic
"
:
{
"
text
"
:
field_value
}
};
return
config
;
}
validation_list
=
""
;
...
...
@@ -2490,9 +2567,9 @@
// TODO: crap to use both layout and children!
// NOTE: securing ? http://nedbatchelder.com/text/stopbots.html
factory
.
form
=
function
(
spec
)
{
var
i
,
j
,
k
,
segment
,
element
,
container
,
area
,
field
,
overrides
,
var
i
,
j
,
k
,
l
,
segment
,
element
,
container
,
area
,
field
,
overrides
,
position
,
doc
,
config
,
value
,
stamp
,
sauce
,
encode
,
secure
,
safety_box
,
fragment
,
wrap
,
item_id
,
input_config
;
safety_box
,
fragment
,
wrap
,
item_id
,
input_config
,
setter
,
setter_list
;
spec
.
set_id
=
"
form_
"
+
util
.
uuid
();
fragment
=
factory
.
util
.
wrapInForm
(
spec
);
...
...
@@ -2606,17 +2683,31 @@
// TODO: can we also generate a field from another portal_type here?
if
(
field
.
type
)
{
input_config
=
field
;
setter
=
input_config
.
logic
.
setValue
;
// make sure value is set correctly
if
(
input_config
.
logic
&&
input_config
.
logic
.
setValue
)
{
input_config
.
direct
.
value
=
input_config
.
logic
.
setValue
+
util
.
uuid
();
if
(
input_config
.
logic
&&
setter
)
{
setter_list
=
input_config
.
logic
.
setters
;
input_config
.
logic
.
skip
=
true
;
if
(
setter_list
)
{
for
(
l
=
0
;
l
<
setter_list
.
length
;
l
+=
1
)
{
input_config
.
logic
[
setter_list
[
l
]]
=
spec
.
data
[
setter
];
}
}
else
{
input_config
.
direct
.
value
=
spec
.
data
[
setter
]
||
(
setter
+
util
.
uuid
());
}
}
}
else
{
config
=
spec
.
fields
[
field
.
field
];
overrides
=
field
.
overrides
;
doc
=
spec
.
data
||
undefined
;
value
=
doc
?
(
doc
[
field
.
field
])
:
undefined
;
if
(
doc
&&
field
.
custom
)
{
setter
=
field
.
setValue
||
undefined
;
}
else
{
setter
=
field
.
field
;
}
value
=
doc
?
(
doc
[
setter
])
:
undefined
;
// map config to what we need
input_config
=
map
.
utils
.
mapFormField
(
...
...
@@ -5347,12 +5438,16 @@
// query string passed? parse it
if
(
default_query
.
query
)
{
query_clean
=
default_query
.
query
.
replace
(
/'/g
,
'
"
'
);
query_object
=
complex_queries
.
QueryFactory
.
create
(
query_clean
);
obj
.
query
=
'
(
'
// missing portal type?
if
(
!
util
.
findKey
(
query_object
,
"
query_list
"
,
"
key
"
,
"
portal_type
"
))
{
obj
.
query
=
'
(portal_type: "
'
+
type
+
'
" AND
'
;
if
(
default_query
.
skip_type
===
undefined
)
{
if
(
!
util
.
findKey
(
query_object
,
"
query_list
"
,
"
key
"
,
"
portal_type
"
))
{
obj
.
query
+=
'
portal_type: "
'
+
type
+
'
" AND
'
;
}
}
// NOTE: json only allows single quotes inside double quotes. Reverse
...
...
@@ -5431,6 +5526,7 @@
obj
.
wildcard_character
=
"
%
"
;
}
}
return
obj
;
};
...
...
@@ -5789,15 +5885,14 @@
pass
.
state
.
query
=
app
.
generateQueryObject
(
pass
.
config
.
initial_query
,
pass
.
type
,
pass
.
config
.
property_dict
.
initial_query_url_identifier
,
pass
.
value
,
pass
.
force_allDocs
?
null
:
pass
.
config
.
property_dict
.
initial_query_url_identifier
,
pass
.
force_allDocs
?
null
:
pass
.
value
,
pass
.
field_list
);
}
// get an item?
if
(
pass
.
mode
!==
"
new
"
||
pass
.
config
.
initial_query
!==
undefined
)
{
console
.
log
(
"
ALORE
"
)
return
app
.
fetchData
({
"
storage
"
:
"
items
"
,
"
query
"
:
pass
.
state
.
query
,
...
...
@@ -6348,7 +6443,6 @@
query
=
parcel
.
query
;
skip
=
query
&&
query
.
limit
&&
query
.
limit
.
length
===
0
&&
storage
.
skip_total
;
// return here, if skipping total query
if
(
skip
)
{
return
{
...
...
@@ -6372,6 +6466,7 @@
convert
=
"
values
"
;
}
return
storage
[
parcel
.
storage
][
method
||
"
allDocs
"
](
parcel
.
query
,
hacked_view
)
.
then
(
function
(
response
)
{
// TODO: best way?
...
...
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