Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ophélie Gagnard
slapos.core
Commits
406112e2
Commit
406112e2
authored
May 24, 2012
by
Thomas Lechauve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix tests bugs (Firefox) and add storage tests
parent
5b10ab7f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
64 additions
and
20 deletions
+64
-20
jquery.slapos/src/jquery.slapos.js
jquery.slapos/src/jquery.slapos.js
+8
-3
jquery.slapos/test/jquery.slapos_test.js
jquery.slapos/test/jquery.slapos_test.js
+37
-3
vifib/static/js/core.js
vifib/static/js/core.js
+11
-11
vifib/static/js/jquery.slapos.js
vifib/static/js/jquery.slapos.js
+8
-3
No files found.
jquery.slapos/src/jquery.slapos.js
View file @
406112e2
...
...
@@ -27,6 +27,10 @@
return
$
(
this
).
slapos
(
'
store
'
,
'
clientID
'
,
value
);
},
deleteStore
:
function
(
name
)
{
delete
window
.
localStorage
[
name
];
},
/* Local storage method */
lStore
:
function
(
name
,
value
)
{
if
(
Modernizr
.
localstorage
)
{
...
...
@@ -82,10 +86,10 @@
datatype
:
'
json
'
,
context
:
$
(
this
),
beforeSend
:
function
(
xhr
)
{
//
xhr.setRequestHeader('REMOTE_USER', 'test_vifib_customer');
xhr
.
setRequestHeader
(
'
REMOTE_USER
'
,
'
test_vifib_customer
'
);
xhr
.
setRequestHeader
(
'
Accept
'
,
'
application/json
'
);
if
(
$
(
this
).
slapos
(
'
access_token
'
)
&&
authentication
)
{
xhr
.
setRequestHeader
(
'
Authorization
'
,
$
(
this
).
slapos
(
'
store
'
,
'
token_type
'
)
+
'
'
+
$
(
this
).
slapos
(
'
access_token
'
));
//
xhr.setRequestHeader('Authorization', $(this).slapos('store', 'token_type') + ' ' + $(this).slapos('access_token'));
}
}
};
...
...
@@ -116,7 +120,8 @@
discovery
:
function
(
callback
)
{
return
this
.
each
(
function
()
{
$
.
ajax
({
url
:
'
http://10.8.2.34:12006/erp5/portal_vifib_rest_api_v1
'
,
url
:
$
(
this
).
slapos
(
"
host
"
),
context
:
$
(
this
),
dataType
:
'
json
'
,
beforeSend
:
function
(
xhr
)
{
xhr
.
setRequestHeader
(
'
Accept
'
,
'
application/json
'
);
...
...
jquery.slapos/test/jquery.slapos_test.js
View file @
406112e2
...
...
@@ -2,7 +2,6 @@ jQuery(function(){
var
response
,
responseBody
,
url
,
data
;
jQuery
(
document
).
slapos
();
module
(
"
Cross-domain Tests
"
);
test
(
"
200 response
"
,
function
(){
...
...
@@ -33,6 +32,34 @@ jQuery(function(){
}});
});
module
(
"
Storage Test
"
,
{
setup
:
function
()
{
this
.
myhost
=
'
http://www.example.com/api
'
;
jQuery
(
document
).
slapos
({
'
host
'
:
this
.
myhost
});
}
});
test
(
""
,
function
()
{
expect
(
5
);
var
test
=
"
testValue
"
,
newToken
=
"
newToken
"
,
nnToken
=
""
;
equal
(
this
.
myhost
,
jQuery
(
document
).
slapos
(
'
host
'
),
"
should contain the same host when initialized
"
);
jQuery
(
document
).
slapos
(
'
store
'
,
'
test
'
,
test
);
equal
(
test
,
window
.
localStorage
.
test
,
'
should add new key "test" in local storage
'
);
jQuery
(
document
).
slapos
(
'
access_token
'
,
newToken
);
equal
(
newToken
,
window
.
localStorage
.
access_token
,
'
should add new key "access_token" by using its shortcut method
'
);
nnToken
=
jQuery
(
document
).
slapos
(
'
access_token
'
);
equal
(
nnToken
,
newToken
,
'
should put "newToken" value in nnToken
'
)
jQuery
(
document
).
slapos
(
'
deleteStore
'
,
'
access_token
'
);
ok
(
window
.
localStorage
.
getItem
(
'
access_token
'
)
===
null
,
'
should delete "access_token" from localStorage
'
);
});
module
(
"
Callback Tests
"
,
{
setup
:
function
(){
this
.
server
=
sinon
.
sandbox
.
useFakeServer
();
...
...
@@ -57,7 +84,7 @@ jQuery(function(){
}
};
var
discoResponse
=
[
200
,
this
.
header
,
JSON
.
stringify
(
discoBody
)];
this
.
server
.
respondWith
(
"
GET
"
,
'
http://10.8.2.34:12006/erp5/portal_vifib_rest_api_v1
'
,
discoResponse
);
this
.
server
.
respondWith
(
"
GET
"
,
'
/api
'
,
discoResponse
);
// Error responses
this
.
bad_request
=
[
400
,
this
.
header
,
'
Bad Request
'
];
...
...
@@ -65,6 +92,8 @@ jQuery(function(){
this
.
payment
=
[
402
,
this
.
header
,
'
Payment required
'
];
this
.
not_found
=
[
404
,
this
.
header
,
'
Not found
'
];
this
.
server_error
=
[
500
,
this
.
header
,
'
Internal server error
'
];
jQuery
(
document
).
slapos
({
'
host
'
:
'
/api
'
});
},
teardown
:
function
(){
this
.
server
.
restore
();
...
...
@@ -81,9 +110,10 @@ jQuery(function(){
statusCode
=
{
400
:
callback
};
jQuery
(
document
).
slapos
(
'
instanceRequest
'
,
{
var
i
=
jQuery
(
document
).
slapos
(
'
instanceRequest
'
,
{
url
:
"
/request_instance
"
,
statusCode
:
statusCode
,
complete
:
function
()
{
start
()
}
});
this
.
server
.
respond
();
});
...
...
@@ -101,6 +131,7 @@ jQuery(function(){
jQuery
(
document
).
slapos
(
'
instanceRequest
'
,
{
url
:
"
/request_instance
"
,
statusCode
:
statusCode
,
complete
:
function
()
{
start
()
}
});
this
.
server
.
respond
();
});
...
...
@@ -118,6 +149,7 @@ jQuery(function(){
jQuery
(
document
).
slapos
(
'
instanceRequest
'
,
{
url
:
"
/request_instance
"
,
statusCode
:
statusCode
,
complete
:
function
()
{
start
()
}
});
this
.
server
.
respond
();
});
...
...
@@ -135,6 +167,7 @@ jQuery(function(){
jQuery
(
document
).
slapos
(
'
instanceRequest
'
,
{
url
:
"
/request_instance
"
,
statusCode
:
statusCode
,
complete
:
function
()
{
start
()
}
});
this
.
server
.
respond
();
});
...
...
@@ -152,6 +185,7 @@ jQuery(function(){
jQuery
(
document
).
slapos
(
'
instanceRequest
'
,
{
url
:
"
/request_instance
"
,
statusCode
:
statusCode
,
complete
:
function
()
{
start
()
}
});
this
.
server
.
respond
();
});
...
...
vifib/static/js/core.js
View file @
406112e2
...
...
@@ -19,7 +19,6 @@
pattern
=
pattern
.
replace
(
/:
\w
+/g
,
'
([^
\
/]+)
'
);
var
regex
=
new
RegExp
(
'
^
'
+
pattern
+
'
$
'
),
result
=
regex
.
exec
(
d
);
console
.
log
(
d
);
if
(
result
)
{
result
.
shift
();
methods
[
callback
].
apply
(
$this
,
result
);
...
...
@@ -77,12 +76,12 @@
$
(
this
).
vifib
(
'
popup
'
,
message
);
},
spinOptions
=
{
color
:
'
#FFF
'
,
lines
:
9
,
length
:
3
,
width
:
2
,
radius
:
6
,
rotate
:
0
,
trail
:
36
,
speed
:
1.0
},
spinOptions
=
{
color
:
"
#FFFFFF
"
,
lines
:
30
,
length
:
0
,
width
:
5
,
radius
:
7
,
rotate
:
0
,
trail
:
60
,
speed
:
1.6
},
methods
=
{
init
:
function
()
{
// Initialize slapos in this context
$
(
this
).
slapos
();
$
(
this
).
slapos
(
{
'
host
'
:
'
http://10.8.2.34:12006/erp5/portal_vifib_rest_api_v1
'
}
);
var
$this
=
$
(
this
);
// Bind Loading content
$
(
'
#loading
'
).
ajaxStart
(
function
()
{
...
...
@@ -110,8 +109,9 @@
},
extractInstanceURIFromHashtag
:
function
()
{
var
loc
=
window
.
location
.
h
ash
.
split
(
'
/
'
),
var
loc
=
window
.
location
.
h
ref
.
split
(
'
#
'
)[
1
]
.
split
(
'
/
'
),
i
=
$
.
inArray
(
"
instance
"
,
loc
);
console
.
log
(
loc
)
return
(
i
!==
-
1
&&
loc
.
length
>
i
)
?
decodeURIComponent
(
loc
[
i
+
1
])
:
""
;
},
...
...
@@ -180,12 +180,12 @@
return
this
.
each
(
function
()
{
var
uri
=
$
(
this
).
vifib
(
"
extractInstanceURIFromHashtag
"
);
$
(
this
).
slapos
(
'
instanceInfo
'
,
uri
,
{
success
:
function
(
data
)
{
if
(
typeof
(
data
)
!==
"
object
"
)
{
data
=
$
.
parseJSON
(
data
);
success
:
function
(
response
)
{
if
(
typeof
(
response
)
!==
"
object
"
)
{
response
=
$
.
parseJSON
(
response
);
}
var
status
=
$
(
this
).
vifib
(
'
getRender
'
,
'
instance.
'
+
data
.
status
)
$
(
"
[name=software_type]
"
).
val
(
data
.
software_type
);
var
status
=
$
(
this
).
vifib
(
'
getRender
'
,
'
instance.
'
+
response
.
status
)
$
(
"
[name=software_type]
"
).
val
(
response
.
software_type
);
$
(
"
#instanceStatus
"
).
html
(
status
);
$
(
this
).
vifib
(
'
bindStopStartButtons
'
);
}
...
...
@@ -299,7 +299,7 @@
503
:
serverError
},
table
=
$
(
this
).
vifib
(
'
render
'
,
'
instance.list
'
).
find
(
'
#instance-table
'
);
//
table.vifib('refresh', methods.refreshListInstance, 30);
table
.
vifib
(
'
refresh
'
,
methods
.
refreshListInstance
,
30
);
$
(
this
).
slapos
(
'
instanceList
'
,
{
success
:
function
(
data
)
{
if
(
typeof
(
data
)
!==
"
object
"
)
{
...
...
@@ -308,7 +308,7 @@
$
.
each
(
data
.
list
,
function
()
{
var
url
=
this
.
toString
(),
row
=
$
(
'
<tr></tr>
'
).
vifib
(
'
fillRowInstance
'
,
url
);
//
row.vifib('refresh', methods.refreshRowInstance, 30);
row
.
vifib
(
'
refresh
'
,
methods
.
refreshRowInstance
,
30
);
table
.
append
(
row
);
});
},
...
...
vifib/static/js/jquery.slapos.js
View file @
406112e2
...
...
@@ -27,6 +27,10 @@
return
$
(
this
).
slapos
(
'
store
'
,
'
clientID
'
,
value
);
},
deleteStore
:
function
(
name
)
{
delete
window
.
localStorage
[
name
];
},
/* Local storage method */
lStore
:
function
(
name
,
value
)
{
if
(
Modernizr
.
localstorage
)
{
...
...
@@ -82,10 +86,10 @@
datatype
:
'
json
'
,
context
:
$
(
this
),
beforeSend
:
function
(
xhr
)
{
//
xhr.setRequestHeader('REMOTE_USER', 'test_vifib_customer');
xhr
.
setRequestHeader
(
'
REMOTE_USER
'
,
'
test_vifib_customer
'
);
xhr
.
setRequestHeader
(
'
Accept
'
,
'
application/json
'
);
if
(
$
(
this
).
slapos
(
'
access_token
'
)
&&
authentication
)
{
xhr
.
setRequestHeader
(
'
Authorization
'
,
$
(
this
).
slapos
(
'
store
'
,
'
token_type
'
)
+
'
'
+
$
(
this
).
slapos
(
'
access_token
'
));
//
xhr.setRequestHeader('Authorization', $(this).slapos('store', 'token_type') + ' ' + $(this).slapos('access_token'));
}
}
};
...
...
@@ -116,7 +120,8 @@
discovery
:
function
(
callback
)
{
return
this
.
each
(
function
()
{
$
.
ajax
({
url
:
'
http://10.8.2.34:12006/erp5/portal_vifib_rest_api_v1
'
,
url
:
$
(
this
).
slapos
(
"
host
"
),
context
:
$
(
this
),
dataType
:
'
json
'
,
beforeSend
:
function
(
xhr
)
{
xhr
.
setRequestHeader
(
'
Accept
'
,
'
application/json
'
);
...
...
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