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
9b71276e
Commit
9b71276e
authored
Mar 05, 2014
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated application handler to working without hacks
parent
e374a231
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
408 additions
and
727 deletions
+408
-727
js/erp5_loader.js
js/erp5_loader.js
+408
-727
No files found.
js/erp5_loader.js
View file @
9b71276e
...
...
@@ -538,92 +538,6 @@
**/
map
.
handlers
=
{
/**
* @method release_list
* @param {object} reply Object received from previous chain element
* @param {object} response Object object passed on to next element
**/
"
installed_services
"
:
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
);
},
/**
* @method release_list
* @param {object} reply Object received from previous chain element
* @param {object} response Object object passed on to next element
**/
"
release_list
"
:
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
);
},
/**
* @method software_list
* @param {object} reply Object received from previous chain element
...
...
@@ -716,50 +630,7 @@
}).
fail
(
util
.
error
);
}
return
(
reply
);
},
/**
* @method ticket_status
* @param {object} reply Object received from previous chain element
* @param {object} response Object object passed on to next element
**/
"
ticket_status
"
:
function
(
reply
)
{
var
fetch
,
config
,
property
,
query
,
href
,
i
,
store
,
reply
,
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
);
},
};
/**
...
...
@@ -774,7 +645,17 @@
* @param {object} obj Action Object
**/
"
new
"
:
function
(
obj
)
{
storage
.
write
(
obj
);
storage
.
write
(
obj
)
.
then
(
function
(
response
)
{
util
.
loader
(
""
,
"
status_dict.saved
"
,
"
check
"
);
app
.
navigate
(
obj
,
response
);
})
.
fail
(
function
(
error
)
{
switch
(
error
.
status
)
{
case
408
:
util
.
loader
(
""
,
"
status_dict.timeout
"
,
"
time
"
);
break
;
default
:
util
.
loader
(
""
,
"
status_dict.error
"
,
"
ban-circle
"
);
break
;
}
});
},
/**
...
...
@@ -783,97 +664,86 @@
* @param {object} obj Action Object
**/
"
update
"
:
function
(
obj
)
{
storage
.
write
(
obj
);
storage
.
write
(
obj
)
.
then
(
function
(
response
)
{
util
.
loader
(
""
,
"
status_dict.saved
"
,
"
check
"
);
app
.
navigate
(
obj
,
response
);
})
.
fail
(
function
(
error
)
{
switch
(
error
.
status
)
{
case
408
:
util
.
loader
(
""
,
"
status_dict.timeout
"
,
"
time
"
);
break
;
default
:
util
.
loader
(
""
,
"
status_dict.error
"
,
"
ban-circle
"
);
break
;
}
});
},
/**
* GET an object
* @method get
* update server scope - custom action, because my_ not implemented,
* same for ticket status updates
* @method update
* @param {object} obj Action Object
**/
"
get
"
:
function
(
obj
)
{
storage
.
fetch
(
obj
);
"
update_scope
"
:
function
(
obj
)
{
obj
.
force_data
=
true
;
storage
.
write
(
obj
)
.
then
(
function
(
response
)
{
util
.
loader
(
""
,
"
status_dict.saved
"
,
"
check
"
);
app
.
navigate
(
obj
,
response
);
})
.
fail
(
function
(
error
)
{
switch
(
error
.
status
)
{
case
408
:
util
.
loader
(
""
,
"
status_dict.timeout
"
,
"
time
"
);
break
;
default
:
util
.
loader
(
""
,
"
status_dict.error
"
,
"
ban-circle
"
);
break
;
}
});
},
/**
*
Create an installation = new service object
*
Install a service on a machine
* @method install
* @param {object} obj Action Object
**/
"
install
"
:
function
(
obj
)
{
//
force new portal type and POST (create new record)
obj
.
gadget
.
state
.
force_type
=
"
Service
"
;
obj
.
gadget
.
state
.
create_new
=
true
;
storage
.
add
(
obj
);
//
HACK: no good way to refer to the calling server!
obj
.
state
.
reference
=
window
.
decodeURIComponent
(
obj
.
state
.
fragment_list
[
1
])
;
storage
.
write
(
obj
);
},
/**
*
Destroy an installation = service object
* @method
destroy
*
Revoke a SSL certificate - custom action, so extra entry
* @method
revoke_ssl
* @param {object} obj Action Object
**/
"
destroy
"
:
function
(
obj
)
{
storage
.
remove
(
obj
);
"
revoke_ssl
"
:
function
(
obj
)
{
util
.
loader
(
""
,
"
status_dict.updating
"
);
storage
.
write
(
obj
)
.
then
(
function
(
response
)
{
util
.
loader
(
""
,
"
status_dict.ssl_revoked
"
,
"
check
"
);
})
.
fail
(
function
(
error
)
{
util
.
loader
(
""
,
"
status_dict.ssl_no
"
,
"
ban-circle
"
);
});
},
/**
*
Start a software instanc
e
* @method
start_instance
*
Request SSL certificat
e
* @method
request_ssl
* @param {object} obj Action Object
**/
"
update_ticket
"
:
function
(
obj
)
{
var
element
=
obj
.
element
,
formData
,
valid
,
replace
,
property
,
value
,
id
,
decode
,
store
;
id
=
obj
.
state
.
fragment_list
[
1
];
formData
=
new
FormData
();
store
=
app
.
storage_dict
;
valid
=
storage
.
validate
(
obj
.
gadget
);
decode
=
/^
[^\/]
*%2
[^\/]
*$/
.
test
(
id
);
if
(
valid
===
undefined
)
{
util
.
loader
(
""
,
"
validation_dict.general
"
,
"
ban-circle
"
);
// form is valid and not "spam"
}
else
{
replace
=
obj
.
gadget
.
id
+
"
_
"
;
for
(
property
in
valid
)
{
if
(
valid
.
hasOwnProperty
(
property
))
{
value
=
valid
[
property
];
// prepare to store
// TODO: add id to captcha fields missing it...
if
(
property
!==
"
undefined
"
)
{
if
(
property
!==
"
identifier
"
)
{
formData
.
append
(
property
.
replace
(
replace
,
""
),
value
);
}
}
}
}
util
.
loader
(
""
,
"
status_dict.updating
"
);
store
.
items
.
get
({
"
_id
"
:
window
.
decodeURIComponent
(
obj
.
state
.
fragment_list
[
1
])},{
"
_view
"
:
"
web_view
"
})
.
then
(
function
(
response
)
{
return
jIO
.
util
.
ajax
({
"
url
"
:
util
.
parse
(
response
).
data
.
_actions
.
update
.
href
,
"
type
"
:
"
POST
"
,
"
data
"
:
formData
,
"
xhrFields
"
:
{
"
withCredentials
"
:
true
}
});
})
.
then
(
function
(
answer
)
{
util
.
loader
(
""
,
"
status_dict.success
"
,
"
check
"
);
$
.
mobile
.
changePage
(
"
#services
"
);
"
request_ssl
"
:
function
(
obj
)
{
util
.
loader
(
""
,
"
status_dict.requesting
"
);
storage
.
write
(
obj
)
.
then
(
function
(
response
)
{
// get certificate!
flux
=
flux
||
{};
flux
.
cert
=
util
.
parse
(
response
.
_temp
);
util
.
loader
(
""
,
"
status_dict.ssl_generated
"
,
"
check
"
);
app
.
navigate
(
obj
,
response
);
})
.
fail
(
function
(
error
)
{
util
.
error
(
error
);
if
(
util
.
parse
(
error
.
target
).
responseText
===
""
&&
id
&&
obj
.
state
.
callback
)
{
$
.
mobile
.
changePage
(
obj
.
state
.
callback
.
replace
(
"
__id__
"
,
decode
?
id
:
window
.
encodeURIComponent
(
id
)));
}
.
fail
(
function
(
error
)
{
util
.
loader
(
""
,
"
status_dict.ssl_error
"
,
"
ban-circle
"
);
});
}
},
/**
...
...
@@ -881,216 +751,92 @@
* @method start_instance
* @param {object} obj Action Object
**/
"
destroy_installation
"
:
function
(
obj
)
{
var
element
=
obj
.
element
,
id
=
obj
.
state
.
fragment_list
[
1
],
decode
=
/^
[^\/]
*%2
[^\/]
*$/
.
test
(
id
);
"
destroy
"
:
function
(
obj
)
{
util
.
loader
(
""
,
"
status_dict.destroying
"
,
"
trash
"
);
jIO
.
util
.
ajax
({
"
url
"
:
window
.
decodeURIComponent
(
element
.
href
),
"
type
"
:
element
.
getAttribute
(
"
data-method
"
),
"
xhrFields
"
:
{
"
withCredentials
"
:
true
}
})
.
then
(
function
(
answer
)
{
storage
.
write
(
obj
)
.
then
(
function
(
response
)
{
util
.
loader
(
""
,
"
status_dict.success
"
,
"
check
"
);
$
.
mobile
.
changePage
(
"
#servers
"
);
})
.
fail
(
function
(
error
)
{
util
.
loader
(
""
,
"
status_dict.success
"
,
"
check
"
);
util
.
error
(
error
);
if
(
util
.
parse
(
error
.
target
).
responseText
===
""
&&
id
&&
obj
.
state
.
callback
)
{
$
.
mobile
.
changePage
(
obj
.
state
.
callback
.
replace
(
"
__id__
"
,
decode
?
id
:
window
.
encodeURIComponent
(
id
)));
}
});
.
fail
(
util
.
error
);
},
/**
* Start a software instance
* @method start
_instance
* @method start
* @param {object} obj Action Object
**/
"
destroy_instance
"
:
function
(
obj
)
{
var
element
=
obj
.
element
;
util
.
loader
(
""
,
"
status_dict.destroying
"
,
"
trash
"
);
jIO
.
util
.
ajax
({
"
url
"
:
window
.
decodeURIComponent
(
element
.
href
),
"
type
"
:
element
.
getAttribute
(
"
data-method
"
),
"
xhrFields
"
:
{
"
withCredentials
"
:
true
}
})
"
start
"
:
function
(
obj
)
{
util
.
loader
(
""
,
"
status_dict.starting
"
,
"
signal
"
);
storage
.
write
(
obj
)
.
then
(
function
(
response
)
{
util
.
loader
(
""
,
"
status_dict.success
"
,
"
check
"
);
$
.
mobile
.
changePage
(
"
#services
"
);
})
.
fail
(
util
.
error
);
},
/**
* St
art
a software instance
* @method st
art
_instance
* St
op
a software instance
* @method st
op
_instance
* @param {object} obj Action Object
**/
"
update_scope
"
:
function
(
obj
)
{
var
element
=
obj
.
element
,
formData
,
valid
,
replace
,
property
,
value
,
id
,
decode
,
store
;
id
=
obj
.
state
.
fragment_list
[
1
];
formData
=
new
FormData
();
store
=
app
.
storage_dict
;
valid
=
storage
.
validate
(
obj
.
gadget
);
decode
=
/^
[^\/]
*%2
[^\/]
*$/
.
test
(
id
);
if
(
valid
===
undefined
)
{
util
.
loader
(
""
,
"
validation_dict.general
"
,
"
ban-circle
"
);
// form is valid and not "spam"
}
else
{
replace
=
obj
.
gadget
.
id
+
"
_
"
;
for
(
property
in
valid
)
{
if
(
valid
.
hasOwnProperty
(
property
))
{
value
=
valid
[
property
];
// prepare to store
// TODO: add id to captcha fields missing it...
if
(
property
!==
"
undefined
"
)
{
if
(
property
!==
"
identifier
"
)
{
formData
.
append
(
property
.
replace
(
replace
,
""
),
value
);
}
}
}
}
util
.
loader
(
""
,
"
status_dict.updating
"
);
store
.
items
.
get
({
"
_id
"
:
window
.
decodeURIComponent
(
obj
.
state
.
fragment_list
[
1
])},{
"
_view
"
:
"
web_view
"
})
.
then
(
function
(
response
)
{
return
jIO
.
util
.
ajax
({
"
url
"
:
util
.
parse
(
response
).
data
.
_actions
.
update_allocation_scope
.
href
,
"
type
"
:
"
POST
"
,
"
data
"
:
formData
,
"
xhrFields
"
:
{
"
withCredentials
"
:
true
}
});
})
.
then
(
function
(
answer
)
{
"
stop
"
:
function
(
obj
)
{
util
.
loader
(
""
,
"
status_dict.stopping
"
,
"
ban-circle
"
);
storage
.
write
(
obj
)
.
then
(
function
(
response
)
{
util
.
loader
(
""
,
"
status_dict.success
"
,
"
check
"
);
$
.
mobile
.
changePage
(
"
#services
"
);
})
.
fail
(
function
(
error
)
{
util
.
error
(
error
);
if
(
util
.
parse
(
error
.
target
).
responseText
===
""
&&
id
&&
obj
.
state
.
callback
)
{
$
.
mobile
.
changePage
(
obj
.
state
.
callback
.
replace
(
"
__id__
"
,
decode
?
id
:
window
.
encodeURIComponent
(
id
)));
}
});
}
.
fail
(
util
.
error
);
},
/**
*
Start a software instance
* @method
start_instance
*
GET an object
* @method
get
* @param {object} obj Action Object
**/
"
request_ssl
"
:
function
(
obj
)
{
var
element
,
formData
,
decode
,
id
,
store
;
id
=
obj
.
state
.
fragment_list
[
1
];
element
=
obj
.
element
;
store
=
app
.
storage_dict
;
formData
=
new
FormData
();
decode
=
/^
[^\/]
*%2
[^\/]
*$/
.
test
(
id
);
util
.
loader
(
""
,
"
status_dict.updating
"
);
store
.
items
.
get
({
"
_id
"
:
window
.
decodeURIComponent
(
obj
.
state
.
fragment_list
[
1
])},{
"
_view
"
:
"
web_view
"
})
.
then
(
function
(
response
)
{
return
jIO
.
util
.
ajax
({
"
url
"
:
util
.
parse
(
response
).
data
.
_actions
.
generate_certificate
.
href
,
"
type
"
:
"
POST
"
,
"
data
"
:
formData
,
"
xhrFields
"
:
{
"
withCredentials
"
:
true
}
});
})
.
then
(
function
(
answer
)
{
// store answer in flux
flux
=
flux
||
{};
flux
.
cert
=
util
.
parse
(
answer
.
target
.
responseText
);
if
(
id
&&
obj
.
state
.
callback
)
{
$
.
mobile
.
changePage
(
obj
.
state
.
callback
.
replace
(
"
__id__
"
,
decode
?
id
:
window
.
encodeURIComponent
(
id
)));
}
})
.
fail
(
function
(
error
){
util
.
error
(
error
);
util
.
loader
(
""
,
"
status_dict.ssl_error
"
,
"
ban-circle
"
);
});
},
"
revoke_ssl
"
:
function
(
obj
)
{
var
element
,
formData
,
decode
,
id
,
store
;
id
=
obj
.
state
.
fragment_list
[
1
];
element
=
obj
.
element
;
store
=
app
.
storage_dict
;
formData
=
new
FormData
();
decode
=
/^
[^\/]
*%2
[^\/]
*$/
.
test
(
id
);
util
.
loader
(
""
,
"
status_dict.updating
"
);
store
.
items
.
get
({
"
_id
"
:
window
.
decodeURIComponent
(
obj
.
state
.
fragment_list
[
1
])},{
"
_view
"
:
"
web_view
"
})
.
then
(
function
(
response
)
{
return
jIO
.
util
.
ajax
({
"
url
"
:
util
.
parse
(
response
).
data
.
_actions
.
revoke_certificate
.
href
,
"
type
"
:
"
POST
"
,
"
data
"
:
formData
,
"
xhrFields
"
:
{
"
withCredentials
"
:
true
}
});
})
.
then
(
function
(
answer
)
{
util
.
loader
(
""
,
"
status_dict.ssl_revoked
"
,
"
check
"
);
})
.
fail
(
function
(
error
){
util
.
error
(
error
);
util
.
loader
(
""
,
"
status_dict.ssl_no
"
,
"
ban-circle
"
);
});
"
get
"
:
function
(
obj
)
{
storage
.
fetch
(
obj
);
},
/**
*
Start a software instance
* @method
start_instance
*
Download a file (as pdf)
* @method
download
* @param {object} obj Action Object
**/
"
start_instance
"
:
function
(
obj
)
{
var
element
=
obj
.
element
;
util
.
loader
(
""
,
"
status_dict.starting
"
,
"
signal
"
);
jIO
.
util
.
ajax
({
"
url
"
:
window
.
decodeURIComponent
(
element
.
href
),
"
type
"
:
element
.
getAttribute
(
"
data-method
"
),
"
xhrFields
"
:
{
"
withCredentials
"
:
true
}
})
"
download
"
:
function
(
obj
)
{
util
.
loader
(
""
,
"
status_dict.downloading
"
);
storage
.
fetch
(
obj
)
.
then
(
function
(
response
)
{
util
.
loader
(
""
,
"
status_dict.success
"
,
"
check
"
);
util
.
loader
(
""
,
"
status_dict.rendering
"
);
window
.
location
.
href
=
response
.
data
.
_links
.
slapos_jump
.
href
;
})
.
fail
(
util
.
error
);
},
// ==============================================
// /**
// * Destroy an installation = service object
// * @method destroy
// * @param {object} obj Action Object
// **/
// "destroy": function (obj) {
// storage.remove(obj);
// },
/**
* St
op
a software instance
* @method st
op
_instance
* St
art
a software instance
* @method st
art
_instance
* @param {object} obj Action Object
**/
"
stop_instance
"
:
function
(
obj
)
{
var
element
=
obj
.
element
;
"
destroy_installation
"
:
function
(
obj
)
{
var
element
=
obj
.
element
,
id
=
obj
.
state
.
fragment_list
[
1
],
decode
=
/^
[^\/]
*%2
[^\/]
*$/
.
test
(
id
);
util
.
loader
(
""
,
"
status_dict.
stopping
"
,
"
ban-circle
"
);
util
.
loader
(
""
,
"
status_dict.
destroying
"
,
"
trash
"
);
jIO
.
util
.
ajax
({
"
url
"
:
window
.
decodeURIComponent
(
element
.
href
),
"
type
"
:
element
.
getAttribute
(
"
data-method
"
),
...
...
@@ -1098,10 +844,17 @@
"
withCredentials
"
:
true
}
})
.
then
(
function
(
response
)
{
.
then
(
function
(
answer
)
{
util
.
loader
(
""
,
"
status_dict.success
"
,
"
check
"
);
$
.
mobile
.
changePage
(
"
#servers
"
);
})
.
fail
(
util
.
error
);
.
fail
(
function
(
error
)
{
util
.
loader
(
""
,
"
status_dict.success
"
,
"
check
"
);
util
.
error
(
error
);
if
(
util
.
parse
(
error
.
target
).
responseText
===
""
&&
id
&&
obj
.
state
.
callback
)
{
$
.
mobile
.
changePage
(
obj
.
state
.
callback
.
replace
(
"
__id__
"
,
decode
?
id
:
window
.
encodeURIComponent
(
id
)));
}
});
},
// ==============================================================
...
...
@@ -3330,7 +3083,6 @@
// add to DOM if scoped
if
(
url_dict
.
data_url
)
{
//util.getPanel(url_dict.data_url).appendChild(panel);
return
panel
;
}
else
{
document
.
body
.
insertBefore
(
panel
,
document
.
body
.
children
[
0
]);
...
...
@@ -3459,14 +3211,7 @@
);
};
// loop over form layout sections
for
(
i
=
0
;
i
<
spec
.
scheme
.
length
;
i
+=
1
)
{
segment
=
spec
.
scheme
[
i
];
area
=
segment
.
position
===
"
center
"
?
2
:
1
;
container
=
wrap
(
area
);
if
(
i
===
0
)
{
// secure form
// secure anyway
// TODO: do properly once we have time
if
(
secure
===
"
default
"
)
{
...
...
@@ -3474,8 +3219,7 @@
encode
=
window
.
btoa
||
window
.
shim
.
Base64
.
encode
;
// TODO: include client IP in hash
sauce
=
encode
(
stamp
.
toString
()
+
spec
.
property_dict
.
secret_hash
);
container
.
appendChild
(
factory
.
formElement
(
fragment
.
appendChild
(
factory
.
formElement
(
{
"
type
"
:
"
input
"
,
"
direct
"
:
{
...
...
@@ -3495,7 +3239,7 @@
}
}
));
container
.
appendChild
(
factory
.
element
(
fragment
.
appendChild
(
factory
.
element
(
"
input
"
,
{
"
type
"
:
"
hidden
"
,
...
...
@@ -3506,7 +3250,7 @@
"
data-created
"
:
stamp
}
));
container
.
appendChild
(
factory
.
formElement
(
fragment
.
appendChild
(
factory
.
formElement
(
{
"
type
"
:
"
input
"
,
"
direct
"
:
{
...
...
@@ -3530,7 +3274,7 @@
// add hidden storage identifier
if
(
item_id
)
{
container
.
appendChild
(
factory
.
element
(
fragment
.
appendChild
(
factory
.
element
(
"
input
"
,
{
"
type
"
:
"
hidden
"
,
...
...
@@ -3539,13 +3283,21 @@
}
));
}
}
// loop over form layout sections
if
(
spec
.
scheme
.
length
>
0
)
{
for
(
i
=
0
;
i
<
spec
.
scheme
.
length
;
i
+=
1
)
{
segment
=
spec
.
scheme
[
i
];
area
=
segment
.
position
===
"
center
"
?
2
:
1
;
container
=
wrap
(
area
);
// loop fieldlist of layout section
for
(
j
=
0
;
j
<
segment
.
fieldlist
.
length
;
j
+=
1
)
{
field
=
segment
.
fieldlist
[
j
];
// allow non-fieldlist form elements to be generated
// TODO: can we also generate a field from another portal_type here?
if
(
field
.
type
)
{
input_config
=
field
;
prefixed_name
=
spec
.
reference
+
"
_
"
+
field
.
direct
.
name
||
util
.
uuid
();
...
...
@@ -3571,6 +3323,7 @@
}
}
}
}
else
{
config
=
spec
.
fields
[
field
.
field
];
overrides
=
field
.
overrides
;
...
...
@@ -3656,6 +3409,7 @@
}
fragment
.
appendChild
(
container
);
}
}
// set captcha or anti spam protection
if
(
secure
===
"
captcha
"
)
{
...
...
@@ -5220,73 +4974,49 @@
/* STORAGE */
/* ====================================================================== */
// generate storage object
storage
=
{};
/*
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
// generate storage object with placeholders
storage
=
{
"
obj
"
:
{},
"
arr
"
:
[],
"
span
"
:
document
.
createElement
(
"
span
"
)
};
}
return {
"pass": pass
}
}).fail(util.error);
}
return (reply);
*/
/**
* Fetch data from storage = GET or ALLDOCS
* @method fetch
* @param {object} obj Action object
*/
// TODO: only use on lookup architecture pass.x or pass.state.x
// TODO: this means state needs to have url_pointer set earilier, so
// there is no need to look it up in oass.config.property_dict...
// TODO: merge pass.x or pass.state.x
// TODO: set pointer directly inside data-action, remove pointer!
// TODO: state needs to have url_pointer set earlier, so
// there is no need to look it up in pass.config.property_dict...
// TODO: jump is bad, it is the lookup for the data to display. rename!
storage
.
fetch
=
function
(
obj
)
{
var
pass
,
query
,
method
,
map
,
config
,
answer
,
lookup
,
pointer
,
action
,
var
pass
,
query
,
method
,
map
,
config
,
answer
,
lookup
,
pointer
,
action
_id
,
quirk
;
pass
=
obj
.
pass
;
quirk
=
obj
.
state
||
pass
.
config
;
lookup
=
obj
.
state
||
quirk
.
property_dict
||
{}
;
query
=
obj
.
query
||
lookup
.
query
||
{}
;
pointer
=
(
lookup
[
"
url_pointer
"
]
||
{}
).
jump
;
lookup
=
obj
.
state
||
quirk
.
property_dict
||
storage
.
obj
;
query
=
obj
.
query
||
lookup
.
query
||
storage
.
obj
;
pointer
=
(
lookup
[
"
url_pointer
"
]
||
storage
.
obj
).
jump
;
// TODO: action handling, should be a form submit not set on element!
action
=
((
obj
.
element
||
{}).
href
||
""
).
split
(
"
/
"
).
pop
();
query
.
_id
=
query
.
_id
||
window
.
decodeURIComponent
(
action
);
// TODO: action > id, this should be triggered via form submit not link!
action_id
=
((
obj
.
element
||
storage
.
obj
).
href
||
""
).
split
(
"
/
"
).
pop
();
if
(
action
)
{
if
(
action
_id
)
{
pointer
=
undefined
;
query
=
{
"
_id
"
:
query
.
_id
}
query
=
{
"
_id
"
:
window
.
decodeURIComponent
(
action_id
)
}
}
switch
(
true
)
{
case
((
query
.
select_list
||
[]).
length
>
0
&&
!
query
.
include_docs
):
// TODO: "hack" for forcing get into allDocs, don't overwrite criteria!
case
!!
pointer
:
map
=
"
values
"
;
query
.
select_list
=
query
.
select_list
||
pass
.
field_list
;
query
.
limit
=
query
.
limit
||
pass
.
config
.
initial_query
.
limit
;
break
;
case
((
query
.
select_list
||
storage
.
arr
).
length
>
0
&&
!
query
.
include_docs
):
map
=
"
values
"
;
break
;
case
(
!!
query
.
_id
):
...
...
@@ -5298,28 +5028,20 @@
break
;
}
// TODO: remove
this
- pass custom query to storage
// TODO: remove - pass custom query to storage
if
(
pointer
&&
!
config
)
{
config
=
{
"
_jump
"
:
pointer
};
}
return
RSVP
.
resolve
(
app
.
storage_dict
.
items
[
method
||
"
allDocs
"
](
query
,
config
)
).
then
(
function
(
response
)
{
if
(
response
.
status
===
200
)
{
// TODO: actions should have their own callback set on state!
if
(
action
)
{
util
.
loader
(
""
,
"
status_dict.rendering
"
);
window
.
location
.
href
=
response
.
data
.
_links
.
slapos_jump
.
href
;
if
(
action_id
)
{
return
response
;
}
answer
=
storage
.
mapResponse
(
response
,
map
);
if
(
app
.
storage_dict
.
property_dict
.
force_sync
)
{
//storage.sync(mapped, parcel.storage);
}
}
return
{
"
response
"
:
answer
||
response
,
...
...
@@ -5334,44 +5056,41 @@
* @param {object} obj Action object
*/
storage
.
write
=
function
(
obj
)
{
var
form
,
data
,
valid
,
prefix
,
decode
,
id
,
answer
,
goto
,
config
,
metho
d
;
var
form
,
data
,
valid
,
prefix
,
config
,
method
,
action
,
pointer
,
i
d
;
form
=
document
.
getElementById
(
obj
.
id
);
pointer
=
(
obj
.
element
||
storage
.
span
).
getAttribute
(
"
data-action
"
),
action
=
obj
.
state
.
url_pointer
[
pointer
];
config
=
{};
prefix
=
obj
.
id
+
"
_
"
;
valid
=
storage
.
validate
(
obj
);
data
=
storage
.
parseForm
(
valid
,
prefix
,
true
);
// TODO: remove, used for update scope, which does not honor form definition
if
(
obj
.
force_data
)
{
config
.
_force_data
=
true
;
}
if
(
form
.
identifier
)
{
//
this must be a PUT,
set id, method and view
//
PUT >
set id, method and view
data
.
_id
=
form
.
identifier
.
value
;
method
=
"
put
"
;
config
=
{
"
_view
"
:
obj
.
state
.
view
};
}
else
{
// POSTING, set action set in JSON config
config
=
{
"
action
"
:
obj
.
state
.
url_pointer
[
obj
.
element
.
getAttribute
(
"
data-action
"
)]
};
config
.
_view
=
obj
.
state
.
view
;
}
RSVP
.
resolve
(
app
.
storage_dict
.
items
[
method
||
"
post
"
](
data
,
config
))
.
then
(
function
(
response
)
{
// TODO: if this is strictly a storage operation, do this elsewhere!
if
(
response
.
status
===
201
)
{
util
.
loader
(
""
,
"
status_dict.saved
"
,
"
check
"
);
if
(
obj
.
state
.
callback
)
{
answer
=
util
.
parse
(
response
);
id
=
answer
.
id
;
decode
=
/^
[^\/]
*%2
[^\/]
*$/
.
test
(
id
);
goto
=
decode
?
id
:
window
.
encodeURIComponent
(
id
);
$
.
mobile
.
changePage
(
obj
.
state
.
callback
.
replace
(
"
__id__
"
,
goto
));
}
}
else
{
util
.
loader
(
""
,
"
status_dict.error
"
,
"
ban-circle
"
);
if
(
pointer
)
{
config
.
_action
=
action
;
// in case action is triggerted that needs retrival from a reference
data
.
_reference
=
obj
.
state
.
reference
;
}
}).
fail
(
util
.
error
);
console
.
log
(
"
DONE
"
)
console
.
log
(
method
)
console
.
log
(
data
)
console
.
log
(
config
)
return
RSVP
.
resolve
(
app
.
storage_dict
.
items
[
method
||
"
post
"
](
data
,
config
)
);
};
/**
...
...
@@ -5777,6 +5496,25 @@
*/
app
.
timer
=
0
;
/**
* Navigate to a new page after performing some action
* @method navigate
* @param {Object} obj The action object
* @param {Object} response The action response
*/
app
.
navigate
=
function
(
obj
,
response
)
{
var
answer
,
id
,
goto
,
decode
;
if
(
obj
.
state
.
callback
)
{
answer
=
util
.
parse
(
response
);
id
=
answer
.
id
;
decode
=
/^
[^\/]
*%2
[^\/]
*$/
.
test
(
id
);
goto
=
decode
?
id
:
window
.
encodeURIComponent
(
id
);
$
.
mobile
.
changePage
(
obj
.
state
.
callback
.
replace
(
"
__id__
"
,
goto
));
}
};
/**
* Handler for search
* @method search
...
...
@@ -6693,6 +6431,7 @@
case
"
ssl_off
"
:
case
"
ssl
"
:
case
"
request
"
:
case
"
installation
"
:
config
.
mode
=
query
[
i
];
break
;
}
...
...
@@ -6941,6 +6680,10 @@
if
(
pass
.
fields
&&
storage
&&
force_fields
)
{
if
(
pass
.
config
.
scheme
)
{
pass
.
field_list
=
storage
.
makeSelectList
(
pass
.
config
.
scheme
);
// make sure at least the id is returned
if
(
pass
.
field_list
.
indexOf
(
"
_id
"
)
===
-
1
)
{
pass
.
field_list
.
push
(
"
_id
"
);
}
}
}
// HACK:
...
...
@@ -7470,68 +7213,6 @@
);
};
// /**
// * Try fetching data from JIO. Fallback to loading fake data until accessible
// * @method fetchData
// * @param {object} parcel Storage, query options and pass to return
// * @return {object} promise object/pass
// */
// storage.fetch = function (parcel) {
// var method, convert, select_list, hacked_view, pass, skip, query, mapped;
//
// pass = parcel.pass;
// query = parcel.query;
// skip = query && query.limit && query.limit.length === 0 &&
// app.storage_dict.property_dict.skip_total_records;
//
//
// // return here, if skipping total query
// if (skip) {
// return {
// "pass": parcel.pass
// };
// }
//
// select_list = parcel.query && parcel.query.select_list && parcel.query.select_list.length;
//
// // single item query GET
// if (parcel.query._id) {
// // TODO: don't set if don't need...
// delete parcel.query.limit;
// hacked_view = {"_view": parcel.pass.config.view}
// method = "get";
// convert = "single_item";
// }
//
// // query that will return value {} object vs. doc
// if (select_list && parcel.query.include_docs === undefined) {
// convert = "values";
// }
//
// return app.storage_dict[parcel.storage][method || "allDocs"](parcel.query, hacked_view)
// .then(function (response) {
//
// // TODO: best way?
// if (convert !== undefined && response.status === 200) {
// mapped = storage.mapResponse(response, convert);
//
// // force sync
// if (app.storage_dict.property_dict.force_sync) {
// //storage.sync(mapped, parcel.storage);
// }
//
// return {
// "response": mapped,
// "pass": parcel.pass
// };
// }
// return {
// "response": response,
// "pass": parcel.pass
// };
// });
// };
/**
* Load files from disk
* @method loadFile
...
...
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