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 @@
...
@@ -538,92 +538,6 @@
**/
**/
map
.
handlers
=
{
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
* @method software_list
* @param {object} reply Object received from previous chain element
* @param {object} reply Object received from previous chain element
...
@@ -716,50 +630,7 @@
...
@@ -716,50 +630,7 @@
}).
fail
(
util
.
error
);
}).
fail
(
util
.
error
);
}
}
return
(
reply
);
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 @@
...
@@ -774,7 +645,17 @@
* @param {object} obj Action Object
* @param {object} obj Action Object
**/
**/
"
new
"
:
function
(
obj
)
{
"
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 @@
...
@@ -783,97 +664,86 @@
* @param {object} obj Action Object
* @param {object} obj Action Object
**/
**/
"
update
"
:
function
(
obj
)
{
"
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
* update server scope - custom action, because my_ not implemented,
* @method get
* same for ticket status updates
* @method update
* @param {object} obj Action Object
* @param {object} obj Action Object
**/
**/
"
get
"
:
function
(
obj
)
{
"
update_scope
"
:
function
(
obj
)
{
storage
.
fetch
(
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
* @method install
* @param {object} obj Action Object
* @param {object} obj Action Object
**/
**/
"
install
"
:
function
(
obj
)
{
"
install
"
:
function
(
obj
)
{
//
force new portal type and POST (create new record)
//
HACK: no good way to refer to the calling server!
obj
.
gadget
.
state
.
force_type
=
"
Service
"
;
obj
.
state
.
reference
=
obj
.
gadget
.
state
.
create_new
=
true
;
window
.
decodeURIComponent
(
obj
.
state
.
fragment_list
[
1
])
;
storage
.
add
(
obj
);
storage
.
write
(
obj
);
},
},
/**
/**
*
Destroy an installation = service object
*
Revoke a SSL certificate - custom action, so extra entry
* @method
destroy
* @method
revoke_ssl
* @param {object} obj Action Object
* @param {object} obj Action Object
**/
**/
"
destroy
"
:
function
(
obj
)
{
"
revoke_ssl
"
:
function
(
obj
)
{
storage
.
remove
(
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
*
Request SSL certificat
e
* @method
start_instance
* @method
request_ssl
* @param {object} obj Action Object
* @param {object} obj Action Object
**/
**/
"
update_ticket
"
:
function
(
obj
)
{
"
request_ssl
"
:
function
(
obj
)
{
var
element
=
obj
.
element
,
formData
,
valid
,
replace
,
property
,
value
,
id
,
util
.
loader
(
""
,
"
status_dict.requesting
"
);
decode
,
store
;
storage
.
write
(
obj
)
.
then
(
function
(
response
)
{
id
=
obj
.
state
.
fragment_list
[
1
];
// get certificate!
formData
=
new
FormData
();
flux
=
flux
||
{};
store
=
app
.
storage_dict
;
flux
.
cert
=
util
.
parse
(
response
.
_temp
);
valid
=
storage
.
validate
(
obj
.
gadget
);
util
.
loader
(
""
,
"
status_dict.ssl_generated
"
,
"
check
"
);
decode
=
/^
[^\/]
*%2
[^\/]
*$/
.
test
(
id
);
app
.
navigate
(
obj
,
response
);
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
"
);
})
})
.
fail
(
function
(
error
)
{
.
fail
(
function
(
error
)
{
util
.
error
(
error
);
util
.
loader
(
""
,
"
status_dict.ssl_error
"
,
"
ban-circle
"
);
if
(
util
.
parse
(
error
.
target
).
responseText
===
""
&&
id
&&
obj
.
state
.
callback
)
{
$
.
mobile
.
changePage
(
obj
.
state
.
callback
.
replace
(
"
__id__
"
,
decode
?
id
:
window
.
encodeURIComponent
(
id
)));
}
});
});
}
},
},
/**
/**
...
@@ -881,216 +751,92 @@
...
@@ -881,216 +751,92 @@
* @method start_instance
* @method start_instance
* @param {object} obj Action Object
* @param {object} obj Action Object
**/
**/
"
destroy_installation
"
:
function
(
obj
)
{
"
destroy
"
:
function
(
obj
)
{
var
element
=
obj
.
element
,
id
=
obj
.
state
.
fragment_list
[
1
],
decode
=
/^
[^\/]
*%2
[^\/]
*$/
.
test
(
id
);
util
.
loader
(
""
,
"
status_dict.destroying
"
,
"
trash
"
);
util
.
loader
(
""
,
"
status_dict.destroying
"
,
"
trash
"
);
jIO
.
util
.
ajax
({
storage
.
write
(
obj
)
"
url
"
:
window
.
decodeURIComponent
(
element
.
href
),
.
then
(
function
(
response
)
{
"
type
"
:
element
.
getAttribute
(
"
data-method
"
),
"
xhrFields
"
:
{
"
withCredentials
"
:
true
}
})
.
then
(
function
(
answer
)
{
util
.
loader
(
""
,
"
status_dict.success
"
,
"
check
"
);
util
.
loader
(
""
,
"
status_dict.success
"
,
"
check
"
);
$
.
mobile
.
changePage
(
"
#servers
"
);
})
})
.
fail
(
function
(
error
)
{
.
fail
(
util
.
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
)));
}
});
},
},
/**
/**
* Start a software instance
* Start a software instance
* @method start
_instance
* @method start
* @param {object} obj Action Object
* @param {object} obj Action Object
**/
**/
"
destroy_instance
"
:
function
(
obj
)
{
"
start
"
:
function
(
obj
)
{
var
element
=
obj
.
element
;
util
.
loader
(
""
,
"
status_dict.starting
"
,
"
signal
"
);
storage
.
write
(
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
(
response
)
{
.
then
(
function
(
response
)
{
util
.
loader
(
""
,
"
status_dict.success
"
,
"
check
"
);
util
.
loader
(
""
,
"
status_dict.success
"
,
"
check
"
);
$
.
mobile
.
changePage
(
"
#services
"
);
})
})
.
fail
(
util
.
error
);
.
fail
(
util
.
error
);
},
},
/**
/**
* St
art
a software instance
* St
op
a software instance
* @method st
art
_instance
* @method st
op
_instance
* @param {object} obj Action Object
* @param {object} obj Action Object
**/
**/
"
update_scope
"
:
function
(
obj
)
{
"
stop
"
:
function
(
obj
)
{
var
element
=
obj
.
element
,
formData
,
valid
,
replace
,
property
,
value
,
id
,
util
.
loader
(
""
,
"
status_dict.stopping
"
,
"
ban-circle
"
);
decode
,
store
;
storage
.
write
(
obj
)
.
then
(
function
(
response
)
{
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
)
{
util
.
loader
(
""
,
"
status_dict.success
"
,
"
check
"
);
util
.
loader
(
""
,
"
status_dict.success
"
,
"
check
"
);
$
.
mobile
.
changePage
(
"
#services
"
);
})
})
.
fail
(
function
(
error
)
{
.
fail
(
util
.
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
)));
}
});
}
},
},
/**
/**
*
Start a software instance
*
GET an object
* @method
start_instance
* @method
get
* @param {object} obj Action Object
* @param {object} obj Action Object
**/
**/
"
request_ssl
"
:
function
(
obj
)
{
"
get
"
:
function
(
obj
)
{
var
element
,
formData
,
decode
,
id
,
store
;
storage
.
fetch
(
obj
);
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
"
);
});
},
},
/**
/**
*
Start a software instance
*
Download a file (as pdf)
* @method
start_instance
* @method
download
* @param {object} obj Action Object
* @param {object} obj Action Object
**/
**/
"
start_instance
"
:
function
(
obj
)
{
"
download
"
:
function
(
obj
)
{
var
element
=
obj
.
element
;
util
.
loader
(
""
,
"
status_dict.downloading
"
);
storage
.
fetch
(
obj
)
util
.
loader
(
""
,
"
status_dict.starting
"
,
"
signal
"
);
jIO
.
util
.
ajax
({
"
url
"
:
window
.
decodeURIComponent
(
element
.
href
),
"
type
"
:
element
.
getAttribute
(
"
data-method
"
),
"
xhrFields
"
:
{
"
withCredentials
"
:
true
}
})
.
then
(
function
(
response
)
{
.
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
);
.
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
* St
art
a software instance
* @method st
op
_instance
* @method st
art
_instance
* @param {object} obj Action Object
* @param {object} obj Action Object
**/
**/
"
stop_instance
"
:
function
(
obj
)
{
"
destroy_installation
"
:
function
(
obj
)
{
var
element
=
obj
.
element
;
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
({
jIO
.
util
.
ajax
({
"
url
"
:
window
.
decodeURIComponent
(
element
.
href
),
"
url
"
:
window
.
decodeURIComponent
(
element
.
href
),
"
type
"
:
element
.
getAttribute
(
"
data-method
"
),
"
type
"
:
element
.
getAttribute
(
"
data-method
"
),
...
@@ -1098,10 +844,17 @@
...
@@ -1098,10 +844,17 @@
"
withCredentials
"
:
true
"
withCredentials
"
:
true
}
}
})
})
.
then
(
function
(
response
)
{
.
then
(
function
(
answer
)
{
util
.
loader
(
""
,
"
status_dict.success
"
,
"
check
"
);
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 @@
...
@@ -3330,7 +3083,6 @@
// add to DOM if scoped
// add to DOM if scoped
if
(
url_dict
.
data_url
)
{
if
(
url_dict
.
data_url
)
{
//util.getPanel(url_dict.data_url).appendChild(panel);
return
panel
;
return
panel
;
}
else
{
}
else
{
document
.
body
.
insertBefore
(
panel
,
document
.
body
.
children
[
0
]);
document
.
body
.
insertBefore
(
panel
,
document
.
body
.
children
[
0
]);
...
@@ -3459,14 +3211,7 @@
...
@@ -3459,14 +3211,7 @@
);
);
};
};
// loop over form layout sections
// secure anyway
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
// TODO: do properly once we have time
// TODO: do properly once we have time
if
(
secure
===
"
default
"
)
{
if
(
secure
===
"
default
"
)
{
...
@@ -3474,8 +3219,7 @@
...
@@ -3474,8 +3219,7 @@
encode
=
window
.
btoa
||
window
.
shim
.
Base64
.
encode
;
encode
=
window
.
btoa
||
window
.
shim
.
Base64
.
encode
;
// TODO: include client IP in hash
// TODO: include client IP in hash
sauce
=
encode
(
stamp
.
toString
()
+
spec
.
property_dict
.
secret_hash
);
sauce
=
encode
(
stamp
.
toString
()
+
spec
.
property_dict
.
secret_hash
);
fragment
.
appendChild
(
factory
.
formElement
(
container
.
appendChild
(
factory
.
formElement
(
{
{
"
type
"
:
"
input
"
,
"
type
"
:
"
input
"
,
"
direct
"
:
{
"
direct
"
:
{
...
@@ -3495,7 +3239,7 @@
...
@@ -3495,7 +3239,7 @@
}
}
}
}
));
));
container
.
appendChild
(
factory
.
element
(
fragment
.
appendChild
(
factory
.
element
(
"
input
"
,
"
input
"
,
{
{
"
type
"
:
"
hidden
"
,
"
type
"
:
"
hidden
"
,
...
@@ -3506,7 +3250,7 @@
...
@@ -3506,7 +3250,7 @@
"
data-created
"
:
stamp
"
data-created
"
:
stamp
}
}
));
));
container
.
appendChild
(
factory
.
formElement
(
fragment
.
appendChild
(
factory
.
formElement
(
{
{
"
type
"
:
"
input
"
,
"
type
"
:
"
input
"
,
"
direct
"
:
{
"
direct
"
:
{
...
@@ -3530,7 +3274,7 @@
...
@@ -3530,7 +3274,7 @@
// add hidden storage identifier
// add hidden storage identifier
if
(
item_id
)
{
if
(
item_id
)
{
container
.
appendChild
(
factory
.
element
(
fragment
.
appendChild
(
factory
.
element
(
"
input
"
,
"
input
"
,
{
{
"
type
"
:
"
hidden
"
,
"
type
"
:
"
hidden
"
,
...
@@ -3539,13 +3283,21 @@
...
@@ -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
// loop fieldlist of layout section
for
(
j
=
0
;
j
<
segment
.
fieldlist
.
length
;
j
+=
1
)
{
for
(
j
=
0
;
j
<
segment
.
fieldlist
.
length
;
j
+=
1
)
{
field
=
segment
.
fieldlist
[
j
];
field
=
segment
.
fieldlist
[
j
];
// allow non-fieldlist form elements to be generated
// allow non-fieldlist form elements to be generated
// TODO: can we also generate a field from another portal_type here?
if
(
field
.
type
)
{
if
(
field
.
type
)
{
input_config
=
field
;
input_config
=
field
;
prefixed_name
=
spec
.
reference
+
"
_
"
+
field
.
direct
.
name
||
util
.
uuid
();
prefixed_name
=
spec
.
reference
+
"
_
"
+
field
.
direct
.
name
||
util
.
uuid
();
...
@@ -3571,6 +3323,7 @@
...
@@ -3571,6 +3323,7 @@
}
}
}
}
}
}
}
else
{
}
else
{
config
=
spec
.
fields
[
field
.
field
];
config
=
spec
.
fields
[
field
.
field
];
overrides
=
field
.
overrides
;
overrides
=
field
.
overrides
;
...
@@ -3656,6 +3409,7 @@
...
@@ -3656,6 +3409,7 @@
}
}
fragment
.
appendChild
(
container
);
fragment
.
appendChild
(
container
);
}
}
}
// set captcha or anti spam protection
// set captcha or anti spam protection
if
(
secure
===
"
captcha
"
)
{
if
(
secure
===
"
captcha
"
)
{
...
@@ -5220,73 +4974,49 @@
...
@@ -5220,73 +4974,49 @@
/* STORAGE */
/* STORAGE */
/* ====================================================================== */
/* ====================================================================== */
// generate storage object
// generate storage object with placeholders
storage
=
{};
storage
=
{
"
obj
"
:
{},
/*
"
arr
"
:
[],
"
span
"
:
document
.
createElement
(
"
span
"
)
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);
*/
/**
/**
* Fetch data from storage = GET or ALLDOCS
* Fetch data from storage = GET or ALLDOCS
* @method fetch
* @method fetch
* @param {object} obj Action object
* @param {object} obj Action object
*/
*/
// TODO: only use on lookup architecture pass.x or pass.state.x
// TODO: merge pass.x or pass.state.x
// TODO: this means state needs to have url_pointer set earilier, so
// TODO: set pointer directly inside data-action, remove pointer!
// there is no need to look it up in oass.config.property_dict...
// 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
)
{
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
;
quirk
;
pass
=
obj
.
pass
;
pass
=
obj
.
pass
;
quirk
=
obj
.
state
||
pass
.
config
;
quirk
=
obj
.
state
||
pass
.
config
;
lookup
=
obj
.
state
||
quirk
.
property_dict
||
{}
;
lookup
=
obj
.
state
||
quirk
.
property_dict
||
storage
.
obj
;
query
=
obj
.
query
||
lookup
.
query
||
{}
;
query
=
obj
.
query
||
lookup
.
query
||
storage
.
obj
;
pointer
=
(
lookup
[
"
url_pointer
"
]
||
{}
).
jump
;
pointer
=
(
lookup
[
"
url_pointer
"
]
||
storage
.
obj
).
jump
;
// TODO: action handling, should be a form submit not set on element!
// TODO: action > id, this should be triggered via form submit not link!
action
=
((
obj
.
element
||
{}).
href
||
""
).
split
(
"
/
"
).
pop
();
action_id
=
((
obj
.
element
||
storage
.
obj
).
href
||
""
).
split
(
"
/
"
).
pop
();
query
.
_id
=
query
.
_id
||
window
.
decodeURIComponent
(
action
);
if
(
action
)
{
if
(
action
_id
)
{
pointer
=
undefined
;
pointer
=
undefined
;
query
=
{
"
_id
"
:
query
.
_id
}
query
=
{
"
_id
"
:
window
.
decodeURIComponent
(
action_id
)
}
}
}
switch
(
true
)
{
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
"
;
map
=
"
values
"
;
break
;
break
;
case
(
!!
query
.
_id
):
case
(
!!
query
.
_id
):
...
@@ -5298,28 +5028,20 @@
...
@@ -5298,28 +5028,20 @@
break
;
break
;
}
}
// TODO: remove
this
- pass custom query to storage
// TODO: remove - pass custom query to storage
if
(
pointer
&&
!
config
)
{
if
(
pointer
&&
!
config
)
{
config
=
{
config
=
{
"
_jump
"
:
pointer
"
_jump
"
:
pointer
};
};
}
}
return
RSVP
.
resolve
(
return
RSVP
.
resolve
(
app
.
storage_dict
.
items
[
method
||
"
allDocs
"
](
query
,
config
)
app
.
storage_dict
.
items
[
method
||
"
allDocs
"
](
query
,
config
)
).
then
(
function
(
response
)
{
).
then
(
function
(
response
)
{
if
(
response
.
status
===
200
)
{
if
(
response
.
status
===
200
)
{
// TODO: actions should have their own callback set on state!
if
(
action_id
)
{
if
(
action
)
{
return
response
;
util
.
loader
(
""
,
"
status_dict.rendering
"
);
window
.
location
.
href
=
response
.
data
.
_links
.
slapos_jump
.
href
;
}
}
answer
=
storage
.
mapResponse
(
response
,
map
);
answer
=
storage
.
mapResponse
(
response
,
map
);
if
(
app
.
storage_dict
.
property_dict
.
force_sync
)
{
//storage.sync(mapped, parcel.storage);
}
}
}
return
{
return
{
"
response
"
:
answer
||
response
,
"
response
"
:
answer
||
response
,
...
@@ -5334,44 +5056,41 @@
...
@@ -5334,44 +5056,41 @@
* @param {object} obj Action object
* @param {object} obj Action object
*/
*/
storage
.
write
=
function
(
obj
)
{
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
);
form
=
document
.
getElementById
(
obj
.
id
);
pointer
=
(
obj
.
element
||
storage
.
span
).
getAttribute
(
"
data-action
"
),
action
=
obj
.
state
.
url_pointer
[
pointer
];
config
=
{};
prefix
=
obj
.
id
+
"
_
"
;
prefix
=
obj
.
id
+
"
_
"
;
valid
=
storage
.
validate
(
obj
);
valid
=
storage
.
validate
(
obj
);
data
=
storage
.
parseForm
(
valid
,
prefix
,
true
);
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
)
{
if
(
form
.
identifier
)
{
//
this must be a PUT,
set id, method and view
//
PUT >
set id, method and view
data
.
_id
=
form
.
identifier
.
value
;
data
.
_id
=
form
.
identifier
.
value
;
method
=
"
put
"
;
method
=
"
put
"
;
config
=
{
config
.
_view
=
obj
.
state
.
view
;
"
_view
"
:
obj
.
state
.
view
};
}
else
{
// POSTING, set action set in JSON config
config
=
{
"
action
"
:
obj
.
state
.
url_pointer
[
obj
.
element
.
getAttribute
(
"
data-action
"
)]
};
}
}
RSVP
.
resolve
(
app
.
storage_dict
.
items
[
method
||
"
post
"
](
data
,
config
))
if
(
pointer
)
{
.
then
(
function
(
response
)
{
config
.
_action
=
action
;
// TODO: if this is strictly a storage operation, do this elsewhere!
// in case action is triggerted that needs retrival from a reference
if
(
response
.
status
===
201
)
{
data
.
_reference
=
obj
.
state
.
reference
;
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
"
);
}
}
}).
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 @@
...
@@ -5777,6 +5496,25 @@
*/
*/
app
.
timer
=
0
;
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
* Handler for search
* @method search
* @method search
...
@@ -6693,6 +6431,7 @@
...
@@ -6693,6 +6431,7 @@
case
"
ssl_off
"
:
case
"
ssl_off
"
:
case
"
ssl
"
:
case
"
ssl
"
:
case
"
request
"
:
case
"
request
"
:
case
"
installation
"
:
config
.
mode
=
query
[
i
];
config
.
mode
=
query
[
i
];
break
;
break
;
}
}
...
@@ -6941,6 +6680,10 @@
...
@@ -6941,6 +6680,10 @@
if
(
pass
.
fields
&&
storage
&&
force_fields
)
{
if
(
pass
.
fields
&&
storage
&&
force_fields
)
{
if
(
pass
.
config
.
scheme
)
{
if
(
pass
.
config
.
scheme
)
{
pass
.
field_list
=
storage
.
makeSelectList
(
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:
// HACK:
...
@@ -7470,68 +7213,6 @@
...
@@ -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
* Load files from disk
* @method loadFile
* @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